From 3903b4a6f245a938b547fa53a97e06f55fe75ffe Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Fri, 26 Oct 2018 10:58:59 +0200 Subject: [PATCH] Refactor read_project/export_project permissions --- app/permissions/project.rb | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/app/permissions/project.rb b/app/permissions/project.rb index 91881a985..8dbde5ace 100644 --- a/app/permissions/project.rb +++ b/app/permissions/project.rb @@ -12,13 +12,27 @@ Canaid::Permissions.register_for(Project) do end end + %i(read_project + export_project) + .each do |perm| + can perm do |user, project| + user.is_member_of_project?(project) || + user.is_admin_of_team?(project.team) || + (project.visible? && user.is_member_of_team?(project.team)) + end + end # project: read, read activities, read comments, read users, read archive, # read notifications # reports: read - can :read_project do |user, project| - user.is_member_of_project?(project) || - user.is_admin_of_team?(project.team) || - (project.visible? && user.is_member_of_team?(project.team)) + can :read_project do |_, _| + # Already checked by the wrapper + true + end + + # team: export projects + can :export_project do |_, _| + # Already checked by the wrapper + true end # project: update/delete, assign/reassign/unassign users @@ -38,13 +52,6 @@ Canaid::Permissions.register_for(Project) do user.is_owner_of_project?(project) && project.archived? end - # team: export projects - can :export_project do |user, project| - user.is_technician_or_higher_of_project?(project) || - user.viewer?(project) || - user.is_admin_of_team?(project.team) || - (project.visible? && user.is_member_of_team?(project.team)) - end # experiment: create can :create_experiments do |user, project|