Commit graph

61 commits

Author SHA1 Message Date
rhymes
397ef313de Improve video controllers caching and retrieving (#5709) [deploy]
* Add tests and improve pagination and caching

* Add two more specs

* Add .with_video scope

* Get rid of N+1

* Only select needed columns

* Improve efficiency of the video page as well

* Add missing set_cache_control_headers to API videos#index
2020-01-27 15:51:12 -05:00
Ben Halpern
071ec03a3c
Fix article description issues (#5679) [deploy]
* Fix article description issues

* Move tag info to decorator

* Fix description edge cases

* Fix description creation logic

* Fix test and adjust naming

* Modify line in processed_description
2020-01-26 14:43:11 -05:00
rhymes
6ec91b0861 API tags: improve caching and purging (#5673) [deploy]
* Add pagination to /tags and proper caching to /tags and /tags/onboarding

* Correctly purge tags

* Fix broken specs

* Make Travis happy
2020-01-24 13:55:22 -05:00
rhymes
6c24357f16 Use edge caching for API Article show endpoint (#5669) [deploy] 2020-01-23 20:12:58 -05:00
rhymes
87167de8c5 Use correct cache keys on the articles API index endpoint (#5606) [deploy]
Surrogate keys are about setting expectations on cache purging.

Presently we use a combination of all parameters to set changing surrogate keys depending on the result of the `ArticleApiIndexService`. This approach has two limitations:

- if two set of params lead to the same exact set of articles, we still create two different caches

- deleted articles will remain for 24 hours in the cache because the cache key doesn't take the record keys into account

By simply using record keys we make sure that different params leading to the same result set will share the same cache and that deleted keys won't appear anymore in the cache.
2020-01-23 08:40:19 -05:00
rhymes
1bc0469b2d Add article's record key to Fastly Surrogate-Key to separate caches (#5543)
* Add article's record key to Fastly Surrogate-Key to separate caches

After #4744 we successfully setup an auto purging system based on Fastly's surrogate key based cache and purging API.
Unfortunately this worked only in the `:show` action as comments are their own tree-based resource.
The `:index` though, is related to a single article, so without the article's record key in the `Surrogate-Key` header the first time we hit the API the result would become the value stored in Fastly's API, for all articles.

* Fix commentable mock for job spec

* Add comment.commentable.purge to the worker as well

* Add more thorough tests for commentable
2020-01-17 08:45:47 -05:00
rhymes
bcd85452e9 Comments API: fix caching issues (#4744) [deploy]
* Use ancestry in the index and add test

* Add tests for show action

* Return complete comments trees for index, kill n+1 and use correct edge cache key

* Return complete comments tree for show, kill n+1 and use correct edge cache key

* Refactor tests and add surrogate keys tests

* Preload users for the whole subtree

* Clarify explanation of the edge cache keys construction

* Refactor partials

* Remove action caching

* Replace .map.flatten with .flat_map

* Fix surrogate key prefix according to Fastly docs

* Add comment.purge to Comments::BustCacheJob to use Fastly-Rails

* Fix surrogate key spec
2020-01-15 10:45:56 -05:00
rhymes
d2e96007c7 Fix (some) n+1/eager loading issues (#5294) [deploy]
* Remove mock from specs to test the actual Suggester

* Fix articles API top articles n+1

* Fix n+1 in articles API with state parameter

* Remove eager loading for organization dashboard

* Eager load notifiables in notifications only when needed

* Algolia does not like this
2020-01-08 18:48:24 -05:00
Cadu Ribeiro
00a97b2051 Migrate Users/FollowJob to Sidekiq (#5403) 2020-01-08 15:03:18 -05:00
Molly Struve
36cf0a6976
Handle unfound github repo in API (#5316) [deploy] 2019-12-31 14:42:45 -05:00
Molly Struve
2415392da5
Return a 401 Response when Github creds are bad via the API (#5249) [deploy] 2019-12-26 14:51:36 -06:00
rhymes
b0343d99c3 Refactor specs for Api::V0::FollowsController (#5239) 2019-12-24 13:14:39 -05:00
Molly Struve
448adfdd23 Use ApiController for ChatChannels and return not_found error if channel cant be accessed by user (#5194) [deploy] 2019-12-24 13:12:29 -05:00
rhymes
2d6df70dea Return an empty result set instead of 404 in case users are not available. (#5238)
A common response in collection endpoint with REST APIs is to return an empty result set when the requested params end up in an empty result. The reason for this is that the resource itself exists (the collection always exists), it just is empty.

See https://github.com/thepracticaldev/dev.to/pull/5192
2019-12-24 13:08:10 -05:00
Molly Struve
212a2a430d Return not_found response if we cant return users via the api (#5192) 2019-12-20 13:43:14 -05:00
Molly Struve
1b2cdfb0c4 Return 422 if params are missing when creating an article via the API (#5182) 2019-12-19 19:21:21 -05:00
Bolarinwa Balogun
8c6adac7ba Remove special characters in tags for articles created via API (#4239) [deploy] 2019-12-13 11:29:02 -05:00
John Curcio
157a6f1ef1 Add pagination to followers and following page in dashboard (#258) (#4375) [deploy]
* Add infinite scroll to followers list (#258)

* Refactor fetchNext function for clarity (#258)

* Sepparate following tab into multiple tabs to support infinite scroll (#258)

* Add infinite scroll to following pages (#258)

* Add tests to infinite scroll api

* Refactor dashboard loading text

* Refactor infine scroll function

* Fix duplicated entries problem in infinite scrolling

* Switch randomized attributes to sequential to avoid InvalidRecord error

* Add acceptance tests for infinite scroll

* Remove unused following method

* parameterize limit per page for followers and followings

* Split follows endpoint into followers and followings

* Authenticate user with api key in followers and followings

* Split followers endpoint into users and organizations

* Add redundant html to sublist partial

* Speed up infinite scroll tests

* Refactor api json responses to use partials

* Authenticate api user before follows create

* Resolve conflicts on scrolling js

* Improve partials organization and fix organization username bug

* Improve readability of unauthorized test

* Use let! to create scrolling test data

* Fix not working podcasts link

* Refactor initScrolling to remove linting errors

* Fix codeclimate coding style issue

* Test tags forms and podcasts hyperlinks

* Fix eslint issue with double equals

* Improve before_action usage and readability
2019-11-20 18:21:18 -05:00
rhymes
40155812bd Comments API: simplify controller code, add tests (#4731) [deploy]
* Use ancestry in the index and add test

* Add tests for show action
2019-11-07 11:37:58 -05:00
Nadiya Karachevska
df857d860a Fix API inconsistencies between articles 'index' and 'show' (#4560)
* Fix API inconsistencies between articles 'index' and 'show'

* Update API docs; revert tags from articles index

* Fix specs

* Update specs
2019-10-24 11:56:55 -04:00
Aleksandr
80316818d5 Fix state=all 500 error bug (#4525) [ci skip] 2019-10-23 17:19:47 -04:00
Nadiya Karachevska
4dad407289 API: Add pagination to articles (#4483)
* Add pagination to articles

* Refactoring

* Update specs
2019-10-22 12:41:00 -04:00
rhymes
9c76663e1a Fix broken error interface in Article creation API (#4458) 2019-10-16 09:02:26 -04:00
Bolarinwa Balogun
a6b51888c5 Improve error message in Api::V0:ArticlesController#create (#4417) 2019-10-15 16:49:26 -04:00
rhymes
e461f0d799 Routine rubocop fixes after gem update (#4309)
* Regenerate rubocop todo

* Fix outstanding problems

* Fix Style/FormatStringToken

* Final update to rubocop todo file

* Set RSpec/ExampleLength to max 10 and regenerate todo file
2019-10-10 17:27:01 -04:00
cyrillefr
82cca496fd Add collection ids to Api (reading + filtering) (#4180)
* Add collection ids to Api (reading + filtering)

  - refactored controller
  - modifyied views
  - added tests

* Add collection ids to Api (reading + filtering): requested changes

  - changed order in service
  - proper test in filtering
2019-10-03 11:26:39 -04:00
Anna Buianova
3c49073c2b Limit access to the API actions when authorized by doorkeeper token (#4170) 2019-10-02 13:17:47 -04:00
Anna Buianova
9778ada44a Doorkeeper default scope (#4066)
* Start with the doorkeeper scopes

* Added read_articles scope

* Proper doorkeeper authorization for the API articles#me
2019-09-24 11:11:12 -07:00
cyrillefr
70631ad2f7 Listings creation and update API (#4014)
* Listings creation and update API

  - new listings controller
  - refactored code to share core functionnality between api and web controllers
  - code in common in classified listing concerns
  - added tests for index/create/update
  - json output as views
  - updated a factory

* Listings creation and update API: code update

  - refactored json calls
  - added test cases
  - added pagination for list of listings
  - refactored jbuilder files
  - typos

* Listings creation and update API: code update

  - tags and tag_list in controller
  - changed view to display both
  - refactored and added test

* Listings creation and update API: code update

  - small change to resolve conflit

* Listings creation and update API: code update

  - added test case
  - deleted unneeded test case
2019-09-24 07:03:52 -07:00
Anna Buianova
0a16bf934a Added association between webhook_endpoints and oauth apps (#4060)
* Added association between webhook_endpoints and oauth apps

* Limit webhooks access by oauth_app_id when authorized by doorkeeper

* Use rails route helpers in webhooks api test
2019-09-18 13:25:40 -07:00
Anna Buianova
ce93c436a7 Implement API endpoint for user's webhooks (#4013) 2019-09-17 13:24:44 -04:00
Mac Siri
5fba3bd4b9
Improve test speed (#3957) [ci skip] 2019-09-12 16:17:20 -04:00
Andy Zhao
8a4030c25d Revert changes as a hotfix (#3964) 2019-09-06 11:54:35 -04:00
rhymes
69c8b24c34 Send JSON 404 response to API error routes (#3959)
* Fix an issue where API 404 calls got the HTML 404 page in response

* Use keyword for consistency
2019-09-06 10:18:50 -04:00
rhymes
2e5a847ab8 API: /api/articles/me defaults to published articles (#3937)
* /api/articles/me defaults to published articles

We want to make it explicit to retrieve unpublished articles, this change defaults `/api/articles/me` to only published articles, also adds `/api/articles/me/published`, `/api/articles/me/unpublished` and `/api/articles/me/all` to make requests more explicit.

* Refactor /me logic into a case switch
2019-09-04 14:02:13 -04:00
rhymes
676cf002bd Webhooks: API fixes and docs (#3901)
* Fix webhook API and add POST /api/webhooks docs

* Document GET /api/webhooks/:id

* Fix DELETE /api/webhooks/{id} and document it

* Add proper 404 specs
2019-09-03 10:41:23 -04:00
Anna Buianova
bfdf636dcf Implement webhook & API endpoints #3715 (#3783) 2019-08-29 10:23:41 -04:00
rhymes
e9db50b7c9 API docs: Document OAuth2 and /api/articles/me (#3707) 2019-08-12 16:00:12 -04:00
rhymes
35526bef9b API: OpenAPI 3 spec and auto generated docs (#3650) 2019-08-12 11:36:04 -04:00
Mac Siri
3b32b29937 Update core API endpoints to support access_token (#3644)
* Update specs for doorkeeper test

* Add bang

* Create #authenticate

* Create /api/articles/ endpoint

* Update specs

* Update me.json.jbuilder

* Fix typo and spacing

* Support pagination for #me

* Update #authenticate! to support cookies

* Make per_page a param

* Disable method-complexity check

* Enable refresh_token

* Create /api/users/me endpoint
2019-08-08 15:55:23 -03:00
Mac Siri
fc9272fe71 Make Doorkeeper inherit from ApplicationController (#3591)
* Resolve doorkeeper issue

* Refactor spec

* Remove comment
2019-07-31 18:41:44 -04:00
rhymes
816c062ea0 Upgrade Rubocop related gems and fix new violations (#3581) [ci skip] 2019-07-30 14:29:05 -04:00
Zak Henry
a9acb8642e Add markdown to article api response (#3394)
* Add failing test asserting markdown is returned

* Add markdown to the get article api response
2019-07-09 10:09:20 -04:00
rhymes
7da7a16d8d Pro: add referrers to dashboard and single article stats (#3295)
* Reorganize PageViewsController

* Add domain and path to PageView model

* Add before_create callback to populate domain and path

* Add list of referrers to AnalyticsService

* Add referrers to the UI

* Remove useless referrers card and tweak table line height

* Add referrer stats to article stats page

* Add not null and empty default to domain and path

* Refactor JS analytics client

* create_list is a step back here

* Revert "Add not null and empty default to domain and path"

This reverts commit bc02440076047a887c65d300bccd4661ecc8ffd0.

* Add index on domain concurrently

* Make the script more robust
2019-06-25 13:58:09 -04:00
rhymes
a8b7f6eea4 Analytics: refactoring for speed improvements (#3072)
* Use proper auth chain before checking parameters

* Refactor AnalyticsController

* Add a bunch of test and rewrite reactions counts with a single query

* Add tests for follows totals

* Use round and add more refactoring

* Add tests to group by day to fallback during refactoring

* Use group by to calculate comments count by day

* Use group by to calculate follows count by day

* Use group by to calculate reactions stats by day

* Use group by to calculate page_views stats by day

* Move calculations per day back in the cached block

* Add a few comments and a little bit of refactoring

* Add indexes (concurrently) for analytics

* Make tests more time robust

* Use a date range cache related to the requesting user or org

* Freezing time in UTC should help when tests are ran on time zones over the day line

* Remove explicit returns

* Page title is escaped, guard against that

* Move Analytics service spec in the proper place
2019-06-10 09:27:39 -04:00
Andy Zhao
47d9ec27fb Allow users to belong to multiple orgs (#2583)
* Allow user to have many orgs

* Allow users to handle multi orgs in settings

* Make rounded buttons inline

* Add multi org function to dashboards

* Fix merge conflicts

* Fix mistake in merge conflict fix oops

* Display the correct membership level

* Fix accessibility issues

* Display organizations for article editors

* Handle submitting org id with preact editors

* Make listings work with multiple organizations

* Allow listings to have multiple orgs on create

* Display the correct number of credits for each org

* Move script tag to Webpack

* Allow multi orgs for purchasing and viewing credits

* Use OrganizationMembership as authorization check

* Display multiple organizations for notifications

* Allow dashboard to be viewable under multi-orgs

* Remove unused method

* Add multi-org functionality for article editors

* Show pro dashboard buttons for member+ org levels

* Leave the correct organization

* Allow article API to change org id

* Add left-out authorization method oops

* Make nav buttons a bit more clear

* Fix merge conflict

* Fix adding org id for /api/articles and tests

* Fix tests for org policy

* Use proper logic for displaying org members

* Update org actions with new authorization

* Use correct org when creating a listing

* Remove additional payment charge oops

* Mark org notifications as read with authorization

* Remove deprecated post_as_organization attribute

* Use new org_admin syntax

* Remove deprecated org logic for article create and update

* Default all RSS posts to not belong to any org

* Render org_member page for guest users

* Update org policy spec to work with multi orgs

* Use org_membership for org traits and move identity code

* Use org_member trait

* Update to work with multi-orgs

* Validate article's org_id if param org_id is blank

* Make  a let variable

* Remove unnecessary eager load for credits

* Fix HTML structure and org logic for non-org users

* Update credits spec for multi-org

* Add test for failed payment when purchased by org

* Lint listings_spec

* Test that the listing was created under the user

* Add tests for POST /listings multi-org

* Use double quotes for classes

* Fix /manage and a few other multi-org bugs

* Fix test for multi org

* Use correct method SQL exists? not Rails exist?

* Fix reads spec for multi-org

* Fix org_controller actions to work with multi org

* Test only multi org and not old usage and fix leave_org

* Fix org showing user profile img test for multi-org

* Fix org logic for users with no orgs

* Remove switch org functionality

* Update tests and add hidden param for org id

* Redirect to the specific organization

* Test other org button actions

* Use settings_notice instead of legacy notice and refactor

* Fix weird extra end issue prob from merge conflicts

* Test for with new flash key

* Fix user_views_org tests for multi-org

* Test for new flash message

* Update snapshot with new a11y html

* Move styling to stylesheet

* Add site admins functionality

* Move org_member? method in user model and refactor

* Use unspent_credits_count for organizations

* Add tests for /listings/new and minor bug fixes

* Use .present? in case of empty array

* Fix a lingering deprecated method

* Use greater than 1 for random numbers

* Add tests for counting spent and unspent credits
2019-06-04 09:30:52 -04:00
rhymes
5e94533f0b Articles API: fix update org and add datetimes (#2913)
* Allow the article to be assigned to an org on update

* Add all the relevant datetimes, those available in the export

* Not all dates are always available
2019-05-21 09:53:30 -04:00
rhymes
2660ae1739 Use cached_tag_list_array for tags (#2857) 2019-05-16 23:29:57 -04:00
rhymes
f3496edb1c Articles update API: send publishing notification and set edited_at (#2859)
* Send notification on the first publishing

* Update edited_at when appropriate
2019-05-16 23:02:05 -04:00
rhymes
61a6c7f17c Add description to articles create/update API (#2858) 2019-05-16 22:56:37 -04:00