mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-06 09:51:24 +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
|
with_options only: :create do
|
||||||
before_action :populate_domain_block_from_params
|
before_action :populate_domain_block_from_params
|
||||||
before_action :prevent_downgrade
|
before_action :prevent_downgrade
|
||||||
|
before_action :attempt_transparent_upgrade, if: :existing_domain_block
|
||||||
end
|
end
|
||||||
|
|
||||||
PERMITTED_PARAMS = %i(
|
PERMITTED_PARAMS = %i(
|
||||||
|
@ -43,12 +44,6 @@ module Admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
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
|
# Require explicit confirmation when suspending
|
||||||
return render :confirm_suspension if requires_confirmation?
|
return render :confirm_suspension if requires_confirmation?
|
||||||
|
|
||||||
|
@ -105,6 +100,14 @@ module Admin
|
||||||
end
|
end
|
||||||
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
|
def existing_domain_block
|
||||||
@existing_domain_block ||= DomainBlock.rule_for(resource_params[:domain]) if resource_params[:domain].present?
|
@existing_domain_block ||= DomainBlock.rule_for(resource_params[:domain]) if resource_params[:domain].present?
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user