Add Attribute required by ObjectClasses in schema viewer,
Attribute is_rdn dynamically calculated, Fix Required by Objectclasses when viewing a DN
This commit is contained in:
parent
8ab5b4f35c
commit
4a84c25ac7
@ -20,9 +20,6 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
|
|||||||
// Is this attribute an internal attribute
|
// Is this attribute an internal attribute
|
||||||
protected(set) bool $is_internal = FALSE;
|
protected(set) bool $is_internal = FALSE;
|
||||||
|
|
||||||
// Is this attribute the RDN?
|
|
||||||
public bool $is_rdn = FALSE;
|
|
||||||
|
|
||||||
// MIN/MAX number of values
|
// MIN/MAX number of values
|
||||||
protected(set) int $min_values_count = 0;
|
protected(set) int $min_values_count = 0;
|
||||||
protected(set) int $max_values_count = 0;
|
protected(set) int $max_values_count = 0;
|
||||||
@ -40,7 +37,7 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
|
|||||||
protected(set) Collection $values_old;
|
protected(set) Collection $values_old;
|
||||||
// Current Values
|
// Current Values
|
||||||
public Collection $values;
|
public Collection $values;
|
||||||
// The other object classes of the entry that include this attribute
|
// The objectclasses of the entry that has this attribute
|
||||||
protected(set) Collection $oc;
|
protected(set) Collection $oc;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -100,7 +97,7 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
|
|||||||
* @param string $dn DN this attribute is used in
|
* @param string $dn DN this attribute is used in
|
||||||
* @param string $name Name of the attribute
|
* @param string $name Name of the attribute
|
||||||
* @param array $values Current Values
|
* @param array $values Current Values
|
||||||
* @param array $oc ObjectClasses that the DN has, that includes this attribute
|
* @param array $oc The objectclasses that the DN of this attribute has
|
||||||
*/
|
*/
|
||||||
public function __construct(string $dn,string $name,array $values,array $oc=[])
|
public function __construct(string $dn,string $name,array $values,array $oc=[])
|
||||||
{
|
{
|
||||||
@ -143,6 +140,10 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
|
|||||||
'hints' => $this->hints(),
|
'hints' => $this->hints(),
|
||||||
// Can this attribute be edited
|
// Can this attribute be edited
|
||||||
'is_editable' => $this->schema ? $this->schema->{$key} : NULL,
|
'is_editable' => $this->schema ? $this->schema->{$key} : NULL,
|
||||||
|
// Objectclasses that required this attribute for an LDAP entry
|
||||||
|
'required' => $this->required(),
|
||||||
|
// Is this attribute an RDN attribute
|
||||||
|
'is_rdn' => $this->isRDN(),
|
||||||
// We prefer the name as per the schema if it exists
|
// We prefer the name as per the schema if it exists
|
||||||
'name' => $this->schema ? $this->schema->{$key} : $this->{$key},
|
'name' => $this->schema ? $this->schema->{$key} : $this->{$key},
|
||||||
// Attribute name in lower case
|
// Attribute name in lower case
|
||||||
@ -232,11 +233,8 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
|
|||||||
// If this attribute name is an alias for the schema attribute name
|
// If this attribute name is an alias for the schema attribute name
|
||||||
// @todo
|
// @todo
|
||||||
|
|
||||||
// objectClasses requiring this attribute
|
if ($this->required()->count())
|
||||||
// @todo limit this to this DNs objectclasses
|
$result->put(__('required'),sprintf('%s: %s',__('Required Attribute by ObjectClass(es)'),$this->required()->join(', ')));
|
||||||
// eg: $result->put('required','Required by objectClasses: a,b');
|
|
||||||
if ($this->required_by->count())
|
|
||||||
$result->put(__('required'),sprintf('%s: %s',__('Required Attribute by ObjectClass(es)'),$this->required_by->join(',')));
|
|
||||||
|
|
||||||
// This attribute has language tags
|
// This attribute has language tags
|
||||||
if ($this->lang_tags->count())
|
if ($this->lang_tags->count())
|
||||||
@ -256,6 +254,22 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
|
|||||||
|| ($this->values->diff($this->values_old)->count() !== 0);
|
|| ($this->values->diff($this->values_old)->count() !== 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Work out if this attribute is an RDN attribute
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isRDN(): bool
|
||||||
|
{
|
||||||
|
// If we dont have an DN, then we cant know
|
||||||
|
if (! $this->dn)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
$rdns = collect(explode('+',substr($this->dn,0,strpos($this->dn,','))));
|
||||||
|
|
||||||
|
return $rdns->filter(fn($item) => str_starts_with($item,$this->name.'='))->count() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the attribute value
|
* Display the attribute value
|
||||||
*
|
*
|
||||||
@ -287,6 +301,19 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
|
|||||||
return Arr::get($this->values,$key);
|
return Arr::get($this->values,$key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Work out if this attribute is required by an objectClass the entry has
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function required(): Collection
|
||||||
|
{
|
||||||
|
// If we dont have any objectclasses then we cant know if it is required
|
||||||
|
return $this->oc->count()
|
||||||
|
? $this->oc->intersect($this->schema->required_by_object_classes->keys())->sort()
|
||||||
|
: collect();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this attribute has RFC3866 Language Tags, this will enable those values to be captured
|
* If this attribute has RFC3866 Language Tags, this will enable those values to be captured
|
||||||
*
|
*
|
||||||
|
@ -21,15 +21,15 @@ final class ObjectClass extends Attribute
|
|||||||
* @param string $dn DN this attribute is used in
|
* @param string $dn DN this attribute is used in
|
||||||
* @param string $name Name of the attribute
|
* @param string $name Name of the attribute
|
||||||
* @param array $values Current Values
|
* @param array $values Current Values
|
||||||
* @param array $oc ObjectClasses that the DN has, that includes this attribute
|
* @param array $oc The objectclasses that the DN of this attribute has
|
||||||
*/
|
*/
|
||||||
public function __construct(string $dn,string $name,array $values,array $oc=[])
|
public function __construct(string $dn,string $name,array $values,array $oc=[])
|
||||||
{
|
{
|
||||||
parent::__construct($dn,$name,$values,$oc);
|
parent::__construct($dn,$name,$values,['top']);
|
||||||
|
|
||||||
$this->oc_schema = config('server')
|
$this->oc_schema = config('server')
|
||||||
->schema('objectclasses')
|
->schema('objectclasses')
|
||||||
->filter(fn($item)=>$this->values->contains($item->name));
|
->filter(fn($item)=>$this->values->merge($this->values_old)->unique()->contains($item->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __get(string $key): mixed
|
public function __get(string $key): mixed
|
||||||
|
@ -320,11 +320,12 @@ final class AttributeType extends Base {
|
|||||||
* that is the list of objectClasses which must have this attribute.
|
* that is the list of objectClasses which must have this attribute.
|
||||||
*
|
*
|
||||||
* @param string $name The name of the objectClass to add.
|
* @param string $name The name of the objectClass to add.
|
||||||
|
* @param bool $structural
|
||||||
*/
|
*/
|
||||||
public function addRequiredByObjectClass(string $name): void
|
public function addRequiredByObjectClass(string $name,bool $structural): void
|
||||||
{
|
{
|
||||||
if (! $this->required_by_object_classes->contains($name))
|
if (! $this->required_by_object_classes->has($name))
|
||||||
$this->required_by_object_classes->push($name);
|
$this->required_by_object_classes->put($name,$structural);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -332,6 +333,7 @@ final class AttributeType extends Base {
|
|||||||
* that is the list of objectClasses which provide this attribute.
|
* that is the list of objectClasses which provide this attribute.
|
||||||
*
|
*
|
||||||
* @param string $name The name of the objectClass to add.
|
* @param string $name The name of the objectClass to add.
|
||||||
|
* @param bool $structural
|
||||||
*/
|
*/
|
||||||
public function addUsedInObjectClass(string $name,bool $structural): void
|
public function addUsedInObjectClass(string $name,bool $structural): void
|
||||||
{
|
{
|
||||||
@ -544,7 +546,7 @@ final class AttributeType extends Base {
|
|||||||
*/
|
*/
|
||||||
public function validation(array $array): ?array
|
public function validation(array $array): ?array
|
||||||
{
|
{
|
||||||
// For each item in array, we need to get the OC heirachy
|
// For each item in array, we need to get the OC hierarchy
|
||||||
$heirachy = collect($array)
|
$heirachy = collect($array)
|
||||||
->filter()
|
->filter()
|
||||||
->map(fn($item)=>config('server')
|
->map(fn($item)=>config('server')
|
||||||
|
@ -428,7 +428,7 @@ final class Server
|
|||||||
// Add Required By.
|
// Add Required By.
|
||||||
foreach ($must_attrs as $attr_name)
|
foreach ($must_attrs as $attr_name)
|
||||||
if ($this->attributetypes->has(strtolower($attr_name)))
|
if ($this->attributetypes->has(strtolower($attr_name)))
|
||||||
$this->attributetypes[strtolower($attr_name)]->addRequiredByObjectClass($object_class->name);
|
$this->attributetypes[strtolower($attr_name)]->addRequiredByObjectClass($object_class->name,$object_class->isStructural());
|
||||||
|
|
||||||
// Force May
|
// Force May
|
||||||
foreach ($object_class->getForceMayAttrs() as $attr_name)
|
foreach ($object_class->getForceMayAttrs() as $attr_name)
|
||||||
|
@ -92,10 +92,10 @@ class HomeController extends Controller
|
|||||||
|
|
||||||
return $request->noheader
|
return $request->noheader
|
||||||
? view(sprintf('components.attribute.widget.%s',$id))
|
? view(sprintf('components.attribute.widget.%s',$id))
|
||||||
->with('o',Factory::create($dn,$id,[],$request->oc ?: []))
|
->with('o',Factory::create($dn,$id,[],$request->objectclasses))
|
||||||
->with('value',$request->value)
|
->with('value',$request->value)
|
||||||
->with('loop',$xx)
|
->with('loop',$xx)
|
||||||
: (new AttributeType(Factory::create($dn,$id,[],$request->oc ?: []),TRUE,collect($request->oc ?: [])))->render();
|
: new AttributeType(Factory::create($dn,$id,[],$request->objectclasses),TRUE)->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function entry_create(EntryAddRequest $request): \Illuminate\Http\RedirectResponse
|
public function entry_create(EntryAddRequest $request): \Illuminate\Http\RedirectResponse
|
||||||
|
@ -16,7 +16,9 @@ use App\Exceptions\InvalidUsage;
|
|||||||
|
|
||||||
class Entry extends Model
|
class Entry extends Model
|
||||||
{
|
{
|
||||||
|
// Our Attribute objects
|
||||||
private Collection $objects;
|
private Collection $objects;
|
||||||
|
/* @deprecated */
|
||||||
private bool $noObjectAttributes = FALSE;
|
private bool $noObjectAttributes = FALSE;
|
||||||
// For new entries, this is the container that this entry will be stored in
|
// For new entries, this is the container that this entry will be stored in
|
||||||
private string $rdnbase;
|
private string $rdnbase;
|
||||||
@ -176,6 +178,7 @@ class Entry extends Model
|
|||||||
private function getAttributesAsObjects(): Collection
|
private function getAttributesAsObjects(): Collection
|
||||||
{
|
{
|
||||||
$result = collect();
|
$result = collect();
|
||||||
|
$entry_oc = Arr::get($this->attributes,'objectclass',[]);
|
||||||
|
|
||||||
foreach ($this->attributes as $attribute => $values) {
|
foreach ($this->attributes as $attribute => $values) {
|
||||||
// If the attribute name has tags
|
// If the attribute name has tags
|
||||||
@ -184,17 +187,22 @@ class Entry extends Model
|
|||||||
$attribute = $matches[1];
|
$attribute = $matches[1];
|
||||||
|
|
||||||
// If the attribute doesnt exist we'll create it
|
// If the attribute doesnt exist we'll create it
|
||||||
$o = Arr::get($result,$attribute,Factory::create($this->dn,$attribute,Arr::get($this->original,$attribute,[]),Arr::get($this->original,'objectclass',[])));
|
$o = Arr::get(
|
||||||
|
$result,
|
||||||
|
$attribute,
|
||||||
|
Factory::create(
|
||||||
|
$this->dn,
|
||||||
|
$attribute,
|
||||||
|
Arr::get($this->original,$attribute,[]),
|
||||||
|
$entry_oc,
|
||||||
|
));
|
||||||
$o->setLangTag($matches[3],$values);
|
$o->setLangTag($matches[3],$values);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$o = Factory::create($this->dn,$attribute,Arr::get($this->original,$attribute,[]),Arr::get($this->original,'objectclass',[]));
|
$o = Factory::create($this->dn,$attribute,Arr::get($this->original,$attribute,[]),$entry_oc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $result->has($attribute)) {
|
if (! $result->has($attribute)) {
|
||||||
// Set the rdn flag
|
|
||||||
$o->is_rdn = preg_match('/^'.$attribute.'=/i',$this->dn);
|
|
||||||
|
|
||||||
// Store our new values to know if this attribute has changed
|
// Store our new values to know if this attribute has changed
|
||||||
$o->values = collect($values);
|
$o->values = collect($values);
|
||||||
|
|
||||||
@ -306,7 +314,7 @@ class Entry extends Model
|
|||||||
private function getRDNObject(): Attribute\RDN
|
private function getRDNObject(): Attribute\RDN
|
||||||
{
|
{
|
||||||
$o = new Attribute\RDN('','dn',['']);
|
$o = new Attribute\RDN('','dn',['']);
|
||||||
// @todo for an existing object, return the base.
|
// @todo for an existing object, rdnbase would be null, so dynamically get it from the DN.
|
||||||
$o->setBase($this->rdnbase);
|
$o->setBase($this->rdnbase);
|
||||||
$o->setAttributes($this->getAvailableAttributes()->filter(fn($item)=>$item->required));
|
$o->setAttributes($this->getAvailableAttributes()->filter(fn($item)=>$item->required));
|
||||||
|
|
||||||
@ -430,6 +438,7 @@ class Entry extends Model
|
|||||||
* Dont convert our $this->attributes to $this->objects when creating a new Entry::class
|
* Dont convert our $this->attributes to $this->objects when creating a new Entry::class
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
public function noObjectAttributes(): static
|
public function noObjectAttributes(): static
|
||||||
{
|
{
|
||||||
|
@ -11,17 +11,15 @@ use App\Classes\LDAP\Attribute as LDAPAttribute;
|
|||||||
|
|
||||||
class AttributeType extends Component
|
class AttributeType extends Component
|
||||||
{
|
{
|
||||||
public Collection $oc;
|
private LDAPAttribute $o;
|
||||||
public LDAPAttribute $o;
|
private bool $new;
|
||||||
public bool $new;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new component instance.
|
* Create a new component instance.
|
||||||
*/
|
*/
|
||||||
public function __construct(LDAPAttribute $o,bool $new=FALSE,?Collection $oc=NULL)
|
public function __construct(LDAPAttribute $o,bool $new=FALSE)
|
||||||
{
|
{
|
||||||
$this->o = $o;
|
$this->o = $o;
|
||||||
$this->oc = $oc;
|
|
||||||
$this->new = $new;
|
$this->new = $new;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +30,6 @@ class AttributeType extends Component
|
|||||||
{
|
{
|
||||||
return view('components.attribute-type')
|
return view('components.attribute-type')
|
||||||
->with('o',$this->o)
|
->with('o',$this->o)
|
||||||
->with('oc',$this->oc)
|
|
||||||
->with('new',$this->new);
|
->with('new',$this->new);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -106,6 +106,24 @@
|
|||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>@lang('Required by ObjectClasses')</td>
|
||||||
|
<td>
|
||||||
|
@if ($o->required_by_object_classes->count())
|
||||||
|
@foreach ($o->required_by_object_classes as $class => $structural)
|
||||||
|
@if($structural)
|
||||||
|
<strong>
|
||||||
|
@endif
|
||||||
|
<a class="objectclass" id="{{ strtolower($class) }}" href="#{{ strtolower($class) }}">{{ $class }}</a>
|
||||||
|
@if($structural)
|
||||||
|
</strong>
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
@else
|
||||||
|
@lang('(none)')
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>@lang('Force as MAY by config')</td><td><strong>@lang($o->forced_as_may ? 'Yes' : 'No')</strong></td>
|
<td>@lang('Force as MAY by config')</td><td><strong>@lang($o->forced_as_may ? 'Yes' : 'No')</strong></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user