forked from Telodendria/Telodendria
[ADD/WIP] Banning users out
Some checks failed
Compile Telodendria / Compile Telodendria (x86, alpine-v3.19) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, debian-v12.4) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, freebsd-v14.0) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, netbsd-v9.3) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, alpine-v3.19) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, debian-v12.4) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, freebsd-v14.0) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, netbsd-v9.3) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, openbsd-v7.4) (push) Has been cancelled
Some checks failed
Compile Telodendria / Compile Telodendria (x86, alpine-v3.19) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, debian-v12.4) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, freebsd-v14.0) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, netbsd-v9.3) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, alpine-v3.19) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, debian-v12.4) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, freebsd-v14.0) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, netbsd-v9.3) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, openbsd-v7.4) (push) Has been cancelled
This commit is contained in:
parent
368690aaeb
commit
15f4de2a25
3 changed files with 11 additions and 6 deletions
|
@ -1076,7 +1076,7 @@ AuthorizeBanMembershipV1(Room * room, PduV1 pdu, HashMap *state)
|
||||||
* the sender's power level, allow. */
|
* the sender's power level, allow. */
|
||||||
ban_pl = RoomMinPL(room, state, NULL, "ban");
|
ban_pl = RoomMinPL(room, state, NULL, "ban");
|
||||||
pdu_pl = RoomUserPL(room, state, pdu.sender);
|
pdu_pl = RoomUserPL(room, state, pdu.sender);
|
||||||
target_pl = RoomUserPL(room, state, pdu.sender);
|
target_pl = RoomUserPL(room, state, pdu.state_key);
|
||||||
if ((pdu_pl >= ban_pl) && (target_pl < pdu_pl))
|
if ((pdu_pl >= ban_pl) && (target_pl < pdu_pl))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -81,7 +81,7 @@ RouterBuild(void)
|
||||||
R("/_matrix/client/v3/rooms/(.*)/state/(.*)", RouteSendState);
|
R("/_matrix/client/v3/rooms/(.*)/state/(.*)", RouteSendState);
|
||||||
R("/_matrix/client/v3/rooms/(.*)/event/(.*)", RouteFetchEvent);
|
R("/_matrix/client/v3/rooms/(.*)/event/(.*)", RouteFetchEvent);
|
||||||
R("/_matrix/client/v3/rooms/(.*)/join", RouteJoinRoom);
|
R("/_matrix/client/v3/rooms/(.*)/join", RouteJoinRoom);
|
||||||
R("/_matrix/client/v3/rooms/(.*)/kick", RouteKickRoom);
|
R("/_matrix/client/v3/rooms/(.*)/(kick|ban)", RouteKickRoom);
|
||||||
R("/_matrix/client/v3/rooms/(.*)/messages", RouteMessages);
|
R("/_matrix/client/v3/rooms/(.*)/messages", RouteMessages);
|
||||||
|
|
||||||
R("/_matrix/client/v3/join/(.*)", RouteJoinRoomAlias);
|
R("/_matrix/client/v3/join/(.*)", RouteJoinRoomAlias);
|
||||||
|
|
|
@ -171,14 +171,17 @@ ROUTE_IMPL(RouteKickRoom, path, argp)
|
||||||
CommonID *id = NULL;
|
CommonID *id = NULL;
|
||||||
|
|
||||||
char *roomId = ArrayGet(path, 0);
|
char *roomId = ArrayGet(path, 0);
|
||||||
|
char *action = ArrayGet(path, 1);
|
||||||
char *kicked = NULL, *reason = NULL;
|
char *kicked = NULL, *reason = NULL;
|
||||||
char *sender = NULL, *serverName = NULL;
|
char *sender = NULL, *serverName = NULL;
|
||||||
|
char *membershipState = StrEquals(action, "kick") ?
|
||||||
|
"leave" : "ban";
|
||||||
|
|
||||||
Room *room = NULL;
|
Room *room = NULL;
|
||||||
|
|
||||||
char *err;
|
char *err;
|
||||||
|
|
||||||
if (!roomId)
|
if (!roomId || !action)
|
||||||
{
|
{
|
||||||
/* Should be impossible */
|
/* Should be impossible */
|
||||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
@ -244,7 +247,7 @@ ROUTE_IMPL(RouteKickRoom, path, argp)
|
||||||
}
|
}
|
||||||
if (!RoomContainsUser(room, kicked))
|
if (!RoomContainsUser(room, kicked))
|
||||||
{
|
{
|
||||||
err = "Kicked user is not present in the room";
|
err = "Victim is not present in the room";
|
||||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||||
response = MatrixErrorCreate(M_BAD_STATE, err);
|
response = MatrixErrorCreate(M_BAD_STATE, err);
|
||||||
goto finish;
|
goto finish;
|
||||||
|
@ -257,7 +260,7 @@ ROUTE_IMPL(RouteKickRoom, path, argp)
|
||||||
content
|
content
|
||||||
);
|
);
|
||||||
|
|
||||||
HashMapSet(content, "membership", JsonValueString("leave"));
|
HashMapSet(content, "membership", JsonValueString(membershipState));
|
||||||
if (reason)
|
if (reason)
|
||||||
{
|
{
|
||||||
HashMapSet(content, "reason", JsonValueString(reason));
|
HashMapSet(content, "reason", JsonValueString(reason));
|
||||||
|
@ -266,9 +269,11 @@ ROUTE_IMPL(RouteKickRoom, path, argp)
|
||||||
pduResponse = RoomEventSend(room, membership);
|
pduResponse = RoomEventSend(room, membership);
|
||||||
if (!pduResponse)
|
if (!pduResponse)
|
||||||
{
|
{
|
||||||
err = "Couldn't accept kick event";
|
err = "Couldn't accept event";
|
||||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||||
response = MatrixErrorCreate(M_UNKNOWN, err);
|
response = MatrixErrorCreate(M_UNKNOWN, err);
|
||||||
|
|
||||||
|
JsonFree(membership);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
JsonFree(pduResponse);
|
JsonFree(pduResponse);
|
||||||
|
|
Loading…
Reference in a new issue