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
|
||||
{
|
||||
return match ($key) {
|
||||
'name' => Str::replaceEnd('.json','',$this->file),
|
||||
'attributes' => collect(array_map('strtolower',array_keys(Arr::get($this->template,$key)))),
|
||||
'objectclasses' => collect(array_map('strtolower',Arr::get($this->template,$key))),
|
||||
'attributes' => collect(Arr::get($this->template,$key))->keys(),
|
||||
'enabled' => Arr::get($this->template,$key,FALSE) && (! $this->invalid),
|
||||
'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),
|
||||
};
|
||||
|
@ -58,8 +58,13 @@ class HomeController extends Controller
|
||||
$template = $o->template($request->validated('template'));
|
||||
$o->objectclass = [Entry::TAG_NOTAG=>$template->objectclasses->toArray()];
|
||||
|
||||
foreach ($o->getAvailableAttributes()->filter(fn($item)=>$item->names_lc->intersect($template->attributes)->count()) as $ao)
|
||||
$o->{$ao->name} = [Entry::TAG_NOTAG=>''];
|
||||
foreach ($o->getAvailableAttributes()
|
||||
->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');
|
||||
|
@ -130,7 +130,7 @@ class Entry extends Model
|
||||
$o = $this->objects->get($attribute) ?: Factory::create($this->dn ?: '',$attribute,[],Arr::get($this->attributes,'objectclass',[]));
|
||||
$o->values = collect($value);
|
||||
|
||||
$this->objects->put($key,$o);
|
||||
$this->addObjectItem($key,$o);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -159,8 +159,11 @@ class Entry extends Model
|
||||
if ($this->dn && (! in_array(strtolower($this->dn),['cn=subschema']))) {
|
||||
$this->templates = $this->templates
|
||||
->filter(fn($item)=>$item->enabled
|
||||
&& (! count($item->objectclasses->diff(array_map('strtolower',Arr::get($this->attributes,'objectclass'))))))
|
||||
->sortBy(fn($item)=>$item);
|
||||
&& (! $item->objectclasses
|
||||
->map('strtolower')
|
||||
->diff(array_map('strtolower',Arr::get($this->attributes,'objectclass')))
|
||||
->count()))
|
||||
->sortBy(fn($item)=>$item->title);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -208,7 +211,19 @@ class Entry extends Model
|
||||
$o = $this->objects->get($attribute) ?: Attribute\Factory::create($this->dn ?: '',$attribute,[]);
|
||||
$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">
|
||||
@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)"/>
|
||||
@endforeach
|
||||
</div>
|
||||
|
@ -19,7 +19,23 @@
|
||||
"attribute2": {
|
||||
"display": "Attribute 2",
|
||||
"hint": "This is an example",
|
||||
"type": "input", // Default is input
|
||||
"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": {
|
||||
"display": "Login Shell",
|
||||
"select": {
|
||||
"type": "select",
|
||||
"options": {
|
||||
"/bin/bash": "Bash",
|
||||
"/bin/csh": "C Shell",
|
||||
"/bin/dash": "Dash",
|
||||
|
Loading…
x
Reference in New Issue
Block a user