From 2c5dfbbf92ed6f0a23055f5003514d1bbe27b9bf Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Thu, 16 Feb 2023 12:33:16 +0200 Subject: [PATCH] feat: add basic block/allow actions --- .../relay-details/relay-details.html | 6 ++--- .../components/relay-details/relay-details.js | 27 ++++++++++--------- views_api.py | 4 ++- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/static/components/relay-details/relay-details.html b/static/components/relay-details/relay-details.html index 399e130..92aec13 100644 --- a/static/components/relay-details/relay-details.html +++ b/static/components/relay-details/relay-details.html @@ -532,7 +532,7 @@ @@ -541,7 +541,7 @@ unelevated color="green" class="float-right" - @click="allowPublicKey()" + @click="allowPublicKey(true)" >Allow @@ -550,7 +550,7 @@ unelevated color="pink" class="float-right" - @click="blockPublicKey()" + @click="blockPublicKey(true)" >Block diff --git a/static/components/relay-details/relay-details.js b/static/components/relay-details/relay-details.js index 861154b..1b47cb2 100644 --- a/static/components/relay-details/relay-details.js +++ b/static/components/relay-details/relay-details.js @@ -9,8 +9,7 @@ async function relayDetails(path) { return { tab: 'info', relay: null, - blockedPubkey: '', - allowedPubkey: '', + accountPubkey: '', formDialogItem: { show: false, data: { @@ -114,33 +113,35 @@ async function relayDetails(path) { this.relay.config.wallet = this.relay.config.wallet || this.walletOptions[0].value }, - allowPublicKey: async function () { + allowPublicKey: async function (allowed) { + await this.updatePublicKey({allowed}) + }, + blockPublicKey: async function (blocked = true) { + await this.updatePublicKey({blocked}) + }, + updatePublicKey: async function (ops) { try { - const {data} = await LNbits.api.request( + await LNbits.api.request( 'PUT', '/nostrrelay/api/v1/account', this.adminkey, { - pubkey: this.allowedPubkey, - allowed: true + relay_id: this.relay.id, + pubkey: this.accountPubkey, + allowed: ops.allowed, + blocked: ops.blocked } ) - this.relay = data - this.$emit('relay-updated', this.relay) this.$q.notify({ type: 'positive', message: 'Account Updated', timeout: 5000 }) - this.allowedPubkey = '' + this.accountPubkey = '' } catch (error) { LNbits.utils.notifyApiError(error) } }, - blockPublicKey: function () { - this.relay.config.blockedPublicKeys.push(this.blockedPubkey) - this.blockedPubkey = '' - }, deleteAllowedPublicKey: function (pubKey) { this.relay.config.allowedPublicKeys = this.relay.config.allowedPublicKeys.filter(p => p !== pubKey) diff --git a/views_api.py b/views_api.py index e5017aa..8eb6965 100644 --- a/views_api.py +++ b/views_api.py @@ -155,12 +155,14 @@ async def api_create_or_update_account( data.pubkey = normalize_public_key(data.pubkey) account = await get_account(data.relay_id, data.pubkey) if not account: - return await create_account(data.relay_id, NostrAccount.parse_obj(data.dict())) + account = NostrAccount(pubkey=data.pubkey, blocked = data.blocked or False, allowed = data.allowed or False) + return await create_account(data.relay_id, account) if data.blocked is not None: account.blocked = data.blocked if data.allowed is not None: account.allowed = data.allowed + return await update_account(data.relay_id, account) except ValueError as ex: