You've already forked Epicnabbo-Catalogus-Updated-Daily
Update EditUser.php
This commit is contained in:
@@ -29,7 +29,7 @@ class EditUser extends EditRecord
|
|||||||
#[\Override]
|
#[\Override]
|
||||||
protected function mutateFormDataBeforeFill(array $data): array
|
protected function mutateFormDataBeforeFill(array $data): array
|
||||||
{
|
{
|
||||||
return static::$resource::fillWithOutsideData(
|
return (array) static::$resource::fillWithOutsideData(
|
||||||
$this->getRecord(),
|
$this->getRecord(),
|
||||||
$data,
|
$data,
|
||||||
);
|
);
|
||||||
@@ -37,7 +37,7 @@ class EditUser extends EditRecord
|
|||||||
|
|
||||||
public static function getEloquentQuery(): Builder
|
public static function getEloquentQuery(): Builder
|
||||||
{
|
{
|
||||||
return static::getModel()::query()->with(['currencies', 'settings']);
|
return static::$resource::getModel()::query()->with(['currencies', 'settings']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,7 +76,7 @@ class EditUser extends EditRecord
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user->online && ! $rcon->isConnected()) {
|
if (! $rcon->isConnected()) {
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->danger()
|
->danger()
|
||||||
->title(__('RCON is not enabled!'))
|
->title(__('RCON is not enabled!'))
|
||||||
@@ -87,8 +87,9 @@ class EditUser extends EditRecord
|
|||||||
}
|
}
|
||||||
|
|
||||||
DB::transaction(function () use ($user, $data, $rcon): void {
|
DB::transaction(function () use ($user, $data, $rcon): void {
|
||||||
if ($data['credits'] != $user->credits) {
|
$newCredits = is_numeric($data['credits'] ?? null) ? (int) $data['credits'] : $user->credits;
|
||||||
$rcon->giveCredits($user, -$user->credits + $data['credits']);
|
if ($newCredits !== $user->credits) {
|
||||||
|
$rcon->giveCredits($user, -$user->credits + $newCredits);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->checkUsernameChangedPermission($user, $data, $rcon);
|
$this->checkUsernameChangedPermission($user, $data, $rcon);
|
||||||
@@ -102,11 +103,15 @@ class EditUser extends EditRecord
|
|||||||
{
|
{
|
||||||
$user->currencies->each(function (UserCurrency $currency) use ($data, $user): void {
|
$user->currencies->each(function (UserCurrency $currency) use ($data, $user): void {
|
||||||
$updatedCurrencyAmount = $data["currency_{$currency->type}"] ?? $currency->amount;
|
$updatedCurrencyAmount = $data["currency_{$currency->type}"] ?? $currency->amount;
|
||||||
if ($updatedCurrencyAmount == $currency->amount) {
|
if (! is_numeric($updatedCurrencyAmount)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$updatedCurrencyAmount = (int) $updatedCurrencyAmount;
|
||||||
|
if ($updatedCurrencyAmount === (int) $currency->amount) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$updated = $user->currencies()->where('type', $currency->type)->update(['amount' => (int) $updatedCurrencyAmount]);
|
$updated = $user->currencies()->where('type', $currency->type)->update(['amount' => $updatedCurrencyAmount]);
|
||||||
|
|
||||||
if ($updated) {
|
if ($updated) {
|
||||||
activity()
|
activity()
|
||||||
@@ -124,7 +129,7 @@ class EditUser extends EditRecord
|
|||||||
});
|
});
|
||||||
|
|
||||||
if ($user->settings) {
|
if ($user->settings) {
|
||||||
$user->settings->update(['can_change_name' => $data['allow_change_username'] ? '1' : '0']);
|
$user->settings->update(['can_change_name' => !empty($data['allow_change_username']) ? '1' : '0']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,12 +180,13 @@ class EditUser extends EditRecord
|
|||||||
|
|
||||||
private function treatChangedUserRank(\App\Models\User $user, array $data, RconService $rcon): void
|
private function treatChangedUserRank(\App\Models\User $user, array $data, RconService $rcon): void
|
||||||
{
|
{
|
||||||
if ($data['rank'] == $user->rank) {
|
$newRank = is_numeric($data['rank'] ?? null) ? (int) $data['rank'] : $user->rank;
|
||||||
|
if ($newRank === $user->rank) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$authUser = auth()->user();
|
$authUser = auth()->user();
|
||||||
$authRank = $authUser instanceof \App\Models\User ? $authUser->rank : 0;
|
$authRank = $authUser instanceof \App\Models\User ? $authUser->rank : 0;
|
||||||
if ($data['rank'] > $authRank) {
|
if ($newRank > $authRank) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +201,7 @@ class EditUser extends EditRecord
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! $user->online) {
|
if (! $user->online) {
|
||||||
$user->update(['rank' => $data['rank']]);
|
$user->update(['rank' => $newRank]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -204,12 +210,13 @@ class EditUser extends EditRecord
|
|||||||
\Illuminate\Support\Sleep::sleep(2);
|
\Illuminate\Support\Sleep::sleep(2);
|
||||||
|
|
||||||
$rcon->disconnectUser($user);
|
$rcon->disconnectUser($user);
|
||||||
$rcon->setRank($user, (int) $data['rank']);
|
$rcon->setRank($user, $newRank);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function treatChangedUserMotto(\App\Models\User $user, array $data, RconService $rcon): void
|
private function treatChangedUserMotto(\App\Models\User $user, array $data, RconService $rcon): void
|
||||||
{
|
{
|
||||||
if ($data['motto'] == $user->motto) {
|
$newMotto = is_string($data['motto'] ?? null) ? $data['motto'] : $user->motto;
|
||||||
|
if ($newMotto === $user->motto) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,12 +231,12 @@ class EditUser extends EditRecord
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! $user->online) {
|
if (! $user->online) {
|
||||||
$user->update(['motto' => $data['motto']]);
|
$user->update(['motto' => $newMotto]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rcon->setMotto($user, is_string($data['motto'] ?? null) ? $data['motto'] : '');
|
$rcon->setMotto($user, $newMotto);
|
||||||
$rcon->alertUser($user, __('Your motto has been changed by a staff member.'));
|
$rcon->alertUser($user, __('Your motto has been changed by a staff member.'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user