mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-08 07:23:10 -06:00
Add MRoomServerACL constant
This commit is contained in:
parent
f5fd6b140f
commit
49abf619bc
|
|
@ -1,5 +1,9 @@
|
||||||
package pushrules
|
package pushrules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/acls"
|
||||||
|
)
|
||||||
|
|
||||||
func defaultOverrideRules(userID string) []*Rule {
|
func defaultOverrideRules(userID string) []*Rule {
|
||||||
return []*Rule{
|
return []*Rule{
|
||||||
&mRuleMasterDefinition,
|
&mRuleMasterDefinition,
|
||||||
|
|
@ -108,7 +112,7 @@ var (
|
||||||
{
|
{
|
||||||
Kind: EventMatchCondition,
|
Kind: EventMatchCondition,
|
||||||
Key: "type",
|
Key: "type",
|
||||||
Pattern: pointer("m.room.server_acl"),
|
Pattern: pointer(acls.MRoomServerACL),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Kind: EventMatchCondition,
|
Kind: EventMatchCondition,
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const MRoomServerACL = "m.room.server_acl"
|
||||||
|
|
||||||
type ServerACLDatabase interface {
|
type ServerACLDatabase interface {
|
||||||
// GetKnownRooms returns a list of all rooms we know about.
|
// GetKnownRooms returns a list of all rooms we know about.
|
||||||
GetKnownRooms(ctx context.Context) ([]string, error)
|
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
|
// do then we'll process it into memory so that we have the regexes to
|
||||||
// hand.
|
// hand.
|
||||||
for _, room := range rooms {
|
for _, room := range rooms {
|
||||||
state, err := db.GetStateEvent(ctx, room, "m.room.server_acl", "")
|
state, err := db.GetStateEvent(ctx, room, MRoomServerACL, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to get server ACLs for room %q", room)
|
logrus.WithError(err).Errorf("Failed to get server ACLs for room %q", room)
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/acls"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"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
|
// We also query the m.room.server_acl, if any, so we can correctly set
|
||||||
// them after joining a room.
|
// them after joining a room.
|
||||||
tuplesNeeded = append(tuplesNeeded, gomatrixserverlib.StateKeyTuple{
|
tuplesNeeded = append(tuplesNeeded, gomatrixserverlib.StateKeyTuple{
|
||||||
EventType: "m.room.server_acl",
|
EventType: acls.MRoomServerACL,
|
||||||
StateKey: "",
|
StateKey: "",
|
||||||
})
|
})
|
||||||
stateBeforeReq := &api.QueryStateAfterEventsRequest{
|
stateBeforeReq := &api.QueryStateAfterEventsRequest{
|
||||||
|
|
@ -585,7 +586,7 @@ func (r *Inputer) processStateBefore(
|
||||||
// Work out what the history visibility/ACLs 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("") {
|
if input.Kind == api.KindNew && event.Type() == acls.MRoomServerACL && event.StateKeyEquals("") {
|
||||||
r.ACLs.OnServerACLUpdate(event)
|
r.ACLs.OnServerACLUpdate(event)
|
||||||
}
|
}
|
||||||
if event.Type() != gomatrixserverlib.MRoomHistoryVisibility || !event.StateKeyEquals("") {
|
if event.Type() != gomatrixserverlib.MRoomHistoryVisibility || !event.StateKeyEquals("") {
|
||||||
|
|
|
||||||
|
|
@ -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()
|
ev := update.NewRoomEvent.Event.Unwrap()
|
||||||
defer r.ACLs.OnServerACLUpdate(ev)
|
defer r.ACLs.OnServerACLUpdate(ev)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -577,7 +577,7 @@ func TestNewServerACLs(t *testing.T) {
|
||||||
alice := test.NewUser(t)
|
alice := test.NewUser(t)
|
||||||
roomWithACL := test.NewRoom(t, alice)
|
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{"*"},
|
Allowed: []string{"*"},
|
||||||
Denied: []string{"localhost"},
|
Denied: []string{"localhost"},
|
||||||
AllowIPLiterals: false,
|
AllowIPLiterals: false,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue