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
|
2021-09-30 17:32:11 +08:00
|
|
|
manage_experiment_tasks
|
|
|
|
manage_experiment_users
|
2018-03-04 21:19:17 +08:00
|
|
|
archive_experiment
|
|
|
|
clone_experiment
|
2021-11-12 04:30:30 +08:00
|
|
|
move_experiment)
|
2018-03-04 21:19:17 +08:00
|
|
|
.each do |perm|
|
|
|
|
can perm do |_, experiment|
|
|
|
|
experiment.active? &&
|
|
|
|
experiment.project.active?
|
|
|
|
end
|
|
|
|
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|
|
2022-08-31 21:26:10 +08:00
|
|
|
next false unless experiment.permission_granted?(user, ExperimentPermissions::MANAGE)
|
|
|
|
|
|
|
|
my_modules = experiment.my_modules
|
|
|
|
unless experiment.association(:my_modules).loaded?
|
|
|
|
my_modules = my_modules.preload(my_module_status: :my_module_status_implications)
|
|
|
|
end
|
|
|
|
|
|
|
|
my_modules.all? do |my_module|
|
|
|
|
if my_module.my_module_status
|
|
|
|
my_module.my_module_status.my_module_status_implications.all? { |implication| implication.call(my_module) }
|
|
|
|
else
|
|
|
|
true
|
2020-07-21 22:00:09 +08:00
|
|
|
end
|
2022-08-31 21:26:10 +08:00
|
|
|
end
|
2018-01-29 18:36:36 +08:00
|
|
|
end
|
|
|
|
|
2021-09-30 17:32:11 +08:00
|
|
|
can :read_experiment do |user, experiment|
|
|
|
|
experiment.permission_granted?(user, ExperimentPermissions::READ)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :read_archived_experiment do |user, experiment|
|
|
|
|
experiment.permission_granted?(user, ExperimentPermissions::READ_ARCHIVED)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :read_experiment_canvas do |user, experiment|
|
|
|
|
experiment.permission_granted?(user, ExperimentPermissions::READ_CANVAS)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :read_experiment_activities do |user, experiment|
|
|
|
|
experiment.permission_granted?(user, ExperimentPermissions::ACTIVITIES_READ)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :read_experiment_users do |user, experiment|
|
|
|
|
experiment.permission_granted?(user, ExperimentPermissions::USERS_READ)
|
|
|
|
end
|
|
|
|
|
|
|
|
can :manage_experiment_users do |user, experiment|
|
2021-09-22 21:28:32 +08:00
|
|
|
experiment.permission_granted?(user, ExperimentPermissions::USERS_MANAGE)
|
2021-06-19 23:17:57 +08:00
|
|
|
end
|
|
|
|
|
2021-09-30 17:32:11 +08:00
|
|
|
can :manage_experiment_tasks do |user, experiment|
|
|
|
|
experiment.permission_granted?(user, ExperimentPermissions::TASKS_MANAGE)
|
|
|
|
end
|
|
|
|
|
2021-10-27 19:48:52 +08:00
|
|
|
can :manage_all_experiment_my_modules do |user, experiment|
|
2022-01-18 17:15:59 +08:00
|
|
|
experiment.my_modules.where.not(id: experiment.my_modules.managable_by_user(user)).none?
|
2021-10-27 19:48:52 +08:00
|
|
|
end
|
|
|
|
|
2018-02-07 18:49:15 +08:00
|
|
|
can :archive_experiment do |user, experiment|
|
2021-09-22 21:28:32 +08:00
|
|
|
experiment.permission_granted?(user, ExperimentPermissions::MANAGE)
|
2018-02-07 18:49:15 +08:00
|
|
|
end
|
|
|
|
|
2018-01-29 18:36:36 +08:00
|
|
|
can :restore_experiment do |user, experiment|
|
2021-01-15 22:08:27 +08:00
|
|
|
project = experiment.project
|
2021-09-22 21:28:32 +08:00
|
|
|
experiment.permission_granted?(user, ExperimentPermissions::MANAGE) &&
|
2021-01-15 22:08:27 +08:00
|
|
|
experiment.archived? &&
|
|
|
|
project.active?
|
2018-02-02 01:41:28 +08:00
|
|
|
end
|
|
|
|
|
2018-02-07 18:49:15 +08:00
|
|
|
can :clone_experiment do |user, experiment|
|
2022-05-25 16:22:50 +08:00
|
|
|
experiment.permission_granted?(user, ExperimentPermissions::READ)
|
2018-01-29 18:36:36 +08:00
|
|
|
end
|
2018-02-07 18:49:15 +08:00
|
|
|
|
|
|
|
can :move_experiment do |user, experiment|
|
2021-09-22 21:28:32 +08:00
|
|
|
experiment.permission_granted?(user, ExperimentPermissions::MANAGE)
|
2018-02-07 18:49:15 +08:00
|
|
|
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|
|
2021-09-22 17:28:32 +08:00
|
|
|
protocol.my_module.permission_granted?(user, MyModulePermissions::READ)
|
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|
|
2021-11-19 20:24:57 +08:00
|
|
|
can_manage_my_module_protocol?(user, protocol.my_module)
|
2018-02-09 23:14:40 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# step: complete/uncomplete
|
|
|
|
can :complete_or_checkbox_step do |user, protocol|
|
2021-09-14 17:08:35 +08:00
|
|
|
can_update_my_module_status?(user, protocol.my_module)
|
2018-01-29 18:36:36 +08:00
|
|
|
end
|
2018-03-04 21:19:17 +08:00
|
|
|
end
|