scinote-web/app/permissions/asset.rb

39 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
can_read_result?(user, 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
can_manage_step?(user, object)
2020-10-29 21:59:14 +08:00
when Result
can_manage_result?(user, object)
2020-10-29 21:59:14 +08:00
when RepositoryCell
if object.repository_column.repository.is_a?(RepositorySnapshot)
false
else
can_manage_repository_assets?(user, object.repository_column.repository)
end
2020-10-22 19:41:17 +08:00
end
end
can :open_asset_locally do |_user, asset|
ENV['ASSET_SYNC_URL'].present?
end
2020-10-22 19:41:17 +08:00
end