Class: WorkItems::BulkUpdateService
- Inherits:
-
Object
- Object
- WorkItems::BulkUpdateService
- Defined in:
- app/services/work_items/bulk_update_service.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(parent:, current_user:, work_item_ids:, widget_params: {}) ⇒ BulkUpdateService
constructor
A new instance of BulkUpdateService.
Constructor Details
#initialize(parent:, current_user:, work_item_ids:, widget_params: {}) ⇒ BulkUpdateService
Returns a new instance of BulkUpdateService.
5 6 7 8 9 10 |
# File 'app/services/work_items/bulk_update_service.rb', line 5 def initialize(parent:, current_user:, work_item_ids:, widget_params: {}) @parent = parent @work_item_ids = work_item_ids @current_user = current_user @widget_params = .dup end |
Instance Method Details
#execute ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/services/work_items/bulk_update_service.rb', line 12 def execute unless @current_user.can?(:"read_#{@parent.to_ability_name}", @parent) return ServiceResponse.error(message: "User can't read parent", reason: :authorization) end updated_work_items = scoped_work_items.find_each(batch_size: 100) # rubocop:disable CodeReuse/ActiveRecord -- Implementation would be identical in model .filter_map do |work_item| next unless @current_user.can?(:update_work_item, work_item) update_result = WorkItems::UpdateService.new( container: work_item.resource_parent, widget_params: @widget_params, current_user: @current_user ).execute(work_item) work_item if update_result[:status] == :success end ServiceResponse.success(payload: { updated_work_item_count: updated_work_items.count }) end |