From e4d23046960946e4e18b2b0e60b0c25fafeadebb Mon Sep 17 00:00:00 2001
From: Deon George <deon@dege.au>
Date: Sat, 5 Apr 2025 14:49:45 +1100
Subject: [PATCH] Attribute is no longer iterable - can be used now that we
 manage attribute tags

---
 app/Classes/LDAP/Attribute.php          | 37 ++++---------------------
 app/Http/Controllers/HomeController.php | 15 ++++++----
 app/Traits/MD5Updates.php               |  4 +--
 3 files changed, 17 insertions(+), 39 deletions(-)

diff --git a/app/Classes/LDAP/Attribute.php b/app/Classes/LDAP/Attribute.php
index eee16d1c..810cea85 100644
--- a/app/Classes/LDAP/Attribute.php
+++ b/app/Classes/LDAP/Attribute.php
@@ -12,7 +12,7 @@ use App\Ldap\Entry;
 /**
  * Represents an attribute of an LDAP Object
  */
-class Attribute implements \Countable, \ArrayAccess, \Iterator
+class Attribute implements \Countable, \ArrayAccess
 {
 	// Attribute Name
 	protected string $name;
@@ -181,44 +181,19 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
 
 	/* INTERFACE */
 
-	public function current(): mixed
-	{
-		return $this->values->get($this->counter);
-	}
-
-	public function next(): void
-	{
-		$this->counter++;
-	}
-
-	public function key(): mixed
-	{
-		return $this->counter;
-	}
-
-	public function valid(): bool
-	{
-		return $this->values->has($this->counter);
-	}
-
-	public function rewind(): void
-	{
-		$this->counter = 0;
-	}
-
 	public function count(): int
 	{
-		return $this->values->count();
+		return $this->_values->dot()->count();
 	}
 
 	public function offsetExists(mixed $offset): bool
 	{
-		return ! is_null($this->values->has($offset));
+		return $this->_values->dot()->has($offset);
 	}
 
 	public function offsetGet(mixed $offset): mixed
 	{
-		return $this->values->get($offset);
+		return $this->_values->dot()->get($offset);
 	}
 
 	public function offsetSet(mixed $offset, mixed $value): void
@@ -323,12 +298,12 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
 
 	public function render_item_old(string $dotkey): ?string
 	{
-		return Arr::get($this->_values_old->dot(),$dotkey);
+		return Arr::get($this->values_old->dot(),$dotkey);
 	}
 
 	public function render_item_new(string $dotkey): ?string
 	{
-		return Arr::get($this->_values->dot(),$dotkey);
+		return Arr::get($this->values->dot(),$dotkey);
 	}
 
 	/**
diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php
index d613bce2..3adc6045 100644
--- a/app/Http/Controllers/HomeController.php
+++ b/app/Http/Controllers/HomeController.php
@@ -267,19 +267,22 @@ class HomeController extends Controller
 		// We need to process and encrypt the password
 		if ($request->userpassword) {
 			$passwords = [];
-			foreach ($request->userpassword as $key => $value) {
+			$po = $o->getObject('userpassword');
+			foreach (Arr::dot($request->userpassword) as $dotkey => $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);
+				if (($old=Arr::get($po,$dotkey)) && ($value === md5($old))) {
+					$passwords[$dotkey] = $value;
 					continue;
 				}
 
 				if ($value) {
-					$type = Arr::get($request->userpassword_hash,$key);
-					array_push($passwords,Password::hash_id($type)->encode($value));
+					$type = Arr::get($request->userpassword_hash,$dotkey);
+					$passwords[$dotkey] = Password::hash_id($type)
+						->encode($value);
 				}
 			}
-			$o->userpassword = $passwords;
+
+			$o->userpassword = Arr::undot($passwords);
 		}
 
 		if (! $o->getDirty())
diff --git a/app/Traits/MD5Updates.php b/app/Traits/MD5Updates.php
index 522619ba..0c8cde18 100644
--- a/app/Traits/MD5Updates.php
+++ b/app/Traits/MD5Updates.php
@@ -11,8 +11,8 @@ trait MD5Updates
 {
 	public function isDirty(): bool
 	{
-		foreach ($this->values->diff($this->values_old) as $key => $value)
-			if (md5(Arr::get($this->values_old,$key)) !== $value)
+		foreach ($this->values_old->dot()->keys()->merge($this->values->dot()->keys())->unique() as $dotkey)
+			if (md5(Arr::get($this->values_old->dot(),$dotkey)) !== Arr::get($this->values->dot(),$dotkey))
 				return TRUE;
 
 		return FALSE;