## Summary - Capture and restore foundation types (assignment filters, scope tags, notification templates) with deterministic mapping. - Apply foundation mappings during restore (scope tags on policy payloads, assignment filter mapping with skip reasons). - Improve restore run UX (item selection, rerun action, preview-only badges). - Enforce preview-only policy types (e.g. Conditional Access) during execution. ## Testing - ./vendor/bin/sail artisan test tests/Feature/Filament/ConditionalAccessPreviewOnlyTest.php ## Notes - Specs/plan/tasks updated under specs/006-sot-foundations-assignments. - No migrations. Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.local> Reviewed-on: #7
122 lines
2.9 KiB
PHP
122 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Support\Concerns\InteractsWithODataTypes;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class BackupItem extends Model
|
|
{
|
|
use HasFactory;
|
|
use InteractsWithODataTypes;
|
|
use SoftDeletes;
|
|
|
|
protected $guarded = [];
|
|
|
|
protected $casts = [
|
|
'payload' => 'array',
|
|
'metadata' => 'array',
|
|
'assignments' => 'array',
|
|
'captured_at' => 'datetime',
|
|
];
|
|
|
|
public function tenant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Tenant::class);
|
|
}
|
|
|
|
public function backupSet(): BelongsTo
|
|
{
|
|
return $this->belongsTo(BackupSet::class);
|
|
}
|
|
|
|
public function policy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Policy::class);
|
|
}
|
|
|
|
public function policyVersion(): BelongsTo
|
|
{
|
|
return $this->belongsTo(PolicyVersion::class);
|
|
}
|
|
|
|
// Assignment helpers
|
|
public function getAssignmentCountAttribute(): int
|
|
{
|
|
return count($this->assignments ?? []);
|
|
}
|
|
|
|
public function hasAssignments(): bool
|
|
{
|
|
return ! empty($this->assignments);
|
|
}
|
|
|
|
public function getGroupIdsAttribute(): array
|
|
{
|
|
return collect($this->assignments ?? [])
|
|
->pluck('target.groupId')
|
|
->filter()
|
|
->unique()
|
|
->values()
|
|
->toArray();
|
|
}
|
|
|
|
public function getScopeTagIdsAttribute(): array
|
|
{
|
|
return $this->metadata['scope_tag_ids'] ?? ['0'];
|
|
}
|
|
|
|
public function getScopeTagNamesAttribute(): array
|
|
{
|
|
return $this->metadata['scope_tag_names'] ?? ['Default'];
|
|
}
|
|
|
|
public function hasOrphanedAssignments(): bool
|
|
{
|
|
return $this->metadata['has_orphaned_assignments'] ?? false;
|
|
}
|
|
|
|
public function assignmentsFetchFailed(): bool
|
|
{
|
|
return $this->metadata['assignments_fetch_failed'] ?? false;
|
|
}
|
|
|
|
public function isFoundation(): bool
|
|
{
|
|
$types = array_column(config('tenantpilot.foundation_types', []), 'type');
|
|
|
|
return in_array($this->policy_type, $types, true);
|
|
}
|
|
|
|
public function resolvedDisplayName(): string
|
|
{
|
|
if ($this->policy) {
|
|
return $this->policy->display_name;
|
|
}
|
|
|
|
$metadata = $this->metadata ?? [];
|
|
$payload = is_array($this->payload) ? $this->payload : [];
|
|
$name = $metadata['displayName']
|
|
?? $metadata['display_name']
|
|
?? $payload['displayName']
|
|
?? $payload['name']
|
|
?? null;
|
|
|
|
if (is_string($name) && $name !== '') {
|
|
return $name;
|
|
}
|
|
|
|
return $this->policy_identifier;
|
|
}
|
|
|
|
// Scopes
|
|
public function scopeWithAssignments($query)
|
|
{
|
|
return $query->whereNotNull('assignments')
|
|
->whereRaw('json_array_length(assignments) > 0');
|
|
}
|
|
}
|