summaryrefslogtreecommitdiff
path: root/app/policies
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-04-26 16:27:41 +0200
committerRémy Coutable <remy@rymai.me>2017-04-26 16:38:34 +0200
commit4a924a5e4edd009b1fe9df57e04d70d4e3c077b1 (patch)
tree605065312db67f9e6bf3e62252d320df22664adc /app/policies
parentc7df97710b5b519c8ea1b5bb92ae17579082d3f4 (diff)
downloadgitlab-ce-4a924a5e4edd009b1fe9df57e04d70d4e3c077b1.tar.gz
Fix Rubocop CyclomaticComplexity offensebackport-cyclomatic_complexity-fix
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'app/policies')
-rw-r--r--app/policies/project_policy.rb44
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.