*/ public function access(?User $actor): array { if (! $actor || ! $actor->hasVerifiedEmail()) { return []; } $profiles = app(PortalProfileAccess::class); $navigation = $profiles->navigation($actor); $legacy = $profiles->legacyWriteAllowed($actor); $documents = app(DocumentManagementAccess::class); $editor = $documents->full($actor) || $documents->editorial($actor); $upload = $editor || $documents->limited($actor); $result = []; if (app(PortalEditorialWorkflow::class)->demographyAccess($actor)) { $result['demography'] = ['index' => '/management/demography']; } if (app(PortalEditorialWorkflow::class)->portfolioAvailable() && $actor->can('manage-portal') && ! $profiles->has($actor, 'auditor')) { $result['portfolio'] = ['index' => '/management/portfolio']; } if (app(ClusterCompetitiveness::class)->editorialEnabled() && $actor->can('manage-portal') && ! $profiles->has($actor, 'auditor')) { $result['clusters'] = ['index' => '/management/clusters']; } if (app(Procurement::class)->available() && app(Procurement::class)->access($actor)) { $result['procurement'] = ['index' => '/management/concursos', 'create' => '/management/concursos/novo']; } if ($legacy || ($navigation['mine'] ?? null) || ($navigation['review'] ?? null)) { $result['opportunities'] = ['index' => $legacy ? '/management/opportunities' : '/minhas-oportunidades', 'create' => $legacy ? '/management/opportunities/create' : ($navigation['create'] ?? null), 'profileWorkflow' => ! $legacy]; } if ($upload) { $result['documents'] = ['index' => '/management/portal-services', 'edit' => $editor]; } if (($editor || isset($result['opportunities'])) && ! $profiles->has($actor, 'auditor') && app(PortalEditorialWorkflow::class)->available()) { $result['editorial'] = ['index' => '/management/editorial']; } return $result; } /** @param array $access * @return list */ public function dashboardNavigation(?User $actor, array $access): array { $workflow = app(PortalEditorialWorkflow::class); if (! $actor || ! $workflow->available() || ! $workflow->canEnter($actor)) { return []; } $items = [['label' => 'Visão geral', 'href' => '/management/editorial']]; $documents = app(DocumentManagementAccess::class); if ($documents->full($actor) || $documents->editorial($actor)) { foreach (['article' => 'Artigos', 'legislation' => 'Legislação', 'document' => 'Documentos'] as $kind => $label) { $items[] = ['label' => $label, 'href' => '/management/editorial?kind='.$kind]; } } foreach (['opportunities' => 'Oportunidades', 'clusters' => 'Competitividade', 'portfolio' => 'Carteira', 'demography' => 'Demografia'] as $key => $label) { if (isset($access[$key]['index'])) { $items[] = ['label' => $label, 'href' => $access[$key]['index']]; } } if (app(PortalEditorialSubjects::class)->available() && $actor->can('manage-portal')) { $items[] = ['label' => 'Estruturas e relações', 'href' => '/management/editorial/subjects']; } $native = app(PortalEditorialNativeNotices::class); if ($native->access($actor, 'territorial-editorial-v1')) { $items[] = ['label' => 'Conteúdos territoriais', 'href' => '/management/territorial/editorial']; } if ($native->access($actor, 'investment-zones')) { $items[] = ['label' => 'Zonas e indicadores', 'href' => '/management/investment/zones']; } $items[] = ['label' => 'Notificações', 'href' => '/management/editorial#notificacoes']; return $items; } /** * @return array */ public function view(User $actor): array { $access = $this->access($actor); abort_unless($access !== [], 403); $counts = []; if (isset($access['opportunities'])) { $counts['opportunities'] = app(PortalProfileAccess::class)->scope(Opportunity::query(), $actor) ->selectRaw("COALESCE(workflow_context->>'working_state',status) as state, count(*) as total") ->groupByRaw("COALESCE(workflow_context->>'working_state',status)")->pluck('total', 'state'); } if (isset($access['documents'])) { $documents = app(DocumentManagementAccess::class); $query = $documents->full($actor) ? DB::table('portal_resources as r')->join('documents as d', 'd.id', '=', 'r.document_id')->whereNull('d.deleted_at') : ($access['documents']['edit'] ? $documents->editorialResources($actor) : null); $counts['documents'] = $query ? $query->select('r.published', DB::raw('count(*) as total'))->groupBy('r.published')->get() ->mapWithKeys(fn ($row) => [$row->published ? 'published' : 'unpublished' => (int) $row->total]) : []; } return ['access' => $access, 'counts' => $counts]; } }