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
|
|
|
|
%i(manage_module
|
2020-11-20 18:59:15 +08:00
|
|
|
archive_module
|
2020-07-15 00:48:18 +08:00
|
|
|
manage_users_in_module
|
|
|
|
assign_repository_rows_to_module
|
|
|
|
create_comments_in_module
|
|
|
|
create_my_module_repository_snapshot
|
2020-11-20 18:59:15 +08:00
|
|
|
manage_my_module_repository_snapshots
|
|
|
|
change_my_module_flow_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
|
|
|
|
|
2020-08-25 21:30:22 +08:00
|
|
|
# module: update
|
2020-07-15 00:48:18 +08:00
|
|
|
# result: create, update
|
|
|
|
can :manage_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
|
|
|
|
|
2020-08-25 21:30:22 +08:00
|
|
|
# module: archive
|
|
|
|
can :archive_module do |user, my_module|
|
2021-02-18 16:54:53 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::ARCHIVE)
|
2020-08-25 21:30:22 +08:00
|
|
|
end
|
|
|
|
|
2020-07-15 00:48:18 +08:00
|
|
|
# NOTE: Must not be dependent on canaid parmision for which we check if it's
|
|
|
|
# active
|
|
|
|
# module: restore
|
|
|
|
can :restore_module do |user, my_module|
|
2021-02-18 16:54:53 +08:00
|
|
|
my_module.archived? && my_module.permission_granted?(user, MyModulePermissions::RESTORE)
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
|
|
|
|
2020-08-25 21:30:22 +08:00
|
|
|
# module: move
|
|
|
|
can :move_module do |user, my_module|
|
2021-02-18 16:54:53 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::MOVE)
|
2020-08-25 21:30:22 +08:00
|
|
|
end
|
|
|
|
|
2021-05-10 00:23:50 +08:00
|
|
|
# module: read
|
|
|
|
can :read_module do |user, my_module|
|
|
|
|
my_module.permission_granted?(user, MyModulePermissions::READ)
|
|
|
|
end
|
|
|
|
|
2020-07-15 00:48:18 +08:00
|
|
|
# module: assign/reassign/unassign users
|
|
|
|
can :manage_users_in_module do |user, my_module|
|
2021-02-18 16:54:53 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::MANAGE_USERS)
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# module: assign/unassign repository record
|
|
|
|
# NOTE: Use 'module_page? &&' before calling this permission!
|
|
|
|
can :assign_repository_rows_to_module do |user, my_module|
|
2021-02-18 16:54:53 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::ASSIGN_REPOSITORY_ROWS)
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# module: change_flow_status
|
|
|
|
can :change_my_module_flow_status do |user, my_module|
|
2021-02-18 16:54:53 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::CHANGE_FLOW_STATUS)
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# module: create comment
|
|
|
|
# result: create comment
|
|
|
|
# step: create comment
|
|
|
|
can :create_comments_in_module do |user, my_module|
|
2021-02-18 16:54:53 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::CREATE_COMMENTS)
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# module: create a snapshot of repository item
|
|
|
|
can :create_my_module_repository_snapshot do |user, my_module|
|
2021-02-18 16:54:53 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::CREATE_REPOSITORY_SNAPSHOT)
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# module: make a repository snapshot selected
|
|
|
|
can :manage_my_module_repository_snapshots do |user, my_module|
|
2021-02-18 16:54:53 +08:00
|
|
|
my_module.permission_granted?(user, MyModulePermissions::MANAGE_REPOSITORY_SNAPSHOT)
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
|
|
|
end
|