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)
|
2017-08-17 22:00:37 +05:30
|
|
|
handle_move_between_iids(issue)
|
|
|
|
filter_spam_check_params
|
2015-12-23 02:04:40 +05:30
|
|
|
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)
|
|
|
|
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-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
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
if issue.previous_changes.include?('milestone_id')
|
|
|
|
create_milestone_note(issue)
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
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)
|
2016-04-02 18:10:28 +05:30
|
|
|
todo_service.reassigned_issue(issue, current_user)
|
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
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
def reopen_service
|
|
|
|
Issues::ReopenService
|
|
|
|
end
|
|
|
|
|
|
|
|
def close_service
|
|
|
|
Issues::CloseService
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def handle_move_between_iids(issue)
|
|
|
|
return unless params[:move_between_iids]
|
|
|
|
|
|
|
|
after_iid, before_iid = params.delete(:move_between_iids)
|
|
|
|
|
|
|
|
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)
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
private
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def get_issue_if_allowed(project, iid)
|
|
|
|
issue = project.issues.find_by(iid: iid)
|
|
|
|
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
|