mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
disable user require operator class higger
This commit is contained in:
@@ -154,9 +154,12 @@ class UserRepository extends BaseRepository
|
|||||||
|
|
||||||
public function disableUser(User $operator, $uid, $reason)
|
public function disableUser(User $operator, $uid, $reason)
|
||||||
{
|
{
|
||||||
$targetUser = User::query()->findOrFail($uid, ['id', 'enabled', 'username']);
|
$targetUser = User::query()->findOrFail($uid, ['id', 'enabled', 'username', 'class']);
|
||||||
if ($targetUser->enabled == User::ENABLED_NO) {
|
if ($targetUser->enabled == User::ENABLED_NO) {
|
||||||
throw new NexusException('Already disabled!');
|
throw new NexusException('Already disabled !');
|
||||||
|
}
|
||||||
|
if ($targetUser->class >= $operator->class) {
|
||||||
|
throw new NexusException('No Permission !');
|
||||||
}
|
}
|
||||||
$banLog = [
|
$banLog = [
|
||||||
'uid' => $uid,
|
'uid' => $uid,
|
||||||
@@ -164,7 +167,7 @@ class UserRepository extends BaseRepository
|
|||||||
'reason' => $reason,
|
'reason' => $reason,
|
||||||
'operator' => $operator->id,
|
'operator' => $operator->id,
|
||||||
];
|
];
|
||||||
$modCommentText = sprintf("Disable by %s, reason: %s.", $operator->username, $reason);
|
$modCommentText = sprintf("%s - Disable by %s, reason: %s.", now()->format('Y-m-d'), $operator->username, $reason);
|
||||||
DB::transaction(function () use ($targetUser, $banLog, $modCommentText) {
|
DB::transaction(function () use ($targetUser, $banLog, $modCommentText) {
|
||||||
$targetUser->updateWithModComment(['enabled' => User::ENABLED_NO], $modCommentText);
|
$targetUser->updateWithModComment(['enabled' => User::ENABLED_NO], $modCommentText);
|
||||||
UserBanLog::query()->insert($banLog);
|
UserBanLog::query()->insert($banLog);
|
||||||
@@ -177,7 +180,7 @@ class UserRepository extends BaseRepository
|
|||||||
{
|
{
|
||||||
$targetUser = User::query()->findOrFail($uid, ['id', 'enabled', 'username', 'class']);
|
$targetUser = User::query()->findOrFail($uid, ['id', 'enabled', 'username', 'class']);
|
||||||
if ($targetUser->enabled == User::ENABLED_YES) {
|
if ($targetUser->enabled == User::ENABLED_YES) {
|
||||||
throw new NexusException('Already enabled!');
|
throw new NexusException('Already enabled !');
|
||||||
}
|
}
|
||||||
$update = [
|
$update = [
|
||||||
'enabled' => User::ENABLED_YES
|
'enabled' => User::ENABLED_YES
|
||||||
@@ -191,7 +194,7 @@ class UserRepository extends BaseRepository
|
|||||||
$update['leechwarn'] = 'no';
|
$update['leechwarn'] = 'no';
|
||||||
$update['leechwarnuntil'] = null;
|
$update['leechwarnuntil'] = null;
|
||||||
}
|
}
|
||||||
$modCommentText = sprintf("Enable by %s.", $operator->username);
|
$modCommentText = sprintf("%s - Enable by %s.", now()->format('Y-m-d'), $operator->username);
|
||||||
$targetUser->updateWithModComment($update, $modCommentText);
|
$targetUser->updateWithModComment($update, $modCommentText);
|
||||||
do_log("user: $uid, $modCommentText, update: " . nexus_json_encode($update));
|
do_log("user: $uid, $modCommentText, update: " . nexus_json_encode($update));
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user