1
0
mirror of https://github.com/funamitech/mastodon synced 2024-11-23 22:57:05 +09:00

Fix Rails/ActionOrder cop (#24692)

This commit is contained in:
Matt Jankowski 2023-04-30 00:46:39 -04:00 committed by GitHub
parent 470b8abb69
commit 6e226f5a32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 93 additions and 120 deletions

View File

@ -1148,32 +1148,6 @@ RSpec/VerifiedDoubles:
- 'spec/workers/feed_insert_worker_spec.rb' - 'spec/workers/feed_insert_worker_spec.rb'
- 'spec/workers/regeneration_worker_spec.rb' - 'spec/workers/regeneration_worker_spec.rb'
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: ExpectedOrder, Include.
# ExpectedOrder: index, show, new, edit, create, update, destroy
# Include: app/controllers/**/*.rb
Rails/ActionOrder:
Exclude:
- 'app/controllers/admin/announcements_controller.rb'
- 'app/controllers/admin/roles_controller.rb'
- 'app/controllers/admin/rules_controller.rb'
- 'app/controllers/admin/warning_presets_controller.rb'
- 'app/controllers/admin/webhooks_controller.rb'
- 'app/controllers/api/v1/admin/domain_allows_controller.rb'
- 'app/controllers/api/v1/admin/domain_blocks_controller.rb'
- 'app/controllers/api/v1/admin/email_domain_blocks_controller.rb'
- 'app/controllers/api/v1/admin/ip_blocks_controller.rb'
- 'app/controllers/api/v1/filters_controller.rb'
- 'app/controllers/api/v1/media_controller.rb'
- 'app/controllers/api/v1/push/subscriptions_controller.rb'
- 'app/controllers/api/v2/filters/keywords_controller.rb'
- 'app/controllers/api/v2/filters/statuses_controller.rb'
- 'app/controllers/api/v2/filters_controller.rb'
- 'app/controllers/auth/registrations_controller.rb'
- 'app/controllers/filters_controller.rb'
- 'app/controllers/settings/applications_controller.rb'
- 'app/controllers/settings/two_factor_authentication/webauthn_credentials_controller.rb'
# This cop supports safe autocorrection (--autocorrect). # This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Include. # Configuration parameters: Include.
# Include: app/models/**/*.rb # Include: app/models/**/*.rb

View File

@ -14,6 +14,10 @@ class Admin::AnnouncementsController < Admin::BaseController
@announcement = Announcement.new @announcement = Announcement.new
end end
def edit
authorize :announcement, :update?
end
def create def create
authorize :announcement, :create? authorize :announcement, :create?
@ -28,10 +32,6 @@ class Admin::AnnouncementsController < Admin::BaseController
end end
end end
def edit
authorize :announcement, :update?
end
def update def update
authorize :announcement, :update? authorize :announcement, :update?

View File

@ -16,6 +16,10 @@ module Admin
@role = UserRole.new @role = UserRole.new
end end
def edit
authorize @role, :update?
end
def create def create
authorize :user_role, :create? authorize :user_role, :create?
@ -30,10 +34,6 @@ module Admin
end end
end end
def edit
authorize @role, :update?
end
def update def update
authorize @role, :update? authorize @role, :update?

View File

@ -11,6 +11,10 @@ module Admin
@rule = Rule.new @rule = Rule.new
end end
def edit
authorize @rule, :update?
end
def create def create
authorize :rule, :create? authorize :rule, :create?
@ -24,10 +28,6 @@ module Admin
end end
end end
def edit
authorize @rule, :update?
end
def update def update
authorize @rule, :update? authorize @rule, :update?

View File

@ -11,6 +11,10 @@ module Admin
@warning_preset = AccountWarningPreset.new @warning_preset = AccountWarningPreset.new
end end
def edit
authorize @warning_preset, :update?
end
def create def create
authorize :account_warning_preset, :create? authorize :account_warning_preset, :create?
@ -24,10 +28,6 @@ module Admin
end end
end end
def edit
authorize @warning_preset, :update?
end
def update def update
authorize @warning_preset, :update? authorize @warning_preset, :update?

View File

@ -10,12 +10,20 @@ module Admin
@webhooks = Webhook.page(params[:page]) @webhooks = Webhook.page(params[:page])
end end
def show
authorize @webhook, :show?
end
def new def new
authorize :webhook, :create? authorize :webhook, :create?
@webhook = Webhook.new @webhook = Webhook.new
end end
def edit
authorize @webhook, :update?
end
def create def create
authorize :webhook, :create? authorize :webhook, :create?
@ -28,14 +36,6 @@ module Admin
end end
end end
def show
authorize @webhook, :show?
end
def edit
authorize @webhook, :update?
end
def update def update
authorize @webhook, :update? authorize @webhook, :update?

View File

@ -16,6 +16,16 @@ class Api::V1::Admin::DomainAllowsController < Api::BaseController
PAGINATION_PARAMS = %i(limit).freeze PAGINATION_PARAMS = %i(limit).freeze
def index
authorize :domain_allow, :index?
render json: @domain_allows, each_serializer: REST::Admin::DomainAllowSerializer
end
def show
authorize @domain_allow, :show?
render json: @domain_allow, serializer: REST::Admin::DomainAllowSerializer
end
def create def create
authorize :domain_allow, :create? authorize :domain_allow, :create?
@ -29,16 +39,6 @@ class Api::V1::Admin::DomainAllowsController < Api::BaseController
render json: @domain_allow, serializer: REST::Admin::DomainAllowSerializer render json: @domain_allow, serializer: REST::Admin::DomainAllowSerializer
end end
def index
authorize :domain_allow, :index?
render json: @domain_allows, each_serializer: REST::Admin::DomainAllowSerializer
end
def show
authorize @domain_allow, :show?
render json: @domain_allow, serializer: REST::Admin::DomainAllowSerializer
end
def destroy def destroy
authorize @domain_allow, :destroy? authorize @domain_allow, :destroy?
UnallowDomainService.new.call(@domain_allow) UnallowDomainService.new.call(@domain_allow)

View File

@ -16,6 +16,16 @@ class Api::V1::Admin::DomainBlocksController < Api::BaseController
PAGINATION_PARAMS = %i(limit).freeze PAGINATION_PARAMS = %i(limit).freeze
def index
authorize :domain_block, :index?
render json: @domain_blocks, each_serializer: REST::Admin::DomainBlockSerializer
end
def show
authorize @domain_block, :show?
render json: @domain_block, serializer: REST::Admin::DomainBlockSerializer
end
def create def create
authorize :domain_block, :create? authorize :domain_block, :create?
@ -28,16 +38,6 @@ class Api::V1::Admin::DomainBlocksController < Api::BaseController
render json: @domain_block, serializer: REST::Admin::DomainBlockSerializer render json: @domain_block, serializer: REST::Admin::DomainBlockSerializer
end end
def index
authorize :domain_block, :index?
render json: @domain_blocks, each_serializer: REST::Admin::DomainBlockSerializer
end
def show
authorize @domain_block, :show?
render json: @domain_block, serializer: REST::Admin::DomainBlockSerializer
end
def update def update
authorize @domain_block, :update? authorize @domain_block, :update?
@domain_block.update!(domain_block_params) @domain_block.update!(domain_block_params)

View File

@ -18,15 +18,6 @@ class Api::V1::Admin::EmailDomainBlocksController < Api::BaseController
limit limit
).freeze ).freeze
def create
authorize :email_domain_block, :create?
@email_domain_block = EmailDomainBlock.create!(resource_params)
log_action :create, @email_domain_block
render json: @email_domain_block, serializer: REST::Admin::EmailDomainBlockSerializer
end
def index def index
authorize :email_domain_block, :index? authorize :email_domain_block, :index?
render json: @email_domain_blocks, each_serializer: REST::Admin::EmailDomainBlockSerializer render json: @email_domain_blocks, each_serializer: REST::Admin::EmailDomainBlockSerializer
@ -37,6 +28,15 @@ class Api::V1::Admin::EmailDomainBlocksController < Api::BaseController
render json: @email_domain_block, serializer: REST::Admin::EmailDomainBlockSerializer render json: @email_domain_block, serializer: REST::Admin::EmailDomainBlockSerializer
end end
def create
authorize :email_domain_block, :create?
@email_domain_block = EmailDomainBlock.create!(resource_params)
log_action :create, @email_domain_block
render json: @email_domain_block, serializer: REST::Admin::EmailDomainBlockSerializer
end
def destroy def destroy
authorize @email_domain_block, :destroy? authorize @email_domain_block, :destroy?
@email_domain_block.destroy! @email_domain_block.destroy!

View File

@ -18,13 +18,6 @@ class Api::V1::Admin::IpBlocksController < Api::BaseController
limit limit
).freeze ).freeze
def create
authorize :ip_block, :create?
@ip_block = IpBlock.create!(resource_params)
log_action :create, @ip_block
render json: @ip_block, serializer: REST::Admin::IpBlockSerializer
end
def index def index
authorize :ip_block, :index? authorize :ip_block, :index?
render json: @ip_blocks, each_serializer: REST::Admin::IpBlockSerializer render json: @ip_blocks, each_serializer: REST::Admin::IpBlockSerializer
@ -35,6 +28,13 @@ class Api::V1::Admin::IpBlocksController < Api::BaseController
render json: @ip_block, serializer: REST::Admin::IpBlockSerializer render json: @ip_block, serializer: REST::Admin::IpBlockSerializer
end end
def create
authorize :ip_block, :create?
@ip_block = IpBlock.create!(resource_params)
log_action :create, @ip_block
render json: @ip_block, serializer: REST::Admin::IpBlockSerializer
end
def update def update
authorize @ip_block, :update? authorize @ip_block, :update?
@ip_block.update(resource_params) @ip_block.update(resource_params)

View File

@ -11,6 +11,10 @@ class Api::V1::FiltersController < Api::BaseController
render json: @filters, each_serializer: REST::V1::FilterSerializer render json: @filters, each_serializer: REST::V1::FilterSerializer
end end
def show
render json: @filter, serializer: REST::V1::FilterSerializer
end
def create def create
ApplicationRecord.transaction do ApplicationRecord.transaction do
filter_category = current_account.custom_filters.create!(filter_params) filter_category = current_account.custom_filters.create!(filter_params)
@ -20,10 +24,6 @@ class Api::V1::FiltersController < Api::BaseController
render json: @filter, serializer: REST::V1::FilterSerializer render json: @filter, serializer: REST::V1::FilterSerializer
end end
def show
render json: @filter, serializer: REST::V1::FilterSerializer
end
def update def update
ApplicationRecord.transaction do ApplicationRecord.transaction do
@filter.update!(keyword_params) @filter.update!(keyword_params)

View File

@ -6,6 +6,10 @@ class Api::V1::MediaController < Api::BaseController
before_action :set_media_attachment, except: [:create] before_action :set_media_attachment, except: [:create]
before_action :check_processing, except: [:create] before_action :check_processing, except: [:create]
def show
render json: @media_attachment, serializer: REST::MediaAttachmentSerializer, status: status_code_for_media_attachment
end
def create def create
@media_attachment = current_account.media_attachments.create!(media_attachment_params) @media_attachment = current_account.media_attachments.create!(media_attachment_params)
render json: @media_attachment, serializer: REST::MediaAttachmentSerializer render json: @media_attachment, serializer: REST::MediaAttachmentSerializer
@ -15,10 +19,6 @@ class Api::V1::MediaController < Api::BaseController
render json: processing_error, status: 500 render json: processing_error, status: 500
end end
def show
render json: @media_attachment, serializer: REST::MediaAttachmentSerializer, status: status_code_for_media_attachment
end
def update def update
@media_attachment.update!(updateable_media_attachment_params) @media_attachment.update!(updateable_media_attachment_params)
render json: @media_attachment, serializer: REST::MediaAttachmentSerializer, status: status_code_for_media_attachment render json: @media_attachment, serializer: REST::MediaAttachmentSerializer, status: status_code_for_media_attachment

View File

@ -6,6 +6,10 @@ class Api::V1::Push::SubscriptionsController < Api::BaseController
before_action :set_push_subscription before_action :set_push_subscription
before_action :check_push_subscription, only: [:show, :update] before_action :check_push_subscription, only: [:show, :update]
def show
render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer
end
def create def create
@push_subscription&.destroy! @push_subscription&.destroy!
@ -21,10 +25,6 @@ class Api::V1::Push::SubscriptionsController < Api::BaseController
render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer
end end
def show
render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer
end
def update def update
@push_subscription.update!(data: data_params) @push_subscription.update!(data: data_params)
render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer

View File

@ -12,13 +12,13 @@ class Api::V2::Filters::KeywordsController < Api::BaseController
render json: @keywords, each_serializer: REST::FilterKeywordSerializer render json: @keywords, each_serializer: REST::FilterKeywordSerializer
end end
def create def show
@keyword = current_account.custom_filters.find(params[:filter_id]).keywords.create!(resource_params)
render json: @keyword, serializer: REST::FilterKeywordSerializer render json: @keyword, serializer: REST::FilterKeywordSerializer
end end
def show def create
@keyword = current_account.custom_filters.find(params[:filter_id]).keywords.create!(resource_params)
render json: @keyword, serializer: REST::FilterKeywordSerializer render json: @keyword, serializer: REST::FilterKeywordSerializer
end end

View File

@ -12,13 +12,13 @@ class Api::V2::Filters::StatusesController < Api::BaseController
render json: @status_filters, each_serializer: REST::FilterStatusSerializer render json: @status_filters, each_serializer: REST::FilterStatusSerializer
end end
def create def show
@status_filter = current_account.custom_filters.find(params[:filter_id]).statuses.create!(resource_params)
render json: @status_filter, serializer: REST::FilterStatusSerializer render json: @status_filter, serializer: REST::FilterStatusSerializer
end end
def show def create
@status_filter = current_account.custom_filters.find(params[:filter_id]).statuses.create!(resource_params)
render json: @status_filter, serializer: REST::FilterStatusSerializer render json: @status_filter, serializer: REST::FilterStatusSerializer
end end

View File

@ -11,13 +11,13 @@ class Api::V2::FiltersController < Api::BaseController
render json: @filters, each_serializer: REST::FilterSerializer, rules_requested: true render json: @filters, each_serializer: REST::FilterSerializer, rules_requested: true
end end
def create def show
@filter = current_account.custom_filters.create!(resource_params)
render json: @filter, serializer: REST::FilterSerializer, rules_requested: true render json: @filter, serializer: REST::FilterSerializer, rules_requested: true
end end
def show def create
@filter = current_account.custom_filters.create!(resource_params)
render json: @filter, serializer: REST::FilterSerializer, rules_requested: true render json: @filter, serializer: REST::FilterSerializer, rules_requested: true
end end

View File

@ -24,16 +24,16 @@ class Auth::RegistrationsController < Devise::RegistrationsController
super(&:build_invite_request) super(&:build_invite_request)
end end
def destroy
not_found
end
def update def update
super do |resource| super do |resource|
resource.clear_other_sessions(current_session.session_id) if resource.saved_change_to_encrypted_password? resource.clear_other_sessions(current_session.session_id) if resource.saved_change_to_encrypted_password?
end end
end end
def destroy
not_found
end
protected protected
def update_resource(resource, params) def update_resource(resource, params)

View File

@ -17,6 +17,8 @@ class FiltersController < ApplicationController
@filter.keywords.build @filter.keywords.build
end end
def edit; end
def create def create
@filter = current_account.custom_filters.build(resource_params) @filter = current_account.custom_filters.build(resource_params)
@ -27,8 +29,6 @@ class FiltersController < ApplicationController
end end
end end
def edit; end
def update def update
if @filter.update(resource_params) if @filter.update(resource_params)
redirect_to filters_path redirect_to filters_path

View File

@ -8,6 +8,8 @@ class Settings::ApplicationsController < Settings::BaseController
@applications = current_user.applications.order(id: :desc).page(params[:page]) @applications = current_user.applications.order(id: :desc).page(params[:page])
end end
def show; end
def new def new
@application = Doorkeeper::Application.new( @application = Doorkeeper::Application.new(
redirect_uri: Doorkeeper.configuration.native_redirect_uri, redirect_uri: Doorkeeper.configuration.native_redirect_uri,
@ -15,8 +17,6 @@ class Settings::ApplicationsController < Settings::BaseController
) )
end end
def show; end
def create def create
@application = current_user.applications.build(application_params) @application = current_user.applications.build(application_params)

View File

@ -8,9 +8,8 @@ module Settings
before_action :require_otp_enabled before_action :require_otp_enabled
before_action :require_webauthn_enabled, only: [:index, :destroy] before_action :require_webauthn_enabled, only: [:index, :destroy]
def new; end
def index; end def index; end
def new; end
def options def options
current_user.update(webauthn_id: WebAuthn.generate_user_id) unless current_user.webauthn_id current_user.update(webauthn_id: WebAuthn.generate_user_id) unless current_user.webauthn_id