fix bug api key managemtn for admin
This commit is contained in:
@@ -1,17 +1,21 @@
|
||||
{% extends "sqladmin/details.html" %}
|
||||
{% extends "sqladmin/edit.html" %}
|
||||
|
||||
{% block content %}
|
||||
{{ super() }}
|
||||
|
||||
{# key_id ใช้ model.id ถ้ามี ไม่งั้น fallback จาก path params #}
|
||||
{% set key_id = model.id if (model is defined and model) else request.path_params.get('pk') %}
|
||||
|
||||
|
||||
<div class="card mt-3">
|
||||
<div class="card-header">
|
||||
<h5>API Key Actions</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<button type="button" class="btn btn-warning me-2" onclick="regenerateApiKey({{ model.id }})">
|
||||
<button type="button" class="btn btn-warning me-2" onclick="regenerateApiKey({{ key_id|default('null') }})">
|
||||
<i class="fa fa-refresh"></i> Regenerate API Key
|
||||
</button>
|
||||
<button type="button" class="btn btn-info" onclick="viewApiKey({{ model.id }})">
|
||||
<button type="button" class="btn btn-info" onclick="viewApiKey({{ key_id|default('null') }})">
|
||||
<i class="fa fa-eye"></i> View API Key (if just created)
|
||||
</button>
|
||||
|
||||
@@ -38,7 +42,10 @@ async function regenerateApiKey(keyId) {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/apiservice/admin/api-keys/${keyId}/regenerate`, {
|
||||
const rootPath = '{{ request.scope.get("root_path", "") }}';
|
||||
const url = `${rootPath}/admin/api-keys/${keyId}/regenerate`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -63,8 +70,11 @@ async function regenerateApiKey(keyId) {
|
||||
|
||||
async function viewApiKey(keyId) {
|
||||
try {
|
||||
const response = await fetch(`/apiservice/admin/api-keys/${keyId}/view`, {
|
||||
method: 'GET',
|
||||
const rootPath = '{{ request.scope.get("root_path", "") }}';
|
||||
const url = `${rootPath}/admin/api-keys/${keyId}/view`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
Reference in New Issue
Block a user