gitlab-org--gitlab-foss/app/services/issues/update_service.rb

83 lines
2.2 KiB
Ruby
Raw Normal View History

module Issues
class UpdateService < Issues::BaseService
2017-02-14 19:07:11 +00:00
include SpamCheckService
def execute(issue)
2017-02-01 18:41:01 +00:00
handle_move_between_iids(issue)
2017-02-14 19:07:11 +00:00
filter_spam_check_params
update(issue)
end
2017-02-14 19:07:11 +00:00
def before_update(issue)
spam_check(issue, current_user)
end
def handle_changes(issue, old_labels: [], old_mentioned_users: [])
if has_changes?(issue, old_labels: old_labels)
2016-02-20 13:59:59 +00:00
todo_service.mark_pending_todos_as_done(issue, current_user)
end
if issue.previous_changes.include?('title') ||
issue.previous_changes.include?('description')
2016-02-20 13:59:59 +00:00
todo_service.update_issue(issue, current_user)
end
if issue.previous_changes.include?('milestone_id')
create_milestone_note(issue)
end
if issue.previous_changes.include?('assignee_id')
create_assignee_note(issue)
notification_service.reassigned_issue(issue, current_user)
2016-02-20 13:59:59 +00:00
todo_service.reassigned_issue(issue, current_user)
end
if issue.previous_changes.include?('confidential')
create_confidentiality_note(issue)
end
added_labels = issue.labels - old_labels
2017-03-02 16:09:48 +00:00
if added_labels.present?
notification_service.relabeled_issue(issue, added_labels, current_user)
end
added_mentions = issue.mentioned_users - old_mentioned_users
2017-03-02 16:09:48 +00:00
if added_mentions.present?
notification_service.new_mentions_in_issue(issue, added_mentions, current_user)
end
end
def reopen_service
Issues::ReopenService
end
def close_service
Issues::CloseService
end
2017-02-01 18:41:01 +00:00
def handle_move_between_iids(issue)
2017-03-07 11:42:17 +00:00
return unless params[:move_between_iids]
2017-03-02 16:09:48 +00:00
2017-03-07 11:42:17 +00:00
after_iid, before_iid = params.delete(:move_between_iids)
2017-03-02 16:09:48 +00:00
issue_before = get_issue_if_allowed(issue.project, before_iid) if before_iid
issue_after = get_issue_if_allowed(issue.project, after_iid) if after_iid
issue.move_between(issue_before, issue_after)
2017-02-01 18:41:01 +00:00
end
private
2017-03-02 16:09:48 +00:00
def get_issue_if_allowed(project, iid)
issue = project.issues.find_by(iid: iid)
issue if can?(current_user, :update_issue, issue)
end
def create_confidentiality_note(issue)
SystemNoteService.change_issue_confidentiality(issue, issue.project, current_user)
end
end
end