From 339ba7258abe43072860acaf025f4a228420d009 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 2 Jul 2025 23:48:44 +0800 Subject: [PATCH] Make the ajax calls POST methods, and make the 'Create Entry' in the tree configurable so calls to children() can just return child entries --- app/Http/Controllers/AjaxController.php | 21 +++++++++++++-------- public/js/custom.js | 5 +++-- routes/web.php | 4 ++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php index 9c4abb14..0b57a6df 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/AjaxController.php @@ -38,7 +38,7 @@ class AjaxController extends Controller */ public function children(Request $request): Collection { - $dn = Crypt::decryptString($request->query('_key')); + $dn = Crypt::decryptString($request->post('_key')); // Sometimes our key has a command, so we'll ignore it if (str_starts_with($dn,'*') && ($x=strpos($dn,'|'))) @@ -57,13 +57,18 @@ class AjaxController extends Controller 'tooltip'=>$item->getDn(), ]) ->prepend( - [ - 'title'=>sprintf('[%s]',__('Create Entry')), - 'item'=>Crypt::encryptString(sprintf('*%s|%s','create',$dn)), - 'lazy'=>FALSE, - 'icon'=>'fas fa-fw fa-square-plus text-warning', - 'tooltip'=>__('Create new LDAP item here'), - ]); + $request->create + ? [ + 'title'=>sprintf('[%s]',__('Create Entry')), + 'item'=>Crypt::encryptString(sprintf('*%s|%s','create',$dn)), + 'lazy'=>FALSE, + 'icon'=>'fas fa-fw fa-square-plus text-warning', + 'tooltip'=>__('Create new LDAP item here'), + ] + : [] + ) + ->filter() + ->values(); } public function schema_view(Request $request) diff --git a/public/js/custom.js b/public/js/custom.js index 46080820..d1ca60a2 100644 --- a/public/js/custom.js +++ b/public/js/custom.js @@ -59,7 +59,7 @@ $(document).ready(function() { if (typeof basedn !== 'undefined') { sources = basedn; } else { - sources = { url: '/ajax/bases' }; + sources = { method: 'POST', url: '/ajax/bases' }; } // Attach the fancytree widget to an existing
element @@ -95,8 +95,9 @@ $(document).ready(function() { source: sources, lazyLoad: function(event,data) { data.result = { + method: 'POST', url: '/ajax/children', - data: {_key: data.node.data.item,depth: 1} + data: {_key: data.node.data.item,create: true} }; expandChildren(data.tree.rootNode); diff --git a/routes/web.php b/routes/web.php index a79180ae..c27ed4a6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -63,8 +63,8 @@ Route::controller(HomeController::class)->group(function() { Route::controller(AjaxController::class) ->prefix('ajax') ->group(function() { - Route::get('bases','bases'); - Route::get('children','children'); + Route::post('bases','bases'); + Route::post('children','children'); Route::post('schema/view','schema_view'); Route::post('schema/objectclass/attrs/{id}','schema_objectclass_attrs'); }); \ No newline at end of file