mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
Update User model and fix role stacking
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum QueueType: int
|
||||||
|
{
|
||||||
|
case NONE = 0;
|
||||||
|
case SABNZBD = 1;
|
||||||
|
case NZBGET = 2;
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::NONE => 'None',
|
||||||
|
self::SABNZBD => 'SABnzbd',
|
||||||
|
self::NZBGET => 'NZBGet',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum SignupError: int
|
||||||
|
{
|
||||||
|
case BAD_USERNAME = -1;
|
||||||
|
case BAD_PASSWORD = -2;
|
||||||
|
case BAD_EMAIL = -3;
|
||||||
|
case USERNAME_IN_USE = -4;
|
||||||
|
case EMAIL_IN_USE = -5;
|
||||||
|
case BAD_INVITE_CODE = -6;
|
||||||
|
case SUCCESS = 1;
|
||||||
|
|
||||||
|
public function message(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::BAD_USERNAME => 'Invalid username provided.',
|
||||||
|
self::BAD_PASSWORD => 'Invalid password provided.',
|
||||||
|
self::BAD_EMAIL => 'Invalid email address provided.',
|
||||||
|
self::USERNAME_IN_USE => 'Username is already in use.',
|
||||||
|
self::EMAIL_IN_USE => 'Email address is already in use.',
|
||||||
|
self::BAD_INVITE_CODE => 'Invalid or expired invite code.',
|
||||||
|
self::SUCCESS => 'Registration successful.',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isError(): bool
|
||||||
|
{
|
||||||
|
return $this->value < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isSuccess(): bool
|
||||||
|
{
|
||||||
|
return $this === self::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum UserRole: int
|
||||||
|
{
|
||||||
|
case USER = 1;
|
||||||
|
case ADMIN = 2;
|
||||||
|
case DISABLED = 3;
|
||||||
|
case MODERATOR = 4;
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::USER => 'User',
|
||||||
|
self::ADMIN => 'Admin',
|
||||||
|
self::DISABLED => 'Disabled',
|
||||||
|
self::MODERATOR => 'Moderator',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isAdmin(): bool
|
||||||
|
{
|
||||||
|
return $this === self::ADMIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isModerator(): bool
|
||||||
|
{
|
||||||
|
return $this === self::MODERATOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDisabled(): bool
|
||||||
|
{
|
||||||
|
return $this === self::DISABLED;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasElevatedPrivileges(): bool
|
||||||
|
{
|
||||||
|
return in_array($this, [self::ADMIN, self::MODERATOR], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -173,7 +173,20 @@ class AdminUserController extends BasePageController
|
|||||||
|
|
||||||
// CRITICAL: Capture the ORIGINAL rolechangedate BEFORE any updates
|
// CRITICAL: Capture the ORIGINAL rolechangedate BEFORE any updates
|
||||||
// This is needed for accurate role history tracking
|
// This is needed for accurate role history tracking
|
||||||
$originalRoleChangeDate = $editedUser->rolechangedate;
|
// Convert to string to avoid any Carbon object reference issues
|
||||||
|
$originalRoleChangeDate = $editedUser->rolechangedate
|
||||||
|
? $editedUser->rolechangedate->toDateTimeString()
|
||||||
|
: null;
|
||||||
|
|
||||||
|
\Log::info('AdminUserController - Before updates', [
|
||||||
|
'user_id' => $editedUser->id,
|
||||||
|
'originalRoleChangeDate' => $originalRoleChangeDate,
|
||||||
|
'current_roles_id' => $editedUser->roles_id,
|
||||||
|
'requested_role' => $request->input('role'),
|
||||||
|
'roleChanged' => $roleChanged,
|
||||||
|
'stackRole' => $stackRole,
|
||||||
|
'form_rolechangedate' => $request->input('rolechangedate'),
|
||||||
|
]);
|
||||||
|
|
||||||
// Handle pending role cancellation
|
// Handle pending role cancellation
|
||||||
if ($request->has('cancel_pending_role') && $request->input('cancel_pending_role')) {
|
if ($request->has('cancel_pending_role') && $request->input('cancel_pending_role')) {
|
||||||
@@ -193,11 +206,24 @@ class AdminUserController extends BasePageController
|
|||||||
$editedUser->update(['rolechangedate' => null]);
|
$editedUser->update(['rolechangedate' => null]);
|
||||||
}
|
}
|
||||||
$editedUser->refresh();
|
$editedUser->refresh();
|
||||||
|
|
||||||
|
\Log::info('AdminUserController - After expiry update', [
|
||||||
|
'user_id' => $editedUser->id,
|
||||||
|
'new_rolechangedate' => $editedUser->rolechangedate,
|
||||||
|
'adminManuallySetExpiry' => $adminManuallySetExpiry,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If role is changing, handle it with stacking logic
|
// If role is changing, handle it with stacking logic
|
||||||
// Pass the original expiry so history records the correct old_expiry_date
|
// Pass the original expiry so history records the correct old_expiry_date
|
||||||
if ($roleChanged && $request->input('role') !== null) {
|
if ($roleChanged && $request->input('role') !== null) {
|
||||||
|
\Log::info('AdminUserController - About to call updateUserRole', [
|
||||||
|
'user_id' => $editedUser->id,
|
||||||
|
'new_role' => (int) $request->input('role'),
|
||||||
|
'originalRoleChangeDate_passed' => $originalRoleChangeDate,
|
||||||
|
'current_user_rolechangedate' => $editedUser->rolechangedate,
|
||||||
|
]);
|
||||||
|
|
||||||
User::updateUserRole(
|
User::updateUserRole(
|
||||||
$editedUser->id,
|
$editedUser->id,
|
||||||
(int) $request->input('role'), // Cast to integer
|
(int) $request->input('role'), // Cast to integer
|
||||||
|
|||||||
+1073
-805
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user