Move "everyone" role and "instance actor" account magic number IDs to constants (#29260)
This commit is contained in:
parent
96ddf1d482
commit
245064bb98
9 changed files with 26 additions and 19 deletions
|
@ -38,6 +38,8 @@ class UserRole < ApplicationRecord
|
|||
delete_user_data: (1 << 19),
|
||||
}.freeze
|
||||
|
||||
EVERYONE_ROLE_ID = -99
|
||||
|
||||
module Flags
|
||||
NONE = 0
|
||||
ALL = FLAGS.values.reduce(&:|)
|
||||
|
@ -94,7 +96,7 @@ class UserRole < ApplicationRecord
|
|||
|
||||
before_validation :set_position
|
||||
|
||||
scope :assignable, -> { where.not(id: -99).order(position: :asc) }
|
||||
scope :assignable, -> { where.not(id: EVERYONE_ROLE_ID).order(position: :asc) }
|
||||
|
||||
has_many :users, inverse_of: :role, foreign_key: 'role_id', dependent: :nullify
|
||||
|
||||
|
@ -103,9 +105,9 @@ class UserRole < ApplicationRecord
|
|||
end
|
||||
|
||||
def self.everyone
|
||||
UserRole.find(-99)
|
||||
UserRole.find(EVERYONE_ROLE_ID)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
UserRole.create!(id: -99, permissions: Flags::DEFAULT)
|
||||
UserRole.create!(id: EVERYONE_ROLE_ID, permissions: Flags::DEFAULT)
|
||||
end
|
||||
|
||||
def self.that_can(*any_of_privileges)
|
||||
|
@ -113,7 +115,7 @@ class UserRole < ApplicationRecord
|
|||
end
|
||||
|
||||
def everyone?
|
||||
id == -99
|
||||
id == EVERYONE_ROLE_ID
|
||||
end
|
||||
|
||||
def nobody?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue