2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-04-02 06:54:41 -04:00
|
|
|
module Issues
|
2014-10-07 10:09:28 -04:00
|
|
|
class BaseService < ::IssuableBaseService
|
2017-11-21 12:13:07 -05:00
|
|
|
def hook_data(issue, action, old_associations: {})
|
|
|
|
hook_data = issue.to_hook_data(current_user, old_associations: old_associations)
|
2017-09-15 13:08:27 -04:00
|
|
|
hook_data[:object_attributes][:action] = action
|
|
|
|
|
|
|
|
hook_data
|
2015-02-19 00:02:57 -05:00
|
|
|
end
|
|
|
|
|
2017-07-20 10:42:33 -04:00
|
|
|
def reopen_service
|
|
|
|
Issues::ReopenService
|
|
|
|
end
|
|
|
|
|
|
|
|
def close_service
|
|
|
|
Issues::CloseService
|
|
|
|
end
|
|
|
|
|
2015-02-19 00:02:57 -05:00
|
|
|
private
|
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
def create_assignee_note(issue, old_assignees)
|
|
|
|
SystemNoteService.change_issue_assignees(
|
|
|
|
issue, issue.project, current_user, old_assignees)
|
|
|
|
end
|
|
|
|
|
2017-11-21 12:13:07 -05:00
|
|
|
def execute_hooks(issue, action = 'open', old_associations: {})
|
|
|
|
issue_data = hook_data(issue, action, old_associations: old_associations)
|
2016-08-30 18:11:46 -04:00
|
|
|
hooks_scope = issue.confidential? ? :confidential_issue_hooks : :issue_hooks
|
|
|
|
issue.project.execute_hooks(issue_data, hooks_scope)
|
|
|
|
issue.project.execute_services(issue_data, hooks_scope)
|
2014-04-02 06:54:41 -04:00
|
|
|
end
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-05-04 08:11:15 -04:00
|
|
|
def filter_assignee(issuable)
|
|
|
|
return if params[:assignee_ids].blank?
|
|
|
|
|
2018-07-05 07:34:42 -04:00
|
|
|
unless issuable.allows_multiple_assignees?
|
|
|
|
params[:assignee_ids] = params[:assignee_ids].take(1)
|
|
|
|
end
|
2017-05-05 11:55:16 -04:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
assignee_ids = params[:assignee_ids].select { |assignee_id| assignee_can_read?(issuable, assignee_id) }
|
|
|
|
|
|
|
|
if params[:assignee_ids].map(&:to_s) == [IssuableFinder::NONE]
|
|
|
|
params[:assignee_ids] = []
|
|
|
|
elsif assignee_ids.any?
|
|
|
|
params[:assignee_ids] = assignee_ids
|
|
|
|
else
|
|
|
|
params.delete(:assignee_ids)
|
|
|
|
end
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-11-09 14:34:21 -05:00
|
|
|
|
|
|
|
def update_project_counter_caches?(issue)
|
|
|
|
super || issue.confidential_changed?
|
|
|
|
end
|
2014-04-02 06:54:41 -04:00
|
|
|
end
|
|
|
|
end
|