When rendering dynamic attributes, dont make them editable. Closes #10 and #89.

Also some minor fixes when returning from a post for a DN with attribute tags.
This commit is contained in:
2025-04-07 22:33:15 +10:00
parent c4d28c8a23
commit 1bf8830887
16 changed files with 63 additions and 26 deletions

View File

@@ -242,6 +242,10 @@ class Attribute implements \Countable, \ArrayAccess
if ($this->required()->count())
$result->put(__('required'),sprintf('%s: %s',__('Required Attribute by ObjectClass(es)'),$this->required()->join(', ')));
// If this attribute is a dynamic attribute
if ($this->isDynamic())
$result->put(__('dynamic'),__('These are dynamic values present as a result of another attribute'));
return $result->toArray();
}
@@ -257,6 +261,19 @@ class Attribute implements \Countable, \ArrayAccess
|| ($a->diff($b)->count() !== 0);
}
/**
* Are these values as a result of a dynamic attribute
*
* @return bool
*/
public function isDynamic(): bool
{
return $this->schema->used_in_object_classes
->keys()
->intersect($this->schema->heirachy($this->oc))
->count() === 0;
}
/**
* Work out if this attribute is an RDN attribute
*

View File

@@ -486,6 +486,28 @@ final class AttributeType extends Base {
return $this->used_in_object_classes;
}
/**
* For a list of objectclasses return all parent objectclasses as well
*
* @param Collection $ocs
* @return Collection
*/
public function heirachy(Collection $ocs): Collection
{
$result = collect();
foreach ($ocs as $oc) {
$schema = config('server')
->schema('objectclasses',$oc)
->getParents(TRUE)
->pluck('name');
$result = $result->merge($schema)->push($oc);
}
return $result;
}
/**
* @return bool
* @deprecated use $this->forced_as_may
@@ -555,15 +577,9 @@ final class AttributeType extends Base {
public function validation(array $array): ?array
{
// For each item in array, we need to get the OC hierarchy
$heirachy = collect($array)
$heirachy = $this->heirachy(collect($array)
->flatten()
->filter()
->map(fn($item)=>config('server')
->schema('objectclasses',$item)
->getSupClasses()
->push($item))
->flatten()
->unique();
->filter());
// Get any config validation
$validation = collect(Arr::get(config('ldap.validation'),$this->name_lc,[]));