Use our Attribute::class when rendering update_confirm

This commit is contained in:
Deon George 2025-01-16 12:47:55 +11:00
parent 293f1ab9ce
commit 30f964b849
5 changed files with 43 additions and 17 deletions

View File

@ -3,6 +3,7 @@
namespace App\Classes\LDAP; namespace App\Classes\LDAP;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use App\Classes\LDAP\Schema\AttributeType; use App\Classes\LDAP\Schema\AttributeType;
@ -259,6 +260,16 @@ class Attribute implements \Countable, \ArrayAccess
->with('new',$new); ->with('new',$new);
} }
public function render_item_old(int $key): ?string
{
return Arr::get($this->old_values,$key);
}
public function render_item_new(int $key): ?string
{
return Arr::get($this->values,$key);
}
/** /**
* Set the objectclasses that require this attribute * Set the objectclasses that require this attribute
* *

View File

@ -3,6 +3,7 @@
namespace App\Classes\LDAP\Attribute; namespace App\Classes\LDAP\Attribute;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Illuminate\Support\Arr;
use App\Classes\LDAP\Attribute; use App\Classes\LDAP\Attribute;
use App\Traits\MD5Updates; use App\Traits\MD5Updates;
@ -22,4 +23,14 @@ final class Password extends Attribute
->with('old',$old) ->with('old',$old)
->with('new',$new); ->with('new',$new);
} }
public function render_item_old(int $key): ?string
{
return Arr::get($this->oldValues,$key) ? str_repeat('x',8) : NULL;
}
public function render_item_new(int $key): ?string
{
return Arr::get($this->values,$key) ? str_repeat('x',8) : NULL;
}
} }

View File

@ -32,7 +32,7 @@ class Entry extends Model
parent::discardChanges(); parent::discardChanges();
// If we are discharging changes, we need to reset our $objects; // If we are discharging changes, we need to reset our $objects;
$this->objects = $this->getAttributesAsObjects($this->attributes); $this->objects = $this->getAttributesAsObjects();
return $this; return $this;
} }
@ -112,7 +112,7 @@ class Entry extends Model
// We only set our objects on DN entries (otherwise we might get into a recursion loop if this is the schema DN) // We only set our objects on DN entries (otherwise we might get into a recursion loop if this is the schema DN)
if ($this->dn && (! in_array($this->dn,Arr::get($this->attributes,'subschemasubentry',[])))) { if ($this->dn && (! in_array($this->dn,Arr::get($this->attributes,'subschemasubentry',[])))) {
$this->objects = $this->getAttributesAsObjects($this->attributes); $this->objects = $this->getAttributesAsObjects();
} else { } else {
$this->objects = collect(); $this->objects = collect();
@ -157,11 +157,11 @@ class Entry extends Model
* @param array $attributes * @param array $attributes
* @return Collection * @return Collection
*/ */
protected function getAttributesAsObjects(array $attributes): Collection public function getAttributesAsObjects(): Collection
{ {
$result = collect(); $result = collect();
foreach ($attributes as $attribute => $value) { foreach ($this->attributes as $attribute => $value) {
// If the attribute name has language tags // If the attribute name has language tags
$matches = []; $matches = [];
if (preg_match('/^([a-zA-Z]+)(;([a-zA-Z-;]+))+/',$attribute,$matches)) { if (preg_match('/^([a-zA-Z]+)(;([a-zA-Z-;]+))+/',$attribute,$matches)) {
@ -271,7 +271,7 @@ class Entry extends Model
{ {
// In case we havent built our objects yet (because they werent available while determining the schema DN) // In case we havent built our objects yet (because they werent available while determining the schema DN)
if ((! $this->objects->count()) && $this->attributes) if ((! $this->objects->count()) && $this->attributes)
$this->objects = $this->getAttributesAsObjects($this->attributes); $this->objects = $this->getAttributesAsObjects();
return $this->objects; return $this->objects;
} }

View File

@ -1,8 +1,8 @@
<!-- @todo We are not handling redirect backs with updated values --> <!-- @todo We are not handling redirect backs with updated values -->
<!-- $o=Password::class --> <!-- $o=Password::class -->
<x-attribute.layout :edit="$edit" :new="$new" :o="$o"> <x-attribute.layout :edit="$edit" :new="$new" :o="$o">
@foreach ($o->values as $value) @foreach($o->values as $value)
@if ($edit) @if($edit)
<div class="input-group has-validation"> <div class="input-group has-validation">
<input type="password" @class(['form-control','is-invalid'=>($e=$errors->get($o->name_lc.'.'.$loop->index)),'mb-1','border-focus'=>$o->values->contains($value)]) name="{{ $o->name_lc }}[]" value="{{ md5($value) }}" @readonly(true)> <input type="password" @class(['form-control','is-invalid'=>($e=$errors->get($o->name_lc.'.'.$loop->index)),'mb-1','border-focus'=>$o->values->contains($value)]) name="{{ $o->name_lc }}[]" value="{{ md5($value) }}" @readonly(true)>
@ -13,11 +13,13 @@
</div> </div>
</div> </div>
@else @else
{{ $value }}<br> {{ str_repeat('x',8) }}
@endif @endif
@endforeach @endforeach
<span class="p-0 m-0"> @if($edit)
<span class="btn btn-sm btn-outline-dark mt-3"><i class="fas fa-user-check"></i> @lang('Check Password')</span> <span class="p-0 m-0">
</span> <span class="btn btn-sm btn-outline-dark mt-3"><i class="fas fa-user-check"></i> @lang('Check Password')</span>
</span>
@endif
</x-attribute.layout> </x-attribute.layout>

View File

@ -16,10 +16,10 @@
<div class="card-body"> <div class="card-body">
<div class="row"> <div class="row">
<div class="col-12 col-lg-6 col-xl-4 mx-auto pt-3"> <div class="col-12 col-lg-6 mx-auto pt-3">
<div class="card-title"><h3>@lang('Do you want to make the following changes?')</h3></div> <div class="card-title"><h3>@lang('Do you want to make the following changes?')</h3></div>
<table class="table table-bordered table-striped"> <table class="table table-bordered table-striped w-100">
<thead> <thead>
<tr> <tr>
<th>Attribute</th> <th>Attribute</th>
@ -29,16 +29,18 @@
</thead> </thead>
<tbody> <tbody>
@foreach ($o->getDirty() as $key => $value) @foreach ($o->getAttributesAsObjects()->filter(fn($item)=>$item->isDirty()) as $key => $oo)
<tr> <tr>
<th rowspan="{{ $x=max(count($value),count(Arr::get($o->getOriginal(),$key,[])))}}">{{ $key }}</th> <th rowspan="{{ $x=max($oo->values->keys()->max(),$oo->old_values->keys()->max())+1}}">
<abbr title="{{ $oo->description }}">{{ $oo->name }}</abbr>
</th>
@for($xx=0;$xx<$x;$xx++) @for($xx=0;$xx<$x;$xx++)
@if($xx) @if($xx)
</tr><tr> </tr><tr>
@endif @endif
<td>{{ Arr::get(Arr::get($o->getOriginal(),$key),$xx,'['.strtoupper(__('New Value')).']') }}</td> <td>{{ $oo->render_item_old($xx) ?: '['.strtoupper(__('New Value')).']' }}</td>
<td>{{ ($y=Arr::get($value,$xx)) ?: '['.strtoupper(__('Deleted')).']' }}<input type="hidden" name="{{ $key }}[]" value="{{ $y }}"></td> <td>{{ $oo->render_item_new($xx) ?: '['.strtoupper(__('Deleted')).']' }}<input type="hidden" name="{{ $key }}[]" value="{{ Arr::get($oo->values,$xx) }}"></td>
@endfor @endfor
</tr> </tr>
@endforeach @endforeach