Endpoint for updating user extensions vie usermanager

This commit is contained in:
benarc 2020-06-15 16:30:24 +01:00
parent c3281399d2
commit d56c2627f4
2 changed files with 36 additions and 1 deletions

View File

@ -212,4 +212,22 @@
</q-card-section>
</q-card>
</q-expansion-item>
<q-expansion-item group="api" dense expand-separator label="POST activate extension">
<q-card>
<q-card-section>
<code
><span class="text-green">POST</span>
/usermanager/api/v1/extensions</code
>
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
<code>{"X-Api-Key": &lt;string&gt;}</code>
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
<code
>curl -X POST {{ request.url_root }}usermanager/api/v1/extensions -d
'{"userid": &lt;string&gt;, "extension": &lt;string&gt;, "active": &lt;integer&gt;}' -H "X-Api-Key: {{
g.user.wallets[0].inkey }}" -H "Content-type: application/json"
</code>
</q-card-section>
</q-card>
</q-expansion-item>
</q-expansion-item>

View File

@ -11,6 +11,9 @@ from base64 import urlsafe_b64encode
from uuid import uuid4
from lnbits.db import open_ext_db
from ...core import (
update_user_extension,
)
###Users
@ -37,13 +40,27 @@ def api_usermanager_users_create():
@usermanager_ext.route("/api/v1/users/<user_id>", methods=["DELETE"])
@api_check_wallet_key(key_type="invoice")
def api_usermanager_users_delete(user_id):
print("cunt")
user = get_usermanager_user(user_id)
if not user:
return jsonify({"message": "User does not exist."}), HTTPStatus.NOT_FOUND
delete_usermanager_user(user_id)
return "", HTTPStatus.NO_CONTENT
###Activate Extension
@usermanager_ext.route("/api/v1/extensions", methods=["POST"])
@api_check_wallet_key(key_type="invoice")
@api_validate_post_request(schema={
"extension": {"type": "string", "empty": False, "required": True},
"userid": {"type": "string", "empty": False, "required": True},
"active": {"type": "boolean", "required": True}
})
def api_usermanager_activate_extension():
user = get_user(g.data["userid"])
if not user:
return jsonify({"error": "no such user"}), HTTPStatus.NO_CONTENT
user = update_user_extension(user_id=g.data["userid"], extension=g.data["extension"], active=g.data["active"])
return jsonify({"extension": "updated"}), HTTPStatus.CREATED
###Wallets