From 8639e3b748966d7d8196b29f6e956b548a4473ba Mon Sep 17 00:00:00 2001 From: jkrsn98 Date: Tue, 11 Aug 2020 08:36:49 -0400 Subject: [PATCH] API: retrieve podcast episodes comments (#9677) * modified index to allow retreival of comments belonging to either articles or podcast episodes * updated comments section in api documentation to include info on podcast comments * Remove DEV badge link (#9675) * [deploy] Profile Admin UI Setup Screen Refactor (v1.5) (#9649) * implement some suggestions from https://github.com/forem/forem/pull/9610 * chore: update the errors based on suggestions * feat: make query readable on blazer * added new parameter p_id to safe parameters * Remove forward slash from br tags in pages partial (#9678) * [deploy] Change lingering `/internal` paths to `/admin` (#9673) * Change lingering `/internal` paths to `/admin` * Fix multiline test expectation * [deploy] Add new support admin role (#9681) * Add new support admin role * Allow support admins to banish users * Fix spec order for new support admin role * Migrate serialization to jsonapi-serializer (#9682) This replaces the abandoned fast_jsonapi. * [deploy] Async Handle Notifications for Comments When Saved (#9680) * [deploy] Optimization: Change Large Table Primary Keys to Bigints (#9476) * [deploy] Revert "Async Handle Notifications for Comments When Saved (#9680)" (#9686) This reverts commit 852223dd8630e492fd600a756ed70a59787443fc. * Bump ddtrace from 0.38.0 to 0.39.0 (#9695) * Bump ddtrace from 0.38.0 to 0.39.0 Bumps [ddtrace](https://github.com/DataDog/dd-trace-rb) from 0.38.0 to 0.39.0. - [Release notes](https://github.com/DataDog/dd-trace-rb/releases) - [Changelog](https://github.com/DataDog/dd-trace-rb/blob/master/CHANGELOG.md) - [Commits](https://github.com/DataDog/dd-trace-rb/compare/v0.38.0...v0.39.0) Signed-off-by: dependabot-preview[bot] * Bump ddtrace from 0.38.0 to 0.39.0 (Update vendor/cache) Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Bump vault from 0.14.0 to 0.15.0 (#9697) * Bump vault from 0.14.0 to 0.15.0 Bumps [vault](https://github.com/hashicorp/vault-ruby) from 0.14.0 to 0.15.0. - [Release notes](https://github.com/hashicorp/vault-ruby/releases) - [Changelog](https://github.com/hashicorp/vault-ruby/blob/master/CHANGELOG.md) - [Commits](https://github.com/hashicorp/vault-ruby/compare/v0.14.0...v0.15.0) Signed-off-by: dependabot-preview[bot] * Bump vault from 0.14.0 to 0.15.0 (Update vendor/cache) Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * [deploy] Optimization:Set Honeybadger send_data_at_exit to False (#9687) * Travis Optimization:Bundle from Bash File to Use Cache (#9705) * Bump stripe from 5.22.0 to 5.23.1 (#9692) * Bump stripe from 5.22.0 to 5.23.1 Bumps [stripe](https://github.com/stripe/stripe-ruby) from 5.22.0 to 5.23.1. - [Release notes](https://github.com/stripe/stripe-ruby/releases) - [Changelog](https://github.com/stripe/stripe-ruby/blob/master/CHANGELOG.md) - [Commits](https://github.com/stripe/stripe-ruby/compare/v5.22.0...v5.23.1) Signed-off-by: dependabot-preview[bot] * Bump stripe from 5.22.0 to 5.23.1 (Update vendor/cache) Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * [deploy] Bump ancestry from 3.0.7 to 3.1.0 (#9689) * Bump ancestry from 3.0.7 to 3.1.0 Bumps [ancestry](https://github.com/stefankroes/ancestry) from 3.0.7 to 3.1.0. - [Release notes](https://github.com/stefankroes/ancestry/releases) - [Changelog](https://github.com/stefankroes/ancestry/blob/master/CHANGELOG.md) - [Commits](https://github.com/stefankroes/ancestry/compare/v3.0.7...v3.1.0) Signed-off-by: dependabot-preview[bot] * Bump ancestry from 3.0.7 to 3.1.0 (Update vendor/cache) Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Bump rubocop from 0.88.0 to 0.89.0 (#9699) * Bump rubocop from 0.88.0 to 0.89.0 Bumps [rubocop](https://github.com/rubocop-hq/rubocop) from 0.88.0 to 0.89.0. - [Release notes](https://github.com/rubocop-hq/rubocop/releases) - [Changelog](https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop-hq/rubocop/compare/v0.88.0...v0.89.0) Signed-off-by: dependabot-preview[bot] * Bump rubocop from 0.88.0 to 0.89.0 (Update vendor/cache) Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Bump twilio-ruby from 5.39.2 to 5.39.3 (#9690) * Bump twilio-ruby from 5.39.2 to 5.39.3 Bumps [twilio-ruby](https://github.com/twilio/twilio-ruby) from 5.39.2 to 5.39.3. - [Release notes](https://github.com/twilio/twilio-ruby/releases) - [Changelog](https://github.com/twilio/twilio-ruby/blob/main/CHANGES.md) - [Commits](https://github.com/twilio/twilio-ruby/compare/5.39.2...5.39.3) Signed-off-by: dependabot-preview[bot] * Bump twilio-ruby from 5.39.2 to 5.39.3 (Update vendor/cache) Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Bump ibm-openapi-validator from 0.28.0 to 0.28.1 (#9703) Bumps [ibm-openapi-validator](https://github.com/IBM/openapi-validator) from 0.28.0 to 0.28.1. - [Release notes](https://github.com/IBM/openapi-validator/releases) - [Changelog](https://github.com/IBM/openapi-validator/blob/master/CHANGELOG.md) - [Commits](https://github.com/IBM/openapi-validator/compare/v0.28.0...v0.28.1) Signed-off-by: dependabot-preview[bot] Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Bump sass-loader from 9.0.2 to 9.0.3 (#9702) Bumps [sass-loader](https://github.com/webpack-contrib/sass-loader) from 9.0.2 to 9.0.3. - [Release notes](https://github.com/webpack-contrib/sass-loader/releases) - [Changelog](https://github.com/webpack-contrib/sass-loader/blob/master/CHANGELOG.md) - [Commits](https://github.com/webpack-contrib/sass-loader/compare/v9.0.2...v9.0.3) Signed-off-by: dependabot-preview[bot] Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Bump jsdom from 16.3.0 to 16.4.0 (#9701) Bumps [jsdom](https://github.com/jsdom/jsdom) from 16.3.0 to 16.4.0. - [Release notes](https://github.com/jsdom/jsdom/releases) - [Changelog](https://github.com/jsdom/jsdom/blob/master/Changelog.md) - [Commits](https://github.com/jsdom/jsdom/compare/16.3.0...16.4.0) Signed-off-by: dependabot-preview[bot] Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Bump eslint-plugin-react from 7.20.3 to 7.20.5 (#9694) Bumps [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react) from 7.20.3 to 7.20.5. - [Release notes](https://github.com/yannickcr/eslint-plugin-react/releases) - [Changelog](https://github.com/yannickcr/eslint-plugin-react/blob/master/CHANGELOG.md) - [Commits](https://github.com/yannickcr/eslint-plugin-react/compare/v7.20.3...v7.20.5) Signed-off-by: dependabot-preview[bot] Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Flaky Spec Fix:HTML Escape Special Characters in Assertion like Template (#9708) * Bump redoc-cli from 0.9.9 to 0.9.10 (#9698) Bumps [redoc-cli](https://github.com/Redocly/redoc) from 0.9.9 to 0.9.10. - [Release notes](https://github.com/Redocly/redoc/releases) - [Changelog](https://github.com/Redocly/redoc/blob/master/CHANGELOG.md) - [Commits](https://github.com/Redocly/redoc/commits) Signed-off-by: dependabot-preview[bot] Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Bump css-loader from 4.2.0 to 4.2.1 (#9700) Bumps [css-loader](https://github.com/webpack-contrib/css-loader) from 4.2.0 to 4.2.1. - [Release notes](https://github.com/webpack-contrib/css-loader/releases) - [Changelog](https://github.com/webpack-contrib/css-loader/blob/master/CHANGELOG.md) - [Commits](https://github.com/webpack-contrib/css-loader/compare/v4.2.0...v4.2.1) Signed-off-by: dependabot-preview[bot] Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Bump brakeman from 4.8.2 to 4.9.0 (#9691) * Bump brakeman from 4.8.2 to 4.9.0 Bumps [brakeman](https://github.com/presidentbeef/brakeman) from 4.8.2 to 4.9.0. - [Release notes](https://github.com/presidentbeef/brakeman/releases) - [Changelog](https://github.com/presidentbeef/brakeman/blob/main/CHANGES.md) - [Commits](https://github.com/presidentbeef/brakeman/compare/v4.8.2...v4.9.0) Signed-off-by: dependabot-preview[bot] * Bump brakeman from 4.8.2 to 4.9.0 (Update vendor/cache) Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Bump @babel/core from 7.11.0 to 7.11.1 (#9693) Bumps [@babel/core](https://github.com/babel/babel/tree/HEAD/packages/babel-core) from 7.11.0 to 7.11.1. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.11.1/packages/babel-core) Signed-off-by: dependabot-preview[bot] Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Bump preact from 10.4.6 to 10.4.7 (#9696) Bumps [preact](https://github.com/preactjs/preact) from 10.4.6 to 10.4.7. - [Release notes](https://github.com/preactjs/preact/releases) - [Commits](https://github.com/preactjs/preact/compare/10.4.6...10.4.7) Signed-off-by: dependabot-preview[bot] Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Enable Rubocop 0.89 cops and fix Lint/ violations (#9709) * Enable new Lint/ cops and run rubocop -a * Fixing last remaining things with rubocop -a * Enable and fix Style/ExplicitBlockArgument and Style/GlobalStdStream * Forgot parenthesis * changed variable name from article to commentable * [deploy] Bug Fix:Dont Set Active Channel if ChatChannel Does Not Exist (#9704) * Rubocop: Enable and fix Style/OptionalBooleanParameter cop (#9711) * Enable and fix Style/OptionalBooleanParameter cop * Keep regular parameters for workers * Keep regular parameters for workers * Fix spec * Trigger Travis correctly * Fix Netlify catch all redirections (#9717) * added test for get comments by podcast episode * [deploy] Upgrade Chartkick to fix CVE-2020-16254 Vulnerability (#9718) * [deploy] Redirect /internal to /admin (#9716) * Update docs with details on where to install Elasticsearch (#9670) [deploy] * Gitignore elasticsearch installations * Add a note to explain that ES should be installed at the root level Remove `/elasticsearch/*` from .gitignore as well! * Update reference to home directory in mac + windows installation guides * [deploy] Improve clean up of user language settings (#9671) * modified index to allow retreival of comments belonging to either articles or podcast episodes * updated comments section in api documentation to include info on podcast comments * changed variable name from article to commentable * added test for get comments by podcast episode * added new parameter p_id to safe parameters * modified index to allow retreival of comments belonging to either articles or podcast episodes * changed variable name from article to commentable * Trigger Travis correctly Co-authored-by: Ben Halpern Co-authored-by: Ridhwana Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com> Co-authored-by: Josh Puetz Co-authored-by: Andy Zhao <17884966+Zhao-Andy@users.noreply.github.com> Co-authored-by: Jan Klimo Co-authored-by: Molly Struve Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: rhymes Co-authored-by: Vaidehi Joshi Co-authored-by: Alex --- app/controllers/api/v0/comments_controller.rb | 6 +++--- config/fastly/snippets/safe_params_list.vcl | 2 +- docs/api_v0.yml | 14 +++++++++++++- spec/requests/api/v0/comments_spec.rb | 16 ++++++++++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v0/comments_controller.rb b/app/controllers/api/v0/comments_controller.rb index b25283497..264cd41d4 100644 --- a/app/controllers/api/v0/comments_controller.rb +++ b/app/controllers/api/v0/comments_controller.rb @@ -9,14 +9,14 @@ module Api private_constant :ATTRIBUTES_FOR_SERIALIZATION def index - article = Article.find(params[:a_id]) + commentable = params[:a_id] ? Article.find(params[:a_id]) : PodcastEpisode.find(params[:p_id]) - @comments = article.comments + @comments = commentable.comments .includes(:user) .select(ATTRIBUTES_FOR_SERIALIZATION) .arrange - set_surrogate_key_header article.record_key, Comment.table_key, edge_cache_keys(@comments) + set_surrogate_key_header commentable.record_key, Comment.table_key, edge_cache_keys(@comments) end def show diff --git a/config/fastly/snippets/safe_params_list.vcl b/config/fastly/snippets/safe_params_list.vcl index 1af167044..bbc24a957 100644 --- a/config/fastly/snippets/safe_params_list.vcl +++ b/config/fastly/snippets/safe_params_list.vcl @@ -2,6 +2,6 @@ import querystring; sub vcl_recv { # return this URL with only the parameters that match this regular expression if (req.url !~ "/admin/" && req.url !~ "/search/" && req.url !~ "/bulk_show") { - set req.url = querystring.regfilter_except(req.url, "^(a_id|args|article_id|article_ids|articles|asc|callback_url|category|chat_channel_id|client_id|code|collection_id|commentable_id|commentable_type|confirmation_token|created_at|end|filter|followable_id|followable_type|fork_id|i|key|message_offset|name|oauth_token|oauth_verifier|offset|org_id|organization_id|p|page|per_page|prefill|preview|purchaser|reactable_ids|redirect_uri|reported_url|reporter_username|response_type|scope|search|signature|sort|source_id|source_type|start|state|status|tag|tag_list|top|type_of|url|username|invitation_token|reset_password_token|ut|verb|invitation_slug)$"); + set req.url = querystring.regfilter_except(req.url, "^(a_id|args|article_id|article_ids|articles|asc|callback_url|category|chat_channel_id|client_id|code|collection_id|commentable_id|commentable_type|confirmation_token|created_at|end|filter|followable_id|followable_type|fork_id|i|key|message_offset|name|oauth_token|oauth_verifier|offset|org_id|organization_id|p|page|per_page|p_id|prefill|preview|purchaser|reactable_ids|redirect_uri|reported_url|reporter_username|response_type|scope|search|signature|sort|source_id|source_type|start|state|status|tag|tag_list|top|type_of|url|username|invitation_token|reset_password_token|ut|verb|invitation_slug)$"); } } diff --git a/docs/api_v0.yml b/docs/api_v0.yml index 5d6c20f86..e8c44d572 100644 --- a/docs/api_v0.yml +++ b/docs/api_v0.yml @@ -2221,7 +2221,7 @@ paths: summary: Comments description: | This endpoint allows the client to retrieve all comments belonging to an - article as threaded conversations. + article or podcast episode as threaded conversations. It will return the all top level comments with their nested comments as threads. See the format specification for further details. @@ -2236,6 +2236,14 @@ paths: format: int32 minimum: 1 example: 270180 + - name: p_id + in: query + description: Podcast Episode identifier. + schema: + type: integer + format: int32 + minimum: 1 + example: 124 responses: "200": description: A list of threads of comments @@ -2266,6 +2274,10 @@ paths: label: curl (all comments of an article) source: | curl https://dev.to/api/comments?a_id=270180 + - lang: Shell + label: curl (all comments of a podcast episode) + source: | + curl https://dev.to/api/comments?p_id=124 /comments/{id}: get: diff --git a/spec/requests/api/v0/comments_spec.rb b/spec/requests/api/v0/comments_spec.rb index d07caf448..6e63ba8fe 100644 --- a/spec/requests/api/v0/comments_spec.rb +++ b/spec/requests/api/v0/comments_spec.rb @@ -156,6 +156,22 @@ RSpec.describe "Api::V0::Comments", type: :request do expect(find_child_comment(response)["children"]).not_to be_empty end end + + context "when getting by podcast episode id" do + let(:podcast) { create(:podcast) } + let(:podcast_episode) { create(:podcast_episode, podcast: podcast) } + let!(:comment) { create(:comment, commentable: podcast_episode) } + + it "not found if bad podcast episode id" do + get api_comments_path(p_id: "asdfghjkl") + expect(response).to have_http_status(:not_found) + end + it "returns comment if good podcast episode id" do + get api_comments_path(p_id: podcast_episode.id) + expect(response).to have_http_status(:ok) + expect(response.parsed_body.size).to eq(1) + end + end end describe "GET /api/comments/:id" do