From d61685a5b26bd32106d2a1bacc4027f6a3f0d0e6 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 2 Feb 2025 09:22:42 +1100 Subject: [PATCH] Work on adding additional objectclasses to an entry --- app/Classes/LDAP/Schema/ObjectClass.php | 10 ++ app/Http/Controllers/HomeController.php | 79 +++++++-- public/css/fixes.css | 5 + .../attribute/objectclass.blade.php | 9 +- .../attribute/widget/objectclass.blade.php | 19 +++ .../attribute/widget/options.blade.php | 150 ++++++++++++++++-- .../views/components/form/select.blade.php | 2 +- resources/views/frames/dn.blade.php | 14 +- routes/web.php | 7 +- 9 files changed, 244 insertions(+), 51 deletions(-) create mode 100644 resources/views/components/attribute/widget/objectclass.blade.php diff --git a/app/Classes/LDAP/Schema/ObjectClass.php b/app/Classes/LDAP/Schema/ObjectClass.php index 66974c8..26dcddc 100644 --- a/app/Classes/LDAP/Schema/ObjectClass.php +++ b/app/Classes/LDAP/Schema/ObjectClass.php @@ -442,6 +442,16 @@ final class ObjectClass extends Base return $this->type; } + /** + * Return if this objectclass is auxiliary + * + * @return bool + */ + public function isAuxiliary(): bool + { + return $this->type === Server::OC_AUXILIARY; + } + /** * Determine if an array is listed in the may_force attrs */ diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 8e02b3d..b2a698a 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -68,6 +68,28 @@ class HomeController extends Controller ->with('page_actions',$page_actions); } + /** + * Render a new attribute view + * + * @param Request $request + * @param string $id + * @return \Closure|\Illuminate\Contracts\View\View|string + */ + public function entry_attr_add(Request $request,string $id) + { + $xx = new \stdClass(); + $xx->index = 0; + + $x = $request->noheader + ? (string)view(sprintf('components.attribute.widget.%s',$id)) + ->with('o',new Attribute($id,[])) + ->with('value',$request->value) + ->with('loop',$xx) + : (new AttributeType(new Attribute($id,[]),TRUE))->render(); + + return $x; + } + public function entry_export(Request $request,string $id) { $dn = Crypt::decryptString($id); @@ -84,10 +106,33 @@ class HomeController extends Controller ->with('result',new LDIFExport($result)); } - public function entry_newattr(string $id) + /** + * Render an available list of objectclasses for an Entry + * + * @param string $id + * @return mixed + */ + public function entry_objectclass_add(string $id) { - $x = new AttributeType(new Attribute($id,[]),TRUE); - return $x->render(); + $dn = Crypt::decryptString($id); + $o = config('server')->fetch($dn); + + $ocs = $o->getObject('objectclass') + ->structural + ->map(fn($item)=>$item->getParents()) + ->flatten() + ->merge( + config('server')->schema('objectclasses') + ->filter(fn($item)=>$item->isAuxiliary()) + ) + ->sortBy(fn($item)=>$item->name); + + return $ocs->groupBy(fn($item)=>$item->isStructural()) + ->map(fn($item,$key) => + [ + 'text' => sprintf('%s Object Class',$key ? 'Structural' : 'Auxiliary'), + 'children' => $item->map(fn($item)=>['id'=>$item->name,'text'=>$item->name]), + ]); } public function entry_password_check(Request $request) @@ -126,20 +171,22 @@ class HomeController extends Controller $o->{$key} = array_filter($value,fn($item)=>! is_null($item)); // We need to process and encrypt the password - $passwords = []; - foreach ($request->userpassword as $key => $value) { - // If the password is still the MD5 of the old password, then it hasnt changed - if (($old=Arr::get($o->userpassword,$key)) && ($value === md5($old))) { - array_push($passwords,$old); - continue; - } + if ($request->userpassword) { + $passwords = []; + foreach ($request->userpassword as $key => $value) { + // If the password is still the MD5 of the old password, then it hasnt changed + if (($old=Arr::get($o->userpassword,$key)) && ($value === md5($old))) { + array_push($passwords,$old); + continue; + } - if ($value) { - $type = Arr::get($request->userpassword_hash,$key); - array_push($passwords,Attribute\Password::hash_id($type)->encode($value)); + if ($value) { + $type = Arr::get($request->userpassword_hash,$key); + array_push($passwords,Attribute\Password::hash_id($type)->encode($value)); + } } + $o->userpassword = $passwords; } - $o->userpassword = $passwords; if (! $o->getDirty()) return back() @@ -294,10 +341,8 @@ class HomeController extends Controller */ public function schema_frame(Request $request) { - $s = config('server'); - // If an invalid key, we'll 404 - if ($request->type && $request->key && ($s->schema($request->type)->has($request->key) === FALSE)) + if ($request->type && $request->key && (! config('server')->schema($request->type)->has($request->key))) abort(404); return view('frames.schema') diff --git a/public/css/fixes.css b/public/css/fixes.css index 2005ad2..81d724e 100644 --- a/public/css/fixes.css +++ b/public/css/fixes.css @@ -290,4 +290,9 @@ select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__ .select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered .select2-selection__placeholder { line-height: 1.0; font-size: 90%; +} + +.select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option[role=group] .select2-results__group { + color: #212529; + font-weight: 800; } \ No newline at end of file diff --git a/resources/views/components/attribute/objectclass.blade.php b/resources/views/components/attribute/objectclass.blade.php index b62c7af..ff90a59 100644 --- a/resources/views/components/attribute/objectclass.blade.php +++ b/resources/views/components/attribute/objectclass.blade.php @@ -2,14 +2,7 @@ @foreach (old($o->name_lc,$o->values) as $value) @if ($edit && ($value === NULL || (! $o->isStructural($value)))) -
- ($e=$errors->get($o->name_lc.'.'.$loop->index)),'mb-1','border-focus'=>$o->values->contains($value)]) name="{{ $o->name_lc }}[]" value="{{ $value }}" placeholder="{{ ! is_null($x=Arr::get($o->values,$loop->index)) ? $x : '['.__('NEW').']' }}" @readonly(true)> -
- @if($e) - {{ join('|',$e) }} - @endif -
-
+ @else {{ $value }} @if ($o->isStructural($value)) diff --git a/resources/views/components/attribute/widget/objectclass.blade.php b/resources/views/components/attribute/widget/objectclass.blade.php new file mode 100644 index 0000000..932aec4 --- /dev/null +++ b/resources/views/components/attribute/widget/objectclass.blade.php @@ -0,0 +1,19 @@ +
+ + ($e=$errors->get($o->name_lc.'.'.$loop->index)),'mb-1','border-focus'=>$o->values->contains($value)]) name="{{ $o->name_lc }}[]" value="{{ $value }}" placeholder="{{ Arr::get($o->values,$loop->index,'['.__('NEW').']') }}" @readonly(true)> +
+ @if($e) + {{ join('|',$e) }} + @endif +
+
+ + + \ No newline at end of file diff --git a/resources/views/components/attribute/widget/options.blade.php b/resources/views/components/attribute/widget/options.blade.php index af22615..6b1649e 100644 --- a/resources/views/components/attribute/widget/options.blade.php +++ b/resources/views/components/attribute/widget/options.blade.php @@ -1,22 +1,138 @@ +@php($clone=FALSE) @if($o->is_rdn) @lang('Rename') @elseif($edit && $o->can_addvalues) - (! $new)]) id="{{ $o->name_lc }}"> @lang('Add Value') - -@endif + @switch(get_class($o)) + @case('App\Classes\LDAP\Attribute\Binary\JpegPhoto') + (! $new)]) id="{{ $o->name_lc }}"> @lang('Upload JpegPhoto') -@section('page-scripts') - @if($edit && $o->can_addvalues) - - @endif -@append \ No newline at end of file + @break + + @case('App\Classes\LDAP\Attribute\ObjectClass') + + + + + + @section('page-scripts') + + @append + @break + + @case('App\Classes\LDAP\Attribute') + @default + @php($clone=TRUE) + (! $new)]) id="{{ $o->name_lc }}"> @lang('Add Value') + + @section('page-scripts') + @if($clone && $edit && $o->can_addvalues) + + @endif + @append + @endswitch + +@endif \ No newline at end of file diff --git a/resources/views/components/form/select.blade.php b/resources/views/components/form/select.blade.php index 8ebfc6c..4c7ed1f 100644 --- a/resources/views/components/form/select.blade.php +++ b/resources/views/components/form/select.blade.php @@ -3,7 +3,7 @@ @endisset