mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 13:22:46 +00:00
Fix /get_missing_events
for rooms with joined
/invited
history_visibility (#2787)
Sytest was using a wrong `history_visibility` for `invited` (https://github.com/matrix-org/sytest/pull/1303), so `invited` was passing for the wrong reason (-> defaulted to `shared`, as `invite` wasn't understood). This change now handles missing events like Synapse, if a server isn't allowed to see the event, it gets a redacted version of it, making the `get_missing_events` tests pass.
This commit is contained in:
parent
0a9aebdf01
commit
3c1474f68f
7 changed files with 33 additions and 34 deletions
|
@ -13,8 +13,6 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
|
@ -30,7 +28,7 @@ func IsServerAllowed(
|
|||
historyVisibility := HistoryVisibilityForRoom(authEvents)
|
||||
|
||||
// 1. If the history_visibility was set to world_readable, allow.
|
||||
if historyVisibility == "world_readable" {
|
||||
if historyVisibility == gomatrixserverlib.HistoryVisibilityWorldReadable {
|
||||
return true
|
||||
}
|
||||
// 2. If the user's membership was join, allow.
|
||||
|
@ -39,12 +37,12 @@ func IsServerAllowed(
|
|||
return true
|
||||
}
|
||||
// 3. If history_visibility was set to shared, and the user joined the room at any point after the event was sent, allow.
|
||||
if historyVisibility == "shared" && serverCurrentlyInRoom {
|
||||
if historyVisibility == gomatrixserverlib.HistoryVisibilityShared && serverCurrentlyInRoom {
|
||||
return true
|
||||
}
|
||||
// 4. If the user's membership was invite, and the history_visibility was set to invited, allow.
|
||||
invitedUserExists := IsAnyUserOnServerWithMembership(serverName, authEvents, gomatrixserverlib.Invite)
|
||||
if invitedUserExists && historyVisibility == "invited" {
|
||||
if invitedUserExists && historyVisibility == gomatrixserverlib.HistoryVisibilityInvited {
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -52,27 +50,16 @@ func IsServerAllowed(
|
|||
return false
|
||||
}
|
||||
|
||||
func HistoryVisibilityForRoom(authEvents []*gomatrixserverlib.Event) string {
|
||||
func HistoryVisibilityForRoom(authEvents []*gomatrixserverlib.Event) gomatrixserverlib.HistoryVisibility {
|
||||
// https://matrix.org/docs/spec/client_server/r0.6.0#id87
|
||||
// By default if no history_visibility is set, or if the value is not understood, the visibility is assumed to be shared.
|
||||
visibility := "shared"
|
||||
knownStates := []string{"invited", "joined", "shared", "world_readable"}
|
||||
visibility := gomatrixserverlib.HistoryVisibilityShared
|
||||
for _, ev := range authEvents {
|
||||
if ev.Type() != gomatrixserverlib.MRoomHistoryVisibility {
|
||||
continue
|
||||
}
|
||||
// TODO: This should be HistoryVisibilityContent to match things like 'MemberContent'. Do this when moving to GMSL
|
||||
content := struct {
|
||||
HistoryVisibility string `json:"history_visibility"`
|
||||
}{}
|
||||
if err := json.Unmarshal(ev.Content(), &content); err != nil {
|
||||
break // value is not understood
|
||||
}
|
||||
for _, s := range knownStates {
|
||||
if s == content.HistoryVisibility {
|
||||
visibility = s
|
||||
break
|
||||
}
|
||||
if vis, err := ev.HistoryVisibility(); err == nil {
|
||||
visibility = vis
|
||||
}
|
||||
}
|
||||
return visibility
|
||||
|
@ -80,6 +67,9 @@ func HistoryVisibilityForRoom(authEvents []*gomatrixserverlib.Event) string {
|
|||
|
||||
func IsAnyUserOnServerWithMembership(serverName gomatrixserverlib.ServerName, authEvents []*gomatrixserverlib.Event, wantMembership string) bool {
|
||||
for _, ev := range authEvents {
|
||||
if ev.Type() != gomatrixserverlib.MRoomMember {
|
||||
continue
|
||||
}
|
||||
membership, err := ev.Membership()
|
||||
if err != nil || membership != wantMembership {
|
||||
continue
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue