-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathheartbeat_policy.rb
43 lines (38 loc) · 1004 Bytes
/
heartbeat_policy.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
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true
module Machines
class HeartbeatPolicy < ApplicationPolicy
authorize :machine
def ping?
verify_permissions!('machine.heartbeat.ping')
verify_environment!(
strict: false,
)
case bearer
in role: Role(:admin | :developer | :environment)
allow!
in role: Role(:product) if machine.product == bearer
allow!
in role: Role(:user) if machine.owner == bearer || machine.license.owner == bearer
!machine.license.protected?
in role: Role(:license) if machine.license == bearer
allow!
else
deny!
end
end
def reset?
verify_permissions!('machine.heartbeat.reset')
verify_environment!(
strict: false,
)
case bearer
in role: Role(:admin | :developer | :sales_agent | :environment)
allow!
in role: Role(:product) if machine.product == bearer
allow!
else
deny!
end
end
end
end