Fix validation in UI when adding comments in MR diff
What does this MR do and why?
- Resolves sub-task 3 of https://gitlab.com/gitlab-org/gitlab/-/issues/411329
- Displays error in the UI when there is an error adding a note in an MR diff - be it a draft note or a normal note
- Currently, we don't have that many validations on notes but this is a blocker to start displaying if the comment being posted by a user is considered spam.
- This MR only addresses adding comments, updating comments will be addressed in a separate MR
Screenshots or screen recordings
User Action | Before | After |
---|---|---|
Adding draft comment | adding-draft-comment-before | adding-draft-comment-after |
Replying with a draft comment | replying-draft-comment-before | replying-draft-comment-after |
Adding a comment | adding-comment-before | adding-comment-after |
Adding a comment (image diff) | adding-comment-image-diff-before | adding-comment-image-diff-after |
How to set up and validate locally
- Create a Merge Request with at least 1 file change and 1 image file added.
- Add a validator to the
Note
andDraftNote
since we don't have a lot of validations for comments.
# Add it to class DraftNote < ApplicationRecord and
# class Note < ApplicationRecord in models/
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
- Try to add comment
TEST_VALIDATION
in theChanges
section.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #411329
Edited by Hinam Mehra