Skip to content

Commit f1316d6

Browse files
committed
Implement DN Entry rename
1 parent 339ba72 commit f1316d6

File tree

7 files changed

+95
-8
lines changed

7 files changed

+95
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Entry Editing:
4848
- [ ] JpegPhoto Create/Delete
4949
- [ ] Binary attribute upload
5050
- [ ] If removing an objectClass, remove all attributes that only that objectclass provided
51-
- [ ] Rename an entry
51+
- [ ] Move an entry
5252
- [ ] Group membership selection
5353
- [ ] Attribute tag creation
5454

app/Http/Controllers/HomeController.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class HomeController extends Controller
2929
{
3030
private const LOGKEY = 'CHc';
3131

32-
private const INTERNAL_POST = ['_auto_value','_key','_rdn','_rdn_value','_step','_template','_token','_userpassword_hash'];
32+
private const INTERNAL_POST = ['_auto_value','_key','_rdn','_rdn_new','_rdn_value','_step','_template','_token','_userpassword_hash'];
3333

3434
/**
3535
* Create a new object in the LDAP server
@@ -307,6 +307,31 @@ public function entry_pending_update(EntryRequest $request): \Illuminate\Http\Re
307307
->with('o',$o);
308308
}
309309

310+
public function entry_rename(Request $request): \Illuminate\Http\RedirectResponse|\Illuminate\View\View
311+
{
312+
$from_dn = Crypt::decryptString($request->post('dn'));
313+
Log::info(sprintf('%s:Renaming [%s] to [%s]',self::LOGKEY,$from_dn,$request->post('_rdn_new')));
314+
315+
$o = config('server')->fetch($from_dn);
316+
317+
if (! $o)
318+
return back()
319+
->withInput()
320+
->with('note',__('DN doesnt exist'));
321+
322+
try {
323+
$o->rename($request->post('_rdn_new'));
324+
325+
} catch (\Exception $e) {
326+
return Redirect::to('/')
327+
->with('failed',$e->getMessage());
328+
}
329+
330+
return Redirect::to('/')
331+
->withInput(['_key'=>Crypt::encryptString('*dn|'.$o->getDN())])
332+
->with('success',sprintf('%s: %s',__('Entry renamed'),$from_dn));
333+
}
334+
310335
/**
311336
* Update a DN entry
312337
*
@@ -505,8 +530,8 @@ private function request_key(Request $request,?Collection $old=NULL): array
505530
// Setup
506531
$cmd = NULL;
507532
$dn = NULL;
508-
$key = $request->get('_key',old('_key'))
509-
? Crypt::decryptString($request->get('_key',old('_key')))
533+
$key = ($x=$request->get('_key',old('_key')))
534+
? Crypt::decryptString($x)
510535
: NULL;
511536

512537
// Determine if our key has a command
@@ -518,9 +543,9 @@ private function request_key(Request $request,?Collection $old=NULL): array
518543
$dn = ($m[2] !== '_NOP') ? $m[2] : NULL;
519544
}
520545

521-
} elseif (old('dn',$request->get('_key'))) {
546+
} elseif ($x=old('dn',$request->get('_key'))) {
522547
$cmd = 'dn';
523-
$dn = Crypt::decryptString(old('dn',$request->get('_key')));
548+
$dn = Crypt::decryptString($x);
524549
}
525550

526551
return ['cmd'=>$cmd,'dn'=>$dn];

resources/views/components/attribute/widget/options.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@php($clone=FALSE)
77
<span class="p-0 m-0">
88
@if($o->is_rdn)
9-
<button class="btn btn-sm btn-outline-focus mt-3" disabled><i class="fas fa-fw fa-exchange"></i> @lang('Rename')</button>
9+
<span id="entry-rename" class="btn btn-sm btn-outline-focus mt-3" data-bs-toggle="modal" data-bs-target="#page-modal"><i class="fas fa-fw fa-exchange"></i> @lang('Rename')</span>
1010
@elseif($edit && $o->can_addvalues)
1111
@switch(get_class($o))
1212
@case(Certificate::class)
@@ -26,7 +26,7 @@
2626
@break
2727

2828
@case(ObjectClass::class)
29-
<span type="button" @class(['btn','btn-sm','btn-outline-primary','mt-3','addable','d-none'=>(! $new)]) data-bs-toggle="modal" data-bs-target="#new_objectclass-modal"><i class="fas fa-fw fa-plus"></i> @lang('Add Objectclass')</span>
29+
<span @class(['btn','btn-sm','btn-outline-primary','mt-3','addable','d-none'=>(! $new)]) data-bs-toggle="modal" data-bs-target="#new_objectclass-modal"><i class="fas fa-fw fa-plus"></i> @lang('Add Objectclass')</span>
3030

3131
<!-- NEW OBJECT CLASS -->
3232
<div class="modal fade" id="new_objectclass-modal" tabindex="-1" aria-labelledby="new_objectclass-label" aria-hidden="true" data-bs-backdrop="static">

resources/views/frames/dn.blade.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,25 @@ function editmode() {
281281
})
282282
break;
283283
284+
case 'entry-rename':
285+
$.ajax({
286+
method: 'GET',
287+
url: '{{ url('modal/rename') }}/'+dn,
288+
dataType: 'html',
289+
cache: false,
290+
beforeSend: function() {
291+
that.empty().append('<span class="p-3"><i class="fas fa-3x fa-spinner fa-pulse"></i></span>');
292+
},
293+
success: function(data) {
294+
that.empty().html(data);
295+
},
296+
error: function(e) {
297+
if (e.status !== 412)
298+
alert('That didnt work? Please try again....');
299+
},
300+
});
301+
break;
302+
284303
default:
285304
switch ($(item.relatedTarget).attr('name')) {
286305
case 'entry-userpassword-check':

resources/views/home.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
@section('main-content')
44
<x-success/>
5+
<x-failed/>
56

67
<div class="card card-solid mb-3">
78
<div class="card-body">
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<div class="modal-header bg-dark text-white">
2+
<h1 class="modal-title fs-5">
3+
<strong>@lang('Rename') <strong>{{ $x=Crypt::decryptString($dn) }}</strong>
4+
</h1>
5+
</div>
6+
7+
<form id="entry-rename-form" method="POST" action="{{ url('entry/rename') }}">
8+
<div class="modal-body">
9+
@csrf
10+
<input type="hidden" name="dn" value="{{ $dn }}">
11+
12+
<div class="row">
13+
<div class="col-12">
14+
<label for="rdn" class="form-label">@lang('New RDN')</label>
15+
<div class="input-group mb-3">
16+
<input type="text" id="rdn" name="_rdn_new" class="form-control w-25" placeholder="{{ $rdn=collect(explode(',',$x))->first() }}" value="{{ $rdn }}">
17+
<span class="input-group-text" id="label">{{ collect(explode(',',$x))->skip(1)->join(',') }}</span>
18+
</div>
19+
</div>
20+
</div>
21+
</div>
22+
23+
<div class="modal-footer">
24+
<x-modal.close/>
25+
<button id="entry-rename" type="submit" class="btn btn-sm btn-primary" disabled>@lang('Rename')</button>
26+
</div>
27+
</form>
28+
29+
<script type="text/javascript">
30+
$(document).ready(function() {
31+
var rdn = '{{ $rdn }}';
32+
33+
// Complete the RDN
34+
$('#rdn').on('input',function(item) {
35+
rdn = $(this).val();
36+
37+
$('button[id=entry-rename]').attr('disabled',! rdn.includes('='));
38+
})
39+
});
40+
</script>

routes/web.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@
4949
Route::post('entry/password/check/','entry_password_check');
5050
Route::post('entry/attr/add/{id}','entry_attr_add');
5151
Route::post('entry/objectclass/add','entry_objectclass_add');
52+
Route::post('entry/rename','entry_rename');
5253
Route::post('entry/update/commit','entry_update');
5354
Route::post('entry/update/pending','entry_pending_update');
5455

5556
Route::post('import/process/{type}','import');
5657

5758
Route::view('modal/delete/{dn}','modals.entry-delete');
5859
Route::view('modal/export/{dn}','modals.entry-export');
60+
Route::view('modal/rename/{dn}','modals.entry-rename');
5961
Route::view('modal/userpassword-check/{dn}','modals.entry-userpassword-check');
6062
});
6163
});

0 commit comments

Comments
 (0)