Move standardised admin APIs to a new file
This commit is contained in:
@@ -7,6 +7,7 @@ import random
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from .groups import groups
|
from .groups import groups
|
||||||
|
from .admin import admin
|
||||||
|
|
||||||
from flask import (
|
from flask import (
|
||||||
Blueprint,
|
Blueprint,
|
||||||
@@ -18,6 +19,7 @@ from flask import (
|
|||||||
client = Blueprint("client", __name__)
|
client = Blueprint("client", __name__)
|
||||||
|
|
||||||
client.register_blueprint(groups)
|
client.register_blueprint(groups)
|
||||||
|
client.register_blueprint(admin)
|
||||||
|
|
||||||
|
|
||||||
@client.route("/_matrix/client/v3/account/password", methods=["POST"])
|
@client.route("/_matrix/client/v3/account/password", methods=["POST"])
|
||||||
@@ -66,52 +68,6 @@ async def spec_versions():
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@client.route("/_matrix/client/v3/admin/whois/<user>")
|
|
||||||
@client.route("/_matrix/client/r0/admin/whois/<user>")
|
|
||||||
async def whois(user):
|
|
||||||
if user.startswith("@"):
|
|
||||||
return jsonify({
|
|
||||||
"devices": {
|
|
||||||
"": {
|
|
||||||
"sessions": [{
|
|
||||||
"connections": [{
|
|
||||||
"ip": "127.0.0.1",
|
|
||||||
"last_seen": config.the_funny_number,
|
|
||||||
"user_agent": f"Vona/{globals.version}"
|
|
||||||
}]
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"user_id": user
|
|
||||||
})
|
|
||||||
|
|
||||||
return jsonify({
|
|
||||||
"errcode": "M_INVALID_PARAM",
|
|
||||||
"error": "Expected UserID string to start with '@'"
|
|
||||||
})
|
|
||||||
|
|
||||||
@client.route("/_matrix/client/unstable/uk.timedout.msc4323/admin/suspend/<user>", methods=["GET", "PUT"])
|
|
||||||
@client.route("/_matrix/client/v1/admin/suspend/<user>", methods=["GET", "PUT"])
|
|
||||||
async def suspend(user):
|
|
||||||
if request.method == "PUT":
|
|
||||||
req = request.get_json()
|
|
||||||
if req and "suspended" in req:
|
|
||||||
return jsonify({"suspended": req["suspended"]})
|
|
||||||
|
|
||||||
return jsonify({"suspended": True})
|
|
||||||
|
|
||||||
|
|
||||||
@client.route("/_matrix/client/unstable/uk.timedout.msc4323/admin/lock/<user>", methods=["GET", "PUT"])
|
|
||||||
@client.route("/_matrix/client/v1/admin/lock/<user>", methods=["GET", "PUT"])
|
|
||||||
async def lock(user):
|
|
||||||
if request.method == "PUT":
|
|
||||||
req = request.get_json()
|
|
||||||
if req and "locked" in req:
|
|
||||||
return jsonify({"locked": req["locked"]})
|
|
||||||
|
|
||||||
return jsonify({"locked": True})
|
|
||||||
|
|
||||||
|
|
||||||
@client.route("/_matrix/client/api/v1/rooms/<room>/members")
|
@client.route("/_matrix/client/api/v1/rooms/<room>/members")
|
||||||
@client.route("/_matrix/client/v3/rooms/<room>/members")
|
@client.route("/_matrix/client/v3/rooms/<room>/members")
|
||||||
@client.route("/_matrix/client/r0/rooms/<room>/members")
|
@client.route("/_matrix/client/r0/rooms/<room>/members")
|
||||||
|
|||||||
59
vona/client/admin.py
Normal file
59
vona/client/admin.py
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import vona.globals as globals
|
||||||
|
import vona.config as config
|
||||||
|
|
||||||
|
from flask import (
|
||||||
|
Blueprint,
|
||||||
|
jsonify,
|
||||||
|
request,
|
||||||
|
)
|
||||||
|
|
||||||
|
admin = Blueprint("admin", __name__)
|
||||||
|
|
||||||
|
# This implements misc standard admin APIs.
|
||||||
|
|
||||||
|
|
||||||
|
@admin.route("/_matrix/client/v3/admin/whois/<user>")
|
||||||
|
@admin.route("/_matrix/client/r0/admin/whois/<user>")
|
||||||
|
async def whois(user):
|
||||||
|
if user.startswith("@"):
|
||||||
|
return jsonify({
|
||||||
|
"devices": {
|
||||||
|
"": {
|
||||||
|
"sessions": [{
|
||||||
|
"connections": [{
|
||||||
|
"ip": "127.0.0.1",
|
||||||
|
"last_seen": config.the_funny_number,
|
||||||
|
"user_agent": f"Vona/{globals.version}"
|
||||||
|
}]
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"user_id": user
|
||||||
|
})
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"errcode": "M_INVALID_PARAM",
|
||||||
|
"error": "Expected UserID string to start with '@'"
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@admin.route("/_matrix/client/unstable/uk.timedout.msc4323/admin/suspend/<user>", methods=["GET", "PUT"])
|
||||||
|
@admin.route("/_matrix/client/v1/admin/suspend/<user>", methods=["GET", "PUT"])
|
||||||
|
async def suspend(user):
|
||||||
|
if request.method == "PUT":
|
||||||
|
req = request.get_json()
|
||||||
|
if req and "suspended" in req:
|
||||||
|
return jsonify({"suspended": req["suspended"]})
|
||||||
|
|
||||||
|
return jsonify({"suspended": True})
|
||||||
|
|
||||||
|
|
||||||
|
@admin.route("/_matrix/client/unstable/uk.timedout.msc4323/admin/lock/<user>", methods=["GET", "PUT"])
|
||||||
|
@admin.route("/_matrix/client/v1/admin/lock/<user>", methods=["GET", "PUT"])
|
||||||
|
async def lock(user):
|
||||||
|
if request.method == "PUT":
|
||||||
|
req = request.get_json()
|
||||||
|
if req and "locked" in req:
|
||||||
|
return jsonify({"locked": req["locked"]})
|
||||||
|
|
||||||
|
return jsonify({"locked": True})
|
||||||
Reference in New Issue
Block a user