From 2abc321ecab5714f9565841d10f0cd0bc3968093 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 8 Apr 2025 14:29:21 +1000 Subject: [PATCH] Fix for showing no_lang_tag attrs (which are displayed without values) on a lang_tag attr pane when viewing a DN --- app/Classes/LDAP/Import/LDIF.php | 5 +++-- app/Http/Controllers/HomeController.php | 4 +++- app/Ldap/Entry.php | 16 ++++++++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/Classes/LDAP/Import/LDIF.php b/app/Classes/LDAP/Import/LDIF.php index 03a0be0b..2cabbbf2 100644 --- a/app/Classes/LDAP/Import/LDIF.php +++ b/app/Classes/LDAP/Import/LDIF.php @@ -66,6 +66,7 @@ class LDIF extends Import $m = []; preg_match('/^([a-zA-Z0-9;-]+)(:+)\s+(.*)$/',$line,$m); + dump(['m'=>$m,'line'=>$line]); switch (Arr::get($m,1)) { case 'changetype': @@ -156,7 +157,7 @@ class LDIF extends Import return $result; } - public function readEntry() { + public function xreadEntry() { static $haveVersion = FALSE; if ($lines = $this->nextLines()) { @@ -218,7 +219,7 @@ class LDIF extends Import default: if (! $server->dnExists($dn)) - return $this->error(_('Unkown change type'),$lines); + return $this->error(_('Unknown change type'),$lines); } } else diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 6b5181a1..5c87e5bf 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -95,8 +95,10 @@ class HomeController extends Controller ? view(sprintf('components.attribute.widget.%s',$id)) ->with('o',Factory::create($dn,$id,[],$request->objectclasses)) ->with('value',$request->value) + ->with('langtag',Entry::TAG_NOTAG) ->with('loop',$xx) - : new AttributeType(Factory::create($dn,$id,[],$request->objectclasses),TRUE)->render(); + : new AttributeType(Factory::create($dn,$id,[],$request->objectclasses),TRUE) + ->render(); } public function entry_create(EntryAddRequest $request): \Illuminate\Http\RedirectResponse diff --git a/app/Ldap/Entry.php b/app/Ldap/Entry.php index 5eddd64f..cc49603a 100644 --- a/app/Ldap/Entry.php +++ b/app/Ldap/Entry.php @@ -422,22 +422,22 @@ class Entry extends Model /** * Return this list of user attributes * - * @param string|null $tag If null return all tags + * @param string $tag If null return all tags * @return Collection */ - public function getVisibleAttributes(?string $tag=NULL): Collection + public function getVisibleAttributes(string $tag=''): Collection { - static $cache = NULL; + static $cache = []; - if (is_null($cache)) { + if (! Arr::get($cache,$tag ?: '_all_')) { $ot = $this->getOtherTags(); - $cache = $this->objects - ->filter(fn($item)=>! $item->is_internal) - ->filter(fn($item)=>is_null($tag) || $ot->has($item->name_lc) || count($item->tagValues($tag)) > 0); + $cache[$tag ?: '_all_'] = $this->objects + ->filter(fn($item)=>(! $item->is_internal) && ((! $item->no_attr_tags) || (! $tag) || ($tag === Entry::TAG_NOTAG))) + ->filter(fn($item)=>(! $tag) || $ot->has($item->name_lc) || count($item->tagValues($tag)) > 0); } - return $cache; + return $cache[$tag ?: '_all_']; } public function hasAttribute(int|string $key): bool