Class: WorkItems::RelatedWorkItemLinks::DestroyService

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/work_items/related_work_item_links/destroy_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#params, #project

Instance Method Summary collapse

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(work_item, user, params) ⇒ DestroyService

Returns a new instance of DestroyService.



6
7
8
9
10
11
12
# File 'app/services/work_items/related_work_item_links/destroy_service.rb', line 6

def initialize(work_item, user, params)
  @work_item = work_item
  @current_user = user
  @params = params.dup
  @failed_ids = []
  @removed_ids = []
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/work_items/related_work_item_links/destroy_service.rb', line 14

def execute
  return error(_('No work item found.'), 403) unless can?(current_user, :admin_work_item_link, work_item)
  return error(_('No work item IDs provided.'), 409) if params[:item_ids].empty?

  destroy_links_for(params[:item_ids])

  if removed_ids.any?
    success(message: response_message, items_removed: removed_ids, items_with_errors: failed_ids.flatten)
  else
    error(error_message)
  end
end