summaryrefslogtreecommitdiff
path: root/app/models/note.rb
diff options
context:
space:
mode:
authorZJ van de Weg <zegerjan@gitlab.com>2016-05-30 14:46:23 +0200
committerZ.J. van de Weg <zegerjan@gitlab.com>2016-05-30 18:54:08 +0200
commitcbd7801b3d1d435a95ec70032c5acc9df33b0337 (patch)
tree7bd367bf31690e4a6b0115d238cf2c312c9fb2ab /app/models/note.rb
parentf99b38c9d5dab11677b2680a671c1a66fb69283b (diff)
parent2485bd7bbf9686f993d2a417943feff5c7d5b6f3 (diff)
downloadgitlab-ce-cbd7801b3d1d435a95ec70032c5acc9df33b0337.tar.gz
Merge branch 'master' into awardables
Diffstat (limited to 'app/models/note.rb')
-rw-r--r--app/models/note.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index 2b1a3f90697..bbe5545dc80 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -28,10 +28,17 @@ 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_type, presence: true
+ validates :noteable_id, presence: true, unless: :for_commit?
+ validates :commit_id, presence: true, if: :for_commit?
validates :author, presence: true
+ validate unless: :for_commit? do |note|
+ unless note.noteable.try(:project) == note.project
+ errors.add(:invalid_project, 'Note and noteable project mismatch')
+ end
+ end
+
mount_uploader :attachment, AttachmentUploader
# Scopes