Revert "mvc: UidField: allow reuse of UID 0 for system scope users"

This reverts commit 649bcb2186.
There is a bug in the old and new behaviour, but without a proper
test case this will not fix easily.  stable/26.7 doesn't use this
yet so it's sane to hotfix.

PR: https://github.com/opnsense/core/issues/10992
(cherry picked from commit 7bbd7a3c4a)
This commit is contained in:
Franco Fichtner
2026-10-09 19:46:50 +02:00
parent 5b0605ae2c
commit ea4f01fe4f
@@ -52,24 +52,18 @@ class UidField extends IntegerField
*/
public function setValue($value)
{
$in_scope = false;
$uids = [];
if ($this->fieldLoaded) {
if (empty((string)$this) && $this->fieldLoaded) {
$uids = [];
foreach ($this->getParentModel()->user->iterateItems() as $user) {
$uids[] = $user->uid->asInt();
}
$in_scope = !$this->getParentNode()->scope->isEqual('system');
}
if (!$this->isSet() || !$in_scope) {
for ($i = 2000; $in_scope; $i++) {
for ($i = 2000; true; $i++) {
if (!in_array($i, $uids)) {
parent::setValue((string)$i);
return;
break;
}
}
} elseif (empty((string)$this)) {
parent::setValue($value);
}
}
@@ -93,6 +87,7 @@ class UidField extends IntegerField
$this->setValue(null);
}
/**
* retrieve field validators for this field type
* @return array returns Text/regex validator