Changeset View
Changeset View
Standalone View
Standalone View
src/app/User.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use App\UserAlias; | use App\UserAlias; | ||||
use App\Traits\BelongsToTenantTrait; | use App\Traits\BelongsToTenantTrait; | ||||
use App\Traits\EntitleableTrait; | use App\Traits\EntitleableTrait; | ||||
use App\Traits\UserAliasesTrait; | use App\Traits\UserAliasesTrait; | ||||
use App\Traits\UserConfigTrait; | use App\Traits\UserConfigTrait; | ||||
use App\Traits\UuidIntKeyTrait; | use App\Traits\UuidIntKeyTrait; | ||||
use App\Traits\SettingsTrait; | use App\Traits\SettingsTrait; | ||||
use App\Traits\StatusPropertyTrait; | |||||
use App\Wallet; | use App\Wallet; | ||||
use Illuminate\Database\Eloquent\SoftDeletes; | use Illuminate\Database\Eloquent\SoftDeletes; | ||||
use Illuminate\Support\Facades\DB; | use Illuminate\Support\Facades\DB; | ||||
use Illuminate\Support\Facades\Hash; | use Illuminate\Support\Facades\Hash; | ||||
use Illuminate\Foundation\Auth\User as Authenticatable; | use Illuminate\Foundation\Auth\User as Authenticatable; | ||||
use Iatstuti\Database\Support\NullableFields; | use Iatstuti\Database\Support\NullableFields; | ||||
use Laravel\Passport\HasApiTokens; | use Laravel\Passport\HasApiTokens; | ||||
use League\OAuth2\Server\Exception\OAuthServerException; | use League\OAuth2\Server\Exception\OAuthServerException; | ||||
Show All 14 Lines | class User extends Authenticatable | ||||
use EntitleableTrait; | use EntitleableTrait; | ||||
use HasApiTokens; | use HasApiTokens; | ||||
use NullableFields; | use NullableFields; | ||||
use UserConfigTrait; | use UserConfigTrait; | ||||
use UserAliasesTrait; | use UserAliasesTrait; | ||||
use UuidIntKeyTrait; | use UuidIntKeyTrait; | ||||
use SettingsTrait; | use SettingsTrait; | ||||
use SoftDeletes; | use SoftDeletes; | ||||
use StatusPropertyTrait; | |||||
// a new user, default on creation | // a new user, default on creation | ||||
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; | ||||
// user has been suspended | // user has been suspended | ||||
public const STATUS_SUSPENDED = 1 << 2; | public const STATUS_SUSPENDED = 1 << 2; | ||||
// user has been deleted | // user has been deleted | ||||
▲ Show 20 Lines • Show All 354 Lines • ▼ Show 20 Lines | class User extends Authenticatable | ||||
* @return \Illuminate\Database\Eloquent\Builder Query builder | * @return \Illuminate\Database\Eloquent\Builder Query builder | ||||
*/ | */ | ||||
public function groups($with_accounts = true) | public function groups($with_accounts = true) | ||||
{ | { | ||||
return $this->entitleables(Group::class, $with_accounts); | return $this->entitleables(Group::class, $with_accounts); | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this user is active. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isActive(): bool | |||||
{ | |||||
return ($this->status & self::STATUS_ACTIVE) > 0; | |||||
} | |||||
/** | |||||
* Returns whether this user (or its wallet owner) is degraded. | * Returns whether this user (or its wallet owner) is degraded. | ||||
* | * | ||||
* @param bool $owner Check also the wallet owner instead just the user himself | * @param bool $owner Check also the wallet owner instead just the user himself | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isDegraded(bool $owner = false): bool | public function isDegraded(bool $owner = false): bool | ||||
mollekopf: Couldn't this function be split into isDegraded (which could be included in the trait), and… | |||||
Done Inline ActionsIt probably could, but separately from this diff. machniak: It probably could, but separately from this diff. | |||||
{ | { | ||||
if ($this->status & self::STATUS_DEGRADED) { | if ($this->status & self::STATUS_DEGRADED) { | ||||
return true; | return true; | ||||
} | } | ||||
if ($owner && ($wallet = $this->wallet())) { | if ($owner && ($wallet = $this->wallet())) { | ||||
return $wallet->owner && $wallet->owner->isDegraded(); | return $wallet->owner && $wallet->owner->isDegraded(); | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this user is deleted. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isDeleted(): bool | |||||
{ | |||||
return ($this->status & self::STATUS_DELETED) > 0; | |||||
} | |||||
/** | |||||
* Returns whether this user is registered in IMAP. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isImapReady(): bool | |||||
{ | |||||
return ($this->status & self::STATUS_IMAP_READY) > 0; | |||||
} | |||||
/** | |||||
* Returns whether this user is registered in LDAP. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isLdapReady(): bool | |||||
{ | |||||
return ($this->status & self::STATUS_LDAP_READY) > 0; | |||||
} | |||||
/** | |||||
* Returns whether this user is new. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isNew(): bool | |||||
{ | |||||
return ($this->status & self::STATUS_NEW) > 0; | |||||
} | |||||
/** | |||||
* Returns whether this user is suspended. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isSuspended(): bool | |||||
{ | |||||
return ($this->status & self::STATUS_SUSPENDED) > 0; | |||||
} | |||||
/** | |||||
* A shortcut to get the user name. | * A shortcut to get the user name. | ||||
* | * | ||||
* @param bool $fallback Return "<aa.name> User" if there's no name | * @param bool $fallback Return "<aa.name> User" if there's no name | ||||
* | * | ||||
* @return string Full user name | * @return string Full user name | ||||
*/ | */ | ||||
public function name(bool $fallback = false): string | public function name(bool $fallback = false): string | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | public function senderPolicyFrameworkWhitelist($clientName) | ||||
continue; | continue; | ||||
} | } | ||||
} | } | ||||
return $matchFound; | return $matchFound; | ||||
} | } | ||||
/** | /** | ||||
* Suspend this user. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function suspend(): void | |||||
{ | |||||
if ($this->isSuspended()) { | |||||
return; | |||||
} | |||||
$this->status |= User::STATUS_SUSPENDED; | |||||
$this->save(); | |||||
} | |||||
/** | |||||
* Un-degrade this user. | * Un-degrade this user. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function undegrade(): void | public function undegrade(): void | ||||
{ | { | ||||
if (!$this->isDegraded()) { | if (!$this->isDegraded()) { | ||||
return; | return; | ||||
} | } | ||||
$this->status ^= User::STATUS_DEGRADED; | $this->status ^= User::STATUS_DEGRADED; | ||||
$this->save(); | $this->save(); | ||||
} | } | ||||
/** | /** | ||||
* Unsuspend this user. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function unsuspend(): void | |||||
{ | |||||
if (!$this->isSuspended()) { | |||||
return; | |||||
} | |||||
$this->status ^= User::STATUS_SUSPENDED; | |||||
$this->save(); | |||||
} | |||||
/** | |||||
* Return users controlled by the current user. | * Return users controlled by the current user. | ||||
* | * | ||||
* @param bool $with_accounts Include users assigned to wallets | * @param bool $with_accounts Include users assigned to wallets | ||||
* the current user controls but not owns. | * the current user controls but not owns. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Builder Query builder | * @return \Illuminate\Database\Eloquent\Builder Query builder | ||||
*/ | */ | ||||
public function users($with_accounts = true) | public function users($with_accounts = true) | ||||
▲ Show 20 Lines • Show All 205 Lines • Show Last 20 Lines |
Couldn't this function be split into isDegraded (which could be included in the trait), and isAccountDegraded(), which can check isDegraded first?