feat: show request details in dialog

This commit is contained in:
Vlad Stan 2024-11-20 16:26:52 +02:00
parent b9370526e9
commit 3efe05b96d
4 changed files with 52 additions and 4 deletions

View File

@ -48,7 +48,7 @@
size="sm"
flat
class="cursor-pointer q-mr-xs"
@click="copyText(props.row[col.name])"
@click="showDetailsDialog(props.row)"
>
<q-tooltip>Request Details</q-tooltip>
</q-btn>
@ -87,6 +87,36 @@
</div>
</div>
<q-dialog v-model="auditDetailsDialog.show" position="top">
<q-card class="q-pa-md q-pt-md lnbits__dialog-card">
<strong>HTTP Request Details</strong>
<q-input
filled
dense
v-model.trim="auditDetailsDialog.data"
type="textarea"
rows="25"
></q-input>
<div class="row q-mt-lg">
<q-btn
@click="copyText(auditDetailsDialog.data)"
icon="copy_content"
color="grey"
flat
v-text="$t('copy')"
></q-btn>
<q-btn
v-close-popup
flat
color="grey"
class="q-ml-auto"
v-text="$t('close')"
></q-btn>
</div>
</q-card>
</q-dialog>
{% endblock %} {% block scripts %} {{ window_vars(user) }}
<script src="{{ static_url_for('static', 'js/audit.js') }}"></script>
{% endblock %}

View File

@ -165,9 +165,12 @@ class AuditMiddleware(BaseHTTPMiddleware):
if settings.lnbits_audit_log_ip_address and request.client
else None
)
user_id = request.scope.get("user_id", None)
if settings.is_super_user(user_id):
user_id = "super_user"
data = AuditEntry(
ip_address=ip_address,
user_id=request.scope.get("user_id", None),
user_id=user_id,
path=getattr(request.scope.get("route", {}), "path", None),
request_type=request.scope.get("type", None),
request_method=http_method,

View File

@ -764,7 +764,7 @@ class Settings(EditableSettings, ReadOnlySettings, TransientSettings, BaseSettin
or user_id == self.super_user
)
def is_super_user(self, user_id: str) -> bool:
def is_super_user(self, user_id: Optional[str] = None) -> bool:
return user_id == self.super_user
def is_admin_user(self, user_id: str) -> bool:

View File

@ -74,12 +74,15 @@ window.app = Vue.createApp({
search: null,
hideEmpty: true,
loading: false
},
auditDetailsDialog: {
data: null,
show: false
}
}
},
async created() {
console.log('### audit entries')
await this.fetchAudit()
},
@ -108,6 +111,18 @@ window.app = Vue.createApp({
await this.fetchAudit()
},
showDetailsDialog(entry) {
const details = JSON.parse(entry?.request_details || '')
try {
if (details.body) {
details.body = JSON.parse(details.body)
}
} catch (e) {
// do nothing
}
this.auditDetailsDialog.data = JSON.stringify(details, null, 4)
this.auditDetailsDialog.show = true
},
formatDate: function (value) {
return Quasar.date.formatDate(new Date(value), 'YYYY-MM-DD HH:mm')
},