diff --git a/src/app/Console/Command.php b/src/app/Console/Command.php --- a/src/app/Console/Command.php +++ b/src/app/Console/Command.php @@ -77,6 +77,10 @@ $model = new $objectClass(); } + if ($this->commandPrefix == 'scalpel') { + return $model; + } + $modelsWithTenant = [ \App\Discount::class, \App\Domain::class, @@ -91,22 +95,20 @@ \App\Wallet::class, ]; - $tenant_id = \config('app.tenant_id'); + $tenantId = \config('app.tenant_id'); // Add tenant filter if (in_array($objectClass, $modelsWithTenant)) { $model = $model->withEnvTenant(); } elseif (in_array($objectClass, $modelsWithOwner)) { - $model = $model->whereExists(function ($query) use ($tenant_id) { + $model = $model->whereExists(function ($query) use ($tenantId) { $query->select(DB::raw(1)) ->from('users') ->whereRaw('wallets.user_id = users.id') - ->whereRaw('users.tenant_id ' . ($tenant_id ? "= $tenant_id" : 'is null')); + ->whereRaw('users.tenant_id ' . ($tenantId ? "= $tenantId" : 'is null')); }); } - // TODO: tenant check for Entitlement, Transaction, etc. - return $model; } diff --git a/src/app/Console/Commands/User/StatusCommand.php b/src/app/Console/Commands/User/StatusCommand.php new file mode 100644 --- /dev/null +++ b/src/app/Console/Commands/User/StatusCommand.php @@ -0,0 +1,71 @@ +withEnvTenant()->where('email', $this->argument('user'))->first(); + + if (!$user) { + $user = \App\User::withTrashed()->withEnvTenant()->where('id', $this->argument('user'))->first(); + } + + if (!$user) { + $this->error("No such user '" . $this->argument('user') . "' within this tenant context."); + $this->info("Try ./artisan scalpel:user:read --attr=email --attr=tenant_id " . $this->argument('user')); + return 1; + } + + $statuses = [ + 'active' => \App\User::STATUS_ACTIVE, + 'suspended' => \App\User::STATUS_SUSPENDED, + 'deleted' => \App\User::STATUS_DELETED, + 'ldapReady' => \App\User::STATUS_LDAP_READY, + 'imapReady' => \App\User::STATUS_IMAP_READY, + ]; + + $user_state = []; + + foreach (\array_keys($statuses) as $state) { + $func = 'is' . \ucfirst($state); + if ($user->$func()) { + $user_state[] = $state; + } + } + + $this->info("Status: " . \implode(',', $user_state)); + } +} diff --git a/src/app/Console/Commands/UserStatus.php b/src/app/Console/Commands/UserStatus.php deleted file mode 100644 --- a/src/app/Console/Commands/UserStatus.php +++ /dev/null @@ -1,53 +0,0 @@ -getUser($this->argument('user')); - - if (!$user) { - return 1; - } - - $statuses = [ - 'active' => User::STATUS_ACTIVE, - 'suspended' => User::STATUS_SUSPENDED, - 'deleted' => User::STATUS_DELETED, - 'ldapReady' => User::STATUS_LDAP_READY, - 'imapReady' => User::STATUS_IMAP_READY, - ]; - - foreach ($statuses as $text => $bit) { - $func = 'is' . \ucfirst($text); - - $this->info(sprintf("%d %s: %s", $bit, $text, $user->$func())); - } - - $this->info("In total: {$user->status}"); - } -} diff --git a/src/app/Console/Development/UserStatus.php b/src/app/Console/Development/UserStatus.php deleted file mode 100644 --- a/src/app/Console/Development/UserStatus.php +++ /dev/null @@ -1,86 +0,0 @@ -argument('userid'))->firstOrFail(); - - $this->info("Found user: {$user->id}"); - - $statuses = [ - 'active' => User::STATUS_ACTIVE, - 'suspended' => User::STATUS_SUSPENDED, - 'deleted' => User::STATUS_DELETED, - 'ldapReady' => User::STATUS_LDAP_READY, - 'imapReady' => User::STATUS_IMAP_READY, - ]; - - // I'd prefer "-state" and "+state" syntax, but it's not possible - $delete = false; - if ($update = $this->option('del')) { - $delete = true; - } elseif ($update = $this->option('add')) { - // do nothing - } - - if (!empty($update)) { - $map = \array_change_key_case($statuses); - $update = \strtolower($update); - - if (isset($map[$update])) { - if ($delete && $user->status & $map[$update]) { - $user->status ^= $map[$update]; - $user->save(); - } elseif (!$delete && !($user->status & $map[$update])) { - $user->status |= $map[$update]; - $user->save(); - } - } - } - - $user_state = []; - foreach (\array_keys($statuses) as $state) { - $func = 'is' . \ucfirst($state); - if ($user->$func()) { - $user_state[] = $state; - } - } - - $this->info("Status: " . \implode(',', $user_state)); - } -}