Commit graph

148 commits

Author SHA1 Message Date
Michael Kohl
b06e9901d5
Add ApplicationRecord#errors_as_sentence (#8265)
* Add ApplicationRecord#errors_as_sentence

* Refactor existing uses

* Use errors as sentence more consistently
2020-06-04 16:02:41 +02:00
Joe Doss
6406b0727b
Allow localhost or 127.0.0.1 to access api/health_checks without health-check-token (#8231)
* This change allows access to api/health_checks if you are coming from localhost
or 127.0.0.1. Pretty sweet huh?

The reason for this change is because I want to easily get to these healthcheck
end points from localhost without having to get the health-check-token beforehand.

Buttttt.... this addition has some issues. You can spoof the host header pretty
easily:

https://daniel.haxx.se/blog/2018/04/05/curl-another-host/

I thought about doing `return if !request.ssl? && request.local?`

to check of the request was over https or not. Any localhost healthcheck we do
directly to puma will be over http. Checking for TLS seemed like a logical next
check, but since we force https on the edge and not necessarily from the edge to
Puma the Host header can still be spoofed to get at these end points.

More info on host header attacks and what Rails 6 is doing about it:

https://github.com/rails/rails/issues/29893

While I do think it is a good idea to protect these healthcheck end points from
the outside world, I do want to be able to get to them easily locally. WWYD?

* Fix Health Check spec by stubbing request

Co-authored-by: mstruve <mollylbs@gmail.com>
2020-06-02 11:29:04 -04:00
Molly Struve
eda0a78d47
Add Health Check Endpoint for Cache (#8222) 2020-06-01 15:19:56 -05:00
Molly Struve
8a4c2c1cb4
[deploy] Add App, Database, and Search Health Check Endpoints (#8071) 2020-05-28 08:33:31 -05:00
Michael Kohl
7f75f99560
[deploy] Rename classified listings (#7910)
* Change models and related files

* Update controllers and specs

* More renaming

* Seek and destroy, I mean search and replace

* Round up the stragglers

* Ground control to Major Travis...

* More fixes

* PR feedback

* Various fixes

* Rename view

* Fix list query builder

* Unify request specs

* Fix some API spec errors

* Fix remaining API specs

* Make spec conform to API

* Fix leftover problems

* Fix JS tests

* Fix column name in select

* Fix API specs

* Fix search specs

* Paging Mr. Travis
2020-05-27 13:35:09 +00:00
Andy Zhao
c42fd3461e
[deploy] Rename positive_reactions_count to public_reactions_count in logic (#7926)
* Rename positive_reactions_count to public_reactions_count

* Add positive reactions count back in so we can remove it

* Use public_category method for reactions

* Add positive_reactions_count in case any old caches rely on it

* Add positive_rxn_count to account for API endpoints

* Remove unused method

* One more spot...

* Add method back in because of caches

* Update specs to match new functionality

* Fix typo

* Remove unused methods
2020-05-26 12:36:28 -04:00
Mac Siri
321b24d2a0
[deploy] Create write_articles oauth scope (#7834) 2020-05-14 09:55:53 -04:00
Molly Struve
ba0ebbafa8
[deploy] RateLimit Refactor: Consolidate Logic for Checking a Limit and Raising an Error (#7636) 2020-05-01 13:31:44 -05:00
Michael Kohl
46f94b135d
[deploy] Classified listings refactor part 3 (#7498)
* Ignore category column

* Move view oriented class methods to helper

* Start refactoring ClassifiedListingsToolkit

* Add attr_accessor instead of category

* Replace old category column with association

* More cleanup

* Trigger Travis

* Don't rename associations, category_slug -> category

* Indiana Kohl and the missing newline

* More refactoring and spec fixes

* Add dashboard for classified listing categories

* Remove TODO comment

Co-authored-by: rhymes <rhymesete@gmail.com>
2020-04-30 18:57:01 -04:00
rhymes
0186fd9aee
Add Retry-After for API rate limit errors and document limits in API spec (#7444)
* Add correct rate limit exception to Articles::Updater

* Send Retry-After with HTTP 429 back to the client

* Update API specs for error 429

* Test build

* Fix spec

* Add retry after to ImageUploadsController and fix specs

* Generalize a bit
2020-04-24 17:35:28 +02:00
Michael Kohl
9df68f3920
Use new classified listing categories (#7250)
* Add ClassifiedListingCategoryModel

* Add data update script for classified listing categories

* Refactor and fix specs

* Resolve conflict

* Incorporate PR feedback
2020-04-23 10:06:58 +07:00
Molly Struve
de88a08ebd
[deploy] handle rate limit errors gracefully (#7422) 2020-04-22 08:55:26 -05:00
rhymes
34848a4209
Upgrade Rubocop to 0.81 (#7219)
* Upgrade rubocop to 0.81.0

* Reordered rubocop file and updated it

* Regenerate todo

* Correct some things

* Fix specs
2020-04-11 10:10:04 +02:00
Michael Kohl
1ae9cfbdc6
Remove POST /api/reactions endpoint (#6968) [deploy] 2020-03-31 16:12:30 +02:00
Michael Kohl
244ab297c8
Move user following suggestions to internal API (#6601) [deploy] 2020-03-13 13:37:24 +01:00
rhymes
1428013ebd
API: add users and videos docs (#6611) [deploy]
* Fix IDs size

* Document /api/users/{id}

* Document /users/me

* Add videos API docs
2020-03-13 09:12:09 +01:00
Michael Kohl
f975c4c9f3
Move chat_channel info to internal API (#6581) [deploy] 2020-03-11 13:57:21 +01:00
rhymes
01e4a0b0f1
API: add docs for /followers/users and remove organizations endpoint (#6551)
* Use api-key for api tests

* Remove /api/followers/organizations endpoint

* Add more tests

* Add documentation for /api/followers/users
2020-03-11 10:56:43 +01:00
Michael Kohl
8ab7a3fb6c
API: Remove reactions onboarding (#6529)
* Move reactions onboarding to internal API

* Don't add reactions onboarding to internal API

* Remove obsolete worker
2020-03-10 10:25:16 -04:00
rhymes
21fca3e0f2
Comments API: hide deleted and hidden comments (plus docs) (#6482) [deploy]
* Modernize index test

* Hide comments body_html and user info if the comment is either deleted or hidden

* Shorten lines a bit

* Freeze repeated strings

* Document all /comments

* Document /comments/{id}
2020-03-07 09:02:10 +01:00
Michael Kohl
8df0a72ce7
Move onboarding tags from public to internal API (#6329)
* Move onboarding tags from public to internal API

* Fix typo

* Undo wrong chang
2020-03-06 19:34:31 +01:00
Michael Kohl
0fd6c948d1
Move followings to internal API (#6494) 2020-03-06 19:33:26 +01:00
rhymes
c8c5088fbd
API: Access unpublished listings only if you are the owner (#6458) [deploy]
* Access only unpublished listings if they belong to the user when authenticated

* Make sure we never send unpublished listings in the index

* Update API docs

* oops

* Remove unused preloading as this loads a single item
2020-03-05 11:28:31 +01:00
rhymes
f3e76e7fe5
Improve API docs for articles, add listings to it and fix bugs (#6413) [deploy]
* Fix articles index state param values

* Update Articles API docs

* Fix ClassifiedListing.cost_by_category with invalid category

* Add docs for GET|POST /listings and fix bugs

* Document PUT /api/listings/:id

* Add docs for /listings/category/{category}

* One variable down

* Improve listings update error handling
2020-03-04 15:30:02 +01:00
Michael Kohl
6ad74517d7
[deploy] Remove github_repos from public API (#6304) 2020-02-26 11:23:39 -05:00
rhymes
145d5e610e
Use scopes for Follow instead of where all the time (#6149) [deploy] 2020-02-25 19:29:52 -05:00
rhymes
fd1c13c7b6
API listings: improve caching (#6247) 2020-02-25 09:24:19 -05:00
Michael Kohl
d13cbbb3c1
Change authorization to signed in users (#6136) [deploy] 2020-02-21 13:53:30 -05:00
rhymes
bc385ae6d5
Switch decorators to Rails builtin decorations - take 2 (#6125) [deploy]
* Revert "Revert "[deploy] Switch decorators from Draper to Rails builtin decorations (#6040)" (#6122) [deploy]"

This reverts commit d438349550.

* Enable serialization for decorators

* Refactor and test default home feed serialization

* Improve spec

* Applied @vaidehijoshi suggestions

* Applied @citizen428 suggestions

* Make CodeClimate happy

* Cleanup stories_index_spec.rb

* Refactor UserDecorator#cached_followed_tags to loop less
2020-02-19 15:30:53 -05:00
rhymes
6cbfb01394
Stop using legacy user's organization_id and remove followers unused code (#6079) [deploy] 2020-02-18 11:27:43 -05:00
rhymes
a56eb8fab0
Enable CORS on public API endpoints (#6116) [deploy]
* Enable CORS for public API

* Add specs for Articles API

* Mention CORS in the API docs
2020-02-18 10:47:07 -05:00
Ben Halpern
d0dd79ac29
Make sure profile images show up in onboarding (#6134) [deploy] 2020-02-17 20:19:06 -05:00
rhymes
d438349550
Revert "[deploy] Switch decorators from Draper to Rails builtin decorations (#6040)" (#6122) [deploy]
This reverts commit cc53b55a4a.
2020-02-17 11:28:32 -05:00
rhymes
cc53b55a4a
[deploy] Switch decorators from Draper to Rails builtin decorations (#6040)
* Convert SponsorshipDecorator to Rails decorator

* Remove empty ReactionDecorator

* Rename SponsorshipDecorator#level_color_hex to level_background_color

* Convert CommentDecorator to Rails decorator

* Add specs and fix bugs for NotificationDecorator

* Convert NotificationDecorator to Rails decorator

* Add specs and fix bugs for OrganizationDecorator

* Convert OrganizationDecorator to Rails decorator

* Add specs to PodcastEpisodeDecorator and fix bugs

* Convert PodcastEpisodeDecorator to a Rails decorator

* Add missing specs for ArticleDecorator and fix bugs

* Convert ArticleDecorator to Rails decorator

* Add missing specs to UserDecorator and fix issues

* Convert UserDecorator to Rails decorator

* Add .decorate_collection method

* Add decorator for AR relations and remove Draper

* Rename BaseDecorator back to ApplicationDecorator

* Rename .decorate_ back to .decorate

* Restore decorate_collection (WTH)

* Add decorated?

* Fix bugs and failing specs

* Decoration should always be explicit
2020-02-17 09:32:32 -05:00
rhymes
1df24046d8
Small API controllers refactoring (#6021) [deploy]
* TagsController inherits from ApiController
* Let ApiController inherit from ActionController::Base to have its own lifecycle
* Remove unused method
* Use only one respond_to :json for the entire API
* ApiController inherits from ActionController::Base
* Use Pundit only where needed
2020-02-12 11:51:42 -05:00
Alex
78a25dfd54
Validate that API article params are a Hash (#5963)
* Add check for article param being a Hash & spec

* Remove unnecessary blank line

* Move logic to private method and before_action call

* Change check_if to validate

* Use is_a? to type check

* Fix type check for specs
2020-02-10 10:24:11 -05:00
rhymes
69b04d38aa
Refactor API Reactions controller and add specs (#5936)
* Add specs

* Check the object, not the ID

* Use permitted params and delete cache only after create

* Inherit from ApiController, bail if the reaction user does not exist, fix naming

* Remove superflous test
2020-02-07 12:39:24 -05:00
rhymes
92f6a9f007
Fix serialization error with video_thumbnail_url (#5933) 2020-02-06 10:50:44 -05:00
rhymes
fd5643bc9d
Improve API controllers efficiency by selecting only columns needed for serialization (#5805) [deploy] 2020-02-06 07:36:56 -05:00
rhymes
5444c53df2 Improve API podcast episodes controller caching and fetching (#5772) [deploy]
* Refactor caching and add some tests

* Only select needed columns

* Add more tests
2020-01-27 16:57:37 -05:00
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
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
Lucas Hiago
fb5cb7005c Change CreateJob to CreateWorker and move to sidekiq (#5559)
* Create new CreateWorker

* Create new spec for CreateWorker

* Change CreateJob to CreateWorker and move to sidekiq

* Update worker

* Update priority of Reactions Create Worker

* Remove leading spaces from spec
2020-01-20 11:29:13 -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
Ben Halpern
f78b89e763
Add suggested tags to SiteConfig (#5426) [deploy]
* Initial base work

* Add suggested tags config

* Downcase suggested tag input
2020-01-10 12:33:37 -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