Skip to content

Commit 996d7bb

Browse files
committed
This commit is mainly as a result of creating DN entries and improves some backend functions:
* Enable creation of new entries, * Change all our ajax frames to go through /frames URI instead of /dn, * Add our frame command to the encrypted DN, * Automatically redirect to root URL when selecting a tree item and currently in another path (as a result of a prior POST activity), * Some validation improvements DNExists/HasStructuralObjectClass
1 parent f08fdb1 commit 996d7bb

27 files changed

+689
-149
lines changed

app/Classes/LDAP/Attribute.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ public function __get(string $key): mixed
145145
// Attribute values
146146
'values' => $this->values,
147147
// Required by Object Classes
148-
'required_by' => $this->schema->required_by_object_classes,
148+
'required_by' => $this->schema?->required_by_object_classes ?: collect(),
149149
// Used in Object Classes
150-
'used_in' => $this->schema->used_in_object_classes,
150+
'used_in' => $this->schema?->used_in_object_classes ?: collect(),
151151

152152
default => throw new \Exception('Unknown key:' . $key),
153153
};

app/Classes/LDAP/Attribute/RDN.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace App\Classes\LDAP\Attribute;
4+
5+
use Illuminate\Contracts\View\View;
6+
use Illuminate\Support\Collection;
7+
8+
use App\Classes\LDAP\Attribute;
9+
10+
/**
11+
* Represents the RDN for an Entry
12+
*/
13+
final class RDN extends Attribute
14+
{
15+
private string $base;
16+
private Collection $attrs;
17+
18+
public function __get(string $key): mixed
19+
{
20+
return match ($key) {
21+
'base' => $this->base,
22+
'attrs' => $this->attrs->pluck('name'),
23+
default => parent::__get($key),
24+
};
25+
}
26+
27+
public function hints(): array
28+
{
29+
return [
30+
'required' => __('RDN is required')
31+
];
32+
}
33+
34+
public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View
35+
{
36+
return view('components.attribute.rdn')
37+
->with('o',$this);
38+
}
39+
40+
public function setAttributes(Collection $attrs): void
41+
{
42+
$this->attrs = $attrs;
43+
}
44+
45+
public function setBase(string $base): void
46+
{
47+
$this->base = $base;
48+
}
49+
}

app/Classes/LDAP/Schema/ObjectClass.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function __construct(string $line,Server $server)
208208
public function __get(string $key): mixed
209209
{
210210
return match ($key) {
211-
'attributes' => $this->getAllAttrs(),
211+
'attributes' => $this->getAllAttrs(TRUE),
212212
'sup' => $this->sup_classes,
213213
'type_name' => match ($this->type) {
214214
Server::OC_STRUCTURAL => 'Structural',
@@ -223,13 +223,18 @@ public function __get(string $key): mixed
223223
/**
224224
* Return a list of attributes that this objectClass provides
225225
*
226+
* @param bool $parents
226227
* @return Collection
227228
* @throws InvalidUsage
228229
*/
229-
public function getAllAttrs(): Collection
230+
public function getAllAttrs(bool $parents=FALSE): Collection
230231
{
231-
return $this->getMustAttrs()
232-
->merge($this->getMayAttrs());
232+
return $this->getMustAttrs($parents)
233+
->transform(function($item) {
234+
$item->required = true;
235+
return $item;
236+
})
237+
->merge($this->getMayAttrs($parents));
233238
}
234239

235240
/**

app/Classes/LDAP/Schema/ObjectClassAttribute.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
final class ObjectClassAttribute extends Base {
1717
// This Attribute's root.
1818
private string $source;
19+
public bool $required = FALSE;
1920

2021
/**
2122
* Creates a new ObjectClassAttribute with specified name and source objectClass.
@@ -31,11 +32,9 @@ public function __construct($name,$source)
3132

3233
public function __get(string $key): mixed
3334
{
34-
switch ($key) {
35-
case 'source':
36-
return $this->source;
37-
38-
default: return parent::__get($key);
39-
}
35+
return match ($key) {
36+
'source' => $this->source,
37+
default => parent::__get($key),
38+
};
4039
}
4140
}

app/Http/Controllers/APIController.php

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ class APIController extends Controller
1616
* Get the LDAP server BASE DNs
1717
*
1818
* @return Collection
19-
* @throws LdapRecord\Query\ObjectNotFoundException
19+
* @throws \LdapRecord\Query\ObjectNotFoundException
2020
*/
2121
public function bases(): Collection
2222
{
2323
$base = Server::baseDNs() ?: collect();
2424

25-
return $base->transform(function($item) {
26-
return [
27-
'title'=>$item->getRdn(),
28-
'item'=>$item->getDNSecure(),
29-
'lazy'=>TRUE,
30-
'icon'=>'fa-fw fas fa-sitemap',
31-
'tooltip'=>$item->getDn(),
32-
];
33-
});
25+
return $base
26+
->transform(fn($item)=>
27+
[
28+
'title'=>$item->getRdn(),
29+
'item'=>$item->getDNSecure(),
30+
'lazy'=>TRUE,
31+
'icon'=>'fa-fw fas fa-sitemap',
32+
'tooltip'=>$item->getDn(),
33+
]);
3434
}
3535

3636
/**
@@ -41,19 +41,31 @@ public function children(Request $request): Collection
4141
{
4242
$levels = $request->query('depth',1);
4343
$dn = Crypt::decryptString($request->query('key'));
44+
45+
// Sometimes our key has a command, so we'll ignore it
46+
if (str_starts_with($dn,'*') && ($x=strpos($dn,'|')))
47+
$dn = substr($dn,$x+1);
48+
4449
Log::debug(sprintf('%s: Query [%s] - Levels [%d]',__METHOD__,$dn,$levels));
4550

4651
return (config('server'))
4752
->children($dn)
48-
->transform(function($item) {
49-
return [
53+
->transform(fn($item)=>
54+
[
5055
'title'=>$item->getRdn(),
5156
'item'=>$item->getDNSecure(),
5257
'icon'=>$item->icon(),
5358
'lazy'=>Arr::get($item->getAttribute('hassubordinates'),0) == 'TRUE',
5459
'tooltip'=>$item->getDn(),
55-
];
56-
});
60+
])
61+
->prepend(
62+
[
63+
'title'=>sprintf('[%s]',__('Create Entry')),
64+
'item'=>Crypt::encryptString(sprintf('*%s|%s','create',$dn)),
65+
'lazy'=>FALSE,
66+
'icon'=>'fas fa-fw fa-square-plus text-warning',
67+
'tooltip'=>__('Create new LDAP item here'),
68+
]);
5769
}
5870

5971
public function schema_view(Request $request)
@@ -63,20 +75,20 @@ public function schema_view(Request $request)
6375
switch($request->type) {
6476
case 'objectclasses':
6577
return view('fragment.schema.objectclasses')
66-
->with('objectclasses',$server->schema('objectclasses')->sortBy(function($item) { return strtolower($item->name); }));
78+
->with('objectclasses',$server->schema('objectclasses')->sortBy(fn($item)=>strtolower($item->name)));
6779

6880
case 'attributetypes':
6981
return view('fragment.schema.attributetypes')
7082
->with('server',$server)
71-
->with('attributetypes',$server->schema('attributetypes')->sortBy(function($item) { return strtolower($item->name); }));
83+
->with('attributetypes',$server->schema('attributetypes')->sortBy(fn($item)=>strtolower($item->name)));
7284

7385
case 'ldapsyntaxes':
7486
return view('fragment.schema.ldapsyntaxes')
75-
->with('ldapsyntaxes',$server->schema('ldapsyntaxes')->sortBy(function($item) { return strtolower($item->description); }));
87+
->with('ldapsyntaxes',$server->schema('ldapsyntaxes')->sortBy(fn($item)=>strtolower($item->description)));
7688

7789
case 'matchingrules':
7890
return view('fragment.schema.matchingrules')
79-
->with('matchingrules',$server->schema('matchingrules')->sortBy(function($item) { return strtolower($item->name); }));
91+
->with('matchingrules',$server->schema('matchingrules')->sortBy(fn($item)=>strtolower($item->name)));
8092

8193
default:
8294
abort(404);

0 commit comments

Comments
 (0)