From 85175f2ead6cf0052892d5aef09a6c7edec33410 Mon Sep 17 00:00:00 2001 From: Craig Williams Date: Tue, 6 Jun 2023 15:51:06 +0100 Subject: [PATCH] Show/hide columns programatically --- src/Controller/OrganisationController.php | 50 ++++++++++++++++++- .../pages/deleted-organisations.html.twig | 3 +- templates/pages/organisations.html.twig | 3 +- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/Controller/OrganisationController.php b/src/Controller/OrganisationController.php index 1cb09c2..cd51f5b 100644 --- a/src/Controller/OrganisationController.php +++ b/src/Controller/OrganisationController.php @@ -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 + ] + ] + ); } diff --git a/templates/pages/deleted-organisations.html.twig b/templates/pages/deleted-organisations.html.twig index 7c878bc..30c4a63 100644 --- a/templates/pages/deleted-organisations.html.twig +++ b/templates/pages/deleted-organisations.html.twig @@ -21,7 +21,8 @@
{% include "tables/deleted-organisations.html.twig" with { "table" : { - "id" : "table-organisations" + "id" : "table-organisations", + "columns" : table.columns } } %} diff --git a/templates/pages/organisations.html.twig b/templates/pages/organisations.html.twig index 57d5749..0297d29 100644 --- a/templates/pages/organisations.html.twig +++ b/templates/pages/organisations.html.twig @@ -21,7 +21,8 @@
{% include "tables/organisations.html.twig" with { "table" : { - "id" : "table-organisations" + "id" : "table-organisations", + "columns" : table.columns } } %}