Files
breadcrumb-the-shire/pages/admin/permissions/data().php

51 lines
1.4 KiB
PHP

<?php
use MintyPHP\Router;
use MintyPHP\Support\Guard;
use MintyPHP\Service\Access\AccessServicesFactory;
use MintyPHP\Service\Access\PermissionAuthorizationPolicy;
Guard::requireLogin();
$currentUserId = (int) ($_SESSION['user']['id'] ?? 0);
$authorizationService = (new AccessServicesFactory())->createAuthorizationService();
$decision = $authorizationService->authorize(PermissionAuthorizationPolicy::ABILITY_ADMIN_PERMISSIONS_VIEW, [
'actor_user_id' => $currentUserId,
]);
if (!$decision->isAllowed()) {
Guard::deny();
}
$limit = (int) ($_GET['limit'] ?? 10);
$offset = (int) ($_GET['offset'] ?? 0);
$search = trim((string) ($_GET['search'] ?? ''));
$order = (string) ($_GET['order'] ?? 'key');
$dir = (string) ($_GET['dir'] ?? 'asc');
$active = (string) ($_GET['active'] ?? '');
$result = permissionGateway()->listPaged([
'limit' => $limit,
'offset' => $offset,
'search' => $search,
'order' => $order,
'dir' => $dir,
'active' => $active,
]);
$rows = [];
foreach ($result['data'] ?? [] as $row) {
$rows[] = [
'id' => $row['id'] ?? null,
'key' => $row['key'] ?? '',
'description' => $row['description'] ?? '',
'active' => (int) ($row['active'] ?? 1),
'is_system' => (int) ($row['is_system'] ?? 0),
'created' => dt($row['created'] ?? ''),
];
}
Router::json([
'data' => $rows,
'total' => $result['total'] ?? 0,
]);