2017-11-27 18:24:41 +08:00
|
|
|
Canaid::Permissions.register_for(Team) do
|
2020-08-31 22:29:23 +08:00
|
|
|
# team: leave, read users, read projects
|
2019-07-17 22:00:49 +08:00
|
|
|
# read protocols
|
2018-02-16 01:46:29 +08:00
|
|
|
#
|
2017-11-27 18:24:41 +08:00
|
|
|
can :read_team do |user, team|
|
2022-05-19 19:46:03 +08:00
|
|
|
user.member_of_team?(team)
|
2017-11-27 18:24:41 +08:00
|
|
|
end
|
2017-11-28 22:41:52 +08:00
|
|
|
|
2018-02-16 01:46:29 +08:00
|
|
|
# team: update
|
2022-05-19 19:46:03 +08:00
|
|
|
can :manage_team do |user, team|
|
|
|
|
team.permission_granted?(user, TeamPermissions::MANAGE)
|
2017-12-04 18:12:35 +08:00
|
|
|
end
|
|
|
|
|
2018-02-16 01:46:29 +08:00
|
|
|
# team: assign/unassing user, change user role
|
2018-01-05 22:15:50 +08:00
|
|
|
can :manage_team_users do |user, team|
|
2022-05-19 19:46:03 +08:00
|
|
|
team.permission_granted?(user, TeamPermissions::USERS_MANAGE)
|
2017-11-28 22:41:52 +08:00
|
|
|
end
|
2017-12-04 20:07:23 +08:00
|
|
|
|
2020-02-27 00:25:38 +08:00
|
|
|
# team: invite new users to the team
|
2022-05-19 19:46:03 +08:00
|
|
|
can :invite_team_users do |user, team|
|
|
|
|
can_manage_team_users?(user, team)
|
2020-02-27 00:25:38 +08:00
|
|
|
end
|
|
|
|
|
2020-12-01 16:59:08 +08:00
|
|
|
# project_folder: create
|
|
|
|
can :create_project_folders do |user, team|
|
2022-05-19 19:46:03 +08:00
|
|
|
can_manage_team?(user, team)
|
2020-12-01 16:59:08 +08:00
|
|
|
end
|
|
|
|
|
2018-02-16 01:46:29 +08:00
|
|
|
# project: create
|
2018-01-05 22:15:50 +08:00
|
|
|
can :create_projects do |user, team|
|
2022-05-19 19:46:03 +08:00
|
|
|
team.permission_granted?(user, TeamPermissions::PROJECTS_CREATE)
|
2017-12-08 00:08:41 +08:00
|
|
|
end
|
|
|
|
|
2018-02-16 01:46:29 +08:00
|
|
|
# protocol in repository: create, import
|
2018-01-05 22:15:50 +08:00
|
|
|
can :create_protocols_in_repository do |user, team|
|
2022-05-19 19:46:03 +08:00
|
|
|
team.permission_granted?(user, TeamPermissions::PROTOCOLS_CREATE)
|
2017-12-04 20:07:23 +08:00
|
|
|
end
|
2017-12-04 23:45:23 +08:00
|
|
|
|
2018-02-16 19:03:44 +08:00
|
|
|
# repository: create, copy
|
2018-01-05 22:15:50 +08:00
|
|
|
can :create_repositories do |user, team|
|
2020-03-05 22:26:25 +08:00
|
|
|
within_limits = Repository.within_global_limits?
|
|
|
|
within_limits = Repository.within_team_limits?(team) if within_limits
|
2022-05-19 19:46:03 +08:00
|
|
|
within_limits && team.permission_granted?(user, TeamPermissions::INVENTORIES_CREATE)
|
2017-12-12 22:35:43 +08:00
|
|
|
end
|
2018-04-18 22:47:52 +08:00
|
|
|
|
2022-05-23 19:32:15 +08:00
|
|
|
can :create_reports do |user, team|
|
|
|
|
team.permission_granted?(user, TeamPermissions::REPORTS_CREATE)
|
2018-04-18 22:47:52 +08:00
|
|
|
end
|
2022-07-26 19:52:40 +08:00
|
|
|
|
|
|
|
can :view_label_templates do |user, team|
|
2022-09-14 21:13:13 +08:00
|
|
|
team.permission_granted?(user, TeamPermissions::LABEL_TEMPLATES_READ)
|
2022-07-26 19:52:40 +08:00
|
|
|
end
|
2022-07-27 16:10:32 +08:00
|
|
|
|
|
|
|
can :manage_label_templates do |user, team|
|
2022-09-14 21:13:13 +08:00
|
|
|
team.permission_granted?(user, TeamPermissions::LABEL_TEMPLATES_MANAGE)
|
2022-07-27 16:10:32 +08:00
|
|
|
end
|
2017-11-28 22:41:52 +08:00
|
|
|
end
|
|
|
|
|
2021-10-01 16:47:32 +08:00
|
|
|
Canaid::Permissions.register_for(ProjectFolder) do
|
|
|
|
# ProjectFolder: delete
|
|
|
|
can :delete_project_folder do |user, project_folder|
|
2022-10-06 01:35:56 +08:00
|
|
|
can_manage_team?(user, project_folder.team) &&
|
2021-10-01 16:47:32 +08:00
|
|
|
project_folder.projects.none? &&
|
|
|
|
project_folder.project_folders.none?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-06 02:51:44 +08:00
|
|
|
Canaid::Permissions.register_for(Protocol) do
|
2023-01-25 04:17:50 +08:00
|
|
|
%i(manage_protocol_in_repository
|
2023-03-15 18:14:20 +08:00
|
|
|
manage_protocol_draft_in_repository
|
2023-02-28 20:48:29 +08:00
|
|
|
clone_protocol_in_repository
|
|
|
|
publish_protocol_in_repository
|
|
|
|
delete_protocol_draft_in_repository
|
2023-03-21 17:59:31 +08:00
|
|
|
save_protocol_version_as_draft)
|
2022-12-09 19:44:41 +08:00
|
|
|
.each do |perm|
|
|
|
|
can perm do |_, protocol|
|
|
|
|
protocol.active?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-16 01:46:29 +08:00
|
|
|
# protocol in repository: read, export, read step, read/download step asset
|
2017-12-06 02:51:44 +08:00
|
|
|
can :read_protocol_in_repository do |user, protocol|
|
2022-12-09 19:44:41 +08:00
|
|
|
protocol.permission_granted?(user, ProtocolPermissions::READ)
|
2017-12-06 02:51:44 +08:00
|
|
|
end
|
2017-12-07 00:23:08 +08:00
|
|
|
|
2018-02-16 01:46:29 +08:00
|
|
|
# protocol in repository: update, create/update/delete/reorder step,
|
2018-02-16 19:03:44 +08:00
|
|
|
# toggle private/public visibility, archive
|
2018-02-16 01:46:29 +08:00
|
|
|
can :manage_protocol_in_repository do |user, protocol|
|
2023-02-13 16:50:39 +08:00
|
|
|
protocol.in_repository_draft? &&
|
2023-01-17 22:44:16 +08:00
|
|
|
protocol.permission_granted?(user, ProtocolPermissions::MANAGE)
|
2022-12-09 19:44:41 +08:00
|
|
|
end
|
|
|
|
|
2023-01-26 22:41:41 +08:00
|
|
|
can :manage_protocol_draft_in_repository do |user, protocol|
|
2023-03-15 18:14:20 +08:00
|
|
|
protocol.in_repository_draft? &&
|
|
|
|
protocol.permission_granted?(user, ProtocolPermissions::MANAGE_DRAFT)
|
2023-01-26 22:41:41 +08:00
|
|
|
end
|
|
|
|
|
2022-12-09 19:44:41 +08:00
|
|
|
can :manage_protocol_users do |user, protocol|
|
2023-05-09 22:23:29 +08:00
|
|
|
protocol.permission_granted?(user, ProtocolPermissions::USERS_MANAGE) ||
|
|
|
|
protocol.team.permission_granted?(user, TeamPermissions::MANAGE)
|
2017-12-07 00:23:08 +08:00
|
|
|
end
|
2017-12-07 18:11:27 +08:00
|
|
|
|
2018-02-16 19:03:44 +08:00
|
|
|
# protocol in repository: restore
|
|
|
|
can :restore_protocol_in_repository do |user, protocol|
|
2023-03-10 18:45:32 +08:00
|
|
|
protocol.archived? && protocol.permission_granted?(user, ProtocolPermissions::MANAGE)
|
2018-02-16 19:03:44 +08:00
|
|
|
end
|
|
|
|
|
2023-02-17 01:03:11 +08:00
|
|
|
can :archive_protocol_in_repository do |user, protocol|
|
2023-03-10 18:45:32 +08:00
|
|
|
protocol.active? && protocol.permission_granted?(user, ProtocolPermissions::MANAGE)
|
2023-02-17 01:03:11 +08:00
|
|
|
end
|
|
|
|
|
2018-02-16 19:03:44 +08:00
|
|
|
# protocol in repository: copy
|
2018-01-05 22:15:50 +08:00
|
|
|
can :clone_protocol_in_repository do |user, protocol|
|
2022-05-19 19:46:03 +08:00
|
|
|
can_read_protocol_in_repository?(user, protocol) && can_create_protocols_in_repository?(user, protocol.team)
|
2017-12-07 18:11:27 +08:00
|
|
|
end
|
2023-01-26 22:41:41 +08:00
|
|
|
|
|
|
|
can :publish_protocol_in_repository do |user, protocol|
|
2023-02-13 16:50:39 +08:00
|
|
|
protocol.in_repository_draft? &&
|
2023-03-10 18:45:32 +08:00
|
|
|
protocol.permission_granted?(user, ProtocolPermissions::MANAGE)
|
2023-01-26 22:41:41 +08:00
|
|
|
end
|
2023-02-22 21:59:48 +08:00
|
|
|
|
|
|
|
can :delete_protocol_draft_in_repository do |user, protocol|
|
|
|
|
protocol.parent_id.present? &&
|
|
|
|
can_manage_protocol_draft_in_repository?(user, protocol)
|
|
|
|
end
|
|
|
|
|
2023-03-21 17:59:31 +08:00
|
|
|
can :save_protocol_version_as_draft do |user, protocol|
|
|
|
|
next false unless protocol.in_repository_published?
|
2023-03-01 21:41:41 +08:00
|
|
|
|
2023-03-21 17:59:31 +08:00
|
|
|
protocol.permission_granted?(user, ProtocolPermissions::MANAGE_DRAFT)
|
2023-02-22 21:59:48 +08:00
|
|
|
end
|
2017-12-06 02:51:44 +08:00
|
|
|
end
|
2022-05-23 19:32:15 +08:00
|
|
|
|
|
|
|
Canaid::Permissions.register_for(Report) do
|
|
|
|
can :read_report do |user, report|
|
2022-10-20 21:35:43 +08:00
|
|
|
can_read_project?(report.project) && report.permission_granted?(user, ReportPermissions::READ)
|
2022-05-23 19:32:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
can :manage_report do |user, report|
|
2022-10-20 21:35:43 +08:00
|
|
|
can_read_project?(report.project) && report.permission_granted?(user, ReportPermissions::MANAGE)
|
2022-05-23 19:32:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
can :manage_report_users do |user, report|
|
|
|
|
report.permission_granted?(user, ReportPermissions::USERS_MANAGE)
|
2017-12-07 18:11:27 +08:00
|
|
|
end
|
2017-12-06 02:51:44 +08:00
|
|
|
end
|