Skip to content

Commit

Permalink
feat: improve how RockShell runs as superuser
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Feb 8, 2024
1 parent 17a372a commit 85bea3c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions App/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Console\Command as ConsoleCommand;
use LogicException;
use ProcessWire\ProcessWire;
use ProcessWire\User;
use ReflectionClass;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -386,18 +387,19 @@ public function success($str)
}

/**
* Change to the first superuser
* Make RockShell run as superuser
* @return void
*/
public function sudo($silent = false): void
public function sudo(): void
{
if (!$this->wire()) return;
$role = $this->wire()->roles->get('superuser');
$su = $this->wire()->users->get("sort=id,roles=$role");
if (!$su->id and !$silent) {
$this->log("No superuser found");
return;
}
// this will create a new superuser at runtime
// this ensures that we can run rockshell without superusers on the system
// it also ensures that the user has the default language set which is
// important to avoid hard to find bugs where scripts set values
// in non-default languages
$su = new User();
$su->addRole("superuser");
$this->wire()->users->setCurrentUser($su);
}

Expand Down

0 comments on commit 85bea3c

Please sign in to comment.