Skip to content

Commit 696d87d

Browse files
committed
Improve entry validation to only require the first item of multi value attributes
1 parent 87bae89 commit 696d87d

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

app/Classes/LDAP/Schema/AttributeType.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,13 @@ public function validation(array $array): ?array
557557
->unique();
558558

559559
$validation = collect(Arr::get(config('ldap.validation'),$this->name_lc,[]));
560+
561+
// Add in schema required by conditions
560562
if (($heirachy->intersect($this->required_by_object_classes->keys())->count() > 0)
561563
&& (! collect($validation->get($this->name_lc))->contains('required'))) {
562-
$validation->put($this->name_lc,array_merge(['required','min:1'],$validation->get($this->name_lc,[])))
563-
->put($this->name_lc.'.*',array_merge(['required','min:1'],$validation->get($this->name_lc.'.*',[])));
564+
$validation
565+
->prepend(array_merge(['required','min:1'],$validation->get($this->name_lc.'.0',[])),$this->name_lc.'.0')
566+
->prepend(array_merge(['required','array','min:1'],$validation->get($this->name_lc,[])),$this->name_lc);
564567
}
565568

566569
return $validation->toArray();

config/ldap.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,12 @@
123123
'validation' => [
124124
'objectclass' => [
125125
'objectclass'=>[
126-
'required',
127-
'array',
128-
'min:1',
129126
new HasStructuralObjectClass,
130127
]
131128
],
132129
'gidnumber' => [
133130
'gidnumber'=> [
134131
'sometimes',
135-
'array',
136132
'max:1'
137133
],
138134
'gidnumber.*' => [
@@ -144,7 +140,6 @@
144140
'mail' => [
145141
'mail'=>[
146142
'sometimes',
147-
'array',
148143
'min:1'
149144
],
150145
'mail.*' => [
@@ -155,7 +150,6 @@
155150
'userpassword' => [
156151
'userpassword' => [
157152
'sometimes',
158-
'array',
159153
'min:1'
160154
],
161155
'userpassword.*' => [
@@ -166,7 +160,6 @@
166160
'uidnumber' => [
167161
'uidnumber' => [
168162
'sometimes',
169-
'array',
170163
'max:1'
171164
],
172165
'uidnumber.*' => [

0 commit comments

Comments
 (0)