## Summary - add the tenant review domain with tenant-scoped review library, canonical workspace review register, lifecycle actions, and review-derived executive pack export - extend review pack, operations, audit, capability, and badge infrastructure to support review composition, publication, export, and recurring review cycles - add product backlog and audit documentation updates for tenant review and semantic-clarity follow-up candidates ## Testing - `vendor/bin/sail bin pint --dirty --format agent` - `vendor/bin/sail artisan test --compact --filter="TenantReview"` - `CI=1 vendor/bin/sail artisan test --compact` ## Notes - Livewire v4+ compliant via existing Filament v5 stack - panel providers remain in `bootstrap/providers.php` via existing Laravel 12 structure; no provider registration moved to `bootstrap/app.php` - `TenantReviewResource` is not globally searchable, so the Filament edit/view global-search constraint does not apply - destructive review actions use action handlers with confirmation and policy enforcement Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #185
196 lines
4.7 KiB
PHP
196 lines
4.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Support\Concerns\DerivesWorkspaceIdFromTenant;
|
|
use App\Support\TenantReviewCompletenessState;
|
|
use App\Support\TenantReviewStatus;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class TenantReview extends Model
|
|
{
|
|
use DerivesWorkspaceIdFromTenant;
|
|
use HasFactory;
|
|
|
|
protected $guarded = [];
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'summary' => 'array',
|
|
'generated_at' => 'datetime',
|
|
'published_at' => 'datetime',
|
|
'archived_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Workspace, $this>
|
|
*/
|
|
public function workspace(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Workspace::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Tenant, $this>
|
|
*/
|
|
public function tenant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Tenant::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<EvidenceSnapshot, $this>
|
|
*/
|
|
public function evidenceSnapshot(): BelongsTo
|
|
{
|
|
return $this->belongsTo(EvidenceSnapshot::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<OperationRun, $this>
|
|
*/
|
|
public function operationRun(): BelongsTo
|
|
{
|
|
return $this->belongsTo(OperationRun::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<User, $this>
|
|
*/
|
|
public function initiator(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'initiated_by_user_id');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<User, $this>
|
|
*/
|
|
public function publisher(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'published_by_user_id');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<ReviewPack, $this>
|
|
*/
|
|
public function currentExportReviewPack(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ReviewPack::class, 'current_export_review_pack_id');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<self, $this>
|
|
*/
|
|
public function supersededByReview(): BelongsTo
|
|
{
|
|
return $this->belongsTo(self::class, 'superseded_by_review_id');
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<self, $this>
|
|
*/
|
|
public function supersededReviews(): HasMany
|
|
{
|
|
return $this->hasMany(self::class, 'superseded_by_review_id');
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<TenantReviewSection, $this>
|
|
*/
|
|
public function sections(): HasMany
|
|
{
|
|
return $this->hasMany(TenantReviewSection::class)->orderBy('sort_order')->orderBy('id');
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<ReviewPack, $this>
|
|
*/
|
|
public function reviewPacks(): HasMany
|
|
{
|
|
return $this->hasMany(ReviewPack::class)->latest('generated_at');
|
|
}
|
|
|
|
/**
|
|
* @param Builder<self> $query
|
|
* @return Builder<self>
|
|
*/
|
|
public function scopeForTenant(Builder $query, int $tenantId): Builder
|
|
{
|
|
return $query->where('tenant_id', $tenantId);
|
|
}
|
|
|
|
/**
|
|
* @param Builder<self> $query
|
|
* @return Builder<self>
|
|
*/
|
|
public function scopeForWorkspace(Builder $query, int $workspaceId): Builder
|
|
{
|
|
return $query->where('workspace_id', $workspaceId);
|
|
}
|
|
|
|
/**
|
|
* @param Builder<self> $query
|
|
* @return Builder<self>
|
|
*/
|
|
public function scopePublished(Builder $query): Builder
|
|
{
|
|
return $query->where('status', TenantReviewStatus::Published->value);
|
|
}
|
|
|
|
/**
|
|
* @param Builder<self> $query
|
|
* @return Builder<self>
|
|
*/
|
|
public function scopeMutable(Builder $query): Builder
|
|
{
|
|
return $query->whereIn('status', [
|
|
TenantReviewStatus::Draft->value,
|
|
TenantReviewStatus::Ready->value,
|
|
TenantReviewStatus::Failed->value,
|
|
]);
|
|
}
|
|
|
|
public function statusEnum(): TenantReviewStatus
|
|
{
|
|
return TenantReviewStatus::from((string) $this->status);
|
|
}
|
|
|
|
public function completenessEnum(): TenantReviewCompletenessState
|
|
{
|
|
return TenantReviewCompletenessState::tryFrom((string) $this->completeness_state)
|
|
?? TenantReviewCompletenessState::Missing;
|
|
}
|
|
|
|
public function isPublished(): bool
|
|
{
|
|
return $this->statusEnum()->isPublished();
|
|
}
|
|
|
|
public function isMutable(): bool
|
|
{
|
|
return $this->statusEnum()->isMutable();
|
|
}
|
|
|
|
/**
|
|
* @return list<string>
|
|
*/
|
|
public function publishBlockers(): array
|
|
{
|
|
$summary = is_array($this->summary) ? $this->summary : [];
|
|
$blockers = $summary['publish_blockers'] ?? [];
|
|
|
|
return is_array($blockers) ? array_values(array_map('strval', $blockers)) : [];
|
|
}
|
|
}
|