Enabled adding new attributes to a DN
This commit is contained in:
@@ -97,6 +97,7 @@ class Attribute
|
||||
$this->name = $name;
|
||||
$this->values = collect($values);
|
||||
$this->lang_tags = collect();
|
||||
$this->required_by = collect();
|
||||
|
||||
// No need to load our schema for internal attributes
|
||||
if (! $this->is_internal)
|
||||
@@ -182,9 +183,10 @@ class Attribute
|
||||
* Display the attribute value
|
||||
*
|
||||
* @param bool $edit
|
||||
* @param bool $blank
|
||||
* @return View
|
||||
*/
|
||||
public function render(bool $edit=FALSE): View
|
||||
public function render(bool $edit=FALSE,bool $blank=FALSE): View
|
||||
{
|
||||
return view('components.attribute')
|
||||
->with('edit',$edit)
|
||||
|
@@ -18,10 +18,11 @@ final class JpegPhoto extends Binary
|
||||
$this->internal = FALSE;
|
||||
}
|
||||
|
||||
public function render(bool $edit=FALSE): View
|
||||
public function render(bool $edit=FALSE,bool $blank=FALSE): View
|
||||
{
|
||||
return view('components.attribute.binary.jpegphoto')
|
||||
->with('edit',$edit)
|
||||
->with('blank',$blank)
|
||||
->with('o',$this)
|
||||
->with('f',new \finfo);
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ abstract class Internal extends Attribute
|
||||
{
|
||||
protected bool $is_internal = TRUE;
|
||||
|
||||
public function render(bool $edit=FALSE): View
|
||||
public function render(bool $edit=FALSE,bool $blank=FALSE): View
|
||||
{
|
||||
// @note Internal attributes cannot be edited
|
||||
return view('components.attribute.internal')
|
||||
|
@@ -11,7 +11,7 @@ use App\Classes\LDAP\Attribute\Internal;
|
||||
*/
|
||||
final class Timestamp extends Internal
|
||||
{
|
||||
public function render(bool $edit=FALSE): View
|
||||
public function render(bool $edit=FALSE,bool $blank=FALSE): View
|
||||
{
|
||||
// @note Internal attributes cannot be edited
|
||||
return view('components.attribute.internal.timestamp')
|
||||
|
@@ -39,7 +39,7 @@ final class ObjectClass extends Attribute
|
||||
return $this->structural->search($value) !== FALSE;
|
||||
}
|
||||
|
||||
public function render(bool $edit=FALSE): View
|
||||
public function render(bool $edit=FALSE,bool $blank=FALSE): View
|
||||
{
|
||||
return view('components.attribute.objectclass')
|
||||
->with('edit',$edit)
|
||||
|
@@ -11,10 +11,11 @@ use App\Classes\LDAP\Attribute;
|
||||
*/
|
||||
final class Password extends Attribute
|
||||
{
|
||||
public function render(bool $edit=FALSE): View
|
||||
public function render(bool $edit=FALSE,bool $blank=FALSE): View
|
||||
{
|
||||
return view('components.attribute.password')
|
||||
->with('edit',$edit)
|
||||
->with('blank',$blank)
|
||||
->with('o',$this);
|
||||
}
|
||||
}
|
@@ -49,7 +49,7 @@ abstract class Schema extends Attribute
|
||||
return Arr::get(($array ? $array->get($string) : []),$key);
|
||||
}
|
||||
|
||||
public function render(bool $edit=FALSE): View
|
||||
public function render(bool $edit=FALSE,bool $blank=FALSE): View
|
||||
{
|
||||
// @note Schema attributes cannot be edited
|
||||
return view('components.attribute.internal')
|
||||
|
@@ -33,7 +33,7 @@ final class Mechanisms extends Schema
|
||||
return parent::_get(config_path('ldap_supported_saslmechanisms.txt'),$string,$key);
|
||||
}
|
||||
|
||||
public function render(bool $edit=FALSE): View
|
||||
public function render(bool $edit=FALSE,bool $blank=FALSE): View
|
||||
{
|
||||
// @note Schema attributes cannot be edited
|
||||
return view('components.attribute.schema.mechanisms')
|
||||
|
@@ -34,7 +34,7 @@ final class OID extends Schema
|
||||
return parent::_get(config_path('ldap_supported_oids.txt'),$string,$key);
|
||||
}
|
||||
|
||||
public function render(bool $edit=FALSE): View
|
||||
public function render(bool $edit=FALSE,bool $blank=FALSE): View
|
||||
{
|
||||
// @note Schema attributes cannot be edited
|
||||
return view('components.attribute.schema.oid')
|
||||
|
@@ -8,14 +8,16 @@ use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use LdapRecord\Exceptions\InsufficientAccessException;
|
||||
use LdapRecord\LdapRecordException;
|
||||
use LdapRecord\Query\ObjectNotFoundException;
|
||||
|
||||
use App\Classes\LDAP\Server;
|
||||
use App\Classes\LDAP\{Attribute,Server};
|
||||
use App\Exceptions\InvalidUsage;
|
||||
use App\Http\Requests\EntryRequest;
|
||||
use App\View\Components\AttributeType;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
@@ -47,7 +49,20 @@ class HomeController extends Controller
|
||||
->with('page_actions',$page_actions);
|
||||
}
|
||||
|
||||
public function entry_update(EntryRequest $request)
|
||||
public function entry_newattr(string $id)
|
||||
{
|
||||
$x = new AttributeType(new Attribute($id,[]),TRUE);
|
||||
return $x->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a confirmation to update a DN
|
||||
*
|
||||
* @param EntryRequest $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse
|
||||
* @throws ObjectNotFoundException
|
||||
*/
|
||||
public function entry_pending_update(EntryRequest $request)
|
||||
{
|
||||
$dn = Crypt::decryptString($request->dn);
|
||||
|
||||
@@ -56,10 +71,60 @@ class HomeController extends Controller
|
||||
foreach ($request->except(['_token','dn']) as $key => $value)
|
||||
$o->{$key} = array_filter($value);
|
||||
|
||||
Session::put('dn',$request->dn);
|
||||
if (! $o->getDirty())
|
||||
return back()
|
||||
->withInput()
|
||||
->with('note',__('No attributes changed'));
|
||||
|
||||
$base = Server::baseDNs() ?: collect();
|
||||
|
||||
$bases = $base->transform(function($item) {
|
||||
return [
|
||||
'title'=>$item->getRdn(),
|
||||
'item'=>$item->getDNSecure(),
|
||||
'lazy'=>TRUE,
|
||||
'icon'=>'fa-fw fas fa-sitemap',
|
||||
'tooltip'=>$item->getDn(),
|
||||
];
|
||||
});
|
||||
|
||||
return view('frames.update')
|
||||
->with('bases',$bases)
|
||||
->with('dn',$dn)
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a DN entry
|
||||
*
|
||||
* @param EntryRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws ObjectNotFoundException
|
||||
*/
|
||||
public function entry_update(EntryRequest $request)
|
||||
{
|
||||
$base = Server::baseDNs() ?: collect();
|
||||
|
||||
$bases = $base->transform(function($item) {
|
||||
return [
|
||||
'title'=>$item->getRdn(),
|
||||
'item'=>$item->getDNSecure(),
|
||||
'lazy'=>TRUE,
|
||||
'icon'=>'fa-fw fas fa-sitemap',
|
||||
'tooltip'=>$item->getDn(),
|
||||
];
|
||||
});
|
||||
|
||||
$dn = Crypt::decryptString($request->dn);
|
||||
|
||||
$o = config('server')->fetch($dn);
|
||||
|
||||
foreach ($request->except(['_token','dn']) as $key => $value)
|
||||
$o->{$key} = array_filter($value);
|
||||
|
||||
if (! $dirty=$o->getDirty())
|
||||
return back()
|
||||
->withInput()
|
||||
->with('note',__('No attributes changed'));
|
||||
|
||||
try {
|
||||
@@ -70,7 +135,8 @@ class HomeController extends Controller
|
||||
|
||||
switch ($x=$e->getDetailedError()->getErrorCode()) {
|
||||
case 50:
|
||||
return back()
|
||||
return Redirect::to('/')
|
||||
->withInput()
|
||||
->withErrors(sprintf('%s: %s (%s)',__('LDAP Server Error Code'),$x,__($e->getDetailedError()->getErrorMessage())));
|
||||
|
||||
default:
|
||||
@@ -82,7 +148,8 @@ class HomeController extends Controller
|
||||
|
||||
switch ($x=$e->getDetailedError()->getErrorCode()) {
|
||||
case 8:
|
||||
return back()
|
||||
return Redirect::to('/')
|
||||
->withInput()
|
||||
->withErrors(sprintf('%s: %s (%s)',__('LDAP Server Error Code'),$x,__($e->getDetailedError()->getErrorMessage())));
|
||||
|
||||
default:
|
||||
@@ -90,7 +157,8 @@ class HomeController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
return back()
|
||||
return Redirect::to('/')
|
||||
->withInput()
|
||||
->with('success',__('Entry updated'))
|
||||
->with('updated',$dirty);
|
||||
}
|
||||
|
@@ -10,16 +10,18 @@ class Attribute extends Component
|
||||
{
|
||||
public LDAPAttribute $o;
|
||||
public bool $edit;
|
||||
public bool $new;
|
||||
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(bool $edit,LDAPAttribute $o)
|
||||
public function __construct(bool $edit,LDAPAttribute $o,bool $new=FALSE)
|
||||
{
|
||||
$this->edit = $edit;
|
||||
$this->o = $o;
|
||||
$this->new = $new;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,6 +31,6 @@ class Attribute extends Component
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return $this->o->render($this->edit);
|
||||
return $this->o->render($this->edit,$this->new);
|
||||
}
|
||||
}
|
34
app/View/Components/AttributeType.php
Normal file
34
app/View/Components/AttributeType.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
use App\Classes\LDAP\Attribute as LDAPAttribute;
|
||||
|
||||
class AttributeType extends Component
|
||||
{
|
||||
public LDAPAttribute $o;
|
||||
public bool $new;
|
||||
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*/
|
||||
public function __construct(LDAPAttribute $o,bool $new=FALSE)
|
||||
{
|
||||
$this->o = $o;
|
||||
$this->new = $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*/
|
||||
public function render(): View|Closure|string
|
||||
{
|
||||
return view('components.attribute-type')
|
||||
->with('o',$this->o)
|
||||
->with('new',$this->new);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user