From b59ce0a60ff4f90bb16a8c3338ad37218af052b8 Mon Sep 17 00:00:00 2001 From: trwnh Date: Mon, 14 Nov 2022 01:34:07 -0600 Subject: [PATCH] Move V2 Filter methods under /api/v2 prefix (#20622) * Move V2 Filter methods under /api/v2 prefix * move over the tests too --- .../{v1 => v2}/filters/keywords_controller.rb | 2 +- .../{v1 => v2}/filters/statuses_controller.rb | 2 +- app/javascript/mastodon/actions/filters.js | 2 +- config/routes.rb | 20 +++++++++---------- .../filters/keywords_controller_spec.rb | 2 +- .../filters/statuses_controller_spec.rb | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) rename app/controllers/api/{v1 => v2}/filters/keywords_controller.rb (95%) rename app/controllers/api/{v1 => v2}/filters/statuses_controller.rb (95%) rename spec/controllers/api/{v1 => v2}/filters/keywords_controller_spec.rb (98%) rename spec/controllers/api/{v1 => v2}/filters/statuses_controller_spec.rb (98%) diff --git a/app/controllers/api/v1/filters/keywords_controller.rb b/app/controllers/api/v2/filters/keywords_controller.rb similarity index 95% rename from app/controllers/api/v1/filters/keywords_controller.rb rename to app/controllers/api/v2/filters/keywords_controller.rb index d3718a1371d..c63e1d986b1 100644 --- a/app/controllers/api/v1/filters/keywords_controller.rb +++ b/app/controllers/api/v2/filters/keywords_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Api::V1::Filters::KeywordsController < Api::BaseController +class Api::V2::Filters::KeywordsController < Api::BaseController before_action -> { doorkeeper_authorize! :read, :'read:filters' }, only: [:index, :show] before_action -> { doorkeeper_authorize! :write, :'write:filters' }, except: [:index, :show] before_action :require_user! diff --git a/app/controllers/api/v1/filters/statuses_controller.rb b/app/controllers/api/v2/filters/statuses_controller.rb similarity index 95% rename from app/controllers/api/v1/filters/statuses_controller.rb rename to app/controllers/api/v2/filters/statuses_controller.rb index b6bed306fca..755c14cffa8 100644 --- a/app/controllers/api/v1/filters/statuses_controller.rb +++ b/app/controllers/api/v2/filters/statuses_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Api::V1::Filters::StatusesController < Api::BaseController +class Api::V2::Filters::StatusesController < Api::BaseController before_action -> { doorkeeper_authorize! :read, :'read:filters' }, only: [:index, :show] before_action -> { doorkeeper_authorize! :write, :'write:filters' }, except: [:index, :show] before_action :require_user! diff --git a/app/javascript/mastodon/actions/filters.js b/app/javascript/mastodon/actions/filters.js index 76326802eae..e9c609fc87c 100644 --- a/app/javascript/mastodon/actions/filters.js +++ b/app/javascript/mastodon/actions/filters.js @@ -43,7 +43,7 @@ export const fetchFilters = () => (dispatch, getState) => { export const createFilterStatus = (params, onSuccess, onFail) => (dispatch, getState) => { dispatch(createFilterStatusRequest()); - api(getState).post(`/api/v1/filters/${params.filter_id}/statuses`, params).then(response => { + api(getState).post(`/api/v2/filters/${params.filter_id}/statuses`, params).then(response => { dispatch(createFilterStatusSuccess(response.data)); if (onSuccess) onSuccess(); }).catch(error => { diff --git a/config/routes.rb b/config/routes.rb index d8af292bfc7..f095ff65514 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -493,18 +493,10 @@ Rails.application.routes.draw do resources :bookmarks, only: [:index] resources :reports, only: [:create] resources :trends, only: [:index], controller: 'trends/tags' - resources :filters, only: [:index, :create, :show, :update, :destroy] do - resources :keywords, only: [:index, :create], controller: 'filters/keywords' - resources :statuses, only: [:index, :create], controller: 'filters/statuses' - end + resources :filters, only: [:index, :create, :show, :update, :destroy] resources :endorsements, only: [:index] resources :markers, only: [:index, :create] - namespace :filters do - resources :keywords, only: [:show, :update, :destroy] - resources :statuses, only: [:show, :destroy] - end - namespace :apps do get :verify_credentials, to: 'credentials#show' end @@ -660,8 +652,16 @@ Rails.application.routes.draw do resources :media, only: [:create] resources :suggestions, only: [:index] - resources :filters, only: [:index, :create, :show, :update, :destroy] resource :instance, only: [:show] + resources :filters, only: [:index, :create, :show, :update, :destroy] do + resources :keywords, only: [:index, :create], controller: 'filters/keywords' + resources :statuses, only: [:index, :create], controller: 'filters/statuses' + end + + namespace :filters do + resources :keywords, only: [:show, :update, :destroy] + resources :statuses, only: [:show, :destroy] + end namespace :admin do resources :accounts, only: [:index] diff --git a/spec/controllers/api/v1/filters/keywords_controller_spec.rb b/spec/controllers/api/v2/filters/keywords_controller_spec.rb similarity index 98% rename from spec/controllers/api/v1/filters/keywords_controller_spec.rb rename to spec/controllers/api/v2/filters/keywords_controller_spec.rb index aecb4e41c93..1201a4ca233 100644 --- a/spec/controllers/api/v1/filters/keywords_controller_spec.rb +++ b/spec/controllers/api/v2/filters/keywords_controller_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Api::V1::Filters::KeywordsController, type: :controller do +RSpec.describe Api::V2::Filters::KeywordsController, type: :controller do render_views let(:user) { Fabricate(:user) } diff --git a/spec/controllers/api/v1/filters/statuses_controller_spec.rb b/spec/controllers/api/v2/filters/statuses_controller_spec.rb similarity index 98% rename from spec/controllers/api/v1/filters/statuses_controller_spec.rb rename to spec/controllers/api/v2/filters/statuses_controller_spec.rb index 3b2399dd898..9740c1eb30a 100644 --- a/spec/controllers/api/v1/filters/statuses_controller_spec.rb +++ b/spec/controllers/api/v2/filters/statuses_controller_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Api::V1::Filters::StatusesController, type: :controller do +RSpec.describe Api::V2::Filters::StatusesController, type: :controller do render_views let(:user) { Fabricate(:user) }