-
Notifications
You must be signed in to change notification settings - Fork 9
/
heliotrope_authority.rb
32 lines (29 loc) · 1.05 KB
/
heliotrope_authority.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true
# Customized authority to include marshaling behaviors
#
# The name is not perfect, but we have some work to do as far as migrating the
# Authority singleton methods. In practice, this instance will be registered in
# the services container, so its name is not relevant except in the services
# initializer.
class HeliotropeAuthority < Checkpoint::Authority
def licenses_for(actor, target)
Greensub::License.where(
id: what(actor, target)
.filter_map { |license| license.id if license.token.type.downcase == 'license' }
)
end
# This might be garbage -- not sure if we want generic marshaling
def credentials_from(tokens)
Array(tokens).map do |token|
# TODO: Probably raise if we find a credential type we can't handle???
# TODO: Deal with group query instead of looping
case token.type.downcase
when 'permission'
Checkpoint::Permission.new(token.id)
when 'license'
# Greensub::License.find(token.id)
License.find(token.id)
end
end
end
end