about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorsdukhovni <dukhovni@mit.edu>2017-07-24 22:26:55 +1000
committerEugen Rochko <eugen@zeonfederated.com>2017-07-24 14:26:55 +0200
commit06d905f415f38ed8e13f6390a93a0db928dee6a7 (patch)
treec2a3ff6b6d0ebc34c7c38e5dc35e312d294ec1af /app
parent0ad41be0f314a9ee16cd167620e0636859349cc8 (diff)
Allow domain blocks that only reject media without silencing or suspending (#4325)
* Allow domain blocks to reject media without silencing or suspending

* Fix typo

* Hide 'Reject media' button when superfluous, instead of disabling it

* Properly hide 'reject media' checkbox on page load if needed

This may happen when resubmitting the domain block form after an error.

* Don't ask whether undoing a media-only block should be retroactive

* Rename :media_only block to :noop

* Display :noop block as None in frontend, allow blocks that do nothing

* Remove 'coding' line auto-added by emacs
Diffstat (limited to 'app')
-rw-r--r--app/models/domain_block.rb2
-rw-r--r--app/services/block_domain_service.rb4
-rw-r--r--app/services/unblock_domain_service.rb2
-rw-r--r--app/views/admin/domain_blocks/show.html.haml19
4 files changed, 16 insertions, 11 deletions
diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb
index f26e8183f..aea8919af 100644
--- a/app/models/domain_block.rb
+++ b/app/models/domain_block.rb
@@ -12,7 +12,7 @@
 #
 
 class DomainBlock < ApplicationRecord
-  enum severity: [:silence, :suspend]
+  enum severity: [:silence, :suspend, :noop]
 
   attr_accessor :retroactive
 
diff --git a/app/services/block_domain_service.rb b/app/services/block_domain_service.rb
index e8b3a870d..a6b3c4cdb 100644
--- a/app/services/block_domain_service.rb
+++ b/app/services/block_domain_service.rb
@@ -11,16 +11,16 @@ class BlockDomainService < BaseService
   private
 
   def process_domain_block
+    clear_media! if domain_block.reject_media?
     if domain_block.silence?
       silence_accounts!
-    else
+    elsif domain_block.suspend?
       suspend_accounts!
     end
   end
 
   def silence_accounts!
     blocked_domain_accounts.in_batches.update_all(silenced: true)
-    clear_media! if domain_block.reject_media?
   end
 
   def clear_media!
diff --git a/app/services/unblock_domain_service.rb b/app/services/unblock_domain_service.rb
index 169d2f781..946b6d465 100644
--- a/app/services/unblock_domain_service.rb
+++ b/app/services/unblock_domain_service.rb
@@ -10,7 +10,7 @@ class UnblockDomainService < BaseService
   end
 
   def process_retroactive_updates
-    blocked_accounts.in_batches.update_all(update_options)
+    blocked_accounts.in_batches.update_all(update_options) unless domain_block.noop?
   end
 
   def blocked_accounts
diff --git a/app/views/admin/domain_blocks/show.html.haml b/app/views/admin/domain_blocks/show.html.haml
index 70dfef9b2..ea1929d44 100644
--- a/app/views/admin/domain_blocks/show.html.haml
+++ b/app/views/admin/domain_blocks/show.html.haml
@@ -3,13 +3,18 @@
 
 = simple_form_for @domain_block, url: admin_domain_block_path(@domain_block), method: :delete do |f|
 
-  = f.input :retroactive,
-    as: :boolean,
-    wrapper: :with_label,
-    label: t(".retroactive.#{@domain_block.severity}"),
-    hint: t(:affected_accounts,
-      scope: [:admin, :domain_blocks, :show],
-      count: @domain_block.accounts_count)
+  - if (@domain_block.noop?)
+    = f.input :retroactive,
+      as: :hidden,
+      input_html: { :value => "0" }
+  - else
+    = f.input :retroactive,
+      as: :boolean,
+      wrapper: :with_label,
+      label: t(".retroactive.#{@domain_block.severity}"),
+      hint: t(:affected_accounts,
+        scope: [:admin, :domain_blocks, :show],
+        count: @domain_block.accounts_count)
 
   .actions
     = f.button :button, t('.undo'), type: :submit