Commit 87c44b0e authored by Grzegorz Bizon's avatar Grzegorz Bizon Committed by Robert Speicher

Improve note validation for project mismatch

parent c31a296c
...@@ -29,13 +29,15 @@ class Note < ActiveRecord::Base ...@@ -29,13 +29,15 @@ class Note < ActiveRecord::Base
# Attachments are deprecated and are handled by Markdown uploader # Attachments are deprecated and are handled by Markdown uploader
validates :attachment, file_size: { maximum: :max_attachment_size } validates :attachment, file_size: { maximum: :max_attachment_size }
validates :noteable_id, presence: true, if: ->(n) { n.noteable_type.present? && n.noteable_type != 'Commit' } validates :noteable_id, presence: true, unless: :for_commit?
validates :commit_id, presence: true, if: ->(n) { n.noteable_type == 'Commit' } validates :commit_id, presence: true, if: :for_commit?
validates :author, presence: true validates :author, presence: true
validate do |note| with_options unless: :for_commit? do
unless note.noteable.project == project validate do |note|
errors.add(:invalid_project, 'Note and noteable project mismatch') unless note.noteable.try(:project) == project
errors.add(:invalid_project, 'Note and noteable project mismatch')
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment