2017-03-10 01:29:11 +00:00
|
|
|
module Notes
|
|
|
|
class BuildService < BaseService
|
|
|
|
def execute
|
|
|
|
in_reply_to_discussion_id = params.delete(:in_reply_to_discussion_id)
|
2017-03-21 15:28:47 +00:00
|
|
|
new_discussion = params.delete(:new_discussion)
|
|
|
|
|
2017-03-10 01:29:11 +00:00
|
|
|
if project && in_reply_to_discussion_id.present?
|
2017-03-31 01:33:45 +00:00
|
|
|
discussion = project.notes.find_discussion(in_reply_to_discussion_id)
|
2017-03-10 01:29:11 +00: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)
|
2017-03-21 15:28:47 +00:00
|
|
|
elsif new_discussion
|
2017-03-17 19:25:52 +00:00
|
|
|
# TODO: Remove when we use a selectbox instead of a submit button
|
|
|
|
params[:type] = DiscussionNote.name
|
2017-03-10 01:29:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
note = Note.new(params)
|
|
|
|
note.project = project
|
|
|
|
note.author = current_user
|
|
|
|
|
|
|
|
note
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|