diff options
author | Regis <boudinot.regis@yahoo.com> | 2017-01-25 14:01:44 -0700 |
---|---|---|
committer | Regis <boudinot.regis@yahoo.com> | 2017-01-25 14:01:44 -0700 |
commit | d4b2f4dd8332701c2df0003a213b34abe0163599 (patch) | |
tree | ec868cb769c6656bbcb4b42b65710ab72717598e /app/models/note.rb | |
parent | 5348985015cd0f3163ed7617eb86df63396db16b (diff) | |
parent | 112f9710b65fe830a058366cde1734a2928764de (diff) | |
download | gitlab-ce-pipeline_index_vue_error_state.tar.gz |
Merge branch 'master' into pipeline_index_vue_error_statepipeline_index_vue_error_state
Diffstat (limited to 'app/models/note.rb')
-rw-r--r-- | app/models/note.rb | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/app/models/note.rb b/app/models/note.rb index 0c1b05dabf2..bf090a0438c 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -43,7 +43,8 @@ class Note < ActiveRecord::Base delegate :name, :email, to: :author, prefix: true delegate :title, to: :noteable, allow_nil: true - validates :note, :project, presence: true + validates :note, presence: true + validates :project, presence: true, unless: :for_personal_snippet? # Attachments are deprecated and are handled by Markdown uploader validates :attachment, file_size: { maximum: :max_attachment_size } @@ -53,7 +54,7 @@ class Note < ActiveRecord::Base validates :commit_id, presence: true, if: :for_commit? validates :author, presence: true - validate unless: [:for_commit?, :importing?] do |note| + validate unless: [:for_commit?, :importing?, :for_personal_snippet?] do |note| unless note.noteable.try(:project) == note.project errors.add(:invalid_project, 'Note and noteable project mismatch') end @@ -83,7 +84,7 @@ class Note < ActiveRecord::Base after_initialize :ensure_discussion_id before_validation :nullify_blank_type, :nullify_blank_line_code before_validation :set_discussion_id - after_save :keep_around_commit + after_save :keep_around_commit, unless: :for_personal_snippet? class << self def model_name @@ -165,6 +166,14 @@ class Note < ActiveRecord::Base noteable_type == "Snippet" end + def for_personal_snippet? + noteable.is_a?(PersonalSnippet) + end + + def skip_project_check? + for_personal_snippet? + end + # override to return commits, which are not active record def noteable if for_commit? @@ -220,6 +229,10 @@ class Note < ActiveRecord::Base note.match(Banzai::Filter::EmojiFilter.emoji_pattern)[1] end + def to_ability_name + for_personal_snippet? ? 'personal_snippet' : noteable_type.underscore + end + private def keep_around_commit |