Changeset View
Changeset View
Standalone View
Standalone View
src/app/Domain.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use App\Wallet; | use App\Wallet; | ||||
use App\Traits\BelongsToTenantTrait; | use App\Traits\BelongsToTenantTrait; | ||||
use App\Traits\DomainConfigTrait; | use App\Traits\DomainConfigTrait; | ||||
use App\Traits\EntitleableTrait; | use App\Traits\EntitleableTrait; | ||||
use App\Traits\SettingsTrait; | use App\Traits\SettingsTrait; | ||||
use App\Traits\StatusPropertyTrait; | |||||
use App\Traits\UuidIntKeyTrait; | use App\Traits\UuidIntKeyTrait; | ||||
use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||
use Illuminate\Database\Eloquent\SoftDeletes; | use Illuminate\Database\Eloquent\SoftDeletes; | ||||
/** | /** | ||||
* The eloquent definition of a Domain. | * The eloquent definition of a Domain. | ||||
* | * | ||||
* @property string $namespace | * @property string $namespace | ||||
* @property int $status | * @property int $status | ||||
* @property int $tenant_id | * @property int $tenant_id | ||||
* @property int $type | * @property int $type | ||||
*/ | */ | ||||
class Domain extends Model | class Domain extends Model | ||||
{ | { | ||||
use BelongsToTenantTrait; | use BelongsToTenantTrait; | ||||
use DomainConfigTrait; | use DomainConfigTrait; | ||||
use EntitleableTrait; | use EntitleableTrait; | ||||
use SettingsTrait; | use SettingsTrait; | ||||
use SoftDeletes; | use SoftDeletes; | ||||
use StatusPropertyTrait; | |||||
use UuidIntKeyTrait; | use UuidIntKeyTrait; | ||||
// we've simply never heard of this domain | // we've simply never heard of this domain | ||||
public const STATUS_NEW = 1 << 0; | public const STATUS_NEW = 1 << 0; | ||||
// it's been activated | // it's been activated | ||||
public const STATUS_ACTIVE = 1 << 1; | public const STATUS_ACTIVE = 1 << 1; | ||||
// domain has been suspended. | // domain has been suspended. | ||||
public const STATUS_SUSPENDED = 1 << 2; | public const STATUS_SUSPENDED = 1 << 2; | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | class Domain extends Model | ||||
public static function getPublicDomains(): array | public static function getPublicDomains(): array | ||||
{ | { | ||||
return self::withEnvTenantContext() | return self::withEnvTenantContext() | ||||
->whereRaw(sprintf('(type & %s)', Domain::TYPE_PUBLIC)) | ->whereRaw(sprintf('(type & %s)', Domain::TYPE_PUBLIC)) | ||||
->get(['namespace'])->pluck('namespace')->toArray(); | ->get(['namespace'])->pluck('namespace')->toArray(); | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this domain is active. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isActive(): bool | |||||
{ | |||||
return ($this->status & self::STATUS_ACTIVE) > 0; | |||||
} | |||||
/** | |||||
* Returns whether this domain is confirmed the ownership of. | * Returns whether this domain is confirmed the ownership of. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isConfirmed(): bool | public function isConfirmed(): bool | ||||
{ | { | ||||
return ($this->status & self::STATUS_CONFIRMED) > 0; | return ($this->status & self::STATUS_CONFIRMED) > 0; | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this domain is deleted. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isDeleted(): bool | |||||
{ | |||||
return ($this->status & self::STATUS_DELETED) > 0; | |||||
} | |||||
/** | |||||
* Returns whether this domain is registered with us. | * Returns whether this domain is registered with us. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isExternal(): bool | public function isExternal(): bool | ||||
{ | { | ||||
return ($this->type & self::TYPE_EXTERNAL) > 0; | return ($this->type & self::TYPE_EXTERNAL) > 0; | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this domain is hosted with us. | * Returns whether this domain is hosted with us. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isHosted(): bool | public function isHosted(): bool | ||||
{ | { | ||||
return ($this->type & self::TYPE_HOSTED) > 0; | return ($this->type & self::TYPE_HOSTED) > 0; | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this domain is new. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isNew(): bool | |||||
{ | |||||
return ($this->status & self::STATUS_NEW) > 0; | |||||
} | |||||
/** | |||||
* Returns whether this domain is public. | * Returns whether this domain is public. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isPublic(): bool | public function isPublic(): bool | ||||
{ | { | ||||
return ($this->type & self::TYPE_PUBLIC) > 0; | return ($this->type & self::TYPE_PUBLIC) > 0; | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this domain is registered in LDAP. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isLdapReady(): bool | |||||
{ | |||||
return ($this->status & self::STATUS_LDAP_READY) > 0; | |||||
} | |||||
/** | |||||
* Returns whether this domain is suspended. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isSuspended(): bool | |||||
{ | |||||
return ($this->status & self::STATUS_SUSPENDED) > 0; | |||||
} | |||||
/** | |||||
* Returns whether this (external) domain has been verified | * Returns whether this (external) domain has been verified | ||||
* to exist in DNS. | * to exist in DNS. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isVerified(): bool | public function isVerified(): bool | ||||
{ | { | ||||
return ($this->status & self::STATUS_VERIFIED) > 0; | return ($this->status & self::STATUS_VERIFIED) > 0; | ||||
▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | public function isEmpty(): bool | ||||
|| \App\UserAlias::whereRaw('substr(alias, ?) = ?', [-$suffixLen, $suffix])->exists() | || \App\UserAlias::whereRaw('substr(alias, ?) = ?', [-$suffixLen, $suffix])->exists() | ||||
|| \App\Group::whereRaw('substr(email, ?) = ?', [-$suffixLen, $suffix])->exists() | || \App\Group::whereRaw('substr(email, ?) = ?', [-$suffixLen, $suffix])->exists() | ||||
|| \App\Resource::whereRaw('substr(email, ?) = ?', [-$suffixLen, $suffix])->exists() | || \App\Resource::whereRaw('substr(email, ?) = ?', [-$suffixLen, $suffix])->exists() | ||||
|| \App\SharedFolder::whereRaw('substr(email, ?) = ?', [-$suffixLen, $suffix])->exists() | || \App\SharedFolder::whereRaw('substr(email, ?) = ?', [-$suffixLen, $suffix])->exists() | ||||
); | ); | ||||
} | } | ||||
/** | /** | ||||
* Suspend this domain. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function suspend(): void | |||||
{ | |||||
if ($this->isSuspended()) { | |||||
return; | |||||
} | |||||
$this->status |= Domain::STATUS_SUSPENDED; | |||||
$this->save(); | |||||
} | |||||
/** | |||||
* Unsuspend this domain. | * Unsuspend this domain. | ||||
* | * | ||||
* The domain is unsuspended through either of the following courses of actions; | * The domain is unsuspended through either of the following courses of actions; | ||||
* | * | ||||
* * The account balance has been topped up, or | * * The account balance has been topped up, or | ||||
* * a suspected spammer has resolved their issues, or | * * a suspected spammer has resolved their issues, or | ||||
* * the command-line is triggered. | * * the command-line is triggered. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |