@@ -17,6 +17,18 @@ class WorkContext
|
||||
'people.third_party' => ['area' => 'people', 'areaLabel' => 'Pessoas e contratações', 'label' => 'Contratações para terceiros', 'operational' => false],
|
||||
];
|
||||
|
||||
public static function operational(string $key): bool
|
||||
{
|
||||
if ($key === 'procurement.sales') {
|
||||
return app(CustomerSales::class)->ready();
|
||||
}
|
||||
if ($key === 'people.third_party') {
|
||||
return config('third_party.people_enabled') === true && Schema::hasTable('business_clients');
|
||||
}
|
||||
|
||||
return self::OPTIONS[$key]['operational'] ?? false;
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
public function purchased(User $user): array
|
||||
{
|
||||
@@ -147,14 +159,20 @@ class WorkContext
|
||||
if ($area === null) {
|
||||
$sharedPaths[] = $path;
|
||||
}
|
||||
if ($area === null || ($active !== null && self::OPTIONS[$active]['operational'] && self::OPTIONS[$active]['area'] === $area)) {
|
||||
if ($area === null || ($active !== null && self::operational($active) && self::OPTIONS[$active]['area'] === $area && self::allowsPath($active, $path))) {
|
||||
$paths[] = $path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$options = self::OPTIONS;
|
||||
foreach ($options as $key => &$option) {
|
||||
$option['operational'] = self::operational($key);
|
||||
}
|
||||
unset($option);
|
||||
|
||||
return ['enforced' => $enabled, 'active' => $active, 'paths' => $paths, 'sharedPaths' => $sharedPaths, 'permissions' => $permissions,
|
||||
'options' => self::OPTIONS, 'available' => $enabled ? $this->available($user) : [],
|
||||
'options' => $options, 'available' => $enabled ? $this->available($user) : [],
|
||||
'purchased' => $user instanceof User ? $this->purchased($user) : []];
|
||||
}
|
||||
|
||||
@@ -167,4 +185,18 @@ class WorkContext
|
||||
|
||||
return $path === '/pessoas' || str_starts_with($path, '/pessoas/') ? 'people' : 'procurement';
|
||||
}
|
||||
|
||||
public static function allowsPath(string $key, string $path): bool
|
||||
{
|
||||
$path = '/'.ltrim(explode('?', $path)[0], '/');
|
||||
if (self::area($path) === null) {
|
||||
return true;
|
||||
}
|
||||
$salesPath = $path === '/vendas' || str_starts_with($path, '/vendas/');
|
||||
if ($key === 'procurement.sales') {
|
||||
return $salesPath || $path === '/general-ledger' || str_starts_with($path, '/general-ledger/');
|
||||
}
|
||||
|
||||
return ! $salesPath;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user