Skip to content

Display errors in UI correctly when updating notes

Hinam Mehra requested to merge 411329-validate-notes-when-updating into master

What does this MR do and why?

  • Resolves sub-task 2 of https://gitlab.com/gitlab-org/gitlab/-/issues/411329
  • Displays error in the UI when there is an error updating a note and don't update the note.
  • Currently, it doesn't display any error if the note-text is invalid, and it even updates the note-html in the database.

Screenshots or screen recordings

Type Before After
Issue updating-comment-issue-before updating-comment-issue-after
Merge Request updating-comment-mr-before updating-comment-mr-after
Snippet (uses deprecated_notes.js) updating-comment-snippet-before updating-comment-snippet-after
Commit (uses deprecated_notes.js) updating-comment-commit-before updating-comment-commit-after

How to set up and validate locally

  1. Add a validator to the app/models/note.rb model since we don't have an easy validation we can test against in the Note model.
validate :test_ui_validation, on: [:create, :update]

def test_ui_validation
    if note.include? 'TEST_VALIDATION'
      self.errors.add(:base,  _('it failed validation'))
    end
end
  1. Navigate to any issue / merge request / snippet / commit and add a note with TEST_VALIDATION.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #411329

Edited by Hinam Mehra

Merge request reports

Loading