Skip to content

Commit d97087b

Browse files
committed
Implemented DN delete
1 parent c8c3939 commit d97087b

File tree

7 files changed

+115
-3
lines changed

7 files changed

+115
-3
lines changed

app/Http/Controllers/HomeController.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,46 @@ public function entry_create(EntryAddRequest $request)
156156
->withFragment($o->getDNSecure());
157157
}
158158

159+
public function entry_delete(Request $request)
160+
{
161+
$dn = Crypt::decryptString($request->dn);
162+
163+
$o = config('server')->fetch($dn);
164+
165+
try {
166+
$o->delete();
167+
168+
} catch (InsufficientAccessException $e) {
169+
$request->flash();
170+
171+
switch ($x=$e->getDetailedError()->getErrorCode()) {
172+
case 50:
173+
return Redirect::to('/')
174+
->withInput()
175+
->withErrors(sprintf('%s: %s (%s)',__('LDAP Server Error Code'),$x,__($e->getDetailedError()->getErrorMessage())));
176+
177+
default:
178+
abort(599,$e->getDetailedError()->getErrorMessage());
179+
}
180+
181+
} catch (LdapRecordException $e) {
182+
$request->flash();
183+
184+
switch ($x=$e->getDetailedError()->getErrorCode()) {
185+
case 8:
186+
return Redirect::to('/')
187+
->withInput()
188+
->withErrors(sprintf('%s: %s (%s)',__('LDAP Server Error Code'),$x,__($e->getDetailedError()->getErrorMessage())));
189+
190+
default:
191+
abort(599,$e->getDetailedError()->getErrorMessage());
192+
}
193+
}
194+
195+
return Redirect::to('/')
196+
->with('success',[sprintf('%s: %s',__('Deleted'),$dn)]);
197+
}
198+
159199
public function entry_export(Request $request,string $id)
160200
{
161201
$dn = Crypt::decryptString($id);

resources/themes/architect/views/layouts/partials/contentheader.blade.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@
3535
<button class="btn btn-outline-dark p-1 m-1" id="entry-edit" data-bs-toggle="tooltip" data-bs-placement="bottom" title="@lang('Edit Entry')"><i class="fas fa-fw fa-edit fs-5"></i></button>
3636
</li>
3737
@endif
38+
<!-- @todo Dont offer the delete button for an entry with children -->
3839
@if(isset($page_actions) && $page_actions->contains('delete'))
3940
<li>
40-
<button class="btn btn-outline-danger p-1 m-1" id="entry-delete" data-bs-custom-class="custom-tooltip-danger" data-bs-toggle="tooltip" data-bs-placement="bottom" title="@lang('Delete Entry')"><i class="fas fa-fw fa-trash-can fs-5"></i></button>
41+
<span id="entry-delete" data-bs-toggle="modal" data-bs-target="#page-modal">
42+
<button class="btn btn-outline-danger p-1 m-1" data-bs-custom-class="custom-tooltip-danger" data-bs-toggle="tooltip" data-bs-placement="bottom" title="@lang('Delete Entry')"><i class="fas fa-fw fa-trash-can fs-5"></i></button>
43+
</span>
4144
</li>
4245
@endif
4346
</ul>
@@ -51,7 +54,6 @@
5154
@section('page-scripts')
5255
<script type="text/javascript">
5356
$(document).ready(function() {
54-
console.log($('button[id=entry-edit]'));
5557
$('button[id=entry-edit]').on('click',function(item) {
5658
item.preventDefault();
5759
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<button type="button" class="btn btn-sm btn-secondary" data-bs-dismiss="modal">@lang('Close')</button>

resources/views/frames/dn.blade.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,16 @@
7171
@endsection
7272

7373
@section('page-modals')
74+
<!-- Frame Modals -->
75+
<div class="modal fade" id="page-modal" tabindex="-1" aria-labelledby="label" aria-hidden="true">
76+
<div class="modal-dialog modal-lg modal-fullscreen-lg-down">
77+
<div class="modal-content"></div>
78+
</div>
79+
</div>
80+
7481
<!-- EXPORT -->
7582
<div class="modal fade" id="entry_export-modal" tabindex="-1" aria-labelledby="entry_export-label" aria-hidden="true">
76-
<div class="modal-dialog modal-lg modal-fullscreen-xl-down">
83+
<div class="modal-dialog modal-lg modal-fullscreen-lg-down">
7784
<div class="modal-content">
7885
<div class="modal-header">
7986
<h1 class="modal-title fs-5" id="entry_export-label">LDIF for {{ $dn }}</h1>
@@ -210,6 +217,34 @@ function editmode() {
210217
download('ldap-export.ldif',ldif.html());
211218
});
212219
220+
$('#page-modal').on('shown.bs.modal',function(item) {
221+
var that = $(this).find('.modal-content');
222+
223+
switch ($(item.relatedTarget).attr('id')) {
224+
case 'entry-delete':
225+
$.ajax({
226+
method: 'GET',
227+
url: '{{ url('modal/delete') }}/'+dn,
228+
dataType: 'html',
229+
cache: false,
230+
beforeSend: function() {
231+
that.empty().append('<span class="p-3"><i class="fas fa-3x fa-spinner fa-pulse"></i></span>');
232+
},
233+
success: function(data) {
234+
that.empty().html(data);
235+
},
236+
error: function(e) {
237+
if (e.status != 412)
238+
alert('That didnt work? Please try again....');
239+
},
240+
})
241+
break;
242+
243+
default:
244+
console.log('No action for button:'+$(item.relatedTarget).attr('id'));
245+
}
246+
});
247+
213248
$('#entry_export-modal').on('shown.bs.modal',function() {
214249
$.ajax({
215250
type: 'GET',

resources/views/home.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
--}}
1313

1414
@section('main-content')
15+
<x-success/>
16+
1517
<div class="card card-solid mb-3">
1618
<div class="card-body">
1719
<div class="row">
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<div class="modal-header bg-danger text-white">
2+
<h1 class="modal-title fs-5" id="entry_export-label">
3+
<i class="fas fa-fw fa-exclamation-triangle"></i> <strong>@lang('WARNING')</strong>: @lang('Delete') <strong>{{ Crypt::decryptString($dn) }}</strong>
4+
</h1>
5+
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
6+
</div>
7+
8+
<div class="modal-body">
9+
@lang('Deleting this DN will permanently delete it from your LDAP server.')
10+
</div>
11+
12+
<div class="modal-footer">
13+
<x-modal.close/>
14+
<button id="entry-delete" type="button" class="btn btn-sm btn-danger">@lang('Delete')</button>
15+
</div>
16+
17+
<form id="entry-delete-form" method="POST" action="{{ url('entry/delete') }}">
18+
@csrf
19+
20+
<input type="hidden" name="dn" value="{{ $dn }}">
21+
</form>
22+
23+
<script type="text/javascript">
24+
$(document).ready(function() {
25+
$('button[id=entry-delete]').on('click',function(item) {
26+
$('form#entry-delete-form').submit();
27+
});
28+
});
29+
</script>

routes/web.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
Route::match(['get','post'],'entry/add','entry_add');
4545
Route::post('entry/create','entry_create');
46+
Route::post('entry/delete','entry_delete');
4647
Route::get('entry/export/{id}','entry_export');
4748
Route::post('entry/password/check/','entry_password_check');
4849
Route::post('entry/attr/add/{id}','entry_attr_add');
@@ -51,5 +52,7 @@
5152
Route::post('entry/update/pending','entry_pending_update');
5253

5354
Route::post('import/process/{type}','import');
55+
56+
Route::view('modal/delete/{dn}','modals.entry-delete');
5457
});
5558
});

0 commit comments

Comments
 (0)