Skip to content

Fix validation on notes added to diff files

Hinam Mehra requested to merge 411329-fix-diff-file-note-validation into master

What does this MR do and why?

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

  1. Create a Merge Request with at least 1 file change and 1 image file added.
  2. Add a validator to the Note and DraftNote 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
  1. Enable feature flag comment_on_files
  2. Navigate to the Changes section and add a comment to a diff file. The tooltip should say Comment on this file. Add TEST_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.

Related to #411329

Edited by Hinam Mehra

Merge request reports