debian-mirror-gitlab/app/services/notes/build_service.rb

44 lines
1.1 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Notes
class BuildService < ::BaseService
def execute
2018-12-05 23:21:45 +05:30
should_resolve = false
2017-08-17 22:00:37 +05:30
in_reply_to_discussion_id = params.delete(:in_reply_to_discussion_id)
if in_reply_to_discussion_id.present?
discussion = find_discussion(in_reply_to_discussion_id)
2019-02-02 18:00:53 +05:30
unless discussion && can?(current_user, :create_note, discussion.noteable)
2017-08-17 22:00:37 +05:30
note = Note.new
2020-01-01 13:55:28 +05:30
note.errors.add(:base, _('Discussion to reply to cannot be found'))
2017-08-17 22:00:37 +05:30
return note
end
2019-03-02 22:35:43 +05:30
discussion = discussion.convert_to_discussion! if discussion.can_convert_to_discussion?
2017-08-17 22:00:37 +05:30
params.merge!(discussion.reply_attributes)
2018-12-05 23:21:45 +05:30
should_resolve = discussion.resolved?
2017-08-17 22:00:37 +05:30
end
note = Note.new(params)
note.project = project
note.author = current_user
2018-12-05 23:21:45 +05:30
if should_resolve
note.resolve_without_save(current_user)
end
2017-08-17 22:00:37 +05:30
note
end
def find_discussion(discussion_id)
if project
project.notes.find_discussion(discussion_id)
else
2019-02-02 18:00:53 +05:30
Note.find_discussion(discussion_id)
2017-08-17 22:00:37 +05:30
end
end
end
end