( req *http.Request, profileAPI userapi.ClientUserAPI, device *userapi.Device, roomID string, cfg *config.ClientAPI, rsAPI roomserverAPI.ClientRoomserverAPI, asAPI appserviceAPI.AppServiceInternalAPI, )
| 39 | var errMissingUserID = errors.New("'user_id' must be supplied") |
| 40 | |
| 41 | func 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 | |
| 84 | func sendMembership(ctx context.Context, profileAPI userapi.ClientUserAPI, device *userapi.Device, |
| 85 | roomID, membership, reason string, cfg *config.ClientAPI, targetUserID string, evTime time.Time, |
no test coverage detected