2018-01-20 01:25:58 +08:00
|
|
|
Canaid::Permissions.register_for(Project) do
|
|
|
|
can :read_project do |user, project|
|
2018-02-03 01:19:03 +08:00
|
|
|
user.is_member_of_project?(project) ||
|
2018-01-20 01:25:58 +08:00
|
|
|
user.is_admin_of_team?(project.team) ||
|
|
|
|
(project.visible? && user.is_member_of_team?(project.team))
|
|
|
|
end
|
|
|
|
|
2018-02-03 01:48:55 +08:00
|
|
|
can :manage_project do |user, project|
|
2018-01-20 01:25:58 +08:00
|
|
|
user.is_owner_of_project?(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :restore_project do |user, project|
|
2018-02-03 01:48:55 +08:00
|
|
|
can_manage_project?(user, project) && project.archived?
|
2018-01-20 01:25:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
can :create_experiment do |user, project|
|
|
|
|
user.is_user_or_higher_of_project?(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :add_comment_to_project do |user, project|
|
|
|
|
user.is_technician_or_higher_of_project?(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
# create, update, delete
|
|
|
|
can :manage_tags do |user, project|
|
|
|
|
user.is_user_or_higher_of_project?(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
# create, update, delete
|
|
|
|
can :manage_reports do |user, project|
|
|
|
|
user.is_technician_or_higher_of_project?(project)
|
|
|
|
end
|
2018-02-03 01:19:03 +08:00
|
|
|
|
2018-02-03 01:48:55 +08:00
|
|
|
%i(read_project
|
|
|
|
update_project
|
|
|
|
create_experiment
|
|
|
|
add_comment_to_project
|
|
|
|
manage_tags
|
|
|
|
manage_reports)
|
2018-02-03 01:19:03 +08:00
|
|
|
.each do |perm|
|
|
|
|
can perm do |_, project|
|
|
|
|
project.active?
|
|
|
|
end
|
|
|
|
end
|
2018-01-20 01:25:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
Canaid::Permissions.register_for(Comment) do
|
|
|
|
can :update_or_delete_project_comment do |user, comment|
|
|
|
|
comment.project.present? && (comment.user == user ||
|
2018-01-22 23:25:53 +08:00
|
|
|
user.is_owner_of_project?(project))
|
2018-01-20 01:25:58 +08:00
|
|
|
end
|
2018-02-03 01:19:03 +08:00
|
|
|
|
2018-02-03 01:48:55 +08:00
|
|
|
%i(update_or_delete_project_comment)
|
2018-02-03 01:19:03 +08:00
|
|
|
.each do |perm|
|
2018-02-03 01:48:55 +08:00
|
|
|
can perm do |_, comment|
|
|
|
|
comment.project.active?
|
2018-02-03 01:19:03 +08:00
|
|
|
end
|
|
|
|
end
|
2018-01-20 01:25:58 +08:00
|
|
|
end
|