debian-mirror-gitlab/app/services/issues/update_service.rb

167 lines
5.4 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
module Issues
class UpdateService < Issues::BaseService
2020-03-09 13:42:32 +05:30
include SpamCheckMethods
2017-08-17 22:00:37 +05:30
2014-09-02 18:07:02 +05:30
def execute(issue)
2018-03-17 18:26:18 +05:30
handle_move_between_ids(issue)
2017-08-17 22:00:37 +05:30
filter_spam_check_params
2017-09-10 17:25:29 +05:30
change_issue_duplicate(issue)
2019-03-02 22:35:43 +05:30
move_issue_to_new_project(issue) || update_task_event(issue) || update(issue)
2015-11-26 14:37:03 +05:30
end
2014-09-02 18:07:02 +05:30
2019-02-15 15:39:39 +05:30
def update(issue)
create_merge_request_from_quick_action
super
end
2019-09-30 21:07:59 +05:30
def before_update(issue, skip_spam_check: false)
spam_check(issue, current_user) unless skip_spam_check
2017-08-17 22:00:37 +05:30
end
def handle_changes(issue, options)
2018-03-17 18:26:18 +05:30
old_associations = options.fetch(:old_associations, {})
old_labels = old_associations.fetch(:labels, [])
old_mentioned_users = old_associations.fetch(:mentioned_users, [])
old_assignees = old_associations.fetch(:assignees, [])
2017-08-17 22:00:37 +05:30
if has_changes?(issue, old_labels: old_labels, old_assignees: old_assignees)
2016-04-02 18:10:28 +05:30
todo_service.mark_pending_todos_as_done(issue, current_user)
end
if issue.previous_changes.include?('title') ||
2017-08-17 22:00:37 +05:30
issue.previous_changes.include?('description')
todo_service.update_issue(issue, current_user, old_mentioned_users)
2016-04-02 18:10:28 +05:30
end
2017-08-17 22:00:37 +05:30
if issue.assignees != old_assignees
create_assignee_note(issue, old_assignees)
2018-10-15 14:42:47 +05:30
notification_service.async.reassigned_issue(issue, current_user, old_assignees)
2019-07-31 22:56:46 +05:30
todo_service.reassigned_issuable(issue, current_user, old_assignees)
2014-09-02 18:07:02 +05:30
end
2016-06-02 11:05:42 +05:30
if issue.previous_changes.include?('confidential')
2018-11-18 11:00:15 +05:30
# don't enqueue immediately to prevent todos removal in case of a mistake
2019-01-03 12:48:30 +05:30
TodosDestroyer::ConfidentialIssueWorker.perform_in(Todo::WAIT_FOR_DELETE, issue.id) if issue.confidential?
2016-06-02 11:05:42 +05:30
create_confidentiality_note(issue)
end
added_labels = issue.labels - old_labels
2017-08-17 22:00:37 +05:30
2016-06-02 11:05:42 +05:30
if added_labels.present?
2018-10-15 14:42:47 +05:30
notification_service.async.relabeled_issue(issue, added_labels, current_user)
2016-06-02 11:05:42 +05:30
end
2016-09-13 17:45:13 +05:30
2018-12-13 13:39:08 +05:30
handle_milestone_change(issue)
2019-12-21 20:55:43 +05:30
added_mentions = issue.mentioned_users(current_user) - old_mentioned_users
2017-08-17 22:00:37 +05:30
2016-09-13 17:45:13 +05:30
if added_mentions.present?
2018-10-15 14:42:47 +05:30
notification_service.async.new_mentions_in_issue(issue, added_mentions, current_user)
2016-09-13 17:45:13 +05:30
end
2015-12-23 02:04:40 +05:30
end
2014-09-02 18:07:02 +05:30
2019-03-02 22:35:43 +05:30
def handle_task_changes(issuable)
todo_service.mark_pending_todos_as_done(issuable, current_user)
todo_service.update_issue(issuable, current_user)
end
2018-03-17 18:26:18 +05:30
def handle_move_between_ids(issue)
return unless params[:move_between_ids]
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
after_id, before_id = params.delete(:move_between_ids)
2018-05-01 15:08:00 +05:30
board_group_id = params.delete(:board_group_id)
2017-08-17 22:00:37 +05:30
2018-05-01 15:08:00 +05:30
issue_before = get_issue_if_allowed(before_id, board_group_id)
issue_after = get_issue_if_allowed(after_id, board_group_id)
2019-09-30 21:07:59 +05:30
raise ActiveRecord::RecordNotFound unless issue_before || issue_after
2017-08-17 22:00:37 +05:30
issue.move_between(issue_before, issue_after)
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2017-09-10 17:25:29 +05:30
def change_issue_duplicate(issue)
canonical_issue_id = params.delete(:canonical_issue_id)
2019-03-02 22:35:43 +05:30
return unless canonical_issue_id
2017-09-10 17:25:29 +05:30
canonical_issue = IssuesFinder.new(current_user).find_by(id: canonical_issue_id)
if canonical_issue
Issues::DuplicateService.new(project, current_user).execute(issue, canonical_issue)
end
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
def move_issue_to_new_project(issue)
target_project = params.delete(:target_project)
return unless target_project &&
issue.can_move?(current_user, target_project) &&
target_project != issue.project
update(issue)
Issues::MoveService.new(project, current_user).execute(issue, target_project)
end
2016-06-02 11:05:42 +05:30
private
2019-02-15 15:39:39 +05:30
def create_merge_request_from_quick_action
create_merge_request_params = params.delete(:create_merge_request)
return unless create_merge_request_params
MergeRequests::CreateFromIssueService.new(project, current_user, create_merge_request_params).execute
end
2018-12-13 13:39:08 +05:30
def handle_milestone_change(issue)
return unless issue.previous_changes.include?('milestone_id')
2020-04-08 14:13:33 +05:30
invalidate_milestone_issue_counters(issue)
send_milestone_change_notification(issue)
end
def invalidate_milestone_issue_counters(issue)
issue.previous_changes['milestone_id'].each do |milestone_id|
next unless milestone_id
milestone = Milestone.find_by_id(milestone_id)
delete_milestone_closed_issue_counter_cache(milestone)
delete_milestone_total_issue_counter_cache(milestone)
end
end
def send_milestone_change_notification(issue)
return if skip_milestone_email
2018-12-13 13:39:08 +05:30
if issue.milestone.nil?
notification_service.async.removed_milestone_issue(issue, current_user)
else
notification_service.async.changed_milestone_issue(issue, issue.milestone, current_user)
end
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2018-05-01 15:08:00 +05:30
def get_issue_if_allowed(id, board_group_id = nil)
return unless id
issue =
if board_group_id
2018-05-09 12:01:36 +05:30
IssuesFinder.new(current_user, group_id: board_group_id, include_subgroups: true).find_by(id: id)
2018-05-01 15:08:00 +05:30
else
project.issues.find(id)
end
2017-08-17 22:00:37 +05:30
issue if can?(current_user, :update_issue, issue)
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2017-08-17 22:00:37 +05:30
2016-06-02 11:05:42 +05:30
def create_confidentiality_note(issue)
SystemNoteService.change_issue_confidentiality(issue, issue.project, current_user)
end
2014-09-02 18:07:02 +05:30
end
end
2019-12-04 20:38:33 +05:30
Issues::UpdateService.prepend_if_ee('EE::Issues::UpdateService')