Skip to content

Commit 1bf8830

Browse files
committed
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.
1 parent c4d28c8 commit 1bf8830

File tree

16 files changed

+63
-26
lines changed

16 files changed

+63
-26
lines changed

app/Classes/LDAP/Attribute.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ public function hints(): array
242242
if ($this->required()->count())
243243
$result->put(__('required'),sprintf('%s: %s',__('Required Attribute by ObjectClass(es)'),$this->required()->join(', ')));
244244

245+
// If this attribute is a dynamic attribute
246+
if ($this->isDynamic())
247+
$result->put(__('dynamic'),__('These are dynamic values present as a result of another attribute'));
248+
245249
return $result->toArray();
246250
}
247251

@@ -257,6 +261,19 @@ public function isDirty(): bool
257261
|| ($a->diff($b)->count() !== 0);
258262
}
259263

264+
/**
265+
* Are these values as a result of a dynamic attribute
266+
*
267+
* @return bool
268+
*/
269+
public function isDynamic(): bool
270+
{
271+
return $this->schema->used_in_object_classes
272+
->keys()
273+
->intersect($this->schema->heirachy($this->oc))
274+
->count() === 0;
275+
}
276+
260277
/**
261278
* Work out if this attribute is an RDN attribute
262279
*

app/Classes/LDAP/Schema/AttributeType.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,28 @@ public function getUsedInObjectClasses(): Collection
486486
return $this->used_in_object_classes;
487487
}
488488

489+
/**
490+
* For a list of objectclasses return all parent objectclasses as well
491+
*
492+
* @param Collection $ocs
493+
* @return Collection
494+
*/
495+
public function heirachy(Collection $ocs): Collection
496+
{
497+
$result = collect();
498+
499+
foreach ($ocs as $oc) {
500+
$schema = config('server')
501+
->schema('objectclasses',$oc)
502+
->getParents(TRUE)
503+
->pluck('name');
504+
505+
$result = $result->merge($schema)->push($oc);
506+
}
507+
508+
return $result;
509+
}
510+
489511
/**
490512
* @return bool
491513
* @deprecated use $this->forced_as_may
@@ -555,15 +577,9 @@ public function setSupAttribute(string $attr): void
555577
public function validation(array $array): ?array
556578
{
557579
// For each item in array, we need to get the OC hierarchy
558-
$heirachy = collect($array)
559-
->flatten()
560-
->filter()
561-
->map(fn($item)=>config('server')
562-
->schema('objectclasses',$item)
563-
->getSupClasses()
564-
->push($item))
580+
$heirachy = $this->heirachy(collect($array)
565581
->flatten()
566-
->unique();
582+
->filter());
567583

568584
// Get any config validation
569585
$validation = collect(Arr::get(config('ldap.validation'),$this->name_lc,[]));

app/View/Components/AttributeType.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ class AttributeType extends Component
1313
{
1414
private LDAPAttribute $o;
1515
private bool $new;
16+
private bool $edit;
1617
private string $langtag;
1718

1819
/**
1920
* Create a new component instance.
2021
*/
21-
public function __construct(LDAPAttribute $o,bool $new=FALSE,string $langtag=Entry::TAG_NOTAG)
22+
public function __construct(LDAPAttribute $o,bool $new=FALSE,bool $edit=FALSE,string $langtag=Entry::TAG_NOTAG)
2223
{
2324
$this->o = $o;
2425
$this->new = $new;
26+
$this->edit = $edit;
2527
$this->langtag = $langtag;
2628
}
2729

@@ -33,6 +35,7 @@ public function render(): View|Closure|string
3335
return view('components.attribute-type')
3436
->with('o',$this->o)
3537
->with('new',$this->new)
38+
->with('edit',$this->edit)
3639
->with('langtag',$this->langtag);
3740
}
3841
}

public/css/custom.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
attribute#userPassword .select2-container--bootstrap-5 .select2-selection {
33
font-size: inherit;
44
width: 9em;
5-
border: #444054 1px solid;
5+
border: var(--bs-gray-500) 1px solid;
66
background-color: #f0f0f0;
77
}
88

resources/views/components/attribute-type.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</div>
1616
</div>
1717

18-
<x-attribute :o="$o" :edit="true" :new="$new ?? FALSE" :langtag="$langtag"/>
18+
<x-attribute :o="$o" :edit="$edit" :new="$new" :langtag="$langtag"/>
1919
</div>
2020
</div>
2121

resources/views/components/attribute.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<!-- $o=Attribute::class -->
2-
<x-attribute.layout :edit="$edit ?? FALSE" :new="$new ?? FALSE" :o="$o">
2+
<x-attribute.layout :edit="$edit" :new="$new" :o="$o">
33
<div class="col-12">
4-
@foreach(Arr::get(old($o->name_lc,[$langtag=>($new ?? FALSE) ? [NULL] : $o->tagValues($langtag)]),$langtag) as $key => $value)
5-
@if(($edit ?? FALSE) && ! $o->is_rdn)
4+
@foreach(Arr::get(old($o->name_lc,[$langtag=>$new ? [NULL] : $o->tagValues($langtag)]),$langtag,[]) as $key => $value)
5+
@if($edit && (! $o->is_rdn))
66
<div class="input-group has-validation">
7-
<input type="text" @class(['form-control','is-invalid'=>($e=$errors->get($o->name_lc.'.'.$langtag.'.'.$loop->index)),'mb-1','border-focus'=>! ($tv=$o->tagValuesOld($langtag))->contains($value)]) name="{{ $o->name_lc }}[{{ $langtag }}][]" value="{{ $value }}" placeholder="{{ ! is_null($x=$tv->get($loop->index)) ? $x : '['.__('NEW').']' }}" @readonly(! ($new ?? FALSE))>
7+
<input type="text" @class(['form-control','is-invalid'=>($e=$errors->get($o->name_lc.'.'.$langtag.'.'.$loop->index)),'mb-1','border-focus'=>! ($tv=$o->tagValuesOld($langtag))->contains($value)]) name="{{ $o->name_lc }}[{{ $langtag }}][]" value="{{ $value }}" placeholder="{{ ! is_null($x=$tv->get($loop->index)) ? $x : '['.__('NEW').']' }}" @readonly(! $new) @disabled($o->isDynamic())>
88

99
<div class="invalid-feedback pb-2">
1010
@if($e)

resources/views/components/attribute/binary/jpegphoto.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- @todo We are not handling redirect backs yet with updated photos -->
22
<!-- $o=Binary\JpegPhoto::class -->
3-
<x-attribute.layout :edit="$edit ?? FALSE" :new="$new ?? FALSE" :o="$o" :langtag="$langtag">
3+
<x-attribute.layout :edit="$edit" :new="$new" :o="$o" :langtag="$langtag">
44
<table class="table table-borderless p-0 m-0">
55
@foreach($o->tagValuesOld() as $key => $value)
66
<tr>

resources/views/components/attribute/krbprincipalkey.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- @todo We are not handling redirect backs yet with updated passwords -->
22
<!-- $o=KrbPrincipleKey::class -->
3-
<x-attribute.layout :edit="$edit ?? FALSE" :new="$new ?? FALSE" :o="$o" :langtag="$langtag">
3+
<x-attribute.layout :edit="$edit" :new="$new" :o="$o" :langtag="$langtag">
44
@foreach($o->tagValuesOld($langtag) as $key => $value)
55
@if($edit)
66
<div class="input-group has-validation mb-3">

resources/views/components/attribute/krbticketflags.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- $o=KrbTicketFlags::class -->
2-
<x-attribute.layout :edit="$edit ?? FALSE" :new="$new ?? FALSE" :o="$o">
2+
<x-attribute.layout :edit="$edit" :new="$new" :o="$o">
33
@foreach(Arr::get(old($o->name_lc,[$langtag=>$o->tagValues($langtag)]),$langtag,[]) as $key => $value)
44
@if($edit)
55
<div id="32"></div>

resources/views/components/attribute/objectclass.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<!-- $o=Attribute/ObjectClass::class -->
22
<x-attribute.layout :edit="$edit" :new="$new" :o="$o" :langtag="$langtag">
3-
@foreach(Arr::get(old($o->name_lc,[$langtag=>($new ?? FALSE) ? [NULL] : $o->tagValues($langtag)]),$langtag) as $key => $value)
3+
@foreach(Arr::get(old($o->name_lc,[$langtag=>$new ? [NULL] : $o->tagValues($langtag)]),$langtag,[]) as $key => $value)
44
@if($edit)
55
<x-attribute.widget.objectclass :o="$o" :edit="$edit" :new="$new" :loop="$loop" :value="$value" :langtag="$langtag"/>
66
@else
7-
{{ $o->render_item_old($langtag.'.'.$key) }}
7+
{{ $o->render_item_old($key) }}
88
@if ($o->isStructural($value))
99
<input type="hidden" name="{{ $o->name_lc }}[{{ $langtag }}][]" value="{{ $value }}">
1010
<span class="float-end">@lang('structural')</span>

0 commit comments

Comments
 (0)