|
|
@ -39,6 +39,7 @@ class UserRole < ApplicationRecord
|
|
|
|
}.freeze
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
|
|
|
|
EVERYONE_ROLE_ID = -99
|
|
|
|
EVERYONE_ROLE_ID = -99
|
|
|
|
|
|
|
|
NOBODY_POSITION = -1
|
|
|
|
|
|
|
|
|
|
|
|
module Flags
|
|
|
|
module Flags
|
|
|
|
NONE = 0
|
|
|
|
NONE = 0
|
|
|
@ -104,7 +105,7 @@ class UserRole < ApplicationRecord
|
|
|
|
has_many :users, inverse_of: :role, foreign_key: 'role_id', dependent: :nullify
|
|
|
|
has_many :users, inverse_of: :role, foreign_key: 'role_id', dependent: :nullify
|
|
|
|
|
|
|
|
|
|
|
|
def self.nobody
|
|
|
|
def self.nobody
|
|
|
|
@nobody ||= UserRole.new(permissions: Flags::NONE, position: -1)
|
|
|
|
@nobody ||= UserRole.new(permissions: Flags::NONE, position: NOBODY_POSITION)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def self.everyone
|
|
|
|
def self.everyone
|
|
|
@ -173,7 +174,7 @@ class UserRole < ApplicationRecord
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def set_position
|
|
|
|
def set_position
|
|
|
|
self.position = -1 if everyone?
|
|
|
|
self.position = NOBODY_POSITION if everyone?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def validate_own_role_edition
|
|
|
|
def validate_own_role_edition
|
|
|
|