Permitir consulta pública dos ecrãs reais com dados privados protegidos
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class PublicNavigation
|
||||
{
|
||||
public const PAGES = [
|
||||
'/dashboard' => 'dashboard', '/requisicoes' => 'requisitions/index', '/requisicoes/criar' => 'requisitions/form',
|
||||
'/fornecedores' => 'suppliers/index', '/cotacoes' => 'quotations/index', '/ordens' => 'purchases/index', '/recepcoes' => 'receipts/index',
|
||||
'/stock' => 'stock/index', '/stock/catalogo' => 'stock/catalogue', '/stock/operacoes' => 'stock/operations', '/equipamentos' => 'equipment/index',
|
||||
'/planeamento' => 'planning/index', '/pessoas' => 'people/index', '/orcamentos' => 'budgets/index', '/facturas' => 'invoices/index', '/pagamentos' => 'payments/index',
|
||||
'/regras-investimento' => 'investment/index', '/politica-admissao' => 'purchases/admission-policy', '/politica-recomendacao' => 'purchases/recommendation-policy',
|
||||
'/revisao-compras' => 'purchase-controls/index', '/settings/appearance' => 'settings/appearance',
|
||||
];
|
||||
|
||||
/** Public navigation deliberately has no tenant, actor or business data provider. */
|
||||
public function enabled(): bool
|
||||
{
|
||||
return (bool) config('public_navigation.enabled');
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
public function props(Request $request): array
|
||||
{
|
||||
$filter = $request->validate(['search' => 'nullable|string|max:100', 'status' => 'nullable|string|max:40', 'view' => ['nullable', Rule::in(['all', 'mine', 'approvals', 'decided'])],
|
||||
'page' => 'nullable|integer|min:1|max:10000', 'receipts_page' => 'nullable|integer|min:1|max:10000', 'kind' => 'nullable|in:staff,service', 'from' => 'nullable|date_format:Y-m-d', 'to' => 'nullable|date_format:Y-m-d', 'warehouse_id' => 'nullable|integer|min:1']);
|
||||
$page = fn (string $name = 'page') => (new LengthAwarePaginator([], 0, 15, (int) ($filter[$name] ?? 1), ['path' => $request->url(), 'pageName' => $name]))->appends($filter);
|
||||
$common = ['publicNavigation' => ['paths' => array_keys(self::PAGES), 'dataScope' => 'none'], 'auth' => ['user' => null], 'organizationAccess' => null, 'canRequest' => false, 'payablesAvailable' => false];
|
||||
$props = match ('/'.$request->path()) {
|
||||
'/dashboard' => ['company' => null, 'stats' => ['total' => 0, 'pending' => 0, 'approved' => 0, 'approvedMinor' => 0, 'awaitingMe' => 0], 'recent' => [], 'approvals' => []],
|
||||
'/requisicoes' => ['requisitions' => $page(), 'filters' => $filter],
|
||||
'/requisicoes/criar' => ['costCenters' => [], 'requisition' => null, 'catalogue' => ['ready' => false, 'items' => [], 'search' => '', 'more' => false]],
|
||||
'/fornecedores' => ['suppliers' => $page(), 'filters' => $filter, 'canCreate' => false, 'canReview' => false],
|
||||
'/cotacoes' => ['requisitions' => $page()],
|
||||
'/ordens' => ['orders' => $page(), 'awards' => $page()],
|
||||
'/recepcoes' => ['orders' => $page(), 'receipts' => $page('receipts_page')],
|
||||
'/stock' => ['items' => [], 'warehouses' => [], 'balances' => [], 'movements' => $page(), 'filters' => $filter, 'canManage' => false],
|
||||
'/stock/catalogo' => ['records' => $page(), 'filters' => $filter, 'ready' => true, 'canManage' => false],
|
||||
'/stock/operacoes' => ['items' => [], 'warehouses' => [], 'balances' => [], 'users' => [], 'operations' => $page(), 'counts' => [], 'equipment' => [], 'canOperate' => false],
|
||||
'/equipamentos' => ['equipment' => [], 'parts' => [], 'links' => [], 'levels' => [], 'items' => [], 'departments' => [], 'history' => $page(), 'canManage' => false, 'canConfigure' => false],
|
||||
'/planeamento' => ['items' => $page(), 'milestones' => [], 'history' => [], 'canManage' => false, 'today' => today()->toDateString(), 'departments' => [], 'users' => [], 'requisitions' => []],
|
||||
'/pessoas' => ['ready' => true, 'kinds' => ['staff', 'service'], 'availableKinds' => ['staff', 'service'], 'filters' => $filter, 'workdesk' => null, 'insights' => null, 'company' => null, 'canPrepare' => [], 'formFields' => ['staff' => PeopleForms::STAFF, 'service' => PeopleForms::SERVICE], 'administration' => [], 'processes' => $page()],
|
||||
'/orcamentos' => ['centers' => [], 'budgets' => [], 'reinforcements' => $page(), 'canManage' => false],
|
||||
'/facturas' => ['invoices' => $page(), 'orders' => [], 'canManage' => false],
|
||||
'/pagamentos' => ['invoices' => [], 'payments' => $page(), 'canManage' => false],
|
||||
'/regras-investimento' => ['policies' => [], 'reviews' => [], 'currentPolicyId' => null, 'canManage' => false],
|
||||
'/politica-admissao', '/politica-recomendacao' => ['policies' => $page(), 'latest' => null],
|
||||
'/revisao-compras' => ['role' => '', 'permissions' => [], 'actorId' => null, 'policies' => [], 'reviews' => [], 'awards' => [], 'cancellations' => [], 'sources' => []],
|
||||
default => [],
|
||||
};
|
||||
|
||||
return [...$common, ...$props];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user