Improve entry validation to only require the first item of multi value attributes

This commit is contained in:
Deon George 2025-03-19 08:34:56 +11:00
parent 87bae89ea3
commit 696d87d190
2 changed files with 5 additions and 9 deletions

View File

@ -557,10 +557,13 @@ final class AttributeType extends Base {
->unique(); ->unique();
$validation = collect(Arr::get(config('ldap.validation'),$this->name_lc,[])); $validation = collect(Arr::get(config('ldap.validation'),$this->name_lc,[]));
// Add in schema required by conditions
if (($heirachy->intersect($this->required_by_object_classes->keys())->count() > 0) if (($heirachy->intersect($this->required_by_object_classes->keys())->count() > 0)
&& (! collect($validation->get($this->name_lc))->contains('required'))) { && (! collect($validation->get($this->name_lc))->contains('required'))) {
$validation->put($this->name_lc,array_merge(['required','min:1'],$validation->get($this->name_lc,[]))) $validation
->put($this->name_lc.'.*',array_merge(['required','min:1'],$validation->get($this->name_lc.'.*',[]))); ->prepend(array_merge(['required','min:1'],$validation->get($this->name_lc.'.0',[])),$this->name_lc.'.0')
->prepend(array_merge(['required','array','min:1'],$validation->get($this->name_lc,[])),$this->name_lc);
} }
return $validation->toArray(); return $validation->toArray();

View File

@ -123,16 +123,12 @@ return [
'validation' => [ 'validation' => [
'objectclass' => [ 'objectclass' => [
'objectclass'=>[ 'objectclass'=>[
'required',
'array',
'min:1',
new HasStructuralObjectClass, new HasStructuralObjectClass,
] ]
], ],
'gidnumber' => [ 'gidnumber' => [
'gidnumber'=> [ 'gidnumber'=> [
'sometimes', 'sometimes',
'array',
'max:1' 'max:1'
], ],
'gidnumber.*' => [ 'gidnumber.*' => [
@ -144,7 +140,6 @@ return [
'mail' => [ 'mail' => [
'mail'=>[ 'mail'=>[
'sometimes', 'sometimes',
'array',
'min:1' 'min:1'
], ],
'mail.*' => [ 'mail.*' => [
@ -155,7 +150,6 @@ return [
'userpassword' => [ 'userpassword' => [
'userpassword' => [ 'userpassword' => [
'sometimes', 'sometimes',
'array',
'min:1' 'min:1'
], ],
'userpassword.*' => [ 'userpassword.*' => [
@ -166,7 +160,6 @@ return [
'uidnumber' => [ 'uidnumber' => [
'uidnumber' => [ 'uidnumber' => [
'sometimes', 'sometimes',
'array',
'max:1' 'max:1'
], ],
'uidnumber.*' => [ 'uidnumber.*' => [