diff options
author | Jarka Kadlecova <jarka@gitlab.com> | 2017-01-05 14:36:06 +0100 |
---|---|---|
committer | Jarka Kadlecova <jarka@gitlab.com> | 2017-01-18 18:38:17 -0500 |
commit | d6b11dafd37e78c12c982c42f274928293cdfa53 (patch) | |
tree | e20c62bc3b11b77e366bce2251146d5f5ec86e0c /app/models | |
parent | 270dc22658424ee7f279db99e56c6fc69acd3eb7 (diff) | |
download | gitlab-ce-d6b11dafd37e78c12c982c42f274928293cdfa53.tar.gz |
Support notes without project
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ability.rb | 11 | ||||
-rw-r--r-- | app/models/concerns/participable.rb | 6 | ||||
-rw-r--r-- | app/models/note.rb | 11 |
3 files changed, 24 insertions, 4 deletions
diff --git a/app/models/ability.rb b/app/models/ability.rb index fa8f8bc3a5f..5bad5c17747 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -22,6 +22,17 @@ class Ability end end + # Given a list of users and a snippet this method returns the users that can + # read the given snippet. + def users_that_can_read_personal_snippet(users, snippet) + case snippet.visibility_level + when Snippet::INTERNAL, Snippet::PUBLIC + users + when Snippet::PRIVATE + users.select { |user| snippet.author == user } + end + end + # Returns an Array of Issues that can be read by the given user. # # issues - The issues to reduce down to those readable by the user. diff --git a/app/models/concerns/participable.rb b/app/models/concerns/participable.rb index 70740c76e43..5d8a223fc21 100644 --- a/app/models/concerns/participable.rb +++ b/app/models/concerns/participable.rb @@ -96,6 +96,10 @@ module Participable participants.merge(ext.users) - Ability.users_that_can_read_project(participants.to_a, project) + if self.is_a?(PersonalSnippet) + Ability.users_that_can_read_personal_snippet(participants.to_a, self) + else + Ability.users_that_can_read_project(participants.to_a, project) + end end end 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? |