Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117366471
D1546.1774816712.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
8 KB
Referenced Files
None
Subscribers
None
D1546.1774816712.diff
View Options
diff --git a/src/app/Console/Commands/DomainAdd.php b/src/app/Console/Commands/DomainAdd.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/DomainAdd.php
@@ -0,0 +1,75 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Domain;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Queue;
+
+class DomainAdd extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'domain:add {domain} {--force}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = "Create a domain.";
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $namespace = \strtolower($this->argument('domain'));
+
+ // must use withTrashed(), because unique constraint
+ $domain = Domain::withTrashed()->where('namespace', $namespace)->first();
+
+ if ($domain && !$this->option('force')) {
+ $this->error("Domain {$namespace} already exists.");
+ return 1;
+ }
+
+ Queue::fake(); // ignore LDAP for now
+
+ if ($domain) {
+ if ($domain->deleted_at) {
+ // revive domain
+ $domain->deleted_at = null;
+ $domain->status = 0;
+ $domain->save();
+
+ // remove existing entitlement
+ $entitlement = Entitlement::withTrashed()->where(
+ [
+ 'entitleable_id' => $domain->id,
+ 'entitleable_type' => \App\Domain::class
+ ]
+ )->first();
+
+ if ($entitlement) {
+ $entitlement->forceDelete();
+ }
+ } else {
+ $this->error("Domain {$namespace} not marked as deleted... examine more closely");
+ return 1;
+ }
+ } else {
+ $domain = Domain::create([
+ 'namespace' => $namespace,
+ 'type' => Domain::TYPE_EXTERNAL,
+ ]);
+ }
+
+ $this->info($domain->id);
+ }
+}
diff --git a/src/app/Console/Commands/DomainStatus.php b/src/app/Console/Commands/DomainSetStatus.php
copy from src/app/Console/Commands/DomainStatus.php
copy to src/app/Console/Commands/DomainSetStatus.php
--- a/src/app/Console/Commands/DomainStatus.php
+++ b/src/app/Console/Commands/DomainSetStatus.php
@@ -4,32 +4,23 @@
use App\Domain;
use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Queue;
-class DomainStatus extends Command
+class DomainSetStatus extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
- protected $signature = 'domain:status {domain}';
+ protected $signature = 'domain:set-status {domain} {status}';
/**
* The console command description.
*
* @var string
*/
- protected $description = 'Display the status of a domain';
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
+ protected $description = "Set a domain's status.";
/**
* Execute the console command.
@@ -44,7 +35,10 @@
return 1;
}
- $this->info("Found domain: {$domain->id}");
+ Queue::fake(); // ignore LDAP for now
+
+ $domain->status = (int) $this->argument('status');
+ $domain->save();
$this->info($domain->status);
}
diff --git a/src/app/Console/Commands/DomainSetWallet.php b/src/app/Console/Commands/DomainSetWallet.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/DomainSetWallet.php
@@ -0,0 +1,68 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Entitlement;
+use App\Domain;
+use App\Sku;
+use App\Wallet;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Queue;
+
+class DomainSetWallet extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'domain:set-wallet {domain} {wallet}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = "Assign a domain to a wallet.";
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $domain = Domain::where('namespace', $this->argument('domain'))->first();
+
+ if (!$domain) {
+ $this->error("Domain not found.");
+ return 1;
+ }
+
+ $wallet = Wallet::find($this->argument('wallet'));
+
+ if (!$wallet) {
+ $this->error("Wallet not found.");
+ return 1;
+ }
+
+ if ($domain->entitlement) {
+ $this->error("Domain already assigned to a wallet: {$domain->entitlement->wallet->id}.");
+ return 1;
+ }
+
+ $sku = Sku::where('title', 'domain-hosting')->first();
+
+ Queue::fake(); // ignore LDAP for now (note: adding entitlements updates the domain)
+
+ Entitlement::create(
+ [
+ 'wallet_id' => $wallet->id,
+ 'sku_id' => $sku->id,
+ 'cost' => 0,
+ 'entitleable_id' => $domain->id,
+ 'entitleable_type' => Domain::class,
+ ]
+ );
+ }
+}
diff --git a/src/app/Console/Commands/DomainStatus.php b/src/app/Console/Commands/DomainStatus.php
--- a/src/app/Console/Commands/DomainStatus.php
+++ b/src/app/Console/Commands/DomainStatus.php
@@ -44,8 +44,6 @@
return 1;
}
- $this->info("Found domain: {$domain->id}");
-
$this->info($domain->status);
}
}
diff --git a/src/app/Observers/UserAliasObserver.php b/src/app/Observers/UserAliasObserver.php
--- a/src/app/Observers/UserAliasObserver.php
+++ b/src/app/Observers/UserAliasObserver.php
@@ -21,17 +21,22 @@
{
$alias->alias = \strtolower($alias->alias);
- if ($exists = User::emailExists($alias->alias, true, $alias_exists)) {
+ list($login, $domain) = explode('@', $alias->alias);
+
+ $domain = Domain::where('namespace', $domain)->first();
+
+ if (!$domain) {
+ \Log::error("Failed creating alias {$alias->alias}. Domain does not exist.");
+ return false;
+ }
+/*
+ if ($exists = User::emailExists($alias->alias, true, $alias_exists, !$domain->isPublic())) {
if (!$alias_exists) {
\Log::error("Failed creating alias {$alias->alias}. Email address exists.");
return false;
}
- list($login, $domain) = explode('@', $alias->alias);
-
- $domain = Domain::where('namespace', $domain)->first();
-
- if (!$domain || $domain->isPublic()) {
+ if ($domain->isPublic()) {
\Log::error("Failed creating alias {$alias->alias}. Alias exists in public domain.");
return false;
}
@@ -41,7 +46,7 @@
return false;
}
}
-
+*/
return true;
}
diff --git a/src/tests/Feature/Controller/UsersTest.php b/src/tests/Feature/Controller/UsersTest.php
--- a/src/tests/Feature/Controller/UsersTest.php
+++ b/src/tests/Feature/Controller/UsersTest.php
@@ -418,6 +418,8 @@
{
$jack = $this->getTestUser('jack@kolab.org');
$john = $this->getTestUser('john@kolab.org');
+ $deleted_priv = $this->getTestUser('deleted@kolab.org');
+ $deleted_priv->delete();
// Test empty request
$response = $this->actingAs($john)->post("/api/v4/users", []);
@@ -481,7 +483,7 @@
'last_name' => 'Doe2',
'email' => 'john2.doe2@kolab.org',
'organization' => 'TestOrg',
- 'aliases' => ['useralias1@kolab.org', 'useralias2@kolab.org'],
+ 'aliases' => ['useralias1@kolab.org', 'deleted@kolab.org'],
];
// Missing package
@@ -523,8 +525,8 @@
$this->assertSame('TestOrg', $user->getSetting('organization'));
$aliases = $user->aliases()->orderBy('alias')->get();
$this->assertCount(2, $aliases);
- $this->assertSame('useralias1@kolab.org', $aliases[0]->alias);
- $this->assertSame('useralias2@kolab.org', $aliases[1]->alias);
+ $this->assertSame('deleted@kolab.org', $aliases[0]->alias);
+ $this->assertSame('useralias1@kolab.org', $aliases[1]->alias);
// Assert the new user entitlements
$this->assertUserEntitlements($user, ['groupware', 'mailbox', 'storage', 'storage']);
// Assert the wallet to which the new user should be assigned to
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 29, 8:38 PM (4 d, 7 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18775836
Default Alt Text
D1546.1774816712.diff (8 KB)
Attached To
Mode
D1546: Fix UserAliasObserver
Attached
Detach File
Event Timeline