Add objects directly to Entry::class when rendering a template. Fix objectclasses and attributes processing for templates
This commit is contained in:
parent
88db4ccc99
commit
98a0b87afe
@ -31,11 +31,12 @@ class Template
|
|||||||
public function __get(string $key): mixed
|
public function __get(string $key): mixed
|
||||||
{
|
{
|
||||||
return match ($key) {
|
return match ($key) {
|
||||||
'name' => Str::replaceEnd('.json','',$this->file),
|
'attributes' => collect(Arr::get($this->template,$key))->keys(),
|
||||||
'attributes' => collect(array_map('strtolower',array_keys(Arr::get($this->template,$key)))),
|
|
||||||
'objectclasses' => collect(array_map('strtolower',Arr::get($this->template,$key))),
|
|
||||||
'enabled' => Arr::get($this->template,$key,FALSE) && (! $this->invalid),
|
'enabled' => Arr::get($this->template,$key,FALSE) && (! $this->invalid),
|
||||||
'icon','regexp','title' => Arr::get($this->template,$key),
|
'icon','regexp','title' => Arr::get($this->template,$key),
|
||||||
|
'name' => Str::replaceEnd('.json','',$this->file),
|
||||||
|
'objectclasses' => collect(Arr::get($this->template,$key)),
|
||||||
|
'order' => collect(Arr::get($this->template,'attributes'))->map(fn($item)=>$item['order']),
|
||||||
|
|
||||||
default => throw new \Exception('Unknown key: '.$key),
|
default => throw new \Exception('Unknown key: '.$key),
|
||||||
};
|
};
|
||||||
|
@ -58,8 +58,13 @@ class HomeController extends Controller
|
|||||||
$template = $o->template($request->validated('template'));
|
$template = $o->template($request->validated('template'));
|
||||||
$o->objectclass = [Entry::TAG_NOTAG=>$template->objectclasses->toArray()];
|
$o->objectclass = [Entry::TAG_NOTAG=>$template->objectclasses->toArray()];
|
||||||
|
|
||||||
foreach ($o->getAvailableAttributes()->filter(fn($item)=>$item->names_lc->intersect($template->attributes)->count()) as $ao)
|
foreach ($o->getAvailableAttributes()
|
||||||
$o->{$ao->name} = [Entry::TAG_NOTAG=>''];
|
->filter(fn($item)=>$item->names_lc->intersect($template->attributes->map('strtolower'))->count())
|
||||||
|
->sortBy(fn($item)=>Arr::get($template->order,$item->name)) as $ao)
|
||||||
|
{
|
||||||
|
$o->addObjectItem($ao->name,
|
||||||
|
Factory::create(dn: '',attribute: $ao->name,values: [Entry::TAG_NOTAG=>''],oc: $o->objectclass));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$step = $request->step ? $request->step+1 : old('step');
|
$step = $request->step ? $request->step+1 : old('step');
|
||||||
|
@ -130,7 +130,7 @@ class Entry extends Model
|
|||||||
$o = $this->objects->get($attribute) ?: Factory::create($this->dn ?: '',$attribute,[],Arr::get($this->attributes,'objectclass',[]));
|
$o = $this->objects->get($attribute) ?: Factory::create($this->dn ?: '',$attribute,[],Arr::get($this->attributes,'objectclass',[]));
|
||||||
$o->values = collect($value);
|
$o->values = collect($value);
|
||||||
|
|
||||||
$this->objects->put($key,$o);
|
$this->addObjectItem($key,$o);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -159,8 +159,11 @@ class Entry extends Model
|
|||||||
if ($this->dn && (! in_array(strtolower($this->dn),['cn=subschema']))) {
|
if ($this->dn && (! in_array(strtolower($this->dn),['cn=subschema']))) {
|
||||||
$this->templates = $this->templates
|
$this->templates = $this->templates
|
||||||
->filter(fn($item)=>$item->enabled
|
->filter(fn($item)=>$item->enabled
|
||||||
&& (! count($item->objectclasses->diff(array_map('strtolower',Arr::get($this->attributes,'objectclass'))))))
|
&& (! $item->objectclasses
|
||||||
->sortBy(fn($item)=>$item);
|
->map('strtolower')
|
||||||
|
->diff(array_map('strtolower',Arr::get($this->attributes,'objectclass')))
|
||||||
|
->count()))
|
||||||
|
->sortBy(fn($item)=>$item->title);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -208,7 +211,19 @@ class Entry extends Model
|
|||||||
$o = $this->objects->get($attribute) ?: Attribute\Factory::create($this->dn ?: '',$attribute,[]);
|
$o = $this->objects->get($attribute) ?: Attribute\Factory::create($this->dn ?: '',$attribute,[]);
|
||||||
$o->addValue($tag,[$value]);
|
$o->addValue($tag,[$value]);
|
||||||
|
|
||||||
$this->objects->put($attribute,$o);
|
$this->addObjectItem($attribute,$o);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new object item directly
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param Attribute $o
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function addObjectItem(string $name,Attribute $o): void
|
||||||
|
{
|
||||||
|
$this->objects->put($name,$o);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
@php($up=(session()->pull('updated') ?: collect()))
|
@php($up=(session()->pull('updated') ?: collect()))
|
||||||
|
|
||||||
@foreach($o->getVisibleAttributes()->filter(fn($item)=>$template->attributes->contains($item->name_lc)) as $ao)
|
@foreach($o->getVisibleAttributes()->filter(fn($item)=>$template->attributes->map('strtolower')->contains($item->name_lc)) as $ao)
|
||||||
<x-attribute-type :o="$ao" :edit="TRUE" :new="FALSE" :template="$template->name" :updated="$up->contains($ao->name_lc)"/>
|
<x-attribute-type :o="$ao" :edit="TRUE" :new="FALSE" :template="$template->name" :updated="$up->contains($ao->name_lc)"/>
|
||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
|
@ -19,7 +19,23 @@
|
|||||||
"attribute2": {
|
"attribute2": {
|
||||||
"display": "Attribute 2",
|
"display": "Attribute 2",
|
||||||
"hint": "This is an example",
|
"hint": "This is an example",
|
||||||
|
"type": "input", // Default is input
|
||||||
"order": 2
|
"order": 2
|
||||||
|
},
|
||||||
|
"attribute3": {
|
||||||
|
"display": "Attribute 3",
|
||||||
|
"type": "select",
|
||||||
|
"options": {
|
||||||
|
"/bin/bash": "Bash",
|
||||||
|
"/bin/csh": "C Shell",
|
||||||
|
"/bin/dash": "Dash",
|
||||||
|
"/bin/sh": "Shell",
|
||||||
|
"/bin/tsh": "Turbo C Shell",
|
||||||
|
"/bin/zsh": "ZSH",
|
||||||
|
"/bin/false": "False",
|
||||||
|
"/usr/sbin/nologin": "No Login"
|
||||||
|
},
|
||||||
|
"order": 8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,8 @@
|
|||||||
},
|
},
|
||||||
"loginShell": {
|
"loginShell": {
|
||||||
"display": "Login Shell",
|
"display": "Login Shell",
|
||||||
"select": {
|
"type": "select",
|
||||||
|
"options": {
|
||||||
"/bin/bash": "Bash",
|
"/bin/bash": "Bash",
|
||||||
"/bin/csh": "C Shell",
|
"/bin/csh": "C Shell",
|
||||||
"/bin/dash": "Dash",
|
"/bin/dash": "Dash",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user