diff options
author | Thibaut Girka <thib@sitedethib.com> | 2019-05-04 16:37:26 +0200 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2019-05-04 16:37:26 +0200 |
commit | 33c80e07838d932efc6214cb1642cefaeb624b67 (patch) | |
tree | 51cae2d9096888cc27ae38ec4b0ceceb1853bb73 /app/controllers/admin | |
parent | 2c2f649200ba5b742ba9d17ac5ba553c752b59aa (diff) | |
parent | c88d9e524b02cba895de9bdb7cba0e29e37703d5 (diff) |
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts: - app/models/media_attachment.rb
Diffstat (limited to 'app/controllers/admin')
-rw-r--r-- | app/controllers/admin/domain_blocks_controller.rb | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/app/controllers/admin/domain_blocks_controller.rb b/app/controllers/admin/domain_blocks_controller.rb index 5f307ddee..dd3f83389 100644 --- a/app/controllers/admin/domain_blocks_controller.rb +++ b/app/controllers/admin/domain_blocks_controller.rb @@ -13,13 +13,25 @@ module Admin authorize :domain_block, :create? @domain_block = DomainBlock.new(resource_params) + existing_domain_block = resource_params[:domain].present? ? DomainBlock.find_by(domain: resource_params[:domain]) : nil - if @domain_block.save - DomainBlockWorker.perform_async(@domain_block.id) - log_action :create, @domain_block - redirect_to admin_instances_path(limited: '1'), notice: I18n.t('admin.domain_blocks.created_msg') - else + if existing_domain_block.present? && !@domain_block.stricter_than?(existing_domain_block) + @domain_block.save + flash[:alert] = I18n.t('admin.domain_blocks.existing_domain_block_html', name: existing_domain_block.domain, unblock_url: admin_domain_block_path(existing_domain_block)).html_safe # rubocop:disable Rails/OutputSafety + @domain_block.errors[:domain].clear render :new + else + if existing_domain_block.present? + @domain_block = existing_domain_block + @domain_block.update(resource_params) + end + if @domain_block.save + DomainBlockWorker.perform_async(@domain_block.id) + log_action :create, @domain_block + redirect_to admin_instances_path(limited: '1'), notice: I18n.t('admin.domain_blocks.created_msg') + else + render :new + end end end |