- Implemented the `show` page for managing URL apps with functionalities like updating name, logo, access URL, and connection status. - Added `UrlAppViewTest` for feature testing, ensuring role-based access, and validation of edit actions. - Updated navigation to route URL apps to their respective management views. - Enhanced `OidcService` to handle updated app settings and redirect URIs.
93 lines
2.4 KiB
PHP
93 lines
2.4 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
|
|
* @property array $settings
|
|
*/
|
|
#[Fillable([
|
|
'name',
|
|
'slug',
|
|
'connection_protocol_id',
|
|
'connection_provider_id',
|
|
'connection_status_id',
|
|
'settings',
|
|
'logo',
|
|
])]
|
|
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');
|
|
}
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'settings' => 'array',
|
|
];
|
|
}
|
|
}
|