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 @@ -5,31 +5,21 @@ use App\Domain; use Illuminate\Console\Command; -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 +34,8 @@ return 1; } - $this->info("Found domain: {$domain->id}"); + $domain->status = (int) $this->argument('status'); + $domain->save(); $this->info($domain->status); } 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