BastionSSO/app/Models/ServerResource.php
Boen_Shi 1ec4cbe941 feat(服务器资源): 支持按资源配置复制临时密码并强化使用校验
- 新增资源开关 allow_copy_temp_password 并持久化

- 使用资源时强制访问用户名与密码必填并返回中文提示

- 解析 sso 链接提取 SSOToken,按开关返回临时密码
2026-04-30 09:53:33 +08:00

59 lines
1.3 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
class ServerResource extends Model
{
use HasFactory;
protected $fillable = [
'name',
'display_name',
'parent_id',
'internal_ip',
'asset_id',
'account_id',
'protocols',
'description',
'allow_copy_temp_password',
'is_active',
];
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id');
}
public function children(): HasMany
{
return $this->hasMany(self::class, 'parent_id');
}
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class, 'user_server_permissions')
->withPivot(['can_ssh', 'can_sftp', 'can_rdp'])
->withTimestamps();
}
public function accessLogs(): HasMany
{
return $this->hasMany(AccessLog::class);
}
protected function casts(): array
{
return [
'protocols' => 'array',
'allow_copy_temp_password' => 'boolean',
'is_active' => 'boolean',
];
}
}