From 181971acc48e0e782869de261d850f2d933c829c Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 24 May 2025 00:01:33 +1000 Subject: [PATCH] Improvements to userPassword handling when redirecting back. No need to use old() when rendering attributes, since they have already been processed by display with any updates --- app/Classes/LDAP/Attribute.php | 26 ++++++++++++++++++- .../views/components/attribute.blade.php | 2 -- .../attribute/krbprincipalkey.blade.php | 5 ++-- .../attribute/krbticketflags.blade.php | 2 +- .../attribute/objectclass.blade.php | 2 +- .../components/attribute/password.blade.php | 5 ++-- .../views/components/attribute/rdn.blade.php | 2 +- 7 files changed, 32 insertions(+), 12 deletions(-) diff --git a/app/Classes/LDAP/Attribute.php b/app/Classes/LDAP/Attribute.php index 74997911..59d93c8f 100644 --- a/app/Classes/LDAP/Attribute.php +++ b/app/Classes/LDAP/Attribute.php @@ -161,7 +161,7 @@ class Attribute implements \Countable, \ArrayAccess // The current attribute values 'values' => ($this->no_attr_tags || $this->is_internal) ? $this->tagValues() : $this->_values, // The original attribute values - 'values_old' => $this->no_attr_tags ? $this->tagValuesOld() : $this->_values_old, + 'values_old' => ($this->no_attr_tags || $this->is_internal) ? $this->tagValuesOld() : $this->_values_old, default => throw new \Exception('Unknown key:' . $key), }; @@ -338,6 +338,12 @@ class Attribute implements \Countable, \ArrayAccess ->with('updated',$updated); } + /** + * Return the value of the original old values + * + * @param string $dotkey + * @return string|null + */ public function render_item_old(string $dotkey): ?string { return match ($this->schema->syntax_oid) { @@ -348,6 +354,12 @@ class Attribute implements \Countable, \ArrayAccess }; } + /** + * Return the value of the new values, which would include any pending udpates + * + * @param string $dotkey + * @return string|null + */ public function render_item_new(string $dotkey): ?string { return Arr::get($this->values->dot(),$dotkey); @@ -366,6 +378,12 @@ class Attribute implements \Countable, \ArrayAccess : collect(); } + /** + * Return the new values for this attribute, which would include any pending updates + * + * @param string $tag + * @return Collection + */ public function tagValues(string $tag=Entry::TAG_NOTAG): Collection { return collect($this->_values @@ -373,6 +391,12 @@ class Attribute implements \Countable, \ArrayAccess ->get($tag,[])); } + /** + * Return the original values for this attribute, as stored in the LDAP server + * + * @param string $tag + * @return Collection + */ public function tagValuesOld(string $tag=Entry::TAG_NOTAG): Collection { return collect($this->_values_old diff --git a/resources/views/components/attribute.blade.php b/resources/views/components/attribute.blade.php index 7f069fa1..b8f1a143 100644 --- a/resources/views/components/attribute.blade.php +++ b/resources/views/components/attribute.blade.php @@ -1,5 +1,3 @@ -@use(App\Ldap\Entry) -
diff --git a/resources/views/components/attribute/krbprincipalkey.blade.php b/resources/views/components/attribute/krbprincipalkey.blade.php index 0e7a72f6..945752f8 100644 --- a/resources/views/components/attribute/krbprincipalkey.blade.php +++ b/resources/views/components/attribute/krbprincipalkey.blade.php @@ -1,10 +1,9 @@ - - @foreach($o->tagValuesOld($langtag) as $key => $value) + @foreach(($o->tagValues($langtag)->count() ? $o->tagValues($langtag) : [$langtag => NULL]) as $key => $value) @if($edit)
- ($e=$errors->get($o->name_lc.'.'.$langtag.'.'.$loop->index)),'mb-1','border-focus'=>! $o->tagValuesOld($langtag)->contains($value),'bg-success-subtle'=>$updated]) name="{{ $o->name_lc }}[{{ $langtag }}][]" value="{{ md5($value) }}" @readonly(! $new)> + ($e=$errors->get($o->name_lc.'.'.$langtag.'.'.$loop->index)),'mb-1','border-focus'=>! $o->tagValuesOld($langtag)->contains($value),'bg-success-subtle'=>$updated]) name="{{ $o->name_lc }}[{{ $langtag }}][]" value="{{ Arr::get(old($o->name_lc),$langtag.'.'.$loop->index,$value ? md5($value) : '') }}" @readonly(! $new)>
@if($e) diff --git a/resources/views/components/attribute/krbticketflags.blade.php b/resources/views/components/attribute/krbticketflags.blade.php index c1aba459..6f57ede1 100644 --- a/resources/views/components/attribute/krbticketflags.blade.php +++ b/resources/views/components/attribute/krbticketflags.blade.php @@ -1,6 +1,6 @@ - @foreach(Arr::get(old($o->name_lc,[$langtag=>$o->tagValues($langtag)]),$langtag,[]) as $key => $value) + @foreach(($o->tagValues($langtag)->count() ? $o->tagValues($langtag) : [$langtag => NULL]) as $key => $value) @if($edit)
diff --git a/resources/views/components/attribute/objectclass.blade.php b/resources/views/components/attribute/objectclass.blade.php index c9a9b133..41b6ff97 100644 --- a/resources/views/components/attribute/objectclass.blade.php +++ b/resources/views/components/attribute/objectclass.blade.php @@ -1,6 +1,6 @@ - @foreach(Arr::get(old($o->name_lc,[$langtag=>$new ? [NULL] : $o->tagValues($langtag)]),$langtag,[]) as $key => $value) + @foreach(($o->tagValues($langtag)->count() ? $o->tagValues($langtag) : [$langtag => NULL]) as $key => $value) @if($edit) @else diff --git a/resources/views/components/attribute/password.blade.php b/resources/views/components/attribute/password.blade.php index 113d8e9d..4d26212f 100644 --- a/resources/views/components/attribute/password.blade.php +++ b/resources/views/components/attribute/password.blade.php @@ -1,11 +1,10 @@ - - @foreach(Arr::get(old($o->name_lc,[$langtag=>$new ? [NULL] : $o->tagValues($langtag)]),$langtag,[]) as $key => $value) + @foreach(($o->tagValues($langtag)->count() ? $o->tagValues($langtag) : [$langtag => NULL]) as $key => $value) @if($edit)
- ($e=$errors->get($o->name_lc.'.'.$langtag.'.'.$loop->index)),'mb-1','border-focus'=>! $o->tagValuesOld($langtag)->contains($value),'bg-success-subtle'=>$updated]) name="{{ $o->name_lc }}[{{ $langtag }}][]" value="{{ md5($value) }}" @readonly(! $new)> + ($e=$errors->get($o->name_lc.'.'.$langtag.'.'.$loop->index)),'mb-1','border-focus'=>! $o->tagValuesOld($langtag)->contains($value),'bg-success-subtle'=>$updated]) name="{{ $o->name_lc }}[{{ $langtag }}][]" value="{{ Arr::get(old($o->name_lc),$langtag.'.'.$loop->index,$value ? md5($value) : '') }}" @readonly(! $new)>
@if($e) diff --git a/resources/views/components/attribute/rdn.blade.php b/resources/views/components/attribute/rdn.blade.php index dbd48861..fc7c23b9 100644 --- a/resources/views/components/attribute/rdn.blade.php +++ b/resources/views/components/attribute/rdn.blade.php @@ -1,6 +1,6 @@ - @foreach(($o->values->count() ? $o->values : ['']) as $value) + @foreach(($o->values->count() ? $o->values : [NULL]) as $value) @if($edit)