From 5c7c79f7c9e0fe0131e8d315eb4961ba94dd1211 Mon Sep 17 00:00:00 2001 From: aynsix Date: Mon, 10 Jun 2024 16:36:14 +0300 Subject: [PATCH] inspector delete application --- .../Controller/Admin/RootController.php | 16 +++++++++ .../Phrasea/ControllerProvider/Admin/Root.php | 5 +++ .../admin/inspector/record-index.html.twig | 33 ++++++++++++++++++- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/lib/Alchemy/Phrasea/Controller/Admin/RootController.php b/lib/Alchemy/Phrasea/Controller/Admin/RootController.php index cadb726c04..6bb203128d 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/RootController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/RootController.php @@ -17,6 +17,7 @@ use Alchemy\Phrasea\Databox\Subdef\MediaSubdefRepository; use Alchemy\Phrasea\Exception\SessionNotFound; use Alchemy\Phrasea\Model\Entities\ApiApplication; +use Alchemy\Phrasea\Model\Manipulator\ApiApplicationManipulator; use Alchemy\Phrasea\Model\Manipulator\ApiOauthTokenManipulator; use Alchemy\Phrasea\Model\Repositories\ApiAccountRepository; use Alchemy\Phrasea\Model\Repositories\ApiOauthTokenRepository; @@ -507,6 +508,13 @@ public function renewAccessToken(Request $request, ApiApplication $application) return $this->app->json(['success' => true]); } + public function deleteApplication(Request $request, ApiApplication $application) + { + $this->getApiApplicationManipulator()->delete($application); + + return $this->app->json(['success' => true]); + } + /** * @return ApiOauthTokenRepository */ @@ -582,4 +590,12 @@ private function getSectionParameters($section) 'off_databoxes' => $off_databoxes, ]; } + + /** + * @return ApiApplicationManipulator + */ + private function getApiApplicationManipulator() + { + return $this->app['manipulator.api-application']; + } } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Root.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Root.php index 600d44f12b..cbc713e8b4 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Root.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Root.php @@ -94,6 +94,11 @@ public function connect(Application $app) ->assert('application', '\d+') ->bind('admin_inspector_application_token'); + $controllers->post('/inspector/application/{application}/delete/', 'controller.admin.root:deleteApplication') + ->before($app['middleware.api-application.converter']) + ->assert('application', '\d+') + ->bind('admin_inspector_application_delete'); + return $controllers; } } diff --git a/templates/web/admin/inspector/record-index.html.twig b/templates/web/admin/inspector/record-index.html.twig index 74238efb6d..5d9ce7330d 100644 --- a/templates/web/admin/inspector/record-index.html.twig +++ b/templates/web/admin/inspector/record-index.html.twig @@ -82,6 +82,7 @@ {{ 'admin::inspector: api creation date' | trans }} {{ 'admin::inspector: api modification date' | trans }} + {% for apiApplication in apiApplications %} @@ -133,6 +134,9 @@ {% endif %} + + + {% endfor %} @@ -237,7 +241,7 @@ $('button.generate_token').bind('click', function (e) { e.preventDefault(); var $this = $(this); - if (confirm('Your are about to generate token for application with ID: ' + $this.data('app-id'))) { + if (confirm('You are about to generate token for application with ID: ' + $this.data('app-id'))) { $.ajax({ type: 'POST', url: $this.attr('href'), @@ -251,5 +255,32 @@ return false; } }); + + $('button.delete_application').bind('click', function (e) { + e.preventDefault(); + var $this = $(this); + if (confirm('You are about to delete application with ID: ' + $this.data('app-id'))) { + $.ajax({ + type: 'POST', + url: $this.attr('href'), + dataType: 'json', + success: function (data) { + if (data.success) { + $('#tree li.selected a').trigger('click'); + + setTimeout(function(){ + $('li a[href="#api-info"]').trigger('click'); + } + , 500 + ); + + } + } + }); + return false; + } else { + return false; + } + }); });