Admin can now control channel creation from the admin dashboard
This commit is contained in:
26
app/Models/PlatformSetting.php
Normal file
26
app/Models/PlatformSetting.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
#[Fillable(['channel_creation_open'])]
|
||||
class PlatformSetting extends Model
|
||||
{
|
||||
protected $attributes = [
|
||||
'channel_creation_open' => false,
|
||||
];
|
||||
|
||||
public static function current(): self
|
||||
{
|
||||
return static::query()->first() ?? static::query()->create();
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'channel_creation_open' => 'boolean',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -13,13 +13,17 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||
|
||||
#[Fillable(['name', 'email', 'password', 'is_admin', 'suspended_at'])]
|
||||
#[Fillable(['name', 'email', 'password', 'is_admin', 'can_create_channel', 'suspended_at'])]
|
||||
#[Hidden(['password', 'two_factor_secret', 'two_factor_recovery_codes', 'remember_token'])]
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable, TwoFactorAuthenticatable;
|
||||
|
||||
protected $attributes = [
|
||||
'can_create_channel' => false,
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
@@ -32,6 +36,7 @@ class User extends Authenticatable
|
||||
'password' => 'hashed',
|
||||
'two_factor_confirmed_at' => 'datetime',
|
||||
'is_admin' => 'boolean',
|
||||
'can_create_channel' => 'boolean',
|
||||
'suspended_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
@@ -50,4 +55,9 @@ class User extends Authenticatable
|
||||
{
|
||||
return $this->suspended_at !== null;
|
||||
}
|
||||
|
||||
public function canCreateChannel(): bool
|
||||
{
|
||||
return $this->can_create_channel || PlatformSetting::current()->channel_creation_open;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user