Change query() to children() - expose hassuborinates

This commit is contained in:
Deon George 2020-09-14 21:08:55 +10:00
parent 1ebdffa358
commit c549d28340
4 changed files with 13 additions and 11 deletions

View File

@ -78,16 +78,17 @@ class Server
* @param string $dn * @param string $dn
* @return |null * @return |null
*/ */
public function query(string $dn) public function children(string $dn)
{ {
try { try {
return ($x=(new Entry) return ($x=(new Entry)
->query() ->query()
->select(['dn','hassubordinates'])
->setDn($dn) ->setDn($dn)
->listing() ->listing()
->get()) ? $x : NULL; ->get()) ? $x : NULL;
// @todo Tidy up this exception // @todo Tidy up this exception
} catch (\Exception $e) { } catch (\Exception $e) {
dd(['e'=>$e]); dd(['e'=>$e]);
} }

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use LdapRecord\Query\Collection; use LdapRecord\Query\Collection;
@ -35,20 +36,20 @@ class APIController extends Controller
* @param Request $request * @param Request $request
* @return Collection * @return Collection
*/ */
public function query(Request $request): Collection public function children(Request $request): Collection
{ {
$levels = $request->query('depth',1); $levels = $request->query('depth',1);
$dn = Crypt::decryptString($request->query('key')); $dn = Crypt::decryptString($request->query('key'));
Log::debug(sprintf('%s: Query [%s] - Levels [%d]',__METHOD__,$dn,$levels)); Log::debug(sprintf('%s: Query [%s] - Levels [%d]',__METHOD__,$dn,$levels));
return (new Server()) return (new Server())
->query($dn) ->children($dn)
->transform(function($item) { ->transform(function($item) {
return [ return [
'title'=>$item->getDn(), 'title'=>$item->getRdn(),
'item'=>Crypt::encryptString($item->getDn()), 'item'=>Crypt::encryptString($item->getDn()),
'icon'=>'fa-fw fas fa-sitemap', 'icon'=>'fa-fw fas fa-sitemap',
'lazy'=>TRUE, 'lazy'=>Arr::get($item->getAttribute('hassubordinates'),0) == 'TRUE',
'tooltip'=>$item->getDn(), 'tooltip'=>$item->getDn(),
]; ];
}); });

6
public/js/custom.js vendored
View File

@ -47,7 +47,7 @@ $(document).ready(function() {
source: sources, source: sources,
lazyLoad: function(event,data) { lazyLoad: function(event,data) {
data.result = { data.result = {
url: "api/query", url: 'api/children',
data: {key: data.node.data.item,depth: 1} data: {key: data.node.data.item,depth: 1}
}; };
@ -55,8 +55,8 @@ $(document).ready(function() {
}, },
keydown: function(event, data){ keydown: function(event, data){
switch( $.ui.fancytree.eventToString(data.originalEvent) ) { switch( $.ui.fancytree.eventToString(data.originalEvent) ) {
case "return": case 'return':
case "space": case 'space':
data.node.toggleExpanded(); data.node.toggleExpanded();
break; break;
} }

View File

@ -20,6 +20,6 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
}); });
*/ */
Route::group([],function() { Route::group([],function() {
Route::get('/bases', 'APIController@bases'); Route::get('/bases','APIController@bases');
Route::get('/query', 'APIController@query'); Route::get('/children','APIController@children');
}); });