users: add new owner level.
Add a new Owner user level for the site owner. Highly sensitive operations like manually changing the passwords of other users will be restricted to the site owner.
This commit is contained in:
@@ -12,6 +12,7 @@ class User < ApplicationRecord
|
||||
BUILDER = 32
|
||||
MODERATOR = 40
|
||||
ADMIN = 50
|
||||
OWNER = 60
|
||||
end
|
||||
|
||||
# Used for `before_action :<role>_only`. Must have a corresponding `is_<role>?` method.
|
||||
@@ -191,6 +192,10 @@ class User < ApplicationRecord
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
module ClassMethods
|
||||
def owner
|
||||
User.find_by!(level: Levels::ADMIN)
|
||||
end
|
||||
|
||||
def system
|
||||
User.find_by!(name: Danbooru.config.system_user)
|
||||
end
|
||||
@@ -208,7 +213,8 @@ class User < ApplicationRecord
|
||||
"Platinum" => Levels::PLATINUM,
|
||||
"Builder" => Levels::BUILDER,
|
||||
"Moderator" => Levels::MODERATOR,
|
||||
"Admin" => Levels::ADMIN
|
||||
"Admin" => Levels::ADMIN,
|
||||
"Owner" => Levels::OWNER
|
||||
}
|
||||
end
|
||||
|
||||
@@ -235,6 +241,9 @@ class User < ApplicationRecord
|
||||
when Levels::ADMIN
|
||||
"Admin"
|
||||
|
||||
when Levels::OWNER
|
||||
"Owner"
|
||||
|
||||
else
|
||||
""
|
||||
end
|
||||
@@ -299,6 +308,10 @@ class User < ApplicationRecord
|
||||
level >= Levels::ADMIN
|
||||
end
|
||||
|
||||
def is_owner?
|
||||
level >= Levels::OWNER
|
||||
end
|
||||
|
||||
def is_approver?
|
||||
can_approve_posts?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user