mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 17:31:12 +00:00
Extract upgrade to before action
This commit is contained in:
parent
36f6fb98c3
commit
9326490325
|
@ -7,6 +7,7 @@ module Admin
|
|||
with_options only: :create do
|
||||
before_action :populate_domain_block_from_params
|
||||
before_action :prevent_downgrade
|
||||
before_action :attempt_transparent_upgrade, if: :existing_domain_block
|
||||
end
|
||||
|
||||
PERMITTED_PARAMS = %i(
|
||||
|
@ -43,12 +44,6 @@ module Admin
|
|||
end
|
||||
|
||||
def create
|
||||
# Allow transparently upgrading a domain block
|
||||
if existing_domain_block.present? && existing_domain_block.domain == TagManager.instance.normalize_domain(@domain_block.domain.strip)
|
||||
@domain_block = existing_domain_block
|
||||
@domain_block.assign_attributes(resource_params)
|
||||
end
|
||||
|
||||
# Require explicit confirmation when suspending
|
||||
return render :confirm_suspension if requires_confirmation?
|
||||
|
||||
|
@ -105,6 +100,14 @@ module Admin
|
|||
end
|
||||
end
|
||||
|
||||
def attempt_transparent_upgrade
|
||||
# Allow transparently upgrading a domain block when existing is an exact match for domain value
|
||||
if existing_domain_block.domain == TagManager.instance.normalize_domain(@domain_block.domain.strip)
|
||||
@domain_block = existing_domain_block
|
||||
@domain_block.assign_attributes(resource_params)
|
||||
end
|
||||
end
|
||||
|
||||
def existing_domain_block
|
||||
@existing_domain_block ||= DomainBlock.rule_for(resource_params[:domain]) if resource_params[:domain].present?
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user