fix: delete account
This commit is contained in:
parent
f7fb926c52
commit
f19fb4a18e
4 changed files with 85 additions and 4 deletions
10
crud.py
10
crud.py
|
|
@ -363,6 +363,16 @@ async def update_account(relay_id: str, a: NostrAccount) -> NostrAccount:
|
||||||
return a
|
return a
|
||||||
|
|
||||||
|
|
||||||
|
async def delete_account(relay_id: str, pubkey: str):
|
||||||
|
await db.execute(
|
||||||
|
"""
|
||||||
|
DELETE FROM nostrrelay.accounts
|
||||||
|
WHERE relay_id = ? AND pubkey = ?
|
||||||
|
""",
|
||||||
|
(relay_id, pubkey),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def get_account(
|
async def get_account(
|
||||||
relay_id: str,
|
relay_id: str,
|
||||||
pubkey: str,
|
pubkey: str,
|
||||||
|
|
|
||||||
|
|
@ -545,7 +545,7 @@
|
||||||
><q-card-section>
|
><q-card-section>
|
||||||
<div class="row items-center no-wrap q-mb-md">
|
<div class="row items-center no-wrap q-mb-md">
|
||||||
<div class="col-2 q-pr-lg">Public Key:</div>
|
<div class="col-2 q-pr-lg">Public Key:</div>
|
||||||
<div class="col-6 q-pr-lg">
|
<div class="col-5 q-pr-lg">
|
||||||
<q-input
|
<q-input
|
||||||
filled
|
filled
|
||||||
dense
|
dense
|
||||||
|
|
@ -557,16 +557,16 @@
|
||||||
<q-btn
|
<q-btn
|
||||||
unelevated
|
unelevated
|
||||||
color="green"
|
color="green"
|
||||||
class="float-right"
|
class="float-left"
|
||||||
@click="allowPublicKey(accountPubkey, true)"
|
@click="allowPublicKey(accountPubkey, true)"
|
||||||
>Allow</q-btn
|
>Allow</q-btn
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-2">
|
<div class="col-3">
|
||||||
<q-btn
|
<q-btn
|
||||||
unelevated
|
unelevated
|
||||||
color="pink"
|
color="pink"
|
||||||
class="float-right"
|
class="float-left"
|
||||||
@click="blockPublicKey(accountPubkey, true)"
|
@click="blockPublicKey(accountPubkey, true)"
|
||||||
>Block</q-btn
|
>Block</q-btn
|
||||||
>
|
>
|
||||||
|
|
@ -613,6 +613,16 @@
|
||||||
>
|
>
|
||||||
<template v-slot:body="props">
|
<template v-slot:body="props">
|
||||||
<q-tr :props="props">
|
<q-tr :props="props">
|
||||||
|
<q-td key="action" :props="props">
|
||||||
|
<q-btn
|
||||||
|
dense
|
||||||
|
color="pink"
|
||||||
|
class="float-right"
|
||||||
|
@click="removePublicKey(props.row.pubkey)"
|
||||||
|
size="sm"
|
||||||
|
>Delete</q-btn
|
||||||
|
>
|
||||||
|
</q-td>
|
||||||
<q-td key="pubkey" :props="props">
|
<q-td key="pubkey" :props="props">
|
||||||
{{props.row.pubkey}}
|
{{props.row.pubkey}}
|
||||||
</q-td>
|
</q-td>
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,12 @@ async function relayDetails(path) {
|
||||||
showAllowedAccounts: false,
|
showAllowedAccounts: false,
|
||||||
accountsTable: {
|
accountsTable: {
|
||||||
columns: [
|
columns: [
|
||||||
|
{
|
||||||
|
name: 'action',
|
||||||
|
align: 'left',
|
||||||
|
label: '',
|
||||||
|
field: ''
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'pubkey',
|
name: 'pubkey',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
|
|
@ -158,6 +164,7 @@ async function relayDetails(path) {
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.warn(error)
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -183,6 +190,13 @@ async function relayDetails(path) {
|
||||||
blockPublicKey: async function (pubkey, blocked = true) {
|
blockPublicKey: async function (pubkey, blocked = true) {
|
||||||
await this.updatePublicKey({pubkey, blocked})
|
await this.updatePublicKey({pubkey, blocked})
|
||||||
},
|
},
|
||||||
|
removePublicKey: async function (pubkey) {
|
||||||
|
LNbits.utils
|
||||||
|
.confirmDialog('This public key will be removed from relay!')
|
||||||
|
.onOk(async () => {
|
||||||
|
await this.deletePublicKey(pubkey)
|
||||||
|
})
|
||||||
|
},
|
||||||
togglePublicKey: async function (account, action) {
|
togglePublicKey: async function (account, action) {
|
||||||
if (action === 'allow') {
|
if (action === 'allow') {
|
||||||
await this.updatePublicKey({
|
await this.updatePublicKey({
|
||||||
|
|
@ -222,6 +236,25 @@ async function relayDetails(path) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
deletePublicKey: async function (pubkey) {
|
||||||
|
try {
|
||||||
|
await LNbits.api.request(
|
||||||
|
'DELETE',
|
||||||
|
`/nostrrelay/api/v1/account/${this.relay.id}/${pubkey}`,
|
||||||
|
this.adminkey,
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
this.$q.notify({
|
||||||
|
type: 'positive',
|
||||||
|
message: 'Account Deleted',
|
||||||
|
timeout: 5000
|
||||||
|
})
|
||||||
|
await this.getAccounts()
|
||||||
|
} catch (error) {
|
||||||
|
LNbits.utils.notifyApiError(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
addSkipAuthForEvent: function () {
|
addSkipAuthForEvent: function () {
|
||||||
value = +this.skipEventKind
|
value = +this.skipEventKind
|
||||||
if (this.relay.config.skipedAuthEvents.indexOf(value) != -1) {
|
if (this.relay.config.skipedAuthEvents.indexOf(value) != -1) {
|
||||||
|
|
|
||||||
28
views_api.py
28
views_api.py
|
|
@ -20,6 +20,7 @@ from . import nostrrelay_ext, scheduled_tasks
|
||||||
from .crud import (
|
from .crud import (
|
||||||
create_account,
|
create_account,
|
||||||
create_relay,
|
create_relay,
|
||||||
|
delete_account,
|
||||||
delete_all_events,
|
delete_all_events,
|
||||||
delete_relay,
|
delete_relay,
|
||||||
get_account,
|
get_account,
|
||||||
|
|
@ -225,6 +226,33 @@ async def api_create_or_update_account(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@nostrrelay_ext.delete("/api/v1/account/{relay_id}/{pubkey}")
|
||||||
|
async def api_delete_account(
|
||||||
|
relay_id: str,
|
||||||
|
pubkey: str,
|
||||||
|
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||||
|
):
|
||||||
|
|
||||||
|
try:
|
||||||
|
pubkey = normalize_public_key(pubkey)
|
||||||
|
|
||||||
|
return await delete_account(relay_id, pubkey)
|
||||||
|
|
||||||
|
except ValueError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
|
except HTTPException as ex:
|
||||||
|
raise ex
|
||||||
|
except Exception as ex:
|
||||||
|
logger.warning(ex)
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
detail="Cannot create account",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@nostrrelay_ext.get("/api/v1/account")
|
@nostrrelay_ext.get("/api/v1/account")
|
||||||
async def api_get_accounts(
|
async def api_get_accounts(
|
||||||
relay_id: str,
|
relay_id: str,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue