Move setting ACLs to processStateBefore

This commit is contained in:
Till Faelligen 2023-03-13 11:53:35 +01:00
parent cb6e9c0684
commit bf89fdae17
No known key found for this signature in database
GPG key ID: ACCDC9606D472758

View file

@ -360,12 +360,6 @@ func (r *Inputer) processRoomEvent(
// doesn't have any associated state to store and we don't need to // doesn't have any associated state to store and we don't need to
// notify anyone about it. // notify anyone about it.
if input.Kind == api.KindOutlier { if input.Kind == api.KindOutlier {
// if the event is an ACL, update our in-memory ACLs now, even if it is an outlier. This is
// going to happen on a restart of Dendrite anyway.
// ACL updates for non-outliers are handled in `ProduceRoomEvents`
if !isRejected && event.Type() == "m.room.server_acl" && event.StateKeyEquals("") {
r.ACLs.OnServerACLUpdate(event)
}
logger.WithField("rejected", isRejected).Debug("Stored outlier") logger.WithField("rejected", isRejected).Debug("Stored outlier")
hooks.Run(hooks.KindNewEventPersisted, headered) hooks.Run(hooks.KindNewEventPersisted, headered)
return nil return nil
@ -555,6 +549,12 @@ func (r *Inputer) processStateBefore(
EventType: gomatrixserverlib.MRoomHistoryVisibility, EventType: gomatrixserverlib.MRoomHistoryVisibility,
StateKey: "", StateKey: "",
}) })
// We also query the m.room.server_acl, if any, so we can correctly set
// them after joining a room.
tuplesNeeded = append(tuplesNeeded, gomatrixserverlib.StateKeyTuple{
EventType: "m.room.server_acl",
StateKey: "",
})
stateBeforeReq := &api.QueryStateAfterEventsRequest{ stateBeforeReq := &api.QueryStateAfterEventsRequest{
RoomID: event.RoomID(), RoomID: event.RoomID(),
PrevEventIDs: event.PrevEventIDs(), PrevEventIDs: event.PrevEventIDs(),
@ -582,15 +582,17 @@ func (r *Inputer) processStateBefore(
if rejectionErr = gomatrixserverlib.Allowed(event, &stateBeforeAuth); rejectionErr != nil { if rejectionErr = gomatrixserverlib.Allowed(event, &stateBeforeAuth); rejectionErr != nil {
return return
} }
// Work out what the history visibility was at the time of the // Work out what the history visibility/ACLs was at the time of the
// event. // event.
for _, event := range stateBeforeEvent { for _, event := range stateBeforeEvent {
if event.Type() == "m.room.server_acl" && event.StateKeyEquals("") {
r.ACLs.OnServerACLUpdate(event)
}
if event.Type() != gomatrixserverlib.MRoomHistoryVisibility || !event.StateKeyEquals("") { if event.Type() != gomatrixserverlib.MRoomHistoryVisibility || !event.StateKeyEquals("") {
continue continue
} }
if hisVis, err := event.HistoryVisibility(); err == nil { if hisVis, err := event.HistoryVisibility(); err == nil {
historyVisibility = hisVis historyVisibility = hisVis
break
} }
} }
return return