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);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return response()->json([
|
||||
'error' => 'An error occured while attempting to remove this key.',
|
||||
], 503);
|
||||
|
|
|
@ -89,6 +89,7 @@ class BaseRoutes
|
|||
]);
|
||||
|
||||
$router->delete('/revoke/{key}', [
|
||||
'as' => 'account.api.revoke',
|
||||
'uses' => 'Base\APIController@revoke',
|
||||
]);
|
||||
});
|
||||
|
|
|
@ -224,8 +224,11 @@ class APIRepository
|
|||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
$model = Models\APIKey::where('public', $key)->where('user', $this->user->id)->firstOrFail();
|
||||
Models\APIPermission::where('key_id', $model->id)->delete();
|
||||
$model = Models\APIKey::with('permissions')->where('public', $key)->where('user_id', $this->user->id)->firstOrFail();
|
||||
foreach($model->permissions as &$permission) {
|
||||
$permission->delete();
|
||||
}
|
||||
|
||||
$model->delete();
|
||||
|
||||
DB::commit();
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -79,3 +79,48 @@
|
|||
</div>
|
||||
</div>
|
||||
@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