2020-12-14 19:50:54 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
Canaid::Permissions.register_for(Result) do
|
|
|
|
can :read_result do |user, result|
|
2021-09-24 19:11:41 +08:00
|
|
|
can_read_my_module?(user, result.my_module)
|
2020-12-14 19:50:54 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
can :manage_result do |user, result|
|
2021-09-24 19:11:41 +08:00
|
|
|
!result.archived? &&
|
2021-09-30 17:32:11 +08:00
|
|
|
!result.my_module.archived_branch? &&
|
2021-09-24 19:11:41 +08:00
|
|
|
result.unlocked?(result) &&
|
|
|
|
result.my_module.permission_granted?(user, MyModulePermissions::RESULTS_MANAGE)
|
2020-12-14 19:50:54 +08:00
|
|
|
end
|
2021-01-20 16:00:45 +08:00
|
|
|
|
|
|
|
can :delete_result do |user, result|
|
2021-09-24 19:11:41 +08:00
|
|
|
result.archived? &&
|
|
|
|
result.unlocked?(result) &&
|
|
|
|
result.my_module.permission_granted?(user, MyModulePermissions::RESULTS_DELETE_ARCHIVED)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Canaid::Permissions.register_for(ResultComment) do
|
|
|
|
# Module, its experiment and its project must be active for all the specified
|
|
|
|
# permissions
|
|
|
|
%i(manage_result_comment)
|
|
|
|
.each do |perm|
|
|
|
|
can perm do |_, comment|
|
2021-09-30 17:32:11 +08:00
|
|
|
!comment.result.my_module.archived_branch?
|
2021-09-24 19:11:41 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# module: update/delete comment
|
|
|
|
# result: update/delete comment
|
|
|
|
# step: update/delete comment
|
|
|
|
can :manage_result_comment do |user, comment|
|
2021-09-30 17:32:11 +08:00
|
|
|
my_module = comment.result.my_module
|
2021-09-24 19:11:41 +08:00
|
|
|
(comment.user == user && my_module.permission_granted?(user, MyModulePermissions::RESULTS_COMMENTS_MANAGE_OWN)) ||
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::RESULTS_COMMENTS_MANAGE)
|
2021-01-20 16:00:45 +08:00
|
|
|
end
|
2020-12-14 19:50:54 +08:00
|
|
|
end
|