Add back API key deletion
This commit is contained in:
parent
d3e4f944f7
commit
516e2dc5ee
5 changed files with 53 additions and 3 deletions
|
@ -79,6 +79,7 @@ class APIController extends Controller
|
||||||
|
|
||||||
return response('', 204);
|
return response('', 204);
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
|
Log::error($ex);
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'error' => 'An error occured while attempting to remove this key.',
|
'error' => 'An error occured while attempting to remove this key.',
|
||||||
], 503);
|
], 503);
|
||||||
|
|
|
@ -89,6 +89,7 @@ class BaseRoutes
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$router->delete('/revoke/{key}', [
|
$router->delete('/revoke/{key}', [
|
||||||
|
'as' => 'account.api.revoke',
|
||||||
'uses' => 'Base\APIController@revoke',
|
'uses' => 'Base\APIController@revoke',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
|
@ -224,8 +224,11 @@ class APIRepository
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$model = Models\APIKey::where('public', $key)->where('user', $this->user->id)->firstOrFail();
|
$model = Models\APIKey::with('permissions')->where('public', $key)->where('user_id', $this->user->id)->firstOrFail();
|
||||||
Models\APIPermission::where('key_id', $model->id)->delete();
|
foreach($model->permissions as &$permission) {
|
||||||
|
$permission->delete();
|
||||||
|
}
|
||||||
|
|
||||||
$model->delete();
|
$model->delete();
|
||||||
|
|
||||||
DB::commit();
|
DB::commit();
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -79,3 +79,48 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
@section('footer-scripts')
|
||||||
|
@parent
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('[data-action="delete"]').click(function (event) {
|
||||||
|
var self = $(this);
|
||||||
|
event.preventDefault();
|
||||||
|
swal({
|
||||||
|
type: 'error',
|
||||||
|
title: 'Revoke API Key',
|
||||||
|
text: 'Once this API key is revoked any applications currently using it will stop working.',
|
||||||
|
showCancelButton: true,
|
||||||
|
allowOutsideClick: true,
|
||||||
|
closeOnConfirm: false,
|
||||||
|
confirmButtonText: 'Revoke',
|
||||||
|
confirmButtonColor: '#d9534f',
|
||||||
|
showLoaderOnConfirm: true
|
||||||
|
}, function () {
|
||||||
|
$.ajax({
|
||||||
|
method: 'DELETE',
|
||||||
|
url: Router.route('account.api.revoke', { key: self.data('attr') }),
|
||||||
|
headers: {
|
||||||
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||||
|
}
|
||||||
|
}).done(function (data) {
|
||||||
|
swal({
|
||||||
|
type: 'success',
|
||||||
|
title: '',
|
||||||
|
text: 'API Key has been revoked.'
|
||||||
|
});
|
||||||
|
self.parent().parent().slideUp();
|
||||||
|
}).fail(function (jqXHR) {
|
||||||
|
console.error(jqXHR);
|
||||||
|
swal({
|
||||||
|
type: 'error',
|
||||||
|
title: 'Whoops!',
|
||||||
|
text: 'An error occured while attempting to revoke this key.'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endsection
|
||||||
|
|
Loading…
Reference in a new issue