Add MRoomServerACL constant

This commit is contained in:
Till Faelligen 2023-03-13 15:56:18 +01:00
parent f5fd6b140f
commit 49abf619bc
No known key found for this signature in database
GPG key ID: ACCDC9606D472758
5 changed files with 13 additions and 6 deletions

View file

@ -1,5 +1,9 @@
package pushrules
import (
"github.com/matrix-org/dendrite/roomserver/acls"
)
func defaultOverrideRules(userID string) []*Rule {
return []*Rule{
&mRuleMasterDefinition,
@ -108,7 +112,7 @@ var (
{
Kind: EventMatchCondition,
Key: "type",
Pattern: pointer("m.room.server_acl"),
Pattern: pointer(acls.MRoomServerACL),
},
{
Kind: EventMatchCondition,

View file

@ -27,6 +27,8 @@ import (
"github.com/sirupsen/logrus"
)
const MRoomServerACL = "m.room.server_acl"
type ServerACLDatabase interface {
// GetKnownRooms returns a list of all rooms we know about.
GetKnownRooms(ctx context.Context) ([]string, error)
@ -55,7 +57,7 @@ func NewServerACLs(db ServerACLDatabase) *ServerACLs {
// do then we'll process it into memory so that we have the regexes to
// hand.
for _, room := range rooms {
state, err := db.GetStateEvent(ctx, room, "m.room.server_acl", "")
state, err := db.GetStateEvent(ctx, room, MRoomServerACL, "")
if err != nil {
logrus.WithError(err).Errorf("Failed to get server ACLs for room %q", room)
continue

View file

@ -24,6 +24,7 @@ import (
"fmt"
"time"
"github.com/matrix-org/dendrite/roomserver/acls"
"github.com/tidwall/gjson"
"github.com/matrix-org/gomatrixserverlib"
@ -552,7 +553,7 @@ func (r *Inputer) processStateBefore(
// 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",
EventType: acls.MRoomServerACL,
StateKey: "",
})
stateBeforeReq := &api.QueryStateAfterEventsRequest{
@ -585,7 +586,7 @@ func (r *Inputer) processStateBefore(
// Work out what the history visibility/ACLs was at the time of the
// event.
for _, event := range stateBeforeEvent {
if event.Type() == "m.room.server_acl" && event.StateKeyEquals("") {
if input.Kind == api.KindNew && event.Type() == acls.MRoomServerACL && event.StateKeyEquals("") {
r.ACLs.OnServerACLUpdate(event)
}
if event.Type() != gomatrixserverlib.MRoomHistoryVisibility || !event.StateKeyEquals("") {

View file

@ -73,7 +73,7 @@ func (r *RoomEventProducer) ProduceRoomEvents(roomID string, updates []api.Outpu
}
}
if eventType == "m.room.server_acl" && update.NewRoomEvent.Event.StateKeyEquals("") {
if eventType == acls.MRoomServerACL && update.NewRoomEvent.Event.StateKeyEquals("") {
ev := update.NewRoomEvent.Event.Unwrap()
defer r.ACLs.OnServerACLUpdate(ev)
}

View file

@ -577,7 +577,7 @@ func TestNewServerACLs(t *testing.T) {
alice := test.NewUser(t)
roomWithACL := test.NewRoom(t, alice)
roomWithACL.CreateAndInsert(t, alice, "m.room.server_acl", acls.ServerACL{
roomWithACL.CreateAndInsert(t, alice, acls.MRoomServerACL, acls.ServerACL{
Allowed: []string{"*"},
Denied: []string{"localhost"},
AllowIPLiterals: false,