Compare commits
3 Commits
8e8a902c80
...
b87b1dcfd0
Author | SHA1 | Date | |
---|---|---|---|
b87b1dcfd0 | |||
d61ecc96db | |||
820f398c2c |
@ -30,15 +30,20 @@ class Template
|
||||
public function __get(string $key): mixed
|
||||
{
|
||||
return match ($key) {
|
||||
'attributes' => array_map('strtolower',array_keys(Arr::get($this->template,$key))),
|
||||
'objectclasses' => array_map('strtolower',Arr::get($this->template,$key)),
|
||||
'enabled' => Arr::get($this->template,$key,FALSE),
|
||||
'icon','regexp' => Arr::get($this->template,$key),
|
||||
'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),
|
||||
'icon','regexp','title' => Arr::get($this->template,$key),
|
||||
|
||||
default => throw new \Exception('Unknown key: '.$key),
|
||||
};
|
||||
}
|
||||
|
||||
public function __isset(string $key): bool
|
||||
{
|
||||
return array_key_exists($key,$this->template);
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->invalid ? '' : Arr::get($this->template,'title','No Template Name');
|
||||
|
@ -55,16 +55,24 @@ class HomeController extends Controller
|
||||
|
||||
$key = $this->request_key($request,collect(old()));
|
||||
|
||||
$template = NULL;
|
||||
$o = new Entry;
|
||||
$o->setRDNBase($key['dn']);
|
||||
|
||||
if (count($x=array_filter(old('objectclass',$request->objectclass)))) {
|
||||
$o->objectclass = $x;
|
||||
if (count($x=collect(old('objectclass',$request->validated('objectclass')))->dot()->filter())) {
|
||||
$o->objectclass = Arr::undot($x);
|
||||
|
||||
// Also add in our required attributes
|
||||
foreach($o->getAvailableAttributes()->filter(fn($item)=>$item->required) as $ao)
|
||||
$o->{$ao->name} = [Entry::TAG_NOTAG=>''];
|
||||
|
||||
$o->setRDNBase($key['dn']);
|
||||
} elseif ($request->validated('template')) {
|
||||
$template = $o->template($request->validated('template'));
|
||||
$o->objectclass = [Entry::TAG_NOTAG=>$template->objectclasses->toArray()];
|
||||
|
||||
// @todo We need to add aliases
|
||||
foreach($o->getAvailableAttributes()->filter(fn($item)=>$template->attributes->contains($item)) as $ao)
|
||||
$o->{$ao->name} = [Entry::TAG_NOTAG=>''];
|
||||
}
|
||||
|
||||
$step = $request->step ? $request->step+1 : old('step');
|
||||
@ -74,6 +82,7 @@ class HomeController extends Controller
|
||||
->with('bases',$this->bases())
|
||||
->with('o',$o)
|
||||
->with('step',$step)
|
||||
->with('template',$template)
|
||||
->with('container',old('container',$key['dn']));
|
||||
}
|
||||
|
||||
@ -383,7 +392,12 @@ class HomeController extends Controller
|
||||
->with('bases',$this->bases());
|
||||
|
||||
// If we are rendering a DN, rebuild our object
|
||||
if ($key['dn']) {
|
||||
if ($key['cmd'] === 'create') {
|
||||
$o = new Entry;
|
||||
$o->setRDNBase($key['dn']);
|
||||
|
||||
} elseif ($key['dn']) {
|
||||
// @todo Need to handle if DN is null, for example if the user's session expired and the ACLs dont let them retrieve $key['dn']
|
||||
$o = config('server')->fetch($key['dn']);
|
||||
|
||||
foreach (collect(old())->except(['key','dn','step','_token','userpassword_hash','rdn','rdn_value']) as $attr => $value)
|
||||
@ -393,6 +407,7 @@ class HomeController extends Controller
|
||||
return match ($key['cmd']) {
|
||||
'create' => $view
|
||||
->with('container',old('container',$key['dn']))
|
||||
->with('o',$o)
|
||||
->with('step',1),
|
||||
|
||||
'dn' => $view
|
||||
|
@ -66,12 +66,43 @@ class EntryAddRequest extends FormRequest
|
||||
'min:1',
|
||||
'max:1',
|
||||
],
|
||||
'objectclass._null_'=>[
|
||||
'required',
|
||||
'objectclass._null_' => [
|
||||
function (string $attribute,mixed $value,\Closure $fail) {
|
||||
$oc = collect($value)->dot()->filter();
|
||||
|
||||
// If this is step 1 and there is no objectclass, and no template, then fail
|
||||
if ((! $oc->count())
|
||||
&& (request()->post('step') == 1)
|
||||
&& (! request()->post('template')))
|
||||
{
|
||||
$fail(__('Select an objectclass or a template'));
|
||||
}
|
||||
|
||||
// Cant have both an objectclass and a template
|
||||
if (request()->post('template') && $oc->count())
|
||||
$fail(__('You cannot select a template and an objectclass'));
|
||||
},
|
||||
'array',
|
||||
'min:1',
|
||||
new HasStructuralObjectClass,
|
||||
]
|
||||
],
|
||||
'template' => [
|
||||
function (string $attribute,mixed $value,\Closure $fail) {
|
||||
$oc = collect(request()->post('objectclass'))->dot()->filter();
|
||||
|
||||
// If this is step 1 and there is no objectclass, and no template, then fail
|
||||
if ((! collect($value)->filter()->count())
|
||||
&& (request()->post('step') == 1)
|
||||
&& (! $oc->count()))
|
||||
{
|
||||
$fail(__('Select an objectclass or a template'));
|
||||
}
|
||||
|
||||
// Cant have both an objectclass and a template
|
||||
if ($oc->count() && strlen($value))
|
||||
$fail(__('You cannot select a template and an objectclass'));
|
||||
},
|
||||
],
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
|
@ -147,8 +147,7 @@ class Entry extends Model
|
||||
// Filter out our templates specific for this entry
|
||||
if ($this->dn && (! in_array(strtolower($this->dn),['cn=subschema']))) {
|
||||
$this->templates = $this->templates
|
||||
->filter(fn($item)=>(! $item->regexp) || preg_match($item->regexp,$this->dn))
|
||||
->filter(fn($item)=>! count(array_diff($item->objectclasses,array_map('strtolower',Arr::get($this->attributes,'objectclass')))));
|
||||
->filter(fn($item)=>! count($item->objectclasses->diff(array_map('strtolower',Arr::get($this->attributes,'objectclass')))));
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -550,6 +549,9 @@ class Entry extends Model
|
||||
throw new InvalidUsage('Cannot set RDN base on existing entries');
|
||||
|
||||
$this->rdnbase = $bdn;
|
||||
|
||||
$this->templates = $this->templates
|
||||
->filter(fn($item)=>(! $item->regexp) || preg_match($item->regexp,$bdn));
|
||||
}
|
||||
|
||||
public function template(string $item): Template|Null
|
||||
|
@ -24,6 +24,7 @@ class HasStructuralObjectClass implements ValidationRule
|
||||
if ($item && config('server')->schema('objectclasses',$item)->isStructural())
|
||||
return;
|
||||
|
||||
$fail('There isnt a Structural Objectclass.');
|
||||
if (collect($value)->dot()->filter()->count())
|
||||
$fail(__('There isnt a Structural Objectclass.'));
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<x-form.select id="newoc" label="Select from..."/>
|
||||
<x-form.select id="newoc" name="newoc" :label="__('Select from').'...'"/>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
|
@ -1,4 +1,4 @@
|
||||
<button id="form-reset" class="btn btn-outline-danger">@lang('Reset')</button>
|
||||
<button id="form-reset" class="btn btn-sm btn-outline-danger">@lang('Reset')</button>
|
||||
|
||||
@section('page-scripts')
|
||||
<script>
|
||||
|
@ -1,28 +1,32 @@
|
||||
<x-form.base {{ $attributes }}>
|
||||
@isset($name)
|
||||
<input type="hidden" id="{{ $id ?? $name }}_disabled" name="{{ $name }}" value="" disabled>
|
||||
@else
|
||||
@php(throw new \Exception('here'))
|
||||
@dd('no name',$id)
|
||||
@endisset
|
||||
<select class="form-select @isset($name)@error((! empty($old)) ? $old : ($id ?? $name)) is-invalid @enderror @endisset" id="{{ $id ?? $name }}" @isset($name)name="{{ $name }}"@endisset @required(isset($required) && $required) @disabled(isset($disabled) && $disabled)>
|
||||
@if((empty($value) && ! empty($options)) || isset($addnew) || isset($choose))
|
||||
|
||||
<select class="form-select @error($old ?? ($id ?? $name)) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" @required($required ?? FALSE) @disabled($disabled ?? FALSE)>
|
||||
@if((empty($value) && ! empty($options)) || isset($addnew))
|
||||
<option value=""></option>
|
||||
|
||||
@isset($addnew)
|
||||
<option value="new">{{ $addnew ?: 'Add New' }}</option>
|
||||
@endisset
|
||||
@endif
|
||||
|
||||
@isset($options)
|
||||
@empty($groupby)
|
||||
@foreach($options as $option)
|
||||
@continue(! Arr::get($option,'value'))
|
||||
<option value="{{ Arr::get($option,'id') }}" @selected(isset($name) && (Arr::get($option,'id') == old($old ?? $name,$value ?? '')))>{{ Arr::get($option,'value') }}</option>
|
||||
<option value="{{ Arr::get($option,'id') }}" @selected(Arr::get($option,'id') == collect(old())->dot()->get(isset($old) ? $old.'.0' : ($id ?? $name)))>{{ Arr::get($option,'value') }}</option>
|
||||
@endforeach
|
||||
|
||||
@else
|
||||
@foreach($options->groupBy($groupby) as $group)
|
||||
<optgroup label="{{ $groupby == 'active' ? (Arr::get($group->first(),$groupby) ? 'Active' : 'Not Active') : Arr::get($group->first(),$groupby) }}">
|
||||
<optgroup label="{{ Arr::get($group->first(),$groupby) }}">
|
||||
@foreach($group as $option)
|
||||
@continue(! Arr::get($option,'value'))
|
||||
<option value="{{ Arr::get($option,'id') }}" @selected(isset($name) && (Arr::get($option,'id') == old($old ?? $name,$value ?? '')))>{{ Arr::get($option,'value') }}</option>
|
||||
<option value="{{ Arr::get($option,'id') }}" @selected(Arr::get($option,'id') == collect(old())->dot()->get(isset($old) ? $old.'.0' : ($id ?? $name)))>{{ Arr::get($option,'value') }}</option>
|
||||
@endforeach
|
||||
</optgroup>
|
||||
@endforeach
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 pt-2">
|
||||
<x-form.select id="newattr" :label="__('Select from').'...'" :options="$o->getMissingAttributes()->sortBy('name')->unique('name')->map(fn($item)=>['id'=>$item->name,'value'=>$item->name])"/>
|
||||
<x-form.select name="newattr" :label="__('Select from').'...'" :options="$o->getMissingAttributes()->sortBy('name')->unique('name')->map(fn($item)=>['id'=>$item->name,'value'=>$item->name])"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -9,7 +9,7 @@
|
||||
@php($up=(session()->pull('updated') ?: collect()))
|
||||
@php($attributes=$o->template($template)?->attributes)
|
||||
|
||||
@foreach($o->getVisibleAttributes()->filter(fn($item)=>in_array($item,$attributes)) as $ao)
|
||||
@foreach($o->getVisibleAttributes()->filter(fn($item)=>$attributes->contains($item)) as $ao)
|
||||
<x-attribute-type :o="$ao" :edit="TRUE" :new="FALSE" :updated="$up->contains($ao->name_lc)"/>
|
||||
@endforeach
|
||||
</div>
|
||||
|
@ -17,7 +17,7 @@
|
||||
<div class="main-card mb-3 card">
|
||||
|
||||
<div class="card-header">
|
||||
@lang('Create New Entry') - @lang('Step') {{ $step }}
|
||||
@lang('Create New Entry') - @lang('Step') {{ $step }} @isset($template) <span class="ms-auto"><i class="fa fa-fw {{ $template->icon }}"></i> {{ $template->title }}</span>@endisset
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
@ -30,19 +30,35 @@
|
||||
@switch($step)
|
||||
@case(1)
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-6">
|
||||
<div class="col-12 col-md-5">
|
||||
<x-form.select
|
||||
id="objectclass"
|
||||
name="objectclass[{{ Entry::TAG_NOTAG }}][]"
|
||||
old="objectclass.{{ Entry::TAG_NOTAG }}"
|
||||
:label="__('Select a Structural ObjectClass...')"
|
||||
:label="__('Select a Structural ObjectClass').'...'"
|
||||
:options="($oc=$server->schema('objectclasses'))
|
||||
->filter(fn($item)=>$item->isStructural())
|
||||
->sortBy(fn($item)=>$item->name_lc)
|
||||
->map(fn($item)=>['id'=>$item->name,'value'=>$item->name])"
|
||||
multiple="false"
|
||||
:allowclear="TRUE"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@if($o->templates->count())
|
||||
<div class="col-md-1">
|
||||
<strong>@lang('OR')</strong>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-md-5">
|
||||
<x-form.select
|
||||
name="template"
|
||||
:label="__('Select a Template').'...'"
|
||||
:options="$o->templates
|
||||
->map(fn($item,$key)=>['id'=>$key,'value'=>$item->title])"
|
||||
:allowclear="TRUE"
|
||||
/>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@break
|
||||
|
||||
@ -53,14 +69,12 @@
|
||||
<x-attribute-type :o="$ao" :edit="TRUE" :new="FALSE" :updated="FALSE"/>
|
||||
@endforeach
|
||||
|
||||
@include('fragment.dn.add_attr')
|
||||
|
||||
@break;
|
||||
@endswitch
|
||||
</form>
|
||||
|
||||
<div class="row d-none pt-3">
|
||||
<div class="col-12 {{ $step > 1 ? 'offset-sm-2' : '' }} col-lg-10">
|
||||
<div class="col-11 {{ $step > 1 ? 'text-end' : '' }} pe-0">
|
||||
<x-form.reset form="dn-create"/>
|
||||
<x-form.submit :action="__('Next')" form="dn-create"/>
|
||||
</div>
|
||||
@ -102,7 +116,15 @@
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
@if($step === 2)
|
||||
@if($step === 1)
|
||||
$('#objectclass').on('select2:open',function(){
|
||||
$('#template').val(null).trigger('change');
|
||||
});
|
||||
|
||||
$('#template').on('select2:open',function(){
|
||||
$('#objectclass').val(null).trigger('change');
|
||||
})
|
||||
@elseif($step === 2)
|
||||
$('#newattr').on('change',function(item) {
|
||||
var oc = $('attribute#objectclass input[type=text]')
|
||||
.map((key,item)=>{return $(item).val()}).toArray();
|
||||
|
@ -13,10 +13,6 @@
|
||||
"dc": {
|
||||
"display": "Domain Component",
|
||||
"order": 1
|
||||
},
|
||||
"associatedDomain": {
|
||||
"display": "Associated Domain",
|
||||
"order": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
"enabled": true,
|
||||
"icon": "fa-building",
|
||||
"rdn": "ou",
|
||||
"regexp": "/^o=/",
|
||||
"regexp": "/^c=.+,?/",
|
||||
|
||||
"objectclasses": [
|
||||
"organization"
|
||||
|
@ -4,7 +4,7 @@
|
||||
"enabled": true,
|
||||
"icon": "fa-layer-group",
|
||||
"rdn": "ou",
|
||||
"regexp": "/^ou=.+,o=/",
|
||||
"regexp": "/^o=.+,?/",
|
||||
|
||||
"objectclasses": [
|
||||
"organizationalUnit"
|
||||
@ -15,11 +15,6 @@
|
||||
"display": "Organisational Unit",
|
||||
"hint": "This is an example",
|
||||
"order": 1
|
||||
},
|
||||
"attribute2": {
|
||||
"display": "Attribute 2",
|
||||
"hint": "This is an example",
|
||||
"order": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
"enabled": true,
|
||||
"icon": "fa-user",
|
||||
"rdn": "cn",
|
||||
"regexp": "/,ou=People,o=/",
|
||||
"regexp": "/^ou=.+,o=.+,?/",
|
||||
|
||||
"objectclasses": [
|
||||
"inetOrgPerson",
|
||||
|
Loading…
x
Reference in New Issue
Block a user