diff --git a/src/di.php b/src/di.php index e0ba38cdf..36c8e4e37 100644 --- a/src/di.php +++ b/src/di.php @@ -487,7 +487,7 @@ $di['set_return_uri'] = function () use ($di): void { /* * Creates a new API object based on the specified role and returns it. * - * @param string $role The role to create the API object for. Can be 'guest', 'client', 'admin', or 'system'. + * @param string $role The role to create the API object for. Can be 'guest', 'client', or 'admin'. * * @return \Api_Handler The new API object that was just created. * @@ -498,7 +498,6 @@ $di['api'] = $di->protect(function ($role) use ($di) { 'guest' => new Model_Guest(), 'client' => $di['loggedin_client'], 'admin' => $di['loggedin_admin'], - 'system' => $di['mod_service']('staff')->getCronAdmin(), default => throw new Exception('Unrecognized Handler type: ' . $role), }; @@ -553,9 +552,15 @@ $di['api_admin'] = fn () => $di['api']('admin'); * * @param void * - * @return \Api_Handler + * @return \Api_Handler Internal-only system API handler used for cron/background processing. */ -$di['api_system'] = fn () => $di['api']('system'); +$di['api_system'] = function () use ($di) { + $identity = $di['mod_service']('staff')->getCronAdmin(); + $api = new Api_Handler($identity); + $api->setDi($di); + + return $api; +}; $di['tools'] = function () use ($di) { $service = new FOSSBilling\Tools(); diff --git a/src/install/sql/content.sql b/src/install/sql/content.sql index 5e1cfd1c6..aaa332cf3 100644 --- a/src/install/sql/content.sql +++ b/src/install/sql/content.sql @@ -310,7 +310,7 @@ LOCK TABLES `setting` WRITE; INSERT INTO `setting` (`id`, `param`, `value`, `public`, `category`, `hash`, `created_at`, `updated_at`) VALUES - (1,'last_patch','52',0,NULL,NULL,'2024-12-30 12:00:00','2024-12-30 12:00:00'), + (1,'last_patch','53',0,NULL,NULL,'2024-12-30 12:00:00','2024-12-30 12:00:00'), (2,'company_name','Company Name',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (3,'company_email','support@yourcompany.com',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (4,'company_signature','FOSSBilling.org - Client Management, Invoicing and Support Software',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), diff --git a/src/library/Box/TwigExtensions.php b/src/library/Box/TwigExtensions.php index 87e9aeba8..383485578 100644 --- a/src/library/Box/TwigExtensions.php +++ b/src/library/Box/TwigExtensions.php @@ -136,6 +136,7 @@ class Box_TwigExtensions extends AbstractExtension implements InjectionAwareInte return [ new TwigFunction('render_widgets', $this->twig_render_widgets(...), ['needs_environment' => true, 'is_safe' => ['html']]), new TwigFunction('svg_sprite', $this->twig_svg_sprite(...), ['needs_environment' => true, 'is_safe' => ['html']]), + new TwigFunction('has_permission', $this->has_permission(...)), // FOSSBilling API functions new TwigFunction('fb_api', $this->fb_api(...), ['is_safe' => ['html']]), @@ -193,6 +194,19 @@ class Box_TwigExtensions extends AbstractExtension implements InjectionAwareInte return $output; } + public function has_permission(string $module, ?string $permission = null): bool + { + if (!$this->di['auth']->isAdminLoggedIn()) { + return false; + } + + try { + return $this->di['mod_service']('Staff')->hasPermission($this->di['loggedin_admin'], $module, $permission); + } catch (Throwable) { + return false; + } + } + public function twig_ipcountryname_filter($value) { if (empty($value)) { diff --git a/src/library/FOSSBilling/UpdatePatcher.php b/src/library/FOSSBilling/UpdatePatcher.php index edf2651d1..607ba09f9 100644 --- a/src/library/FOSSBilling/UpdatePatcher.php +++ b/src/library/FOSSBilling/UpdatePatcher.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace FOSSBilling; +use Doctrine\DBAL\ParameterType; use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Path; @@ -294,6 +295,7 @@ class UpdatePatcher implements InjectionAwareInterface 50 => 'patch50', 51 => 'patch51', 52 => 'patch52', + 53 => 'patch53', ]; ksort($patches, SORT_NATURAL); @@ -824,6 +826,79 @@ class UpdatePatcher implements InjectionAwareInterface } } + private function patch53(): void + { + $dbal = $this->di['dbal']; + $tools = $this->di['tools']; + $now = date('Y-m-d H:i:s'); + + $dbal->beginTransaction(); + + try { + $batchSize = 1000; + $adminUpdateStmt = $dbal->prepare('UPDATE admin SET api_token = :api_token, updated_at = :updated_at WHERE id = :id'); + $clientUpdateStmt = $dbal->prepare('UPDATE client SET api_token = :api_token, updated_at = :updated_at WHERE id = :id'); + + $lastAdminId = 0; + do { + $adminIds = $dbal->createQueryBuilder() + ->select('id') + ->from('admin') + ->where('id > :lastId') + ->orderBy('id', 'ASC') + ->setMaxResults($batchSize) + ->setParameter('lastId', $lastAdminId) + ->executeQuery() + ->fetchFirstColumn(); + + foreach ($adminIds as $adminId) { + $adminUpdateStmt->bindValue('api_token', $tools->generatePassword(32)); + $adminUpdateStmt->bindValue('updated_at', $now); + $adminUpdateStmt->bindValue('id', (int) $adminId, ParameterType::INTEGER); + $adminUpdateStmt->executeStatement(); + } + + if (!empty($adminIds)) { + $lastAdminId = (int) end($adminIds); + } + } while (!empty($adminIds)); + + $lastClientId = 0; + do { + $clientIds = $dbal->createQueryBuilder() + ->select('id') + ->from('client') + ->where('id > :lastId') + ->orderBy('id', 'ASC') + ->setMaxResults($batchSize) + ->setParameter('lastId', $lastClientId) + ->executeQuery() + ->fetchFirstColumn(); + + foreach ($clientIds as $clientId) { + $clientUpdateStmt->bindValue('api_token', $tools->generatePassword(32)); + $clientUpdateStmt->bindValue('updated_at', $now); + $clientUpdateStmt->bindValue('id', (int) $clientId, ParameterType::INTEGER); + $clientUpdateStmt->executeStatement(); + } + + if (!empty($clientIds)) { + $lastClientId = (int) end($clientIds); + } + } while (!empty($clientIds)); + + $dbal->createQueryBuilder() + ->delete('session') + ->executeStatement(); + + $dbal->commit(); + } catch (\Throwable $e) { + $dbal->rollBack(); + + throw $e; + } + } + /** * If we end up needing a newly introduced package during the update process, composer's autoloader won't have it until the next load. * As a workaround, we can register AntLoader and point it at the Vendor folder which will then act as fallback to find the needed classes. diff --git a/src/modules/Api/Controller/Client.php b/src/modules/Api/Controller/Client.php index 4f89f6e18..1bb23be66 100644 --- a/src/modules/Api/Controller/Client.php +++ b/src/modules/Api/Controller/Client.php @@ -45,8 +45,9 @@ class Client implements InjectionAwareInterface public function register(\Box_App &$app): void { - $app->post('/api/:role/:class/:method', 'post_method', ['role', 'class', 'method'], static::class); - $app->get('/api/:role/:class/:method', 'get_method', ['role', 'class', 'method'], static::class); + $allowedRouteRoles = $this->registerAllowedRouteRoles(); + $app->post('/api/:role/:class/:method', 'post_method', $allowedRouteRoles, static::class); + $app->get('/api/:role/:class/:method', 'get_method', $allowedRouteRoles, static::class); // all other requests are error requests $app->get('/api/:page', 'show_error', ['page' => '(.?)+'], static::class); @@ -187,24 +188,12 @@ class Client implements InjectionAwareInterface $this->checkHttpReferer(); $this->isRoleAllowed($role); - $hasTokenAuthCredentials = in_array($role, ['client', 'admin'], true) && $this->hasTokenAuthCredentials(); - $hasValidSession = false; - - try { - $this->isRoleLoggedIn($role); - $hasValidSession = true; - } catch (\Exception) { - } - - if ($hasTokenAuthCredentials) { - // Token auth via the Authorization header is not vulnerable to CSRF (browsers cannot send - // Authorization headers cross-origin automatically), so skip CSRF and perform token login. - $this->_tryTokenLogin(); - } elseif (!$hasValidSession) { - $this->_tryTokenLogin(); - } elseif ($role == 'client' || $role == 'admin') { - // Authenticated browser session for privileged roles must pass CSRF checks. - $this->_checkCSRFToken(); + if ($role !== 'guest') { + if ($this->shouldUseTokenLogin($role)) { + $this->_tryTokenLogin($role); + } else { + $this->requireSessionAuth($role); + } } $api = $this->di['api']($role); @@ -236,11 +225,14 @@ class Client implements InjectionAwareInterface private function getAuth(): array { - if (isset($_SERVER['HTTP_AUTHORIZATION'])) { - $auth_params = explode(':', base64_decode(substr((string) $_SERVER['HTTP_AUTHORIZATION'], 6))); - $_SERVER['PHP_AUTH_USER'] = $auth_params[0]; - unset($auth_params[0]); - $_SERVER['PHP_AUTH_PW'] = implode('', $auth_params); + if (!isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['HTTP_AUTHORIZATION'])) { + $parsedAuth = $this->tryParseBasicAuthHeader(); + if ($parsedAuth === null) { + throw new \FOSSBilling\InformationException('Authentication Failed', null, 201); + } + + $_SERVER['PHP_AUTH_USER'] = $parsedAuth['username']; + $_SERVER['PHP_AUTH_PW'] = $parsedAuth['password']; } if (!isset($_SERVER['PHP_AUTH_USER'])) { @@ -258,11 +250,14 @@ class Client implements InjectionAwareInterface return [$_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']]; } - protected function _tryTokenLogin(): void + protected function _tryTokenLogin(string $routeRole): void { [$username, $password] = $this->getAuth(); + if ($username !== $routeRole) { + throw new \FOSSBilling\InformationException('Authentication Failed', null, 203); + } - switch ($username) { + switch ($routeRole) { case 'client': $model = $this->di['db']->findOne('Client', 'api_token = ?', [$password]); if (!$model instanceof \Model_Client) { @@ -277,6 +272,12 @@ class Client implements InjectionAwareInterface if (!$model instanceof \Model_Admin) { throw new \FOSSBilling\InformationException('Authentication Failed', null, 205); } + + $cronAdmin = $this->di['mod_service']('staff')->getCronAdmin(); + if ($cronAdmin instanceof \Model_Admin && (int) $model->id === (int) $cronAdmin->id) { + throw new \FOSSBilling\InformationException('Authentication Failed', null, 205); + } + $sessionAdminArray = [ 'id' => $model->id, 'email' => $model->email, @@ -287,21 +288,96 @@ class Client implements InjectionAwareInterface break; - case 'guest': // do not allow at the moment default: throw new \FOSSBilling\InformationException('Authentication Failed', null, 203); } } - protected function hasTokenAuthCredentials(): bool + private function registerAllowedRouteRoles(): array { - try { - [$username, $password] = $this->getAuth(); - } catch (\Exception) { + return [ + 'role' => 'guest|client|admin', + 'class' => '[a-zA-Z0-9_]+', + 'method' => '[a-zA-Z0-9_]+', + ]; + } + + protected function shouldUseTokenLogin(string $routeRole): bool + { + if (!in_array($routeRole, ['client', 'admin'], true)) { return false; } - return in_array($username, ['client', 'admin'], true) && $password !== ''; + $username = $this->getProvidedBasicAuthUsername(); + if ($username === null) { + return false; + } + + if ($username !== $routeRole) { + throw new \FOSSBilling\InformationException('Authentication Failed', null, 203); + } + + return true; + } + + private function getProvidedBasicAuthUsername(): ?string + { + if (isset($_SERVER['PHP_AUTH_USER']) && in_array($_SERVER['PHP_AUTH_USER'], ['client', 'admin'], true)) { + return (string) $_SERVER['PHP_AUTH_USER']; + } + + $parsedAuth = $this->tryParseBasicAuthHeader(); + if ($parsedAuth === null) { + return null; + } + + $username = $parsedAuth['username']; + if (!in_array($username, ['client', 'admin'], true)) { + return null; + } + + return $username; + } + + /** + * @return array{username: string, password: string}|null + */ + private function tryParseBasicAuthHeader(): ?array + { + if (!isset($_SERVER['HTTP_AUTHORIZATION'])) { + return null; + } + + $authorization = trim((string) $_SERVER['HTTP_AUTHORIZATION']); + if (stripos($authorization, 'Basic ') !== 0) { + return null; + } + + $decoded = base64_decode(substr($authorization, 6), true); + if ($decoded === false || !str_contains($decoded, ':')) { + return null; + } + + [$username, $password] = explode(':', $decoded, 2); + + return [ + 'username' => $username, + 'password' => $password, + ]; + } + + private function requireSessionAuth(string $role): void + { + try { + $this->isRoleLoggedIn($role); + if ($role === 'client' || $role === 'admin') { + $this->_checkCSRFToken(); + } + } catch (\FOSSBilling\InformationException $exception) { + throw $exception; + } catch (\Exception) { + throw new \FOSSBilling\InformationException('Authentication Failed', null, 201); + } } /** @@ -312,8 +388,8 @@ class Client implements InjectionAwareInterface private function isRoleAllowed($role): bool { $allowed = ['guest', 'client', 'admin']; - if (!in_array($role, $allowed)) { - new \FOSSBilling\Exception('Unknown API call :call', [':call' => ''], 701); + if (!in_array($role, $allowed, true)) { + throw new \FOSSBilling\Exception('Unknown API call :call', [':call' => (string) $role], 701); } return true; @@ -341,10 +417,12 @@ class Client implements InjectionAwareInterface error_log("{$e->getMessage()} {$e->getCode()}."); $code = $e->getCode() ?: 9999; $result = ['result' => null, 'error' => ['message' => $e->getMessage(), 'code' => $code]]; - $authFailed = [201, 202, 206, 204, 205, 203, 403, 1004, 1002]; + $authFailed = [201, 202, 206, 204, 205, 203, 1004, 1002]; if (in_array($code, $authFailed)) { header('HTTP/1.1 401 Unauthorized'); + } elseif ($code == 403) { + header('HTTP/1.1 403 Forbidden'); } elseif ($code == 701 || $code == 879) { header('HTTP/1.1 400 Bad Request'); } diff --git a/src/modules/Client/Api/Admin.php b/src/modules/Client/Api/Admin.php index 40eceb04d..d04e1b455 100644 --- a/src/modules/Client/Api/Admin.php +++ b/src/modules/Client/Api/Admin.php @@ -31,6 +31,8 @@ class Admin extends \Api_Abstract */ public function get_list($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'view'); + $per_page = $data['per_page'] ?? $this->di['pager']->getDefaultPerPage(); [$sql, $params] = $this->getService()->getSearchQuery($data); $pager = $this->di['pager']->getPaginatedResultSet($sql, $params, $per_page); @@ -52,6 +54,8 @@ class Admin extends \Api_Abstract */ public function get_pairs($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'view'); + $service = $this->di['mod_service']('client'); return $service->getPairs($data); @@ -66,10 +70,13 @@ class Admin extends \Api_Abstract */ public function get($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'view'); + $service = $this->getService(); $client = $service->get($data); + $includeSensitive = $this->di['mod_service']('Staff')->hasPermission(null, 'client', 'manage_api_keys'); - return $service->toApiArray($client, true, $this->getIdentity()); + return $service->toApiArray($client, true, $this->getIdentity(), $includeSensitive); } /** @@ -80,6 +87,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'ID required'])] public function login($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'impersonate_login'); + $client = $this->di['db']->getExistingModelById('Client', $data['id'], 'Client not found'); $service = $this->di['mod_service']('client'); @@ -138,6 +147,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['email' => 'Email required', 'first_name' => 'First name is required'])] public function create($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'create'); + $validator = $this->di['validator']; $data['email'] = $this->di['tools']->validateAndSanitizeEmail($data['email']); @@ -161,6 +172,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'Client ID is missing'])] public function delete($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'delete'); + $model = $this->di['db']->getExistingModelById('Client', $data['id'], 'Client not found'); $this->di['events_manager']->fire(['event' => 'onBeforeAdminClientDelete', 'params' => ['id' => $model->id]]); @@ -215,6 +228,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'Client ID was not passed'])] public function update($data = []): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'edit_profile'); + $client = $this->di['db']->getExistingModelById('Client', $data['id'], 'Client not found'); $service = $this->di['mod_service']('client'); @@ -279,6 +294,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'ID required', 'password' => 'Password required', 'password_confirm' => 'Password confirmation required'])] public function change_password($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'change_password'); + $this->di['validator']->passwordsMatch($data); $this->di['validator']->isPasswordStrong($data['password']); @@ -332,6 +349,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'Client ID was not passed'])] public function balance_delete($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'manage_balance'); + $model = $this->di['db']->getExistingModelById('ClientBalance', $data['id'], 'Balance line not found'); $id = $model->id; @@ -354,6 +373,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'Client ID required', 'amount' => 'Amount is required', 'description' => 'Description is required'])] public function balance_add_funds($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'manage_balance'); + $client = $this->di['db']->getExistingModelById('Client', $data['id'], 'Client not found'); $service = $this->di['mod_service']('client'); @@ -387,6 +408,8 @@ class Admin extends \Api_Abstract */ public function login_history_get_list($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'view_login_history'); + [$q, $params] = $this->getService()->getHistorySearchQuery($data); $per_page = $data['per_page'] ?? $this->di['pager']->getDefaultPerPage(); $pager = $this->di['pager']->getPaginatedResultSet($q, $params, $per_page); @@ -440,6 +463,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['title' => 'Group title is missing'])] public function group_create($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'manage_groups'); + return $this->getService()->createGroup($data); } @@ -451,6 +476,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'Group ID is missing'])] public function group_update($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'manage_groups'); + $model = $this->di['db']->getExistingModelById('ClientGroup', $data['id'], 'Group not found'); $model->title = $data['title'] ?? $model->title; @@ -468,6 +495,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'Group ID is missing'])] public function group_delete($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'manage_groups'); + $model = $this->di['db']->getExistingModelById('ClientGroup', $data['id'], 'Group not found'); $clients = $this->di['db']->find('Client', 'client_group_id = :group_id', [':group_id' => $data['id']]); @@ -498,6 +527,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['ids' => 'IDs were not passed'])] public function batch_delete($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'bulk_delete'); + foreach ($data['ids'] as $id) { $this->delete(['id' => $id]); } @@ -507,6 +538,8 @@ class Admin extends \Api_Abstract public function export_csv($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'export'); + $data['headers'] ??= []; return $this->getService()->exportCSV($data['headers']); diff --git a/src/modules/Client/Service.php b/src/modules/Client/Service.php index 31b25f1c0..6d076871c 100644 --- a/src/modules/Client/Service.php +++ b/src/modules/Client/Service.php @@ -20,6 +20,73 @@ class Service implements InjectionAwareInterface { protected ?\Pimple\Container $di = null; + public function getModulePermissions(): array + { + return [ + 'view' => [ + 'type' => 'bool', + 'display_name' => __trans('View client details'), + 'description' => __trans('Allows the staff member to view client account details and listings.'), + ], + 'create' => [ + 'type' => 'bool', + 'display_name' => __trans('Create clients'), + 'description' => __trans('Allows the staff member to create new client accounts.'), + ], + 'edit_profile' => [ + 'type' => 'bool', + 'display_name' => __trans('Edit client profiles'), + 'description' => __trans('Allows the staff member to update client profile details and account settings.'), + ], + 'impersonate_login' => [ + 'type' => 'bool', + 'display_name' => __trans('Login as client'), + 'description' => __trans('Allows the staff member to authenticate as any client account.'), + ], + 'manage_api_keys' => [ + 'type' => 'bool', + 'display_name' => __trans('Manage client API keys'), + 'description' => __trans('Allows the staff member to view and generate API keys for client accounts.'), + ], + 'change_password' => [ + 'type' => 'bool', + 'display_name' => __trans('Change client passwords'), + 'description' => __trans('Allows the staff member to set new passwords for client accounts.'), + ], + 'manage_balance' => [ + 'type' => 'bool', + 'display_name' => __trans('Manage client balance'), + 'description' => __trans('Allows the staff member to add or remove balance entries for client accounts.'), + ], + 'view_login_history' => [ + 'type' => 'bool', + 'display_name' => __trans('View client login history'), + 'description' => __trans('Allows the staff member to view client login history and IP addresses.'), + ], + 'manage_groups' => [ + 'type' => 'bool', + 'display_name' => __trans('Manage client groups'), + 'description' => __trans('Allows the staff member to create, update, and delete client groups.'), + ], + 'delete' => [ + 'type' => 'bool', + 'display_name' => __trans('Delete clients'), + 'description' => __trans('Allows the staff member to permanently remove client accounts.'), + ], + 'bulk_delete' => [ + 'type' => 'bool', + 'display_name' => __trans('Bulk delete clients'), + 'description' => __trans('Allows the staff member to permanently remove multiple client accounts in a single action.'), + ], + 'export' => [ + 'type' => 'bool', + 'display_name' => __trans('Export clients'), + 'description' => __trans('Allows the staff member to export client account data.'), + ], + 'manage_settings' => [], + ]; + } + public function setDi(\Pimple\Container $di): void { $this->di = $di; @@ -339,7 +406,7 @@ class Service implements InjectionAwareInterface return $this->di['db']->findOne('Client', 'email = ? and pass = ? and status = ?', [$email, $password, \Model_Client::ACTIVE]); } - public function toApiArray(\Model_Client $model, $deep = false, $identity = null): array + public function toApiArray(\Model_Client $model, $deep = false, $identity = null, bool $includeSensitive = false): array { $details = [ 'id' => $model->id, @@ -385,13 +452,16 @@ class Service implements InjectionAwareInterface if ($identity instanceof \Model_Admin) { $details['auth_type'] = $model->auth_type; - $details['api_token'] = $model->api_token; $details['ip'] = $model->ip; $details['status'] = $model->status; $details['tax_exempt'] = $model->tax_exempt; $details['group'] = ($clientGroup) ? $clientGroup->title : null; $details['updated_at'] = $model->updated_at; $details['email_approved'] = $model->email_approved; + + if ($includeSensitive) { + $details['api_token'] = $model->api_token; + } } return $details; diff --git a/src/modules/Client/templates/admin/mod_client_group.html.twig b/src/modules/Client/templates/admin/mod_client_group.html.twig index 53f375a67..c4e545ff4 100644 --- a/src/modules/Client/templates/admin/mod_client_group.html.twig +++ b/src/modules/Client/templates/admin/mod_client_group.html.twig @@ -1,6 +1,7 @@ {% extends 'layout_default.html.twig' %} {% set active_menu = 'client' %} +{% set can_manage_groups = has_permission('client', 'manage_groups') %} {% block meta_title %}{{ group.title}}{% endblock %} @@ -25,6 +26,7 @@