scinote-web/app/permissions/asset.rb

36 lines
1 KiB
Ruby
Raw Normal View History

2020-10-22 19:41:17 +08:00
# frozen_string_literal: true
Canaid::Permissions.register_for(Asset) do
can :read_asset do |user, asset|
2020-10-29 21:59:14 +08:00
object = asset.step || asset.result || asset.repository_cell
2020-10-22 19:41:17 +08:00
2020-10-29 21:59:14 +08:00
case object
when Step
2020-10-22 19:41:17 +08:00
protocol = object.protocol
can_read_protocol_in_module?(user, protocol) || can_read_protocol_in_repository?(user, protocol)
2020-10-29 21:59:14 +08:00
when Result
2020-12-14 19:50:54 +08:00
can_read_result?(object)
2020-10-29 21:59:14 +08:00
when RepositoryCell
2020-10-22 19:41:17 +08:00
can_read_repository?(user, object.repository_column.repository)
end
end
can :manage_asset do |user, asset|
2020-10-29 21:59:14 +08:00
object = asset.step || asset.result || asset.repository_cell
2020-10-22 19:41:17 +08:00
2020-10-29 21:59:14 +08:00
case object
when Step
2020-10-22 19:41:17 +08:00
protocol = object.protocol
can_manage_protocol_in_module?(user, protocol) || can_manage_protocol_in_repository?(user, protocol)
2020-10-29 21:59:14 +08:00
when Result
2020-12-14 19:50:54 +08:00
can_manage_result?(object)
2020-10-29 21:59:14 +08:00
when RepositoryCell
if object.repository_column.repository.is_a?(RepositorySnapshot)
false
else
can_manage_repository?(user, object.repository_column.repository)
end
2020-10-22 19:41:17 +08:00
end
end
end