44 lines
1.6 KiB
PHP
44 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\PeopleProcess;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
|
|
/** Client identity and the provider's Direction authority in the existing hiring lifecycle. */
|
|
final class ThirdPartyHiring
|
|
{
|
|
public function creationContext(User $actor): string
|
|
{
|
|
$contexts = app(WorkContext::class);
|
|
$key = $contexts->enforced($actor) && app()->bound('request') && request()->hasSession()
|
|
? $contexts->active(request()) : 'people.internal';
|
|
abort_unless(in_array($key, ['people.internal', 'people.third_party'], true) && WorkContext::operational($key), 403);
|
|
|
|
return $key;
|
|
}
|
|
|
|
public function isClientProcess(PeopleProcess $record): bool
|
|
{
|
|
return $record->getAttribute('work_context_key') === 'people.third_party';
|
|
}
|
|
|
|
public function direction(User $actor): bool
|
|
{
|
|
// The existing separately assigned Direction authority never follows from Admin.
|
|
return in_array('people_contract_formalize', app(OrganizationAccess::class)->permissions($actor), true)
|
|
&& ! app(OrganizationAccess::class)->maintenanceOnly($actor);
|
|
}
|
|
|
|
/** @return array<string,mixed> */
|
|
public function clientRules(User $actor, int $client, int $version): array
|
|
{
|
|
$snapshot = app(BusinessClients::class)->snapshot($actor, $client, $version);
|
|
$provider = Tenant::query()->findOrFail($actor->tenant_id);
|
|
|
|
return ['client' => $snapshot, 'provider' => ['tenant_id' => $actor->tenant_id, 'name' => $provider->name],
|
|
'decision_authority' => 'provider_direction'];
|
|
}
|
|
}
|