Skip to content

Commit

Permalink
login admin backend min class configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Sep 2, 2023
1 parent 8776f70 commit d4648cd
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,19 @@ 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;
}
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');
Expand Down
2 changes: 1 addition & 1 deletion include/constants.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.7');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-08-29');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-09-03');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
Expand Down
2 changes: 1 addition & 1 deletion include/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2671,7 +2671,7 @@ function stdhead($title = "", $msgalert = true, $script = "", $place = "")
<?php if($attendance){ printf(' <a href="attendance.php" class="">'.$lang_functions['text_attended'].'</a>', $attendance->points, $CURUSER['attendance_card']); }else{ printf(' <a href="attendance.php" class="faqlink">%s</a>', $lang_functions['text_attendance']);}?>
<a href="medal.php">[<?php echo nexus_trans('medal.label')?>]</a>
<font class = 'color_invite'><?php echo $lang_functions['text_invite'] ?></font>[<a href="invite.php?id=<?php echo $CURUSER['id']?>"><?php echo $lang_functions['text_send'] ?></a>]: <?php echo sprintf('%s(%s)', $CURUSER['invites'], \App\Models\Invite::query()->where('inviter', $CURUSER['id'])->where('invitee', '')->where('expired_at', '>', now())->count())?>
<?php if(get_user_class() >= \App\Models\User::CLASS_ADMINISTRATOR) printf('[<a href="%s" target="_blank">%s</a>]', nexus_env('FILAMENT_PATH', 'nexusphp'), $lang_functions['text_management_system'])?>
<?php if(get_user_class() >= \App\Models\User::getAccessAdminClassMin()) printf('[<a href="%s" target="_blank">%s</a>]', nexus_env('FILAMENT_PATH', 'nexusphp'), $lang_functions['text_management_system'])?>
<br />
<font class="color_ratio"><?php echo $lang_functions['text_ratio'] ?></font> <?php echo $ratio?>
<font class='color_uploaded'><?php echo $lang_functions['text_uploaded'] ?></font> <?php echo mksize($CURUSER['uploaded'])?>
Expand Down
1 change: 1 addition & 0 deletions nexus/Install/settings.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
);
2 changes: 2 additions & 0 deletions resources/lang/en/label.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/zh_CN/label.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/zh_TW/label.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down

0 comments on commit d4648cd

Please sign in to comment.