diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-04-26 20:59:29 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-04-26 20:59:29 +0000 |
commit | 43fb9279ce39d51b1deceb5108560bf37b8d340d (patch) | |
tree | f707f405a5a2f59601c2568514320db5053ed9c4 /app | |
parent | bdc4902fc4a20f6a113e03964a12e1836b01a723 (diff) | |
parent | 4a924a5e4edd009b1fe9df57e04d70d4e3c077b1 (diff) | |
download | gitlab-ce-43fb9279ce39d51b1deceb5108560bf37b8d340d.tar.gz |
Merge branch 'backport-cyclomatic_complexity-fix' into 'master'
Fix Rubocop CyclomaticComplexity offense
See merge request !10941
Diffstat (limited to 'app')
-rw-r--r-- | app/policies/project_policy.rb | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/app/policies/project_policy.rb b/app/policies/project_policy.rb index f8594e29547..5baac9ebe4b 100644 --- a/app/policies/project_policy.rb +++ b/app/policies/project_policy.rb @@ -2,20 +2,13 @@ class ProjectPolicy < BasePolicy def rules team_access!(user) - owner = project.owner == user || - (project.group && project.group.has_owner?(user)) - - owner_access! if user.admin? || owner - team_member_owner_access! if owner + owner_access! if user.admin? || owner? + team_member_owner_access! if owner? if project.public? || (project.internal? && !user.external?) guest_access! public_access! - - if project.request_access_enabled && - !(owner || user.admin? || project.team.member?(user) || project_group_member?(user)) - can! :request_access - end + can! :request_access if access_requestable? end archived_access! if project.archived? @@ -27,6 +20,13 @@ class ProjectPolicy < BasePolicy @subject end + def owner? + return @owner if defined?(@owner) + + @owner = project.owner == user || + (project.group && project.group.has_owner?(user)) + end + def guest_access! can! :read_project can! :read_board @@ -226,14 +226,6 @@ class ProjectPolicy < BasePolicy disabled_features! end - def project_group_member?(user) - project.group && - ( - project.group.members_with_parents.exists?(user_id: user.id) || - project.group.requesters.exists?(user_id: user.id) - ) - end - def block_issues_abilities unless project.feature_available?(:issues, user) cannot! :read_issue if project.default_issues_tracker? @@ -254,6 +246,22 @@ class ProjectPolicy < BasePolicy private + def project_group_member?(user) + project.group && + ( + project.group.members_with_parents.exists?(user_id: user.id) || + project.group.requesters.exists?(user_id: user.id) + ) + end + + def access_requestable? + project.request_access_enabled && + !owner? && + !user.admin? && + !project.team.member?(user) && + !project_group_member?(user) + end + # A base set of abilities for read-only users, which # is then augmented as necessary for anonymous and other # read-only users. |