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
|
2023-02-02 22:09:45 +08:00
|
|
|
manage_project_tags)
|
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|
|
2023-06-12 18:55:32 +08:00
|
|
|
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|
|
2022-08-31 21:26:10 +08:00
|
|
|
next false unless project.permission_granted?(user, ProjectPermissions::MANAGE)
|
|
|
|
|
|
|
|
experiments = project.experiments
|
|
|
|
unless project.association(:experiments).loaded?
|
|
|
|
experiments = experiments.preload(my_modules: { my_module_status: :my_module_status_implications })
|
|
|
|
end
|
|
|
|
|
|
|
|
experiments.all? do |experiment|
|
|
|
|
experiment.my_modules.all? do |my_module|
|
|
|
|
if my_module.my_module_status
|
|
|
|
my_module.my_module_status.my_module_status_implications.all? { |implication| implication.call(my_module) }
|
|
|
|
else
|
|
|
|
true
|
2020-07-21 22:00:09 +08:00
|
|
|
end
|
|
|
|
end
|
2022-08-31 21:26:10 +08:00
|
|
|
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|
|
2022-10-14 21:51:37 +08:00
|
|
|
project.permission_granted?(user, ProjectPermissions::USERS_MANAGE) ||
|
|
|
|
project.team.permission_granted?(user, TeamPermissions::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-10-28 20:48:28 +08:00
|
|
|
can :read_project_comments do |user, project|
|
|
|
|
project.permission_granted?(user, ProjectPermissions::COMMENTS_READ)
|
|
|
|
end
|
|
|
|
|
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|
|
2021-11-04 20:29:34 +08:00
|
|
|
project.permission_granted?(user, ProjectPermissions::TAGS_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
|
2021-10-04 21:43:50 +08:00
|
|
|
%i(manage_project_comment)
|
|
|
|
.each do |perm|
|
|
|
|
can perm do |_, comment|
|
|
|
|
project = comment.project
|
|
|
|
project.active?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-30 17:32:11 +08:00
|
|
|
can :manage_project_comment do |user, comment|
|
2021-10-04 21:43:50 +08:00
|
|
|
project = comment.project
|
|
|
|
project.permission_granted?(user, ProjectPermissions::COMMENTS_MANAGE) ||
|
|
|
|
((comment.user == user) && project.permission_granted?(user, ProjectPermissions::COMMENTS_MANAGE_OWN))
|
2021-09-30 17:32:11 +08:00
|
|
|
end
|
|
|
|
end
|