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

106 lines
3.3 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
module Issues
class UpdateService < Issues::BaseService
2017-08-17 22:00:37 +05:30
include SpamCheckService
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)
2018-03-17 18:26:18 +05:30
move_issue_to_new_project(issue) || update(issue)
2015-11-26 14:37:03 +05:30
end
2014-09-02 18:07:02 +05:30
2017-08-17 22:00:37 +05:30
def before_update(issue)
spam_check(issue, current_user)
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)
notification_service.reassigned_issue(issue, current_user, old_assignees)
2018-03-17 18:26:18 +05:30
todo_service.reassigned_issue(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')
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?
notification_service.relabeled_issue(issue, added_labels, current_user)
end
2016-09-13 17:45:13 +05:30
added_mentions = issue.mentioned_users - old_mentioned_users
2017-08-17 22:00:37 +05:30
2016-09-13 17:45:13 +05:30
if added_mentions.present?
notification_service.new_mentions_in_issue(issue, added_mentions, current_user)
end
2015-12-23 02:04:40 +05:30
end
2014-09-02 18:07:02 +05:30
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)
2017-08-17 22:00:37 +05:30
issue.move_between(issue_before, issue_after)
end
2017-09-10 17:25:29 +05:30
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
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
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
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