From d4648cd59c1bcc7773445a12ba27a6c224e3bf5f Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sun, 3 Sep 2023 03:29:25 +0800 Subject: [PATCH] login admin backend min class configurable --- .../Resources/System/SettingResource/Pages/EditSetting.php | 6 ++++++ app/Models/User.php | 7 ++++++- include/constants.php | 2 +- include/functions.php | 2 +- nexus/Install/settings.default.php | 1 + resources/lang/en/label.php | 2 ++ resources/lang/zh_CN/label.php | 2 ++ resources/lang/zh_TW/label.php | 2 ++ 8 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/Filament/Resources/System/SettingResource/Pages/EditSetting.php b/app/Filament/Resources/System/SettingResource/Pages/EditSetting.php index af1d9c53e..a0039d432 100644 --- a/app/Filament/Resources/System/SettingResource/Pages/EditSetting.php +++ b/app/Filament/Resources/System/SettingResource/Pages/EditSetting.php @@ -8,6 +8,7 @@ use App\Models\SearchBox; use App\Models\Setting; use App\Models\Tag; +use App\Models\User; use App\Repositories\MeiliSearchRepository; use Filament\Facades\Filament; use Filament\Forms\ComponentContainer; @@ -155,6 +156,11 @@ private function getTabs(): array ->label(__('label.setting.system.is_invite_pre_email_and_username')) ->helperText(__('label.setting.system.is_invite_pre_email_and_username_help')) , + Forms\Components\Select::make('system.access_admin_class_min') + ->options(User::listClass(User::CLASS_VIP)) + ->label(__('label.setting.system.access_admin_class_min')) + ->helperText(__('label.setting.system.access_admin_class_min_help')) + , ])->columns(2); $tabs = apply_filter('nexus_setting_tabs', $tabs); diff --git a/app/Models/User.php b/app/Models/User.php index 0fd3c0c25..649818289 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -547,7 +547,7 @@ public function updateWithComment(array $update, $comment, $commentField): bool public function canAccessAdmin(): bool { - $targetClass = self::CLASS_ADMINISTRATOR; + $targetClass = self::getAccessAdminClassMin(); if (!$this->class || $this->class < $targetClass) { do_log(sprintf('user: %s, no class or class < %s, can not access admin.', $this->id, $targetClass)); return false; @@ -555,6 +555,11 @@ public function canAccessAdmin(): bool return true; } + public static function getAccessAdminClassMin() + { + return Setting::get("system.access_admin_class_min") ?: User::CLASS_ADMINISTRATOR; + } + public function isDonating(): bool { $rawDonorUntil = $this->getRawOriginal('donoruntil'); diff --git a/include/constants.php b/include/constants.php index 3f30d339d..a584af428 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ '.$lang_functions['text_attended'].'', $attendance->points, $CURUSER['attendance_card']); }else{ printf(' %s', $lang_functions['text_attendance']);}?> [] []: where('inviter', $CURUSER['id'])->where('invitee', '')->where('expired_at', '>', now())->count())?> - = \App\Models\User::CLASS_ADMINISTRATOR) printf('[%s]', nexus_env('FILAMENT_PATH', 'nexusphp'), $lang_functions['text_management_system'])?> + = \App\Models\User::getAccessAdminClassMin()) printf('[%s]', nexus_env('FILAMENT_PATH', 'nexusphp'), $lang_functions['text_management_system'])?>
diff --git a/nexus/Install/settings.default.php b/nexus/Install/settings.default.php index 2d0b9b3a6..88665e1e9 100644 --- a/nexus/Install/settings.default.php +++ b/nexus/Install/settings.default.php @@ -451,5 +451,6 @@ 'cookie_valid_days' => 365, 'maximum_upload_speed' => 8000, 'is_invite_pre_email_and_username' => 'No', + 'access_admin_class_min' => User::CLASS_ADMINISTRATOR, ], ); diff --git a/resources/lang/en/label.php b/resources/lang/en/label.php index c0888677e..5566176e2 100644 --- a/resources/lang/en/label.php +++ b/resources/lang/en/label.php @@ -104,6 +104,8 @@ 'maximum_upload_speed_help' => 'A single torrent upload speed exceeding this value is instantly disabled for the account, in Mbps. For example: 100 Mbps = 12.5 MB/s', 'is_invite_pre_email_and_username' => 'Invite whether to pre-book an email and username', 'is_invite_pre_email_and_username_help' => "Default: 'No'. If pre-booked, email and username may not be changed when the user registers.", + 'access_admin_class_min' => 'Minimum class for logging into admin backend', + 'access_admin_class_min_help' => 'Default: administrator, users with a user class greater than or equal to the set value can log into the admin backend', ], ], 'user' => [ diff --git a/resources/lang/zh_CN/label.php b/resources/lang/zh_CN/label.php index 0f6bbbe7c..59949b37f 100644 --- a/resources/lang/zh_CN/label.php +++ b/resources/lang/zh_CN/label.php @@ -104,6 +104,8 @@ 'maximum_upload_speed_help' => '单种上传速度超过此值账号即刻禁用,单位 Mbps。如:100 Mbps = 12.5 MB/s', 'is_invite_pre_email_and_username' => '邀请是否预定邮箱和用户名', 'is_invite_pre_email_and_username_help' => "默认: 'No'。若预定,用户注册时不可修改邮箱和用户名", + 'access_admin_class_min' => '登录管理后台最小等级', + 'access_admin_class_min_help' => '默认:管理员,用户等级大于等于设定值的用户可以登录管理后台', ], ], 'user' => [ diff --git a/resources/lang/zh_TW/label.php b/resources/lang/zh_TW/label.php index a85f77f3d..5e92f96dd 100644 --- a/resources/lang/zh_TW/label.php +++ b/resources/lang/zh_TW/label.php @@ -104,6 +104,8 @@ 'maximum_upload_speed_help' => '單種上傳速度超過此值賬號即刻禁用,單位 Mbps。如:100 Mbps = 12.5 MB/s', 'is_invite_pre_email_and_username' => '邀請是否預定郵箱和用戶名', 'is_invite_pre_email_and_username_help' => "默認: 'No'。若預定,用戶註冊時不可修改郵箱和用戶名", + 'access_admin_class_min' => '登錄管理後臺最小等級', + 'access_admin_class_min_help' => '默認:管理員,用戶等級大於等於設定值的用戶可以登錄管理後臺', ], ], 'user' => [