Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117976974
D4776.1775516824.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
D4776.1775516824.diff
View Options
diff --git a/src/app/Console/Commands/Tenant/CreateCommand.php b/src/app/Console/Commands/Tenant/CreateCommand.php
--- a/src/app/Console/Commands/Tenant/CreateCommand.php
+++ b/src/app/Console/Commands/Tenant/CreateCommand.php
@@ -13,14 +13,14 @@
*
* @var string
*/
- protected $signature = 'tenant:create {user} {--title=}';
+ protected $signature = 'tenant:create {user} {domain} {--title=} {--password=}';
/**
* The console command description.
*
* @var string
*/
- protected $description = "Create a tenant (with a set of SKUs/plans/packages) and make the user a reseller.";
+ protected $description = "Create a tenant (with a set of SKUs/plans/packages), and a reseller user and domain for it.";
/**
* Execute the console command.
@@ -29,11 +29,12 @@
*/
public function handle()
{
- $user = $this->getUser($this->argument('user'));
+ $user = \App\User::where('email', $this->argument('user'))->first();
if (!$user) {
- $this->error('User not found.');
- return 1;
+ $user = new \App\User();
+ $user->email = $this->argument('user');
+ $user->password = $this->option('password');
}
DB::beginTransaction();
@@ -162,5 +163,36 @@
}
$this->info("Created tenant {$tenant->id}.");
+
+ // Set up the primary tenant domain
+ $domain = \App\Domain::where('namespace', $this->argument('domain'))->first();
+ if (!$domain) {
+ // Set up the primary tenant domain
+ $domain = \App\Domain::create(
+ [
+ 'namespace' => $this->argument('domain'),
+ 'type' => \App\Domain::TYPE_PUBLIC,
+ ]
+ );
+ }
+ $domain->type = \App\Domain::TYPE_PUBLIC;
+ $domain->tenant_id = $tenant->id;
+ $domain->status = \App\Domain::STATUS_CONFIRMED | \App\Domain::STATUS_ACTIVE;
+ $domain->save();
+
+ $this->info("Created domain {$domain->id}.");
+
+ $tenant->setSettings([
+ "app.name" => $this->option("title"),
+ "app.url" => $this->argument("domain"),
+ "app.public_url" => "https://" . $this->argument("domain"),
+ "app.support_url" => "https://" . $this->argument("domain") . "/support",
+ "mail.sender.address" => "noreply@" . $this->argument("domain"),
+ "mail.sender.name" => $this->option("title"),
+ "mail.replyto.address" => "noreply@" . $this->argument("domain"),
+ "mail.replyto.name" => $this->option("title"),
+ ]);
+
+ $this->info("Applied default tenant settings.");
}
}
diff --git a/src/tests/Feature/Console/Tenant/CreateTest.php b/src/tests/Feature/Console/Tenant/CreateTest.php
--- a/src/tests/Feature/Console/Tenant/CreateTest.php
+++ b/src/tests/Feature/Console/Tenant/CreateTest.php
@@ -17,6 +17,7 @@
parent::setUp();
$this->deleteTestUser('test-tenant@kolabnow.com');
+ $this->deleteTestDomain('tenant.com');
}
/**
@@ -31,6 +32,7 @@
\App\Plan::where('tenant_id', $this->tenantId)->delete();
\App\Package::where('tenant_id', $this->tenantId)->delete();
\App\Sku::where('tenant_id', $this->tenantId)->delete();
+ \App\Domain::where('tenant_id', $this->tenantId)->delete();
\App\Tenant::find($this->tenantId)->delete();
}
@@ -48,10 +50,10 @@
// allow us to test "empty output" cases
// User not existing
- $code = \Artisan::call("tenant:create unknown@user.com");
+ $code = \Artisan::call("tenant:create unknown@user.com user.com");
$output = trim(\Artisan::output());
- $this->assertSame(1, $code);
- $this->assertSame("User not found.", $output);
+ $this->assertSame(0, $code);
+ $this->assertMatchesRegularExpression("/^Created tenant [0-9]+./", $output);
$user = $this->getTestUser('test-tenant@kolabnow.com');
@@ -59,7 +61,7 @@
$this->assertEquals($user->tenant_id, \config('app.tenant_id'));
// Existing user
- $code = \Artisan::call("tenant:create {$user->email} --title=\"Test Tenant\"");
+ $code = \Artisan::call("tenant:create {$user->email} tenant.com --title=\"Test Tenant\"");
$output = trim(\Artisan::output());
$this->assertSame(0, $code);
$this->assertMatchesRegularExpression("/^Created tenant [0-9]+./", $output);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Apr 6, 11:07 PM (15 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18839970
Default Alt Text
D4776.1775516824.diff (4 KB)
Attached To
Mode
D4776: Setup all a tenant needs in a single command
Attached
Detach File
Event Timeline