MCPcopy Create free account
hub / github.com/daodst/chat / SendBan

Function SendBan

clientapi/routing/membership.go:41–82  ·  view source on GitHub ↗
(
	req *http.Request, profileAPI userapi.ClientUserAPI, device *userapi.Device,
	roomID string, cfg *config.ClientAPI,
	rsAPI roomserverAPI.ClientRoomserverAPI, asAPI appserviceAPI.AppServiceInternalAPI,
)

Source from the content-addressed store, hash-verified

39var errMissingUserID = errors.New("'user_id' must be supplied")
40
41func SendBan(
42 req *http.Request, profileAPI userapi.ClientUserAPI, device *userapi.Device,
43 roomID string, cfg *config.ClientAPI,
44 rsAPI roomserverAPI.ClientRoomserverAPI, asAPI appserviceAPI.AppServiceInternalAPI,
45) util.JSONResponse {
46 body, evTime, roomVer, reqErr := extractRequestData(req, roomID, rsAPI)
47 if reqErr != nil {
48 return *reqErr
49 }
50
51 errRes := checkMemberInRoom(req.Context(), rsAPI, device.UserID, roomID)
52 if errRes != nil {
53 return *errRes
54 }
55
56 plEvent := roomserverAPI.GetStateEvent(req.Context(), rsAPI, roomID, gomatrixserverlib.StateKeyTuple{
57 EventType: gomatrixserverlib.MRoomPowerLevels,
58 StateKey: "",
59 })
60 if plEvent == nil {
61 return util.JSONResponse{
62 Code: 403,
63 JSON: jsonerror.Forbidden("You don't have permission to ban this user, no power_levels event in this room."),
64 }
65 }
66 pl, err := plEvent.PowerLevels()
67 if err != nil {
68 return util.JSONResponse{
69 Code: 403,
70 JSON: jsonerror.Forbidden("You don't have permission to ban this user, the power_levels event for this room is malformed so auth checks cannot be performed."),
71 }
72 }
73 allowedToBan := pl.UserLevel(device.UserID) >= pl.Ban
74 if !allowedToBan {
75 return util.JSONResponse{
76 Code: 403,
77 JSON: jsonerror.Forbidden("You don't have permission to ban this user, power level too low."),
78 }
79 }
80
81 return sendMembership(req.Context(), profileAPI, device, roomID, "ban", body.Reason, cfg, body.UserID, evTime, roomVer, rsAPI, asAPI)
82}
83
84func sendMembership(ctx context.Context, profileAPI userapi.ClientUserAPI, device *userapi.Device,
85 roomID, membership, reason string, cfg *config.ClientAPI, targetUserID string, evTime time.Time,

Callers 1

SetupFunction · 0.85

Calls 6

extractRequestDataFunction · 0.85
checkMemberInRoomFunction · 0.85
sendMembershipFunction · 0.85
ContextMethod · 0.80
PowerLevelsMethod · 0.80
GetStateEventMethod · 0.65

Tested by

no test coverage detected