Refactor read_project/export_project permissions

This commit is contained in:
Jure Grabnar 2018-10-26 10:58:59 +02:00
parent bd5a2a43fd
commit 3903b4a6f2

View file

@ -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|