forked from fa/breadcrumb-the-shire
fix(help-center): resolve API docs visibility via layout provider
The api_docs.view ability was missing from layoutAuth after removing the sidebar.admin_nav_item slot from the api-docs module. Add a HelpCenterLayoutProvider that checks the ability via AuthorizationService and provides the result in layout nav context (help-center.nav). Panel template now reads can_view_api_docs from the provider instead of layoutAuth. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Module\HelpCenter\Providers;
|
||||
|
||||
use MintyPHP\App\AppContainer;
|
||||
use MintyPHP\App\Module\Contracts\LayoutContextProvider;
|
||||
use MintyPHP\Service\Access\AuthorizationService;
|
||||
|
||||
final class HelpCenterLayoutProvider implements LayoutContextProvider
|
||||
{
|
||||
public function provide(array $session, AppContainer $container): array
|
||||
{
|
||||
$userId = (int) ($session['user']['id'] ?? 0);
|
||||
if ($userId <= 0) {
|
||||
return ['help-center.nav' => ['can_view_api_docs' => false]];
|
||||
}
|
||||
|
||||
try {
|
||||
$authService = $container->get(AuthorizationService::class);
|
||||
$canViewApiDocs = $authService->authorize('api_docs.view', [
|
||||
'actor_user_id' => $userId,
|
||||
])->isAllowed();
|
||||
} catch (\Throwable) {
|
||||
$canViewApiDocs = false;
|
||||
}
|
||||
|
||||
return ['help-center.nav' => ['can_view_api_docs' => $canViewApiDocs]];
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,9 @@ return [
|
||||
'search_resources' => [],
|
||||
'asset_groups' => [],
|
||||
'scheduler_jobs' => [],
|
||||
'layout_context_providers' => [],
|
||||
'layout_context_providers' => [
|
||||
\MintyPHP\Module\HelpCenter\Providers\HelpCenterLayoutProvider::class,
|
||||
],
|
||||
'session_providers' => [],
|
||||
'permissions' => [],
|
||||
'event_listeners' => [],
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
use MintyPHP\Service\Docs\DocsCatalogService;
|
||||
|
||||
$layoutAuth = is_array($viewAuth['layout'] ?? null) ? $viewAuth['layout'] : [];
|
||||
$layoutNav = is_array($layoutNav ?? null) ? $layoutNav : [];
|
||||
$helpNav = is_array($layoutNav['help-center.nav'] ?? null) ? $layoutNav['help-center.nav'] : [];
|
||||
$canViewDocs = !empty($layoutAuth['can_view_docs']);
|
||||
$canViewApiDocs = !empty($layoutAuth['api_docs.view']);
|
||||
$canViewApiDocs = !empty($helpNav['can_view_api_docs']);
|
||||
$canViewSystemInfo = !empty($layoutAuth['can_view_system_info']);
|
||||
|
||||
$docsDefaultSlug = $canViewDocs ? DocsCatalogService::defaultSlug() : '';
|
||||
|
||||
Reference in New Issue
Block a user