Show/hide columns programatically

This commit is contained in:
2023-06-06 15:51:06 +01:00
parent 3a097fabca
commit 85175f2ead
3 changed files with 52 additions and 4 deletions

View File

@@ -1103,6 +1103,9 @@ class OrganisationController extends SimpleController
/** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager $authorizer */
$authorizer = $this->ci->authorizer;
/** @var \UserFrosting\Support\Repository\Repository $config */
$config = $this->ci->config;
/** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */
$currentUser = $this->ci->currentUser;
@@ -1111,7 +1114,34 @@ class OrganisationController extends SimpleController
throw new ForbiddenException();
}
return $this->ci->view->render($response, 'pages/organisations.html.twig');
$tableColumns = [ 'description' ];
if ($currentUser->organisations(true)->count() == 0) {
$tableColumns[] = 'join';
} else {
if (!$config['organisation']['membership']['single_membership']) {
$tableColumns[] = 'join';
}
}
if ($currentUser->organisations(true)->wherePivot('flag_admin', true) |
$authorizer->checkAccess($currentUser, 'delete_organisation') |
$authorizer->checkAccess($currentUser, 'update_organisation_field') |
$authorizer->checkAccess($currentUser, 'approve_organisation') |
$authorizer->checkAccess($currentUser, 'merge_organisations')) {
$tableColumns[] = 'status';
$tableColumns[] = 'actions';
}
return $this->ci->view->render(
$response,
'pages/organisations.html.twig',
[
'table' => [
'columns' => $tableColumns
]
]
);
}
/**
@@ -1142,7 +1172,23 @@ class OrganisationController extends SimpleController
throw new ForbiddenException();
}
return $this->ci->view->render($response, 'pages/deleted-organisations.html.twig');
$tableColumns = [ 'description' ];
if ($authorizer->checkAccess($currentUser, 'restore_organisation') |
$authorizer->checkAccess($currentUser, 'permanently_delete_organisation')) {
$tableColumns[] = 'status';
$tableColumns[] = 'actions';
}
return $this->ci->view->render(
$response,
'pages/deleted-organisations.html.twig',
[
'table' => [
'columns' => $tableColumns
]
]
);
}