## 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
54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\TenantReviews;
|
|
|
|
use App\Models\Tenant;
|
|
use App\Models\TenantReview;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
use App\Models\WorkspaceMembership;
|
|
use App\Services\Auth\RoleCapabilityMap;
|
|
use App\Support\Auth\Capabilities;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
final class TenantReviewRegisterService
|
|
{
|
|
/**
|
|
* @return array<int, Tenant>
|
|
*/
|
|
public function authorizedTenants(User $user, Workspace $workspace): array
|
|
{
|
|
$roles = RoleCapabilityMap::rolesWithCapability(Capabilities::TENANT_REVIEW_VIEW);
|
|
|
|
return $user->tenants()
|
|
->where('tenants.workspace_id', (int) $workspace->getKey())
|
|
->wherePivotIn('role', $roles)
|
|
->orderBy('tenants.name')
|
|
->get()
|
|
->keyBy(static fn (Tenant $tenant): int => (int) $tenant->getKey())
|
|
->all();
|
|
}
|
|
|
|
public function query(User $user, Workspace $workspace): Builder
|
|
{
|
|
$tenantIds = array_keys($this->authorizedTenants($user, $workspace));
|
|
|
|
return TenantReview::query()
|
|
->with(['tenant', 'evidenceSnapshot', 'currentExportReviewPack'])
|
|
->forWorkspace((int) $workspace->getKey())
|
|
->whereIn('tenant_id', $tenantIds === [] ? [-1] : $tenantIds)
|
|
->latest('generated_at')
|
|
->latest('id');
|
|
}
|
|
|
|
public function canAccessWorkspace(User $user, Workspace $workspace): bool
|
|
{
|
|
return WorkspaceMembership::query()
|
|
->where('workspace_id', (int) $workspace->getKey())
|
|
->where('user_id', (int) $user->getKey())
|
|
->exists();
|
|
}
|
|
}
|