From e95e2cf152be6bb909a9a6eef8dc8c133840c580 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 14 May 2024 15:40:45 +0200 Subject: [PATCH] feat: Add AdminRemoveUser command to remove users from the database --- app/Console/Commands/AdminRemoveUser.php | 54 +++++++++++++++++++ app/Console/Commands/Cloud.php | 33 ------------ app/Console/Commands/RootResetPassword.php | 1 - .../Project/Shared/ScheduledTask/All.php | 1 - 4 files changed, 54 insertions(+), 35 deletions(-) create mode 100644 app/Console/Commands/AdminRemoveUser.php delete mode 100644 app/Console/Commands/Cloud.php diff --git a/app/Console/Commands/AdminRemoveUser.php b/app/Console/Commands/AdminRemoveUser.php new file mode 100644 index 000000000..76af0a97f --- /dev/null +++ b/app/Console/Commands/AdminRemoveUser.php @@ -0,0 +1,54 @@ +argument('email'); + $confirm = $this->confirm('Are you sure you want to remove user with email: ' . $email . '?'); + if (!$confirm) { + $this->info('User removal cancelled.'); + return; + } + $this->info("Removing user with email: $email"); + $user = User::whereEmail($email)->firstOrFail(); + $teams = $user->teams; + foreach ($teams as $team) { + if ($team->members->count() > 1) { + $this->error('User is a member of a team with more than one member. Please remove user from team first.'); + return; + } + $team->delete(); + } + $user->delete(); + } catch (\Exception $e) { + $this->error('Failed to remove user.'); + $this->error($e->getMessage()); + return; + } + } +} diff --git a/app/Console/Commands/Cloud.php b/app/Console/Commands/Cloud.php deleted file mode 100644 index 1386b296c..000000000 --- a/app/Console/Commands/Cloud.php +++ /dev/null @@ -1,33 +0,0 @@ -whereNotNull('team.subscription')->where('team.subscription.stripe_trial_already_ended',true)->each(function($server){ - $this->info($server->name); - }); - } -} diff --git a/app/Console/Commands/RootResetPassword.php b/app/Console/Commands/RootResetPassword.php index df385002e..af2b1a45c 100644 --- a/app/Console/Commands/RootResetPassword.php +++ b/app/Console/Commands/RootResetPassword.php @@ -29,7 +29,6 @@ class RootResetPassword extends Command */ public function handle() { - // $this->info('You are about to reset the root password.'); $password = password('Give me a new password for root user: '); $passwordAgain = password('Again'); diff --git a/app/Livewire/Project/Shared/ScheduledTask/All.php b/app/Livewire/Project/Shared/ScheduledTask/All.php index 73b2733b4..5182639d7 100644 --- a/app/Livewire/Project/Shared/ScheduledTask/All.php +++ b/app/Livewire/Project/Shared/ScheduledTask/All.php @@ -20,7 +20,6 @@ public function mount() if ($this->resource->type() == 'service') { $this->containerNames = $this->resource->applications()->pluck('name'); $this->containerNames = $this->containerNames->merge($this->resource->databases()->pluck('name')); - ray($this->containerNames); } elseif ($this->resource->type() == 'application') { if ($this->resource->build_pack === 'dockercompose') { $parsed = $this->resource->parseCompose();