diff options
author | Mark Chao <mchao@gitlab.com> | 2019-11-14 05:50:19 +0300 |
---|---|---|
committer | Mark Chao <mchao@gitlab.com> | 2019-11-25 04:06:22 +0300 |
commit | 2858452b68380e3434832cc790a2a9c8b566efcd (patch) | |
tree | 082ea67e2729f9815e5b22641ec2d69efe51064d /app/models/project_feature.rb | |
parent | 03c0e9ba65c400e8e391b24c341cd51b01590fad (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/models/project_feature.rb')
-rw-r--r-- | app/models/project_feature.rb | 13 |
1 files changed, 8 insertions, 5 deletions
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) |