Skip to content

Commit 516e2dc

Browse files
committed
Add back API key deletion
1 parent d3e4f94 commit 516e2dc

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

app/Http/Controllers/Base/APIController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public function revoke(Request $request, $key)
7979

8080
return response('', 204);
8181
} catch (\Exception $ex) {
82+
Log::error($ex);
8283
return response()->json([
8384
'error' => 'An error occured while attempting to remove this key.',
8485
], 503);

app/Http/Routes/BaseRoutes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function map(Router $router)
8989
]);
9090

9191
$router->delete('/revoke/{key}', [
92+
'as' => 'account.api.revoke',
9293
'uses' => 'Base\APIController@revoke',
9394
]);
9495
});

app/Repositories/APIRepository.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,11 @@ public function revoke($key)
224224
DB::beginTransaction();
225225

226226
try {
227-
$model = Models\APIKey::where('public', $key)->where('user', $this->user->id)->firstOrFail();
228-
Models\APIPermission::where('key_id', $model->id)->delete();
227+
$model = Models\APIKey::with('permissions')->where('public', $key)->where('user_id', $this->user->id)->firstOrFail();
228+
foreach($model->permissions as &$permission) {
229+
$permission->delete();
230+
}
231+
229232
$model->delete();
230233

231234
DB::commit();

public/js/laroute.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/themes/pterodactyl/base/api/index.blade.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,48 @@
7979
</div>
8080
</div>
8181
@endsection
82+
83+
@section('footer-scripts')
84+
@parent
85+
<script>
86+
$(document).ready(function() {
87+
$('[data-action="delete"]').click(function (event) {
88+
var self = $(this);
89+
event.preventDefault();
90+
swal({
91+
type: 'error',
92+
title: 'Revoke API Key',
93+
text: 'Once this API key is revoked any applications currently using it will stop working.',
94+
showCancelButton: true,
95+
allowOutsideClick: true,
96+
closeOnConfirm: false,
97+
confirmButtonText: 'Revoke',
98+
confirmButtonColor: '#d9534f',
99+
showLoaderOnConfirm: true
100+
}, function () {
101+
$.ajax({
102+
method: 'DELETE',
103+
url: Router.route('account.api.revoke', { key: self.data('attr') }),
104+
headers: {
105+
'X-CSRF-TOKEN': '{{ csrf_token() }}'
106+
}
107+
}).done(function (data) {
108+
swal({
109+
type: 'success',
110+
title: '',
111+
text: 'API Key has been revoked.'
112+
});
113+
self.parent().parent().slideUp();
114+
}).fail(function (jqXHR) {
115+
console.error(jqXHR);
116+
swal({
117+
type: 'error',
118+
title: 'Whoops!',
119+
text: 'An error occured while attempting to revoke this key.'
120+
});
121+
});
122+
});
123+
});
124+
});
125+
</script>
126+
@endsection

0 commit comments

Comments
 (0)