diff options
Diffstat (limited to 'app/services/notes/update_service.rb')
-rw-r--r-- | app/services/notes/update_service.rb | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/app/services/notes/update_service.rb b/app/services/notes/update_service.rb index e04891da7f8..52940281018 100644 --- a/app/services/notes/update_service.rb +++ b/app/services/notes/update_service.rb @@ -9,6 +9,8 @@ module Notes note.assign_attributes(params) + return note unless note.valid? + track_note_edit_usage_for_issues(note) if note.for_issue? track_note_edit_usage_for_merge_requests(note) if note.for_merge_request? @@ -23,10 +25,7 @@ module Notes note.note = content end - if note.note_changed? - note.assign_attributes(last_edited_at: Time.current, updated_by: current_user) - end - + update_note(note, only_commands) note.save unless only_commands || note.for_personal_snippet? @@ -45,7 +44,6 @@ module Notes if only_commands delete_note(note, message) - note = nil else note.save end @@ -56,6 +54,13 @@ module Notes private + def update_note(note, only_commands) + return unless note.note_changed? + + note.assign_attributes(last_edited_at: Time.current, updated_by: current_user) + note.check_for_spam(action: :update, user: current_user) unless only_commands + end + def delete_note(note, message) # We must add the error after we call #save because errors are reset # when #save is called |