Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorMark Chao <mchao@gitlab.com>2019-11-14 05:50:19 +0300
committerDylan Griffith <dyl.griffith@gmail.com>2019-11-15 12:58:41 +0300
commitb577a0e3e259faa722bab3ebe66efcb6546e9b0b (patch)
treea89c072d9b2141bd7596a8787aa67a63f0e61c0b /app
parentf44727bba9a87e86634112a2a155f312cc543f7d (diff)
Internalize private project minimum access level
Some feature allows GUEST to access only if project is not private. This method returns access level when targeting private projects.
Diffstat (limited to 'app')
-rw-r--r--app/models/project.rb12
-rw-r--r--app/models/project_feature.rb13
2 files changed, 13 insertions, 12 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 624a4c5d38f..b0d305e80d6 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -516,13 +516,11 @@ class Project < ApplicationRecord
# This scope returns projects where user has access to both the project and the feature.
def self.filter_by_feature_visibility(feature, user)
- scope = with_feature_available_for_user(feature, user)
-
- if ProjectFeature.guest_allowed_on_private_project?(feature)
- scope.public_or_visible_to_user(user)
- else
- scope.public_or_visible_to_user(user, Gitlab::Access::REPORTER)
- end
+ with_feature_available_for_user(feature, user)
+ .public_or_visible_to_user(
+ user,
+ ProjectFeature.required_minimum_access_level_for_private_project(feature)
+ )
end
scope :active, -> { joins(:issues, :notes, :merge_requests).order('issues.created_at, notes.created_at, merge_requests.created_at DESC') }
diff --git a/app/models/project_feature.rb b/app/models/project_feature.rb
index 564e531c320..caa65d32c86 100644
--- a/app/models/project_feature.rb
+++ b/app/models/project_feature.rb
@@ -24,7 +24,7 @@ class ProjectFeature < ApplicationRecord
FEATURES = %i(issues merge_requests wiki snippets builds repository pages).freeze
PRIVATE_FEATURES_MIN_ACCESS_LEVEL = { merge_requests: Gitlab::Access::REPORTER }.freeze
- FEATURES_ALLOWED_BY_GUEST_ON_PRIVATE_PROJECT = %i(issues wiki).freeze
+ PRIVATE_FEATURES_MIN_ACCESS_LEVEL_FOR_PRIVATE_PROJECT = { repository: Gitlab::Access::REPORTER }.freeze
STRING_OPTIONS = HashWithIndifferentAccess.new({
'disabled' => DISABLED,
'private' => PRIVATE,
@@ -46,16 +46,19 @@ class ProjectFeature < ApplicationRecord
"#{table}.#{attribute}"
end
- def guest_allowed_on_private_project?(feature)
+ def required_minimum_access_level(feature)
feature = ensure_feature!(feature)
- FEATURES_ALLOWED_BY_GUEST_ON_PRIVATE_PROJECT.include?(feature)
+ PRIVATE_FEATURES_MIN_ACCESS_LEVEL.fetch(feature, Gitlab::Access::GUEST)
end
- def required_minimum_access_level(feature)
+ # Guest users can perform certain features on public and internal projects, but not private projects.
+ def required_minimum_access_level_for_private_project(feature)
feature = ensure_feature!(feature)
- PRIVATE_FEATURES_MIN_ACCESS_LEVEL.fetch(feature, Gitlab::Access::GUEST)
+ PRIVATE_FEATURES_MIN_ACCESS_LEVEL_FOR_PRIVATE_PROJECT.fetch(feature) do
+ required_minimum_access_level(feature)
+ end
end
def access_level_from_str(level)