Skip to content

Commit 8846da2

Browse files
authored
Merge pull request #873 from HiEventsDev/develop
2 parents dd7381f + 3c2a389 commit 8846da2

File tree

108 files changed

+4544
-153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+4544
-153
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
namespace HiEvents\Console\Commands;
4+
5+
use Exception;
6+
use HiEvents\DomainObjects\Enums\Role;
7+
use HiEvents\Repository\Interfaces\AccountUserRepositoryInterface;
8+
use HiEvents\Repository\Interfaces\UserRepositoryInterface;
9+
use Illuminate\Console\Command;
10+
use Psr\Log\LoggerInterface;
11+
12+
class AssignSuperAdminCommand extends Command
13+
{
14+
protected $signature = 'user:make-superadmin {userId : The ID of the user to make a superadmin}';
15+
16+
protected $description = 'Assign SUPERADMIN role to a user. WARNING: This grants complete system access.';
17+
18+
public function __construct(
19+
private readonly UserRepositoryInterface $userRepository,
20+
private readonly AccountUserRepositoryInterface $accountUserRepository,
21+
private readonly LoggerInterface $logger,
22+
)
23+
{
24+
parent::__construct();
25+
}
26+
27+
public function handle(): int
28+
{
29+
$userId = $this->argument('userId');
30+
31+
$this->warn('⚠️ WARNING: This command will grant COMPLETE SYSTEM ACCESS to the user.');
32+
$this->warn('⚠️ SUPERADMIN users have unrestricted access to all accounts and data.');
33+
$this->newLine();
34+
35+
if (!$this->confirm('Are you sure you want to proceed?', false)) {
36+
$this->info('Operation cancelled.');
37+
return self::FAILURE;
38+
}
39+
40+
try {
41+
$user = $this->userRepository->findById((int)$userId);
42+
} catch (Exception $exception) {
43+
$this->error("Error finding user with ID: $userId" . " Message: " . $exception->getMessage());
44+
return self::FAILURE;
45+
}
46+
47+
$this->info("Found user: {$user->getFullName()} ({$user->getEmail()})");
48+
$this->newLine();
49+
50+
if (!$this->confirm('Confirm assigning SUPERADMIN role to this user?', false)) {
51+
$this->info('Operation cancelled.');
52+
return self::FAILURE;
53+
}
54+
55+
$accountUsers = $this->accountUserRepository->findWhere([
56+
'user_id' => $userId,
57+
]);
58+
59+
if ($accountUsers->isEmpty()) {
60+
$this->error('User is not associated with any accounts.');
61+
return self::FAILURE;
62+
}
63+
64+
$updatedCount = 0;
65+
foreach ($accountUsers as $accountUser) {
66+
if ($accountUser->getRole() === Role::SUPERADMIN->name) {
67+
$this->comment("User already has SUPERADMIN role for account ID: {$accountUser->getAccountId()}");
68+
continue;
69+
}
70+
71+
$this->accountUserRepository->updateWhere(
72+
attributes: [
73+
'role' => Role::SUPERADMIN->name,
74+
],
75+
where: [
76+
'id' => $accountUser->getId(),
77+
]
78+
);
79+
80+
$updatedCount++;
81+
82+
$this->logger->critical('SUPERADMIN role assigned via console command', [
83+
'user_id' => $userId,
84+
'user_email' => $user->getEmail(),
85+
'account_id' => $accountUser->getAccountId(),
86+
'previous_role' => $accountUser->getRole(),
87+
'command' => $this->signature,
88+
]);
89+
}
90+
91+
$this->newLine();
92+
$this->info("✓ Successfully assigned SUPERADMIN role to user across $updatedCount account(s).");
93+
$this->warn("⚠️ User {$user->getFullName()} now has COMPLETE SYSTEM ACCESS.");
94+
95+
$this->logger->critical('SUPERADMIN role assignment completed', [
96+
'user_id' => $userId,
97+
'accounts_updated' => $updatedCount,
98+
]);
99+
100+
return self::SUCCESS;
101+
}
102+
}

backend/app/DomainObjects/Enums/Role.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ enum Role: string
66
{
77
use BaseEnum;
88

9+
case SUPERADMIN = 'SUPERADMIN';
910
case ADMIN = 'ADMIN';
1011
case ORGANIZER = 'ORGANIZER';
12+
13+
public static function getAssignableRoles(): array
14+
{
15+
return [
16+
self::ADMIN->value,
17+
self::ORGANIZER->value,
18+
];
19+
}
1120
}
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
<?php
2+
3+
namespace HiEvents\DomainObjects\Generated;
4+
5+
/**
6+
* THIS FILE IS AUTOGENERATED - DO NOT EDIT IT DIRECTLY.
7+
* @package HiEvents\DomainObjects\Generated
8+
*/
9+
abstract class OrderPaymentPlatformFeeDomainObjectAbstract extends \HiEvents\DomainObjects\AbstractDomainObject
10+
{
11+
final public const SINGULAR_NAME = 'order_payment_platform_fee';
12+
final public const PLURAL_NAME = 'order_payment_platform_fees';
13+
final public const ID = 'id';
14+
final public const ORDER_ID = 'order_id';
15+
final public const PAYMENT_PLATFORM = 'payment_platform';
16+
final public const FEE_ROLLUP = 'fee_rollup';
17+
final public const PAYMENT_PLATFORM_FEE_AMOUNT = 'payment_platform_fee_amount';
18+
final public const APPLICATION_FEE_AMOUNT = 'application_fee_amount';
19+
final public const CURRENCY = 'currency';
20+
final public const TRANSACTION_ID = 'transaction_id';
21+
final public const PAID_AT = 'paid_at';
22+
final public const DELETED_AT = 'deleted_at';
23+
final public const CREATED_AT = 'created_at';
24+
final public const UPDATED_AT = 'updated_at';
25+
26+
protected int $id;
27+
protected int $order_id;
28+
protected string $payment_platform;
29+
protected array|string|null $fee_rollup = null;
30+
protected float $payment_platform_fee_amount;
31+
protected float $application_fee_amount = 0.0;
32+
protected string $currency = 'USD';
33+
protected ?string $transaction_id = null;
34+
protected ?string $paid_at = null;
35+
protected ?string $deleted_at = null;
36+
protected ?string $created_at = null;
37+
protected ?string $updated_at = null;
38+
39+
public function toArray(): array
40+
{
41+
return [
42+
'id' => $this->id ?? null,
43+
'order_id' => $this->order_id ?? null,
44+
'payment_platform' => $this->payment_platform ?? null,
45+
'fee_rollup' => $this->fee_rollup ?? null,
46+
'payment_platform_fee_amount' => $this->payment_platform_fee_amount ?? null,
47+
'application_fee_amount' => $this->application_fee_amount ?? null,
48+
'currency' => $this->currency ?? null,
49+
'transaction_id' => $this->transaction_id ?? null,
50+
'paid_at' => $this->paid_at ?? null,
51+
'deleted_at' => $this->deleted_at ?? null,
52+
'created_at' => $this->created_at ?? null,
53+
'updated_at' => $this->updated_at ?? null,
54+
];
55+
}
56+
57+
public function setId(int $id): self
58+
{
59+
$this->id = $id;
60+
return $this;
61+
}
62+
63+
public function getId(): int
64+
{
65+
return $this->id;
66+
}
67+
68+
public function setOrderId(int $order_id): self
69+
{
70+
$this->order_id = $order_id;
71+
return $this;
72+
}
73+
74+
public function getOrderId(): int
75+
{
76+
return $this->order_id;
77+
}
78+
79+
public function setPaymentPlatform(string $payment_platform): self
80+
{
81+
$this->payment_platform = $payment_platform;
82+
return $this;
83+
}
84+
85+
public function getPaymentPlatform(): string
86+
{
87+
return $this->payment_platform;
88+
}
89+
90+
public function setFeeRollup(array|string|null $fee_rollup): self
91+
{
92+
$this->fee_rollup = $fee_rollup;
93+
return $this;
94+
}
95+
96+
public function getFeeRollup(): array|string|null
97+
{
98+
return $this->fee_rollup;
99+
}
100+
101+
public function setPaymentPlatformFeeAmount(float $payment_platform_fee_amount): self
102+
{
103+
$this->payment_platform_fee_amount = $payment_platform_fee_amount;
104+
return $this;
105+
}
106+
107+
public function getPaymentPlatformFeeAmount(): float
108+
{
109+
return $this->payment_platform_fee_amount;
110+
}
111+
112+
public function setApplicationFeeAmount(float $application_fee_amount): self
113+
{
114+
$this->application_fee_amount = $application_fee_amount;
115+
return $this;
116+
}
117+
118+
public function getApplicationFeeAmount(): float
119+
{
120+
return $this->application_fee_amount;
121+
}
122+
123+
public function setCurrency(string $currency): self
124+
{
125+
$this->currency = $currency;
126+
return $this;
127+
}
128+
129+
public function getCurrency(): string
130+
{
131+
return $this->currency;
132+
}
133+
134+
public function setTransactionId(?string $transaction_id): self
135+
{
136+
$this->transaction_id = $transaction_id;
137+
return $this;
138+
}
139+
140+
public function getTransactionId(): ?string
141+
{
142+
return $this->transaction_id;
143+
}
144+
145+
public function setPaidAt(?string $paid_at): self
146+
{
147+
$this->paid_at = $paid_at;
148+
return $this;
149+
}
150+
151+
public function getPaidAt(): ?string
152+
{
153+
return $this->paid_at;
154+
}
155+
156+
public function setDeletedAt(?string $deleted_at): self
157+
{
158+
$this->deleted_at = $deleted_at;
159+
return $this;
160+
}
161+
162+
public function getDeletedAt(): ?string
163+
{
164+
return $this->deleted_at;
165+
}
166+
167+
public function setCreatedAt(?string $created_at): self
168+
{
169+
$this->created_at = $created_at;
170+
return $this;
171+
}
172+
173+
public function getCreatedAt(): ?string
174+
{
175+
return $this->created_at;
176+
}
177+
178+
public function setUpdatedAt(?string $updated_at): self
179+
{
180+
$this->updated_at = $updated_at;
181+
return $this;
182+
}
183+
184+
public function getUpdatedAt(): ?string
185+
{
186+
return $this->updated_at;
187+
}
188+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace HiEvents\DomainObjects;
4+
5+
class OrderPaymentPlatformFeeDomainObject extends Generated\OrderPaymentPlatformFeeDomainObjectAbstract
6+
{
7+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace HiEvents\Http\Actions\Admin\Accounts;
6+
7+
use HiEvents\DomainObjects\Enums\Role;
8+
use HiEvents\Http\Actions\BaseAction;
9+
use HiEvents\Resources\Account\AdminAccountResource;
10+
use HiEvents\Services\Application\Handlers\Admin\DTO\GetAllAccountsDTO;
11+
use HiEvents\Services\Application\Handlers\Admin\GetAllAccountsHandler;
12+
use Illuminate\Http\JsonResponse;
13+
use Illuminate\Http\Request;
14+
15+
class GetAllAccountsAction extends BaseAction
16+
{
17+
public function __construct(
18+
private readonly GetAllAccountsHandler $handler,
19+
)
20+
{
21+
}
22+
23+
public function __invoke(Request $request): JsonResponse
24+
{
25+
$this->minimumAllowedRole(Role::SUPERADMIN);
26+
27+
$accounts = $this->handler->handle(new GetAllAccountsDTO(
28+
perPage: min((int)$request->query('per_page', 20), 100),
29+
search: $request->query('search'),
30+
));
31+
32+
return $this->resourceResponse(
33+
resource: AdminAccountResource::class,
34+
data: $accounts
35+
);
36+
}
37+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace HiEvents\Http\Actions\Admin\Events;
6+
7+
use HiEvents\DomainObjects\Enums\Role;
8+
use HiEvents\Http\Actions\BaseAction;
9+
use HiEvents\Resources\Event\EventResource;
10+
use HiEvents\Services\Application\Handlers\Admin\DTO\GetUpcomingEventsDTO;
11+
use HiEvents\Services\Application\Handlers\Admin\GetUpcomingEventsHandler;
12+
use Illuminate\Http\JsonResponse;
13+
use Illuminate\Http\Request;
14+
15+
class GetUpcomingEventsAction extends BaseAction
16+
{
17+
public function __construct(
18+
private readonly GetUpcomingEventsHandler $handler,
19+
)
20+
{
21+
}
22+
23+
public function __invoke(Request $request): JsonResponse
24+
{
25+
$this->minimumAllowedRole(Role::SUPERADMIN);
26+
27+
$events = $this->handler->handle(new GetUpcomingEventsDTO(
28+
perPage: min((int)$request->query('per_page', 20), 100),
29+
));
30+
31+
return $this->resourceResponse(
32+
resource: EventResource::class,
33+
data: $events
34+
);
35+
}
36+
}

0 commit comments

Comments
 (0)