2018-07-17 12:50:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-09 20:29:11 -05:00
|
|
|
module Notes
|
2017-04-04 18:27:23 -04:00
|
|
|
class BuildService < ::BaseService
|
2017-03-09 20:29:11 -05:00
|
|
|
def execute
|
2018-09-23 17:15:29 -04:00
|
|
|
should_resolve = false
|
2017-03-09 20:29:11 -05:00
|
|
|
in_reply_to_discussion_id = params.delete(:in_reply_to_discussion_id)
|
2017-03-21 11:28:47 -04:00
|
|
|
|
2017-05-03 04:48:01 -04:00
|
|
|
if in_reply_to_discussion_id.present?
|
|
|
|
discussion = find_discussion(in_reply_to_discussion_id)
|
2017-03-09 20:29:11 -05:00
|
|
|
|
|
|
|
unless discussion
|
|
|
|
note = Note.new
|
|
|
|
note.errors.add(:base, 'Discussion to reply to cannot be found')
|
|
|
|
return note
|
|
|
|
end
|
|
|
|
|
|
|
|
params.merge!(discussion.reply_attributes)
|
2018-09-23 17:15:29 -04:00
|
|
|
should_resolve = discussion.resolved?
|
2017-03-09 20:29:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
note = Note.new(params)
|
|
|
|
note.project = project
|
|
|
|
note.author = current_user
|
|
|
|
|
2018-09-23 17:15:29 -04:00
|
|
|
if should_resolve
|
|
|
|
note.resolve_without_save(current_user)
|
|
|
|
end
|
|
|
|
|
2017-03-09 20:29:11 -05:00
|
|
|
note
|
|
|
|
end
|
2017-05-03 04:48:01 -04:00
|
|
|
|
|
|
|
def find_discussion(discussion_id)
|
|
|
|
if project
|
|
|
|
project.notes.find_discussion(discussion_id)
|
|
|
|
else
|
|
|
|
discussion = Note.find_discussion(discussion_id)
|
|
|
|
noteable = discussion.noteable
|
|
|
|
|
2018-02-28 02:48:23 -05:00
|
|
|
return nil unless noteable_without_project?(noteable)
|
2017-05-03 04:48:01 -04:00
|
|
|
|
|
|
|
discussion
|
|
|
|
end
|
|
|
|
end
|
2018-02-28 02:48:23 -05:00
|
|
|
|
|
|
|
def noteable_without_project?(noteable)
|
|
|
|
return true if noteable.is_a?(PersonalSnippet) && can?(current_user, :comment_personal_snippet, noteable)
|
|
|
|
|
|
|
|
false
|
|
|
|
end
|
2017-03-09 20:29:11 -05:00
|
|
|
end
|
|
|
|
end
|