From 3dc2e01c28c177fd538a0af26494a6f5eabccae8 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 21 Apr 2019 17:21:31 -0300 Subject: [PATCH] admin_api.guilds: add PATCH /api/v6/admin/guilds/:id currently does not do anything else other than updating and returning the guild, as we don't store the availability of it on the database as of rn. --- docs/admin_api.md | 11 +++++++++++ litecord/admin_schemas.py | 4 ++++ litecord/blueprints/admin_api/guilds.py | 18 +++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/docs/admin_api.md b/docs/admin_api.md index d19658f..6a04aff 100644 --- a/docs/admin_api.md +++ b/docs/admin_api.md @@ -132,6 +132,17 @@ Returns empty body with 204 status code on success. Returns a partial guild object. +### PATCH `/guilds/` + +Update a single guild. + +Dispatches `GUILD_UPDATE` to subscribers of the guild, returns the guild object +on success. + +| field | type | description | +| --: | :-- | :-- | +| unavailable | bool | if the guild is unavailable | + ## Guild features The currently supported features are: diff --git a/litecord/admin_schemas.py b/litecord/admin_schemas.py index d4dba63..fc96dc9 100644 --- a/litecord/admin_schemas.py +++ b/litecord/admin_schemas.py @@ -50,3 +50,7 @@ USER_CREATE = { INSTANCE_INVITE = { 'max_uses': {'type': 'integer', 'required': True} } + +GUILD_UPDATE = { + 'unavailable': {'type': 'boolean', 'required': False} +} diff --git a/litecord/blueprints/admin_api/guilds.py b/litecord/blueprints/admin_api/guilds.py index d779c02..f658cf6 100644 --- a/litecord/blueprints/admin_api/guilds.py +++ b/litecord/blueprints/admin_api/guilds.py @@ -17,9 +17,11 @@ along with this program. If not, see . """ -from quart import Blueprint, jsonify, current_app as app +from quart import Blueprint, jsonify, current_app as app, request from litecord.auth import admin_check +# from litecord.schemas import validate +# from litecord.admin_schemas import GUILD_UPDATE bp = Blueprint('guilds_admin', __name__) @@ -31,3 +33,17 @@ async def get_guild(guild_id: int): return jsonify( await app.storage.get_guild(guild_id) ) + +@bp.route('/', methods=['PATCH']) +async def update_guild(guild_id: int): + await admin_check() + + # j = validate(await request.get_json(), GUILD_UPDATE) + + # TODO: add guild availability update, we don't store it, should we? + # TODO: what happens to the other guild attributes when its + # unavailable? do they vanish? + + guild = await app.storage.get_guild(guild_id) + await app.dispatcher.dispatch_guild(guild_id, 'GUILD_UPDATE', guild) + return jsonify(guild)