Changeset View
Changeset View
Standalone View
Standalone View
src/app/Domain.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
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\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; | ||||
Show All 37 Lines | class Domain extends Model | ||||
public const TYPE_HOSTED = 1 << 1; | public const TYPE_HOSTED = 1 << 1; | ||||
// zone registered externally | // zone registered externally | ||||
public const TYPE_EXTERNAL = 1 << 2; | public const TYPE_EXTERNAL = 1 << 2; | ||||
public const HASH_CODE = 1; | public const HASH_CODE = 1; | ||||
public const HASH_TEXT = 2; | public const HASH_TEXT = 2; | ||||
public const HASH_CNAME = 3; | public const HASH_CNAME = 3; | ||||
protected $fillable = [ | /** @var array<string, string> The attributes that should be cast */ | ||||
'namespace', | protected $casts = [ | ||||
'status', | 'created_at' => 'datetime:Y-m-d H:i:s', | ||||
'type' | 'deleted_at' => 'datetime:Y-m-d H:i:s', | ||||
'updated_at' => 'datetime:Y-m-d H:i:s', | |||||
]; | ]; | ||||
/** @var array<int, string> The attributes that are mass assignable */ | |||||
protected $fillable = ['namespace', 'status', 'type']; | |||||
/** | /** | ||||
* Assign a package to a domain. The domain should not belong to any existing entitlements. | * Assign a package to a domain. The domain should not belong to any existing entitlements. | ||||
* | * | ||||
* @param \App\Package $package The package to assign. | * @param \App\Package $package The package to assign. | ||||
* @param \App\User $user The wallet owner. | * @param \App\User $user The wallet owner. | ||||
* | * | ||||
* @return \App\Domain Self | * @return \App\Domain Self | ||||
*/ | */ | ||||
Show All 19 Lines | class Domain extends Model | ||||
} | } | ||||
/** | /** | ||||
* Return list of public+active domain names (for current tenant) | * Return list of public+active domain names (for current tenant) | ||||
*/ | */ | ||||
public static function getPublicDomains(): array | public static function getPublicDomains(): array | ||||
{ | { | ||||
return self::withEnvTenantContext() | return self::withEnvTenantContext() | ||||
->whereRaw(sprintf('(type & %s)', Domain::TYPE_PUBLIC)) | ->where('type', '&', Domain::TYPE_PUBLIC) | ||||
->get(['namespace'])->pluck('namespace')->toArray(); | ->pluck('namespace')->all(); | ||||
} | } | ||||
/** | /** | ||||
* 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 | ||||
▲ Show 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | public function isEmpty(): bool | ||||
// FIXME: These queries will not use indexes, so maybe we should consider | // FIXME: These queries will not use indexes, so maybe we should consider | ||||
// wallet/entitlements to search in objects that belong to this domain account? | // wallet/entitlements to search in objects that belong to this domain account? | ||||
$suffix = '@' . $this->namespace; | $suffix = '@' . $this->namespace; | ||||
$suffixLen = strlen($suffix); | $suffixLen = strlen($suffix); | ||||
return !( | return !( | ||||
\App\User::whereRaw('substr(email, ?) = ?', [-$suffixLen, $suffix])->exists() | User::whereRaw('substr(email, ?) = ?', [-$suffixLen, $suffix])->exists() | ||||
|| \App\UserAlias::whereRaw('substr(alias, ?) = ?', [-$suffixLen, $suffix])->exists() | || UserAlias::whereRaw('substr(alias, ?) = ?', [-$suffixLen, $suffix])->exists() | ||||
|| \App\Group::whereRaw('substr(email, ?) = ?', [-$suffixLen, $suffix])->exists() | || Group::whereRaw('substr(email, ?) = ?', [-$suffixLen, $suffix])->exists() | ||||
|| \App\Resource::whereRaw('substr(email, ?) = ?', [-$suffixLen, $suffix])->exists() | || Resource::whereRaw('substr(email, ?) = ?', [-$suffixLen, $suffix])->exists() | ||||
|| \App\SharedFolder::whereRaw('substr(email, ?) = ?', [-$suffixLen, $suffix])->exists() | || SharedFolder::whereRaw('substr(email, ?) = ?', [-$suffixLen, $suffix])->exists() | ||||
); | ); | ||||
} | } | ||||
/** | /** | ||||
* 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; | ||||
* | * | ||||
Show All 34 Lines | public function users(): array | ||||
} | } | ||||
$wallet = $this->wallet(); | $wallet = $this->wallet(); | ||||
if (!$wallet) { | if (!$wallet) { | ||||
return []; | return []; | ||||
} | } | ||||
$mailboxSKU = \App\Sku::withObjectTenantContext($this)->where('title', 'mailbox')->first(); | $mailboxSKU = Sku::withObjectTenantContext($this)->where('title', 'mailbox')->first(); | ||||
if (!$mailboxSKU) { | if (!$mailboxSKU) { | ||||
\Log::error("No mailbox SKU available."); | \Log::error("No mailbox SKU available."); | ||||
return []; | return []; | ||||
} | } | ||||
return $wallet->entitlements() | return $wallet->entitlements() | ||||
->where('entitleable_type', \App\User::class) | ->where('entitleable_type', User::class) | ||||
->where('sku_id', $mailboxSKU->id) | ->where('sku_id', $mailboxSKU->id) | ||||
->get() | ->get() | ||||
->pluck('entitleable') | ->pluck('entitleable') | ||||
->all(); | ->all(); | ||||
} | } | ||||
/** | /** | ||||
* Verify if a domain exists in DNS | * Verify if a domain exists in DNS | ||||
Show All 28 Lines |