@@ -6,6 +6,7 @@ use App\Models\ExistingBusiness;
|
||||
use App\Models\User;
|
||||
use App\Services\PortalProfileAccess;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ExistingBusinessPolicy
|
||||
{
|
||||
@@ -96,6 +97,50 @@ class ExistingBusinessPolicy
|
||||
}
|
||||
}
|
||||
|
||||
/** Supplement-only authority never changes the normal content/workflow abilities. */
|
||||
public function prepareClassification(User $user, ExistingBusiness $business): bool
|
||||
{
|
||||
return $this->owns($user, $business) && ! app(PortalProfileAccess::class)->has($user, 'auditor')
|
||||
&& in_array($business->status, ['draft', 'needs_information', 'published'], true);
|
||||
}
|
||||
|
||||
public function reviewClassification(User $user, ExistingBusiness $business): bool
|
||||
{
|
||||
return ! $business->trashed() && $business->owner_user_id !== $user->id
|
||||
&& ! app(PortalProfileAccess::class)->has($user, 'auditor')
|
||||
&& in_array($business->status, ['triage', 'in_review', 'needs_information', 'published'], true)
|
||||
&& $this->designated($user, 'reviewers', $business);
|
||||
}
|
||||
|
||||
/** Current responsibility check without requiring a reviewer's live browser session on public reads. */
|
||||
public function classificationReviewerScope(User $user, ExistingBusiness $business, string $dimension): bool
|
||||
{
|
||||
if ($business->trashed() || ! $user->hasVerifiedEmail() || (int) $business->owner_user_id === (int) $user->id) {
|
||||
return false;
|
||||
}
|
||||
$access = app(PortalProfileAccess::class);
|
||||
if ($access->has($user, 'auditor')) { return false; }
|
||||
if (! $access->available()) {
|
||||
return $access->legacyWriteAllowed($user) && (bool) $user->two_factor_confirmed_at && (bool) $user->two_factor_secret
|
||||
&& in_array(strtolower($user->email), config('existing-business.reviewers', []), true);
|
||||
}
|
||||
if ($business->modality !== 'company_sale') { return false; }
|
||||
$responsibility = $dimension === 'regulation' ? 'legal_reviewer' : 'technical_reviewer';
|
||||
return collect($access->grants($user, 'validator'))->contains(fn ($g) => $g->organization_id === null
|
||||
&& in_array('business_sale', json_decode($g->opportunity_types, true), true)
|
||||
&& in_array($responsibility, json_decode($g->responsibilities, true), true));
|
||||
}
|
||||
|
||||
public function discloseClassification(User $user, ExistingBusiness $business): bool
|
||||
{
|
||||
if ($business->trashed() || $business->status !== 'published' || (int) $business->owner_user_id === (int) $user->id
|
||||
|| app(PortalProfileAccess::class)->has($user, 'auditor') || ! $this->designated($user, 'publishers', $business)) {
|
||||
return false;
|
||||
}
|
||||
return ! DB::table('business_workflow_transitions')->where('existing_business_id', $business->id)
|
||||
->whereIn('to_status', ['approval_l2', 'approved'])->where('actor_id', $user->id)->exists();
|
||||
}
|
||||
|
||||
private function designatedAny(User $user, ?ExistingBusiness $business = null): bool
|
||||
{
|
||||
foreach (['reviewers', 'triagers', 'approvers_l1', 'approvers_l2', 'publishers'] as $designation) {
|
||||
|
||||
Reference in New Issue
Block a user