2014-09-02 18:07:02 +05:30
|
|
|
module Notes
|
|
|
|
class CreateService < BaseService
|
|
|
|
def execute
|
|
|
|
note = project.notes.new(params)
|
|
|
|
note.author = current_user
|
|
|
|
note.system = false
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
return unless valid_project?(note)
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
if note.save
|
2016-04-02 18:10:28 +05:30
|
|
|
# Finish the harder work in the background
|
|
|
|
NewNoteWorker.perform_in(2.seconds, note.id, params)
|
|
|
|
TodoService.new.new_note(note, current_user)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
note
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def valid_project?(note)
|
|
|
|
return false unless project
|
|
|
|
return true if note.for_commit?
|
|
|
|
|
|
|
|
note.noteable.try(:project) == project
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|