2020-11-20 18:59:15 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-07-15 00:48:18 +08:00
|
|
|
Canaid::Permissions.register_for(MyModule) do
|
|
|
|
# Module, its experiment and its project must be active for all the specified
|
|
|
|
# permissions
|
2021-09-14 17:08:35 +08:00
|
|
|
%i(manage_my_module
|
2023-06-01 17:31:54 +08:00
|
|
|
archive_my_module
|
2021-12-06 22:36:49 +08:00
|
|
|
manage_my_module_protocol
|
2021-09-14 17:08:35 +08:00
|
|
|
manage_my_module_users
|
2021-12-06 22:36:49 +08:00
|
|
|
manage_my_module_designated_users
|
2021-09-14 17:08:35 +08:00
|
|
|
assign_my_module_repository_rows
|
2021-12-06 22:36:49 +08:00
|
|
|
manage_my_module_repository_rows
|
|
|
|
create_results
|
2021-09-14 17:08:35 +08:00
|
|
|
create_my_module_comments
|
2021-12-06 22:36:49 +08:00
|
|
|
create_comments_in_my_module_steps
|
|
|
|
create_my_module_result_comments
|
2021-09-14 17:08:35 +08:00
|
|
|
create_my_module_repository_snapshots
|
2020-11-20 18:59:15 +08:00
|
|
|
manage_my_module_repository_snapshots
|
2021-12-06 22:36:49 +08:00
|
|
|
update_my_module_start_date
|
|
|
|
update_my_module_due_date
|
|
|
|
complete_my_module
|
|
|
|
update_my_module_description
|
|
|
|
manage_my_module_tags
|
|
|
|
update_my_module_status
|
|
|
|
manage_my_module_steps
|
|
|
|
complete_my_module_steps
|
|
|
|
uncomplete_my_module_steps
|
|
|
|
check_my_module_steps
|
|
|
|
uncheck_my_module_steps)
|
2020-07-15 00:48:18 +08:00
|
|
|
.each do |perm|
|
|
|
|
can perm do |_, my_module|
|
|
|
|
my_module.active? &&
|
2020-09-11 22:08:03 +08:00
|
|
|
!my_module.status_changing? &&
|
2020-07-15 00:48:18 +08:00
|
|
|
my_module.experiment.active? &&
|
|
|
|
my_module.experiment.project.active?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-14 17:08:35 +08:00
|
|
|
can :read_my_module do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::READ)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :manage_my_module do |user, my_module|
|
2021-02-18 16:54:53 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::MANAGE)
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
|
|
|
|
2023-07-05 22:21:26 +08:00
|
|
|
can :share_my_module do |user, my_module|
|
2024-07-24 22:38:29 +08:00
|
|
|
my_module.team.shareable_links_enabled? && my_module.permission_granted?(user, MyModulePermissions::SHARE)
|
2023-07-05 22:21:26 +08:00
|
|
|
end
|
|
|
|
|
2021-09-14 17:08:35 +08:00
|
|
|
can :restore_my_module do |user, my_module|
|
|
|
|
my_module.archived? && my_module.permission_granted?(user, MyModulePermissions::MANAGE)
|
2020-08-25 21:30:22 +08:00
|
|
|
end
|
|
|
|
|
2021-09-14 17:08:35 +08:00
|
|
|
can :archive_my_module do |user, my_module|
|
2023-06-01 17:31:54 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::MANAGE)
|
2021-06-19 23:17:57 +08:00
|
|
|
end
|
|
|
|
|
2021-11-23 18:08:46 +08:00
|
|
|
can :move_my_module do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::MANAGE)
|
|
|
|
end
|
|
|
|
|
2021-09-14 17:08:35 +08:00
|
|
|
can :update_my_module_start_date do |user, my_module|
|
2021-11-19 20:24:57 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::UPDATE_START_DATE)
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
|
|
|
|
2021-09-22 17:28:32 +08:00
|
|
|
can :update_my_module_due_date do |user, my_module|
|
2021-11-19 20:24:57 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::UPDATE_DUE_DATE)
|
2020-08-25 21:30:22 +08:00
|
|
|
end
|
|
|
|
|
2021-11-19 20:24:57 +08:00
|
|
|
can :update_my_module_description do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::UPDATE_DESCRIPTION)
|
2021-09-14 17:08:35 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
can :manage_my_module_tags do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::TAGS_MANAGE)
|
2021-05-10 00:23:50 +08:00
|
|
|
end
|
|
|
|
|
2021-09-14 17:08:35 +08:00
|
|
|
can :manage_my_module_steps do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::STEPS_MANAGE)
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
|
|
|
|
2021-09-14 17:08:35 +08:00
|
|
|
can :create_my_module_comments do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::COMMENTS_CREATE)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :assign_my_module_repository_rows do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::REPOSITORY_ROWS_ASSIGN)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :manage_my_module_repository_rows do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::REPOSITORY_ROWS_MANAGE)
|
|
|
|
end
|
|
|
|
|
2021-09-24 19:11:41 +08:00
|
|
|
can :create_results do |user, my_module|
|
2021-09-14 17:08:35 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::RESULTS_MANAGE)
|
|
|
|
end
|
|
|
|
|
2021-09-24 19:11:41 +08:00
|
|
|
can :create_my_module_result_comments do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::RESULTS_COMMENTS_CREATE)
|
2021-09-14 17:08:35 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
can :manage_my_module_protocol do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::PROTOCOL_MANAGE)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :complete_my_module do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::COMPLETE)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :update_my_module_status do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::UPDATE_STATUS)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :complete_my_module_steps do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::STEPS_COMPLETE)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :uncomplete_my_module_steps do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::STEPS_UNCOMPLETE)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :check_my_module_steps do |user, my_module|
|
2021-09-22 21:28:32 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::STEPS_CHECKLIST_CHECK)
|
2021-09-14 17:08:35 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
can :uncheck_my_module_steps do |user, my_module|
|
2021-09-22 21:28:32 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::STEPS_CHECKLIST_UNCHECK)
|
2021-09-14 17:08:35 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
can :create_comments_in_my_module_steps do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::STEPS_COMMENTS_CREATE)
|
|
|
|
end
|
|
|
|
|
2021-10-28 20:48:28 +08:00
|
|
|
can :read_my_module_users do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::USERS_READ)
|
|
|
|
end
|
|
|
|
|
2021-09-14 17:08:35 +08:00
|
|
|
can :manage_my_module_users do |user, my_module|
|
2021-10-28 20:48:28 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::USERS_MANAGE)
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
|
|
|
|
2021-11-19 20:24:57 +08:00
|
|
|
can :manage_my_module_designated_users do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::DESIGNATED_USERS_MANAGE)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :read_my_module_activities do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::ACTIVITIES_READ)
|
|
|
|
end
|
|
|
|
|
2021-09-14 17:08:35 +08:00
|
|
|
can :restore_my_module do |user, my_module|
|
|
|
|
my_module.archived? && my_module.permission_granted?(user, MyModulePermissions::MANAGE)
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
|
|
|
|
2021-09-14 17:08:35 +08:00
|
|
|
can :create_my_module_repository_snapshots do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::REPOSITORY_ROWS_MANAGE)
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
can :manage_my_module_repository_snapshots do |user, my_module|
|
2021-09-14 17:08:35 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::REPOSITORY_ROWS_MANAGE)
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
2022-01-25 19:41:16 +08:00
|
|
|
|
|
|
|
can :update_my_module_stock_consumption do |user, my_module|
|
2022-03-29 18:33:28 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::STOCK_CONSUMPTION_UPDATE) &&
|
2022-04-01 19:54:08 +08:00
|
|
|
RepositoryBase.stock_management_enabled?
|
2022-01-25 19:41:16 +08:00
|
|
|
end
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
2021-09-16 20:12:51 +08:00
|
|
|
|
2021-09-22 17:28:32 +08:00
|
|
|
Canaid::Permissions.register_for(TaskComment) do
|
2021-09-16 20:12:51 +08:00
|
|
|
# Module, its experiment and its project must be active for all the specified
|
|
|
|
# permissions
|
2021-09-22 17:28:32 +08:00
|
|
|
%i(manage_my_module_comment)
|
2021-09-16 20:12:51 +08:00
|
|
|
.each do |perm|
|
|
|
|
can perm do |_, comment|
|
2021-09-30 17:32:11 +08:00
|
|
|
my_module = comment.my_module
|
2021-09-22 17:28:32 +08:00
|
|
|
my_module.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
my_module.experiment.project.active?
|
2021-09-16 20:12:51 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-22 17:28:32 +08:00
|
|
|
can :manage_my_module_comment do |user, comment|
|
2021-09-30 17:32:11 +08:00
|
|
|
my_module = comment.my_module
|
2021-09-22 17:28:32 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::COMMENTS_MANAGE) ||
|
|
|
|
((comment.user == user) && my_module.permission_granted?(user, MyModulePermissions::COMMENTS_MANAGE_OWN))
|
2021-09-16 20:12:51 +08:00
|
|
|
end
|
|
|
|
end
|
2021-09-30 17:32:11 +08:00
|
|
|
|
|
|
|
Canaid::Permissions.register_for(StepComment) do
|
|
|
|
# Module, its experiment and its project must be active for all the specified
|
|
|
|
# permissions
|
|
|
|
%i(delete_comment_in_my_module_steps
|
|
|
|
update_comment_in_my_module_steps)
|
|
|
|
.each do |perm|
|
|
|
|
can perm do |_, comment|
|
|
|
|
my_module = comment.step.my_module
|
|
|
|
my_module.active? &&
|
|
|
|
!my_module.archived_branch? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
my_module.experiment.project.active?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
can :delete_comment_in_my_module_steps do |user, comment|
|
|
|
|
my_module = comment.step.my_module
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::STEPS_COMMENTS_DELETE) ||
|
|
|
|
((comment.user == user) && my_module.permission_granted?(user, MyModulePermissions::STEPS_COMMENTS_DELETE_OWN))
|
|
|
|
end
|
|
|
|
|
|
|
|
can :update_comment_in_my_module_steps do |user, comment|
|
|
|
|
my_module = comment.step.my_module
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::STEPS_COMMENTS_UPDATE) ||
|
|
|
|
((comment.user == user) && my_module.permission_granted?(user, MyModulePermissions::STEPS_COMMENTS_UPDATE_OWN))
|
|
|
|
end
|
|
|
|
end
|