mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 07:28:27 +00:00
Handle the case that the join rules are nonsense
This commit is contained in:
parent
9ea8dc71eb
commit
6123c0edca
1 changed files with 9 additions and 6 deletions
|
@ -244,10 +244,7 @@ func (r *Joiner) performJoinRoomByID(
|
||||||
// Check if the room is a restricted room. If so, update the event
|
// Check if the room is a restricted room. If so, update the event
|
||||||
// builder content.
|
// builder content.
|
||||||
if restricted, roomIDs, rerr := r.checkIfRestrictedJoin(ctx, req); rerr != nil {
|
if restricted, roomIDs, rerr := r.checkIfRestrictedJoin(ctx, req); rerr != nil {
|
||||||
return "", "", &rsAPI.PerformError{
|
return "", "", err
|
||||||
Code: rsAPI.PerformErrorNotAllowed,
|
|
||||||
Msg: rerr.Error(),
|
|
||||||
}
|
|
||||||
} else if restricted {
|
} else if restricted {
|
||||||
for _, roomID := range roomIDs {
|
for _, roomID := range roomIDs {
|
||||||
if err = r.attemptRestrictedJoinUsingRoomID(ctx, req, roomID, &eb); err == nil {
|
if err = r.attemptRestrictedJoinUsingRoomID(ctx, req, roomID, &eb); err == nil {
|
||||||
|
@ -345,13 +342,19 @@ func (r *Joiner) checkIfRestrictedJoin(
|
||||||
// restricted room or not.
|
// restricted room or not.
|
||||||
joinRuleEvent, err := r.DB.GetStateEvent(ctx, req.RoomIDOrAlias, gomatrixserverlib.MRoomJoinRules, "")
|
joinRuleEvent, err := r.DB.GetStateEvent(ctx, req.RoomIDOrAlias, gomatrixserverlib.MRoomJoinRules, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil, fmt.Errorf("r.DB.GetStateEvent: %w", err)
|
return false, nil, &rsAPI.PerformError{
|
||||||
|
Code: rsAPI.PerformErrorNotAllowed,
|
||||||
|
Msg: fmt.Sprintf("Unable to retrieve the join rules: %s", err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
joinRuleContent := &gomatrixserverlib.JoinRuleContent{
|
joinRuleContent := &gomatrixserverlib.JoinRuleContent{
|
||||||
JoinRule: gomatrixserverlib.Public,
|
JoinRule: gomatrixserverlib.Public,
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(joinRuleEvent.Content(), &joinRuleContent); err != nil {
|
if err = json.Unmarshal(joinRuleEvent.Content(), &joinRuleContent); err != nil {
|
||||||
return false, nil, fmt.Errorf("json.Unmarshal: %w", err)
|
return false, nil, &rsAPI.PerformError{
|
||||||
|
Code: rsAPI.PerformErrorNotAllowed,
|
||||||
|
Msg: fmt.Sprintf("The room join rules are invalid: %s", err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
roomIDs := make([]string, 0, len(joinRuleContent.Allow))
|
roomIDs := make([]string, 0, len(joinRuleContent.Allow))
|
||||||
for _, allowed := range joinRuleContent.Allow {
|
for _, allowed := range joinRuleContent.Allow {
|
||||||
|
|
Loading…
Reference in a new issue