mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-06 13:43:09 -06:00
Return Restricted to determine if the room was restricted or not
This commit is contained in:
parent
ab5f992567
commit
5e801bb5b1
|
|
@ -386,18 +386,36 @@ func checkRestrictedJoin(
|
|||
if err := rsAPI.QueryRestrictedJoinAllowed(httpReq.Context(), req, res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch {
|
||||
case !res.Restricted:
|
||||
// The join rules for the room don't restrict membership.
|
||||
return nil, nil
|
||||
|
||||
case !res.Resident:
|
||||
// The join rules restrict membership but our server isn't currently
|
||||
// joined to all of the allowed rooms, so we can't actually decide
|
||||
// whether or not to allow the user to join. This error code should
|
||||
// tell the joining server to try joining via another resident server
|
||||
// instead.
|
||||
return &util.JSONResponse{
|
||||
Code: http.StatusBadRequest,
|
||||
JSON: jsonerror.UnableToAuthoriseJoin("This server cannot authorise the join."),
|
||||
}, nil
|
||||
|
||||
case !res.Allowed:
|
||||
// The join rules restrict membership, our server is in the relevant
|
||||
// rooms and the user wasn't joined to join any of the allowed rooms
|
||||
// and therefore can't join this room.
|
||||
return &util.JSONResponse{
|
||||
Code: http.StatusForbidden,
|
||||
JSON: jsonerror.Forbidden("You are not joined to any matching rooms."),
|
||||
}, nil
|
||||
|
||||
default:
|
||||
// The join rules restrict membership, our server is in the relevant
|
||||
// rooms and the user was allowed to join because they belong to one
|
||||
// of the allowed rooms.
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -354,6 +354,7 @@ type QueryRestrictedJoinAllowedRequest struct {
|
|||
}
|
||||
|
||||
type QueryRestrictedJoinAllowedResponse struct {
|
||||
Restricted bool `json:"restricted"` // Is the room membership restricted?
|
||||
Resident bool `json:"resident"` // Is our homeserver in the relevant rooms?
|
||||
Allowed bool `json:"allowed"` // Is the join allowed by the rules?
|
||||
}
|
||||
|
|
|
|||
|
|
@ -787,7 +787,8 @@ func (r *Queryer) QueryRestrictedJoinAllowed(ctx context.Context, req *api.Query
|
|||
return fmt.Errorf("json.Unmarshal: %w", err)
|
||||
}
|
||||
// If the join rule isn't "restricted" then there's nothing more to do.
|
||||
if joinRules.JoinRule != gomatrixserverlib.Restricted {
|
||||
res.Restricted = joinRules.JoinRule == gomatrixserverlib.Restricted
|
||||
if !res.Restricted {
|
||||
return nil
|
||||
}
|
||||
// Start off by populating the "resident" flag in the response. If we
|
||||
|
|
|
|||
Loading…
Reference in a new issue