Update Request validation, so that it also knows about required schema attributes
This commit is contained in:
parent
0684424328
commit
f08fdb1bcd
@ -289,7 +289,6 @@ final class AttributeType extends Base {
|
|||||||
case 'type': return $this->type;
|
case 'type': return $this->type;
|
||||||
case 'usage': return $this->usage;
|
case 'usage': return $this->usage;
|
||||||
case 'used_in_object_classes': return $this->used_in_object_classes;
|
case 'used_in_object_classes': return $this->used_in_object_classes;
|
||||||
case 'validation': return Arr::get(config('ldap.validation'),$this->name_lc);
|
|
||||||
|
|
||||||
default: return parent::__get($key);
|
default: return parent::__get($key);
|
||||||
}
|
}
|
||||||
@ -601,4 +600,34 @@ final class AttributeType extends Base {
|
|||||||
|
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return Request validation array
|
||||||
|
*
|
||||||
|
* This will merge configured validation with schema required attributes
|
||||||
|
*
|
||||||
|
* @param array $array
|
||||||
|
* @return array|null
|
||||||
|
*/
|
||||||
|
public function validation(array $array): ?array
|
||||||
|
{
|
||||||
|
// For each item in array, we need to get the OC heirachy
|
||||||
|
$heirachy = collect($array)
|
||||||
|
->filter()
|
||||||
|
->map(fn($item)=>config('server')
|
||||||
|
->schema('objectclasses',$item)
|
||||||
|
->getSupClasses()
|
||||||
|
->push($item))
|
||||||
|
->flatten()
|
||||||
|
->unique();
|
||||||
|
|
||||||
|
$validation = collect(Arr::get(config('ldap.validation'),$this->name_lc,[]));
|
||||||
|
if (($heirachy->intersect($this->required_by_object_classes)->count() > 0)
|
||||||
|
&& (! collect($validation->get($this->name_lc))->contains('required'))) {
|
||||||
|
$validation->put($this->name_lc,array_merge(['required','min:1'],$validation->get($this->name_lc,[])))
|
||||||
|
->put($this->name_lc.'.*',array_merge(['required','min:1'],$validation->get($this->name_lc.'.*',[])));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $validation->toArray();
|
||||||
|
}
|
||||||
}
|
}
|
@ -26,9 +26,9 @@ class EntryRequest extends FormRequest
|
|||||||
return config('server')
|
return config('server')
|
||||||
->schema('attributetypes')
|
->schema('attributetypes')
|
||||||
->intersectByKeys($this->request)
|
->intersectByKeys($this->request)
|
||||||
->transform(function($item) { return $item->validation; })
|
->map(fn($item)=>$item->validation(request()->get('objectclass')))
|
||||||
->filter()
|
->filter()
|
||||||
->flatMap(function($item) { return $item; })
|
->flatMap(fn($item)=>$item)
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Rules\HasStructuralObjectClass;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -119,8 +121,10 @@ return [
|
|||||||
'validation' => [
|
'validation' => [
|
||||||
'objectclass' => [
|
'objectclass' => [
|
||||||
'objectclass'=>[
|
'objectclass'=>[
|
||||||
|
'required',
|
||||||
'array',
|
'array',
|
||||||
'min:1'
|
'min:1',
|
||||||
|
new HasStructuralObjectClass,
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'gidnumber' => [
|
'gidnumber' => [
|
||||||
@ -170,4 +174,4 @@ return [
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
Loading…
x
Reference in New Issue
Block a user