2018-07-17 12:50:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 11:12:13 -04:00
|
|
|
module Notes
|
|
|
|
class UpdateService < BaseService
|
2015-07-30 08:45:54 -04:00
|
|
|
def execute(note)
|
|
|
|
return note unless note.editable?
|
2014-09-02 11:12:13 -04:00
|
|
|
|
2017-03-28 02:25:43 -04:00
|
|
|
old_mentioned_users = note.mentioned_users.to_a
|
|
|
|
|
2018-07-02 06:43:06 -04:00
|
|
|
note.update(params.merge(updated_by: current_user))
|
2015-10-28 08:09:51 -04:00
|
|
|
note.create_new_cross_references!(current_user)
|
2014-09-02 11:12:13 -04:00
|
|
|
|
2016-02-16 17:21:24 -05:00
|
|
|
if note.previous_changes.include?('note')
|
2017-03-28 02:25:43 -04:00
|
|
|
TodoService.new.update_note(note, current_user, old_mentioned_users)
|
2016-02-16 17:21:24 -05:00
|
|
|
end
|
|
|
|
|
2018-12-13 14:17:19 -05:00
|
|
|
if note.supports_suggestion?
|
|
|
|
Suggestion.transaction do
|
|
|
|
note.suggestions.delete_all
|
|
|
|
Suggestions::CreateService.new(note).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
# We need to refresh the previous suggestions call cache
|
|
|
|
# in order to get the new records.
|
|
|
|
note.reload
|
|
|
|
end
|
|
|
|
|
2014-09-02 11:12:13 -04:00
|
|
|
note
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|