2014-04-02 06:54:41 -04:00
|
|
|
module Issues
|
2014-04-02 12:55:23 -04:00
|
|
|
class UpdateService < Issues::BaseService
|
2017-02-14 14:07:11 -05:00
|
|
|
include SpamCheckService
|
|
|
|
|
2014-04-02 06:54:41 -04:00
|
|
|
def execute(issue)
|
2017-08-28 17:56:49 -04:00
|
|
|
handle_move_between_ids(issue)
|
2017-02-14 14:07:11 -05:00
|
|
|
filter_spam_check_params
|
2017-07-20 10:42:33 -04:00
|
|
|
change_issue_duplicate(issue)
|
2017-08-09 11:37:06 -04:00
|
|
|
move_issue_to_new_project(issue) || update(issue)
|
2014-04-02 06:54:41 -04:00
|
|
|
end
|
2015-11-12 18:13:45 -05:00
|
|
|
|
2017-02-14 14:07:11 -05:00
|
|
|
def before_update(issue)
|
|
|
|
spam_check(issue, current_user)
|
|
|
|
end
|
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
def handle_changes(issue, options)
|
|
|
|
old_labels = options[:old_labels] || []
|
|
|
|
old_mentioned_users = options[:old_mentioned_users] || []
|
|
|
|
old_assignees = options[:old_assignees] || []
|
|
|
|
|
|
|
|
if has_changes?(issue, old_labels: old_labels, old_assignees: old_assignees)
|
2016-02-20 08:59:59 -05:00
|
|
|
todo_service.mark_pending_todos_as_done(issue, current_user)
|
2016-02-18 16:12:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if issue.previous_changes.include?('title') ||
|
2016-12-15 17:14:20 -05:00
|
|
|
issue.previous_changes.include?('description')
|
2017-03-28 02:25:43 -04:00
|
|
|
todo_service.update_issue(issue, current_user, old_mentioned_users)
|
2016-02-15 21:26:33 -05:00
|
|
|
end
|
|
|
|
|
2015-11-12 18:13:45 -05:00
|
|
|
if issue.previous_changes.include?('milestone_id')
|
|
|
|
create_milestone_note(issue)
|
|
|
|
end
|
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
if issue.assignees != old_assignees
|
|
|
|
create_assignee_note(issue, old_assignees)
|
|
|
|
notification_service.reassigned_issue(issue, current_user, old_assignees)
|
2016-02-20 08:59:59 -05:00
|
|
|
todo_service.reassigned_issue(issue, current_user)
|
2015-11-12 18:13:45 -05:00
|
|
|
end
|
2016-02-12 09:58:39 -05:00
|
|
|
|
2016-04-20 18:41:11 -04:00
|
|
|
if issue.previous_changes.include?('confidential')
|
|
|
|
create_confidentiality_note(issue)
|
|
|
|
end
|
|
|
|
|
2016-03-01 11:33:13 -05:00
|
|
|
added_labels = issue.labels - old_labels
|
2017-03-02 11:09:48 -05:00
|
|
|
|
2016-03-01 11:33:13 -05:00
|
|
|
if added_labels.present?
|
|
|
|
notification_service.relabeled_issue(issue, added_labels, current_user)
|
2016-02-12 09:58:39 -05:00
|
|
|
end
|
2016-08-12 17:54:32 -04:00
|
|
|
|
|
|
|
added_mentions = issue.mentioned_users - old_mentioned_users
|
2017-03-02 11:09:48 -05:00
|
|
|
|
2016-08-12 17:54:32 -04:00
|
|
|
if added_mentions.present?
|
|
|
|
notification_service.new_mentions_in_issue(issue, added_mentions, current_user)
|
|
|
|
end
|
2015-11-12 18:13:45 -05:00
|
|
|
end
|
2015-11-17 06:42:43 -05:00
|
|
|
|
2017-08-31 15:34:57 -04:00
|
|
|
def handle_move_between_ids(issue)
|
2017-08-28 17:56:49 -04:00
|
|
|
return unless params[:move_between_ids]
|
2017-03-02 11:09:48 -05:00
|
|
|
|
2017-08-28 17:56:49 -04:00
|
|
|
after_id, before_id = params.delete(:move_between_ids)
|
2017-03-02 11:09:48 -05:00
|
|
|
|
2017-08-28 17:56:49 -04:00
|
|
|
issue_before = get_issue_if_allowed(issue.project, before_id) if before_id
|
|
|
|
issue_after = get_issue_if_allowed(issue.project, after_id) if after_id
|
2017-03-02 11:09:48 -05:00
|
|
|
|
|
|
|
issue.move_between(issue_before, issue_after)
|
2017-02-01 13:41:01 -05:00
|
|
|
end
|
|
|
|
|
2017-07-20 10:42:33 -04:00
|
|
|
def change_issue_duplicate(issue)
|
|
|
|
canonical_issue_id = params.delete(:canonical_issue_id)
|
|
|
|
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
|
|
|
|
|
2017-08-09 11:37:06 -04:00
|
|
|
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-05-18 13:56:13 -04:00
|
|
|
private
|
|
|
|
|
2017-08-28 17:56:49 -04:00
|
|
|
def get_issue_if_allowed(project, id)
|
|
|
|
issue = project.issues.find(id)
|
2017-03-02 11:09:48 -05:00
|
|
|
issue if can?(current_user, :update_issue, issue)
|
|
|
|
end
|
|
|
|
|
2016-05-18 13:56:13 -04:00
|
|
|
def create_confidentiality_note(issue)
|
|
|
|
SystemNoteService.change_issue_confidentiality(issue, issue.project, current_user)
|
|
|
|
end
|
2014-04-02 06:54:41 -04:00
|
|
|
end
|
|
|
|
end
|