Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117814413
D2641.1775282211.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None
D2641.1775282211.diff
View Options
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 @@
+<?php
+
+namespace App\Console\Commands\User;
+
+use Illuminate\Console\Command;
+
+class StatusCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'user:status {user}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = "Show a user's status.";
+
+ /**
+ * Create a new command instance.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $user = \App\User::withTrashed()->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 @@
-<?php
-
-namespace App\Console\Commands;
-
-use App\Console\Command;
-use App\User;
-
-class UserStatus extends Command
-{
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'user:status {user}';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Display the status of a user';
-
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $user = $this->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 @@
-<?php
-
-namespace App\Console\Development;
-
-use App\User;
-use Illuminate\Console\Command;
-
-class UserStatus extends Command
-{
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'user:status {userid} {--add=} {--del=}';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = "Set/get a user's status.";
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $user = User::where('email', $this->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));
- }
-}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 4, 5:56 AM (1 d, 14 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18828300
Default Alt Text
D2641.1775282211.diff (7 KB)
Attached To
Mode
D2641: Enhance user:status command to fix running within the environment as well as include deleted users
Attached
Detach File
Event Timeline