summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorKerri Miller <kerrizor@kerrizor.com>2019-10-25 07:46:40 -0500
committerKerri Miller <kerrizor@kerrizor.com>2019-11-20 07:39:50 -0800
commitdebb36496b4805beae28262fbb24a692018178e2 (patch)
treeedfda5416822ccba914b2b6a1db627a6832f6655 /app
parent9d3adee84c62861b87b7891d15005d4a950d9c5a (diff)
downloadgitlab-ce-debb36496b4805beae28262fbb24a692018178e2.tar.gz
Restrict branches visible to guests in Issue feed
Notes related to branch creation should not be shown in an issue's activity feed when the user doesn't have access to :download_code.
Diffstat (limited to 'app')
-rw-r--r--app/models/note.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index a0c5414aede..8bb4df9a20b 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -37,6 +37,10 @@ class Note < ApplicationRecord
redact_field :note
+ TYPES_RESTRICTED_BY_ABILITY = {
+ branch: :download_code
+ }.freeze
+
# Aliases to make application_helper#edited_time_ago_with_tooltip helper work properly with notes.
# See https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/10392/diffs#note_28719102
alias_attribute :last_edited_at, :updated_at
@@ -330,7 +334,7 @@ class Note < ApplicationRecord
end
def visible_for?(user)
- !cross_reference_not_visible_for?(user)
+ !cross_reference_not_visible_for?(user) && system_note_viewable_by?(user)
end
def award_emoji?
@@ -483,6 +487,15 @@ class Note < ApplicationRecord
private
+ def system_note_viewable_by?(user)
+ return true unless system_note_metadata
+
+ restriction = TYPES_RESTRICTED_BY_ABILITY[system_note_metadata.action.to_sym]
+ return Ability.allowed?(user, restriction, project) if restriction
+
+ true
+ end
+
def keep_around_commit
project.repository.keep_around(self.commit_id)
end