blob: fe8168725e653c0e46d5358ff83cb0e459341de3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
class Agency < ApplicationRecord
include Bitfields
belongs_to :agent
belongs_to :user
bitfield :roles, :observer, :editor, :maintainer, :leader
class << self
# Grant role in agent to user
def grant(agent, user, role)
r = find_or_create_by(agent: agent, user: user)
r&.public_send("#{role}=", true) && r&.save
end
# Revoke role in agent from user
def revoke(agent, user, role)
r = find_by(agent: agent, user: user)
r&.public_send("#{role}=", false) && r&.save
end
end
end
|