summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-04-26 09:35:03 +0200
committerRobert Speicher <rspeicher@gmail.com>2016-05-29 15:03:00 -0400
commit87c44b0e91959439014fb8c923f3febc039d1cd0 (patch)
tree611948b49b8dd1af79600ad75dfa9d6994e95fce
parentc31a296c94c48d865ce3171ccea9c48aa691466c (diff)
downloadgitlab-ce-87c44b0e91959439014fb8c923f3febc039d1cd0.tar.gz
Improve note validation for project mismatch
-rw-r--r--app/models/note.rb12
1 files changed, 7 insertions, 5 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index 8743b5eb472..02a98a37117 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -29,13 +29,15 @@ class Note < ActiveRecord::Base
# Attachments are deprecated and are handled by Markdown uploader
validates :attachment, file_size: { maximum: :max_attachment_size }
- validates :noteable_id, presence: true, if: ->(n) { n.noteable_type.present? && n.noteable_type != 'Commit' }
- validates :commit_id, presence: true, if: ->(n) { n.noteable_type == 'Commit' }
+ validates :noteable_id, presence: true, unless: :for_commit?
+ validates :commit_id, presence: true, if: :for_commit?
validates :author, presence: true
- validate do |note|
- unless note.noteable.project == project
- errors.add(:invalid_project, 'Note and noteable project mismatch')
+ with_options unless: :for_commit? do
+ validate do |note|
+ unless note.noteable.try(:project) == project
+ errors.add(:invalid_project, 'Note and noteable project mismatch')
+ end
end
end