Try using power levels instead

This commit is contained in:
Neil Alexander 2021-11-15 16:08:57 +00:00
parent 2d91fe0df1
commit fcf21da988
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -25,7 +25,6 @@ import (
"github.com/getsentry/sentry-go" "github.com/getsentry/sentry-go"
fsAPI "github.com/matrix-org/dendrite/federationsender/api" fsAPI "github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/dendrite/internal/eventutil" "github.com/matrix-org/dendrite/internal/eventutil"
"github.com/matrix-org/dendrite/roomserver/api"
rsAPI "github.com/matrix-org/dendrite/roomserver/api" rsAPI "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/roomserver/internal/helpers" "github.com/matrix-org/dendrite/roomserver/internal/helpers"
"github.com/matrix-org/dendrite/roomserver/internal/input" "github.com/matrix-org/dendrite/roomserver/internal/input"
@ -259,19 +258,29 @@ func (r *Joiner) performJoinRoomByID(
} }
} }
if !success { if !success {
queryReq := &api.QueryMembershipsForRoomRequest{} var powerLevelsEvent *gomatrixserverlib.HeaderedEvent
queryRes := &api.QueryMembershipsForRoomResponse{} var powerLevelsContent gomatrixserverlib.PowerLevelContent
if err = r.RSAPI.QueryMembershipsForRoom(ctx, queryReq, queryRes); err != nil { powerLevelsEvent, err = r.DB.GetStateEvent(ctx, req.RoomIDOrAlias, gomatrixserverlib.MRoomPowerLevels, "")
return "", "", &api.PerformError{ if err != nil {
Code: rsAPI.PerformErrorBadRequest, return "", "", &rsAPI.PerformError{
Msg: fmt.Sprintf("Can't satisfy restricted join to room %q locally: %s", req.RoomIDOrAlias, err), Code: rsAPI.PerformErrorNotAllowed,
Msg: fmt.Sprintf("Unable to retrieve the power levels: %s", err),
}
}
if err = json.Unmarshal(powerLevelsEvent.Content(), &powerLevelsContent); err != nil {
return "", "", &rsAPI.PerformError{
Code: rsAPI.PerformErrorNotAllowed,
Msg: fmt.Sprintf("Unable to parse the power levels: %s", err),
} }
} }
var serverName gomatrixserverlib.ServerName var serverName gomatrixserverlib.ServerName
joinEvents: joinEvents:
for _, q := range queryRes.JoinEvents { for userID, pl := range powerLevelsContent.Users {
_, serverName, err = gomatrixserverlib.SplitID('@', *q.StateKey) if pl <= powerLevelsContent.Invite {
continue
}
_, serverName, err = gomatrixserverlib.SplitID('@', userID)
if err != nil { if err != nil {
continue continue
} }