File transfer
This commit is contained in:
73
app/Addons/AdvancedAdmin/Models/Role.php
Normal file
73
app/Addons/AdvancedAdmin/Models/Role.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Ball Studios <https://git.balls.studio>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Addons\AdvancedAdmin\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $description
|
||||
* @property string $color
|
||||
* @property int $priority
|
||||
* @property bool $is_default
|
||||
* @property int $created_by
|
||||
*/
|
||||
class Role extends Model
|
||||
{
|
||||
protected $table = 'addon_roles';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'color',
|
||||
'priority',
|
||||
'is_default',
|
||||
'created_by',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'priority' => 'integer',
|
||||
'is_default' => 'boolean',
|
||||
];
|
||||
|
||||
public function permissions(): HasMany
|
||||
{
|
||||
return $this->hasMany(RolePermission::class, 'role_id');
|
||||
}
|
||||
|
||||
public function assignments(): HasMany
|
||||
{
|
||||
return $this->hasMany(ServerRoleAssignment::class, 'role_id');
|
||||
}
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\Pterodactyl\Models\User::class, 'created_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this role is still assigned anywhere.
|
||||
*/
|
||||
public function isInUse(): bool
|
||||
{
|
||||
return $this->assignments()->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get permission value for a given key.
|
||||
* Returns 'allow', 'deny', or null (not set).
|
||||
*/
|
||||
public function getPermission(string $permission): ?string
|
||||
{
|
||||
$perm = $this->permissions()->where('permission', $permission)->first();
|
||||
return $perm?->value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user