- Introduced `ConnectedAppFactory` for generating connected app data. - Added `MockDataSeeder` to create sample roles, users, and apps with dynamic role-app assignments. - Extended `RoleAndAppsPermissionEnum` with `ConnectApps` permission. - Updated access-manager UI to handle app-connection actions with proper authorization. - Integrated app-role connection logic in Livewire component and updated `roles-and-apps` view for permissions-based actions.
78 lines
2.1 KiB
PHP
78 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\{Model, Relations\BelongsTo, Relations\BelongsToMany, SoftDeletes};
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Spatie\Activitylog\Models\Concerns\LogsActivity;
|
|
use Spatie\Activitylog\Support\LogOptions;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property AppRole $pivot
|
|
*/
|
|
#[Fillable([
|
|
'name',
|
|
'slug',
|
|
'connection_protocol_id',
|
|
'connection_provider_id',
|
|
'connection_status_id',
|
|
])]
|
|
class ConnectedApp extends Model
|
|
{
|
|
use HasFactory, LogsActivity, SoftDeletes;
|
|
|
|
/**
|
|
* @return HasOne<ConnectionProtocol, $this>
|
|
*/
|
|
public function protocol(): HasOne
|
|
{
|
|
return $this->hasOne(ConnectionProtocol::class, 'id', 'connection_protocol_id');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<ConnectionProvider, $this>
|
|
*/
|
|
public function provider(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ConnectionProvider::class, 'connection_provider_id');
|
|
}
|
|
|
|
/**
|
|
* @return HasOne<ConnectionStatus, $this>
|
|
*/
|
|
public function status(): HasOne
|
|
{
|
|
return $this->hasOne(ConnectionStatus::class, 'id', 'connection_status_id');
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logFillable() // Log all fillable attributes
|
|
->logOnlyDirty() // Log only attributes that actually changed
|
|
->dontLogIfAttributesChangedOnly(['updated_at']) // Skip if only updated_at changed
|
|
->dontLogEmptyChanges() // Prevent saving logs with no changed attributes
|
|
->setDescriptionForEvent(fn (
|
|
string $eventName
|
|
) => ":causer.name {$eventName} connected app ':subject.name'");
|
|
}
|
|
|
|
public function roles(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
Role::class,
|
|
'app_roles',
|
|
'app_id',
|
|
'role_id',
|
|
)
|
|
->using(AppRole::class)
|
|
->withPivot('duration');
|
|
}
|
|
}
|