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
|
|
|
|
manage_my_module_users
|
|
|
|
assign_my_module_repository_rows
|
|
|
|
create_my_module_comments
|
|
|
|
create_my_module_repository_snapshots
|
2020-11-20 18:59:15 +08:00
|
|
|
manage_my_module_repository_snapshots
|
2021-09-14 17:08:35 +08:00
|
|
|
update_my_module_status)
|
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
|
|
|
|
|
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|
|
|
|
|
!my_module.archived? && my_module.permission_granted?(user, MyModulePermissions::MANAGE)
|
2021-06-19 23:17:57 +08:00
|
|
|
end
|
|
|
|
|
2021-09-14 17:08:35 +08:00
|
|
|
can :update_my_module_start_date do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::UPDATE_START_DATE)
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
|
|
|
|
2021-09-14 17:08:35 +08:00
|
|
|
can :update_my_module_start_date do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::UPDATE_DUE_DATE)
|
2020-08-25 21:30:22 +08:00
|
|
|
end
|
|
|
|
|
2021-09-14 17:08:35 +08:00
|
|
|
can :update_my_module_start_date do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::UPDATE_NOTES)
|
|
|
|
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
|
|
|
|
|
|
|
|
can :manage_my_module_results do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::RESULTS_MANAGE)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :delete_my_module_archived_results do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::RESULTS_DELETE_ARCHIVED)
|
|
|
|
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|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::STEPS_CHECK)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :uncheck_my_module_steps do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::STEPS_UNCHECK)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :create_comments_in_my_module_steps do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::STEPS_COMMENTS_CREATE)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :delete_comments_in_my_module_steps do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::STEPS_COMMENTS_DELETE)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :delete_own_comments_in_my_module_steps do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::STEPS_COMMENTS_DELETE_OWN)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :update_comments_in_my_module_steps do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::STEPS_COMMENTS_UPDATE)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :update_own_comments_in_my_module_steps do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::STEPS_COMMENT_UPDATE_OWN)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :manage_my_module_users do |user, my_module|
|
|
|
|
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 :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
|
|
|
|
end
|
2021-09-16 20:12:51 +08:00
|
|
|
|
|
|
|
Canaid::Permissions.register_for(Comment) do
|
|
|
|
# Module, its experiment and its project must be active for all the specified
|
|
|
|
# permissions
|
|
|
|
%i(manage_my_module_comments)
|
|
|
|
.each do |perm|
|
|
|
|
can perm do |_, comment|
|
|
|
|
my_module = ::PermissionsUtil.get_comment_module(comment)
|
|
|
|
!my_module.archived_branch?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# module: update/delete comment
|
|
|
|
# result: update/delete comment
|
|
|
|
# step: update/delete comment
|
|
|
|
can :manage_my_module_comments do |user, comment|
|
|
|
|
my_module = ::PermissionsUtil.get_comment_module(comment)
|
|
|
|
(comment.user == user && my_module.permission_granted?(user, MyModulePermissions::COMMENTS_MANAGE_OWN)) ||
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::COMMENTS_MANAGE)
|
|
|
|
end
|
|
|
|
end
|