diff --git a/backend/app/Console/Commands/UserPromoteCommand.php b/backend/app/Console/Commands/UserPromoteCommand.php new file mode 100644 index 0000000..9c6e0a6 --- /dev/null +++ b/backend/app/Console/Commands/UserPromoteCommand.php @@ -0,0 +1,59 @@ +argument('email'); + if (! is_string($rawEmail) || $rawEmail === '') { + $this->error('email is required'); + + return self::FAILURE; + } + + try { + $email = new EmailAddress($rawEmail); + } catch (InvalidArgumentException $exception) { + $this->error($exception->getMessage()); + + return self::FAILURE; + } + + $user = $userRepo->findByEmail($email); + if ($user === null) { + $this->error("user not found: {$rawEmail}"); + + return self::FAILURE; + } + + if ($user->isAdmin()) { + $this->info("{$rawEmail} is already an admin"); + + return self::SUCCESS; + } + + $userRepo->update(new User( + id: $user->getId(), + email: $user->getEmail(), + displayName: $user->getDisplayName(), + passwordHash: $user->getPasswordHash(), + isAdmin: true, + emailConfirmedAt: $user->getEmailConfirmedAt(), + )); + $this->info("{$rawEmail} is now an admin"); + + return self::SUCCESS; + } +}