Fix validation on notes added to diff files
What does this MR do and why?
- Resolves sub-task 5 of https://gitlab.com/gitlab-org/gitlab/-/issues/411329
- A new-type of comment was added in !121429 (merged), which allowed users to comment on a file in the MR instead of a line
- This MR adds error-handling to that comment-type. Follows up from !122849 (merged)
Screenshots or screen recordings
User Action | Before | After |
---|---|---|
Adding a draft comment | add-comment-now-before | add-comment-now-after |
Adding a comment | add-to-review-after | add-to-review-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
- Enable feature flag
comment_on_files
- Navigate to the
Changes
section and add a comment to a diff file. The tooltip should sayComment on this file
. AddTEST_VALIDATION
as the comment, which should trigger the error message.
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