Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit c4528b2

Browse files
BtbNkegsay
andauthored
Allow users to kick themselves (#3157)
As per the spec: https://spec.matrix.org/v1.7/rooms/v10/#authorization-rules "If membership is leave" -> "If the sender matches state_key, allow if and only if that user’s current membership state is invite, join, or knock." I.e. a user can kick themselves. Bridges use this to make a user leave while giving a reason. Some recent change (likely 8ea1a11 but I'm not 100% sure) changed that behaviour, resulting in heisenbridge being unable to make users leave while giving a reason. This works fine on Synapse. Signed-off-by: Timo Rothenpieler <[email protected]> Co-authored-by: kegsay <[email protected]>
1 parent f25cce2 commit c4528b2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

clientapi/routing/membership.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,25 +181,26 @@ func SendKick(
181181
return *errRes
182182
}
183183

184+
bodyUserID, err := spec.NewUserID(body.UserID, true)
185+
if err != nil {
186+
return util.JSONResponse{
187+
Code: http.StatusBadRequest,
188+
JSON: spec.BadJSON("body userID is invalid"),
189+
}
190+
}
191+
184192
pl, errRes := getPowerlevels(req, rsAPI, roomID)
185193
if errRes != nil {
186194
return *errRes
187195
}
188-
allowedToKick := pl.UserLevel(*senderID) >= pl.Kick
196+
allowedToKick := pl.UserLevel(*senderID) >= pl.Kick || bodyUserID.String() == deviceUserID.String()
189197
if !allowedToKick {
190198
return util.JSONResponse{
191199
Code: http.StatusForbidden,
192200
JSON: spec.Forbidden("You don't have permission to kick this user, power level too low."),
193201
}
194202
}
195203

196-
bodyUserID, err := spec.NewUserID(body.UserID, true)
197-
if err != nil {
198-
return util.JSONResponse{
199-
Code: http.StatusBadRequest,
200-
JSON: spec.BadJSON("body userID is invalid"),
201-
}
202-
}
203204
var queryRes roomserverAPI.QueryMembershipForUserResponse
204205
err = rsAPI.QueryMembershipForUser(req.Context(), &roomserverAPI.QueryMembershipForUserRequest{
205206
RoomID: roomID,

0 commit comments

Comments
 (0)