2021-02-09 17:45:12 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-01-20 01:25:58 +08:00
|
|
|
Canaid::Permissions.register_for(Project) do
|
2021-02-09 17:45:12 +08:00
|
|
|
include PermissionExtends
|
|
|
|
|
2018-03-04 21:19:17 +08:00
|
|
|
# Project must be active for all the specified permissions
|
2020-12-13 05:46:30 +08:00
|
|
|
%i(manage_project
|
2018-03-04 21:19:17 +08:00
|
|
|
archive_project
|
2021-09-07 17:27:52 +08:00
|
|
|
create_project_experiments
|
|
|
|
create_project_comments
|
|
|
|
manage_project_tags
|
|
|
|
manage_project_users)
|
2018-03-04 21:19:17 +08:00
|
|
|
.each do |perm|
|
|
|
|
can perm do |_, project|
|
|
|
|
project.active?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-26 16:58:59 +08:00
|
|
|
%i(read_project
|
|
|
|
export_project)
|
|
|
|
.each do |perm|
|
|
|
|
can perm do |user, project|
|
2021-08-31 20:21:02 +08:00
|
|
|
user.is_admin_of_team?(project.team) || project.permission_granted?(user, ProjectPermissions::READ)
|
2018-10-26 16:58:59 +08:00
|
|
|
end
|
|
|
|
end
|
2018-01-20 01:25:58 +08:00
|
|
|
|
2018-02-03 01:48:55 +08:00
|
|
|
can :manage_project do |user, project|
|
2021-02-09 17:45:12 +08:00
|
|
|
project.permission_granted?(user, ProjectPermissions::MANAGE) &&
|
2020-09-25 16:14:57 +08:00
|
|
|
MyModule.joins(experiment: :project)
|
|
|
|
.where(experiments: { project: project })
|
|
|
|
.preload(my_module_status: :my_module_status_implications)
|
|
|
|
.all? do |my_module|
|
2020-07-21 22:00:09 +08:00
|
|
|
if my_module.my_module_status
|
|
|
|
my_module.my_module_status.my_module_status_implications.all? { |implication| implication.call(my_module) }
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
2018-01-20 01:25:58 +08:00
|
|
|
end
|
|
|
|
|
2021-09-30 17:32:11 +08:00
|
|
|
can :read_project_users do |user, project|
|
|
|
|
project.permission_granted?(user, ProjectPermissions::USERS_READ)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :read_project_activities do |user, project|
|
|
|
|
project.permission_granted?(user, ProjectPermissions::ACTIVITIES_READ)
|
|
|
|
end
|
|
|
|
|
2021-09-07 17:27:52 +08:00
|
|
|
can :manage_project_users do |user, project|
|
|
|
|
project.permission_granted?(user, ProjectPermissions::USERS_MANAGE)
|
2021-06-19 23:17:57 +08:00
|
|
|
end
|
|
|
|
|
2018-02-03 04:07:24 +08:00
|
|
|
can :archive_project do |user, project|
|
2021-09-07 17:27:52 +08:00
|
|
|
project.permission_granted?(user, ProjectPermissions::MANAGE)
|
2018-02-03 04:07:24 +08:00
|
|
|
end
|
|
|
|
|
2018-01-20 01:25:58 +08:00
|
|
|
can :restore_project do |user, project|
|
2021-09-07 17:27:52 +08:00
|
|
|
project.archived? && project.permission_granted?(user, ProjectPermissions::MANAGE)
|
2018-01-20 01:25:58 +08:00
|
|
|
end
|
|
|
|
|
2021-09-07 17:27:52 +08:00
|
|
|
can :create_project_experiments do |user, project|
|
|
|
|
project.permission_granted?(user, ProjectPermissions::EXPERIMENTS_CREATE)
|
|
|
|
end
|
2021-05-08 16:33:43 +08:00
|
|
|
|
2021-09-07 17:27:52 +08:00
|
|
|
can :create_project_comments do |user, project|
|
|
|
|
project.permission_granted?(user, ProjectPermissions::COMMENTS_CREATE)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :manage_project_tags do |user, project|
|
|
|
|
project.permission_granted?(user, ProjectPermissions::MANAGE)
|
2021-02-12 01:27:16 +08:00
|
|
|
end
|
2021-09-14 17:08:35 +08:00
|
|
|
|
|
|
|
can :manage_project_my_modules do |user, project|
|
2021-09-17 16:41:28 +08:00
|
|
|
project.permission_granted?(user, ProjectPermissions::TASKS_MANAGE)
|
2021-09-14 17:08:35 +08:00
|
|
|
end
|
2021-02-12 01:27:16 +08:00
|
|
|
end
|
2021-09-30 17:32:11 +08:00
|
|
|
|
|
|
|
Canaid::Permissions.register_for(ProjectComment) do
|
|
|
|
can :manage_project_comment do |user, comment|
|
|
|
|
comment.project.permission_granted?(user, ProjectPermissions::COMMENTS_MANAGE)
|
|
|
|
end
|
|
|
|
end
|