2018-01-29 18:36:36 +08:00
|
|
|
Canaid::Permissions.register_for(Experiment) do
|
2018-03-04 21:19:17 +08:00
|
|
|
# Experiment and its project must be active for all the specified permissions
|
2020-12-13 05:46:30 +08:00
|
|
|
%i(manage_experiment
|
2018-03-04 21:19:17 +08:00
|
|
|
archive_experiment
|
|
|
|
clone_experiment
|
|
|
|
move_experiment)
|
|
|
|
.each do |perm|
|
|
|
|
can perm do |_, experiment|
|
|
|
|
experiment.active? &&
|
|
|
|
experiment.project.active?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-09 23:14:40 +08:00
|
|
|
# experiment: read (read archive)
|
|
|
|
# canvas: read
|
|
|
|
# module: read (read users, read comments, read archive)
|
|
|
|
# result: read (read comments)
|
2018-01-29 18:36:36 +08:00
|
|
|
can :read_experiment do |user, experiment|
|
2018-02-12 21:17:17 +08:00
|
|
|
can_read_project?(user, experiment.project)
|
2018-01-29 18:36:36 +08:00
|
|
|
end
|
|
|
|
|
2018-02-16 01:46:29 +08:00
|
|
|
# experiment: create/update/delete
|
|
|
|
# canvas: update
|
2018-02-16 19:03:44 +08:00
|
|
|
# module: create, copy, reposition, create/update/delete connection,
|
2018-02-09 23:14:40 +08:00
|
|
|
# assign/reassign/unassign tags
|
2018-01-29 18:36:36 +08:00
|
|
|
can :manage_experiment do |user, experiment|
|
2020-07-21 22:00:09 +08:00
|
|
|
user.is_user_or_higher_of_project?(experiment.project) &&
|
2020-09-25 16:14:57 +08:00
|
|
|
MyModule.joins(:experiment)
|
|
|
|
.where(experiment: experiment)
|
|
|
|
.preload(my_module_status: :my_module_status_implications)
|
|
|
|
.all? do |my_module|
|
2020-07-21 22:00:09 +08:00
|
|
|
if my_module.my_module_status
|
|
|
|
my_module.my_module_status.my_module_status_implications.all? { |implication| implication.call(my_module) }
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
2018-01-29 18:36:36 +08:00
|
|
|
end
|
|
|
|
|
2018-02-07 18:49:15 +08:00
|
|
|
# experiment: archive
|
|
|
|
can :archive_experiment do |user, experiment|
|
|
|
|
can_manage_experiment?(user, experiment)
|
|
|
|
end
|
|
|
|
|
2018-02-19 21:47:36 +08:00
|
|
|
# NOTE: Must not be dependent on canaid parmision for which we check if it's
|
|
|
|
# active
|
2018-02-07 18:49:15 +08:00
|
|
|
# experiment: restore
|
2018-01-29 18:36:36 +08:00
|
|
|
can :restore_experiment do |user, experiment|
|
2018-02-19 21:47:36 +08:00
|
|
|
user.is_user_or_higher_of_project?(experiment.project) &&
|
|
|
|
experiment.archived?
|
2018-02-02 01:41:28 +08:00
|
|
|
end
|
|
|
|
|
2018-02-16 19:03:44 +08:00
|
|
|
# experiment: copy
|
2018-02-07 18:49:15 +08:00
|
|
|
can :clone_experiment do |user, experiment|
|
2018-02-02 01:41:28 +08:00
|
|
|
user.is_user_or_higher_of_project?(experiment.project) &&
|
|
|
|
user.is_normal_user_or_admin_of_team?(experiment.project.team)
|
2018-01-29 18:36:36 +08:00
|
|
|
end
|
2018-02-07 18:49:15 +08:00
|
|
|
|
|
|
|
# experiment: move
|
|
|
|
can :move_experiment do |user, experiment|
|
|
|
|
can_clone_experiment?(user, experiment)
|
|
|
|
end
|
2018-03-04 21:19:17 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
Canaid::Permissions.register_for(Protocol) do
|
|
|
|
# Protocol needs to be in a module for all Protocol permissions below
|
|
|
|
# experiment level
|
|
|
|
%i(read_protocol_in_module
|
|
|
|
manage_protocol_in_module
|
|
|
|
complete_or_checkbox_step)
|
|
|
|
.each do |perm|
|
|
|
|
can perm do |_, protocol|
|
|
|
|
protocol.in_module?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-14 00:14:57 +08:00
|
|
|
# Module, its experiment and its project must be active for all the specified
|
|
|
|
# permissions
|
2020-12-11 00:47:10 +08:00
|
|
|
%i(manage_protocol_in_module
|
2018-03-04 21:19:17 +08:00
|
|
|
complete_or_checkbox_step)
|
|
|
|
.each do |perm|
|
|
|
|
can perm do |_, protocol|
|
|
|
|
my_module = protocol.my_module
|
2018-02-10 01:18:41 +08:00
|
|
|
my_module.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
my_module.experiment.project.active?
|
2018-02-07 18:49:15 +08:00
|
|
|
end
|
2018-01-29 18:36:36 +08:00
|
|
|
end
|
|
|
|
|
2018-02-07 18:49:15 +08:00
|
|
|
# protocol in module: read
|
2018-02-16 01:46:29 +08:00
|
|
|
# step in module: read, read comments, read/download assets
|
2018-02-02 01:41:28 +08:00
|
|
|
can :read_protocol_in_module do |user, protocol|
|
2018-03-04 22:17:46 +08:00
|
|
|
can_read_experiment?(user, protocol.my_module.experiment)
|
2018-01-29 18:36:36 +08:00
|
|
|
end
|
|
|
|
|
2018-02-12 21:17:17 +08:00
|
|
|
# protocol in module: create/update/delete, unlink, revert, update from
|
2018-02-07 18:49:15 +08:00
|
|
|
# protocol in repository, update from file
|
2018-02-16 01:46:29 +08:00
|
|
|
# step in module: create/update/delete, reorder
|
2018-02-02 01:41:28 +08:00
|
|
|
can :manage_protocol_in_module do |user, protocol|
|
2018-03-04 22:17:46 +08:00
|
|
|
can_manage_module?(user, protocol.my_module)
|
2018-02-09 23:14:40 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# step: complete/uncomplete
|
|
|
|
can :complete_or_checkbox_step do |user, protocol|
|
2020-07-15 00:48:18 +08:00
|
|
|
can_change_my_module_flow_status?(user, protocol.my_module)
|
2018-01-29 18:36:36 +08:00
|
|
|
end
|
2018-03-04 21:19:17 +08:00
|
|
|
end
|
2018-02-07 18:49:15 +08:00
|
|
|
|
2018-03-04 21:19:17 +08:00
|
|
|
Canaid::Permissions.register_for(Result) do
|
2018-02-14 00:14:57 +08:00
|
|
|
# Module, its experiment and its project must be active for all the specified
|
|
|
|
# permissions
|
2018-03-04 21:19:17 +08:00
|
|
|
%i(manage_result).each do |perm|
|
|
|
|
can perm do |_, result|
|
|
|
|
my_module = result.my_module
|
2018-02-09 23:14:40 +08:00
|
|
|
my_module.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
my_module.experiment.project.active?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-19 21:47:36 +08:00
|
|
|
# result: delete, archive
|
|
|
|
can :manage_result do |user, result|
|
|
|
|
result.unlocked?(result) &&
|
|
|
|
user.is_owner_of_project?(result.my_module.experiment.project)
|
|
|
|
end
|
2018-03-04 21:19:17 +08:00
|
|
|
end
|
2018-02-19 21:47:36 +08:00
|
|
|
|
2018-03-04 21:19:17 +08:00
|
|
|
Canaid::Permissions.register_for(Comment) do
|
2018-02-19 21:47:36 +08:00
|
|
|
# Module, its experiment and its project must be active for all the specified
|
|
|
|
# permissions
|
2018-03-04 21:19:17 +08:00
|
|
|
%i(manage_comment_in_module)
|
|
|
|
.each do |perm|
|
|
|
|
can perm do |_, comment|
|
|
|
|
my_module = ::PermissionsUtil.get_comment_module(comment)
|
2018-02-19 21:47:36 +08:00
|
|
|
my_module.active? &&
|
|
|
|
my_module.experiment.active? &&
|
|
|
|
my_module.experiment.project.active?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-09 23:14:40 +08:00
|
|
|
# module: update/delete comment
|
|
|
|
# result: update/delete comment
|
|
|
|
# step: update/delete comment
|
|
|
|
can :manage_comment_in_module do |user, comment|
|
2018-02-22 03:22:13 +08:00
|
|
|
my_module = ::PermissionsUtil.get_comment_module(comment)
|
2018-02-13 21:59:30 +08:00
|
|
|
project = my_module.experiment.project
|
|
|
|
# Same check as in `can_manage_comment_in_project?`
|
2018-02-09 23:14:40 +08:00
|
|
|
project.present? &&
|
2018-02-13 21:59:30 +08:00
|
|
|
(user.is_owner_of_project?(project) || comment.user == user)
|
2018-02-09 23:14:40 +08:00
|
|
|
end
|
2018-01-29 18:36:36 +08:00
|
|
|
end
|