diff options
author | alpaca-tc <alpaca-tc@alpaca.tc> | 2017-05-07 00:03:34 +0900 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-05-06 17:03:34 +0200 |
commit | a0b19517915f6c6ae839b036ba466aacd46a9485 (patch) | |
tree | 6d8a666d6cc4a034ebc199fd617ad4e6499c1bad | |
parent | 2d45794956d3a3041b041c857891202933ea39f7 (diff) |
Refactor domain_blocks_controller (#2843)
* Set domain_block by before_action * Cast value with ActiveRecord::Type * Batch update
-rw-r--r-- | app/controllers/admin/domain_blocks_controller.rb | 13 | ||||
-rw-r--r-- | app/services/block_domain_service.rb | 2 | ||||
-rw-r--r-- | app/services/unblock_domain_service.rb | 6 |
3 files changed, 13 insertions, 8 deletions
diff --git a/app/controllers/admin/domain_blocks_controller.rb b/app/controllers/admin/domain_blocks_controller.rb index 10396899b..1ab620e03 100644 --- a/app/controllers/admin/domain_blocks_controller.rb +++ b/app/controllers/admin/domain_blocks_controller.rb @@ -2,6 +2,8 @@ module Admin class DomainBlocksController < BaseController + before_action :set_domain_block, only: [:show, :destroy] + def index @domain_blocks = DomainBlock.page(params[:page]) end @@ -21,24 +23,25 @@ module Admin end end - def show - @domain_block = DomainBlock.find(params[:id]) - end + def show; end def destroy - @domain_block = DomainBlock.find(params[:id]) UnblockDomainService.new.call(@domain_block, retroactive_unblock?) redirect_to admin_domain_blocks_path, notice: I18n.t('admin.domain_blocks.destroyed_msg') end private + def set_domain_block + @domain_block = DomainBlock.find(params[:id]) + end + def resource_params params.require(:domain_block).permit(:domain, :severity, :reject_media, :retroactive) end def retroactive_unblock? - resource_params[:retroactive] == '1' + ActiveRecord::Type.lookup(:boolean).cast(resource_params[:retroactive]) end end end diff --git a/app/services/block_domain_service.rb b/app/services/block_domain_service.rb index d15a1e83c..3f8f5b385 100644 --- a/app/services/block_domain_service.rb +++ b/app/services/block_domain_service.rb @@ -19,7 +19,7 @@ class BlockDomainService < BaseService end def silence_accounts! - blocked_domain_accounts.update_all(silenced: true) + blocked_domain_accounts.in_batches.update_all(silenced: true) clear_media! if domain_block.reject_media? end diff --git a/app/services/unblock_domain_service.rb b/app/services/unblock_domain_service.rb index 9794e439d..77460f76b 100644 --- a/app/services/unblock_domain_service.rb +++ b/app/services/unblock_domain_service.rb @@ -3,10 +3,12 @@ class UnblockDomainService < BaseService def call(domain_block, retroactive) if retroactive + accounts = Account.where(domain: domain_block.domain).in_batches + if domain_block.silence? - Account.where(domain: domain_block.domain).update_all(silenced: false) + accounts.update_all(silenced: false) else - Account.where(domain: domain_block.domain).update_all(suspended: false) + accounts.update_all(suspended: false) end end |