Merge remote-tracking branch 'parent/main' into upstream-20240218

This commit is contained in:
KMY 2024-02-20 09:25:49 +09:00
commit 7684b5de6f
47 changed files with 412 additions and 115 deletions

View file

@ -40,6 +40,8 @@ class UserRole < ApplicationRecord
manage_ng_words: (1 << 30),
}.freeze
EVERYONE_ROLE_ID = -99
module Flags
NONE = 0
ALL = FLAGS.values.reduce(&:|)
@ -98,7 +100,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
@ -107,9 +109,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)
@ -117,7 +119,7 @@ class UserRole < ApplicationRecord
end
def everyone?
id == -99
id == EVERYONE_ROLE_ID
end
def nobody?