From d6b11dafd37e78c12c982c42f274928293cdfa53 Mon Sep 17 00:00:00 2001 From: Jarka Kadlecova Date: Thu, 5 Jan 2017 14:36:06 +0100 Subject: Support notes without project --- app/models/note.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index 0c1b05dabf2..cbf1d0adda7 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,10 @@ class Note < ActiveRecord::Base noteable_type == "Snippet" end + def for_personal_snippet? + noteable_type == "Snippet" && noteable.type == 'PersonalSnippet' + end + # override to return commits, which are not active record def noteable if for_commit? -- cgit v1.2.1 From 0c350b79395d6712c7c4fee649cdbd77aa4052cc Mon Sep 17 00:00:00 2001 From: Jarka Kadlecova Date: Fri, 20 Jan 2017 11:28:40 +0100 Subject: address comments --- app/models/note.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index cbf1d0adda7..bf090a0438c 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -167,7 +167,11 @@ class Note < ActiveRecord::Base end def for_personal_snippet? - noteable_type == "Snippet" && noteable.type == 'PersonalSnippet' + noteable.is_a?(PersonalSnippet) + end + + def skip_project_check? + for_personal_snippet? end # override to return commits, which are not active record @@ -225,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 -- cgit v1.2.1