[MOD] Revert single-property route

This commit is contained in:
lda 2023-11-15 13:33:12 +01:00
parent 2233e5b7c6
commit 213f9fbb09
Signed by: lda
GPG key ID: 6898757653ABE3E6
2 changed files with 4 additions and 24 deletions

View file

@ -1,14 +0,0 @@
{
"header": "Schema\/AdminDeactivate.h",
"types": {
"DeactivateRequest": {
"fields": {
"reason": {
"type": "string"
}
},
"type": "struct"
}
},
"guard": "TELODENDRIA_SCHEMA_ADMINDEACTIVATE_H"
}

View file

@ -29,8 +29,6 @@
#include <User.h> #include <User.h>
#include <Schema/AdminDeactivate.h>
ROUTE_IMPL(RouteAdminDeactivate, path, argp) ROUTE_IMPL(RouteAdminDeactivate, path, argp)
{ {
RouteArgs *args = argp; RouteArgs *args = argp;
@ -39,7 +37,6 @@ ROUTE_IMPL(RouteAdminDeactivate, path, argp)
JsonValue *val; JsonValue *val;
char *reason = "Deactivated by admin"; char *reason = "Deactivated by admin";
char *err;
char *removedLocalpart = ArrayGet(path, 0); char *removedLocalpart = ArrayGet(path, 0);
char *token; char *token;
@ -50,8 +47,6 @@ ROUTE_IMPL(RouteAdminDeactivate, path, argp)
HttpRequestMethod method = HttpRequestMethodGet(args->context); HttpRequestMethod method = HttpRequestMethodGet(args->context);
DeactivateRequest deactReq;
if ((method != HTTP_DELETE) && (method != HTTP_PUT)) if ((method != HTTP_DELETE) && (method != HTTP_PUT))
{ {
char * msg = "Route only supports DELETE and PUT as for now."; char * msg = "Route only supports DELETE and PUT as for now.";
@ -67,10 +62,10 @@ ROUTE_IMPL(RouteAdminDeactivate, path, argp)
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
return MatrixErrorCreate(M_NOT_JSON, NULL); return MatrixErrorCreate(M_NOT_JSON, NULL);
} }
if (!DeactivateRequestFromJson(request, &deactReq, &err)) val = HashMapGet(request, "reason");
if (val && JsonValueType(val) == JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); reason = JsonValueAsString(val);
return MatrixErrorCreate(M_BAD_JSON, err);
} }
} }
@ -104,7 +99,7 @@ ROUTE_IMPL(RouteAdminDeactivate, path, argp)
response = HashMapCreate(); response = HashMapCreate();
JsonSet(response, JsonValueString(removedLocalpart), 1, "user"); JsonSet(response, JsonValueString(removedLocalpart), 1, "user");
JsonSet(response, JsonValueString(deactReq.reason), 1, "reason"); JsonSet(response, JsonValueString(reason), 1, "reason");
JsonSet(response, JsonValueString(UserGetName(user)), 1, "banned_by"); JsonSet(response, JsonValueString(UserGetName(user)), 1, "banned_by");
} }
else else
@ -116,7 +111,6 @@ ROUTE_IMPL(RouteAdminDeactivate, path, argp)
finish: finish:
UserUnlock(user); UserUnlock(user);
UserUnlock(removed); UserUnlock(removed);
DeactivateRequestFree(&deactReq);
JsonFree(request); JsonFree(request);
return response; return response;
} }