mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-14 05:12:26 +03:00
Merge SenderID & Per Room User Key work (#3109)
This commit is contained in:
parent
7a2e325d10
commit
e4665979bf
75 changed files with 801 additions and 379 deletions
|
@ -15,7 +15,7 @@ package auth
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/matrix-org/dendrite/roomserver/storage"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||
)
|
||||
|
@ -25,7 +25,7 @@ import (
|
|||
// IsServerAllowed returns true if the server is allowed to see events in the room
|
||||
// at this particular state. This function implements https://matrix.org/docs/spec/client_server/r0.6.0#id87
|
||||
func IsServerAllowed(
|
||||
ctx context.Context, db storage.RoomDatabase,
|
||||
ctx context.Context, querier api.QuerySenderIDAPI,
|
||||
serverName spec.ServerName,
|
||||
serverCurrentlyInRoom bool,
|
||||
authEvents []gomatrixserverlib.PDU,
|
||||
|
@ -41,7 +41,7 @@ func IsServerAllowed(
|
|||
return true
|
||||
}
|
||||
// 2. If the user's membership was join, allow.
|
||||
joinedUserExists := IsAnyUserOnServerWithMembership(ctx, db, serverName, authEvents, spec.Join)
|
||||
joinedUserExists := IsAnyUserOnServerWithMembership(ctx, querier, serverName, authEvents, spec.Join)
|
||||
if joinedUserExists {
|
||||
return true
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ func IsServerAllowed(
|
|||
return true
|
||||
}
|
||||
// 4. If the user's membership was invite, and the history_visibility was set to invited, allow.
|
||||
invitedUserExists := IsAnyUserOnServerWithMembership(ctx, db, serverName, authEvents, spec.Invite)
|
||||
invitedUserExists := IsAnyUserOnServerWithMembership(ctx, querier, serverName, authEvents, spec.Invite)
|
||||
if invitedUserExists && historyVisibility == gomatrixserverlib.HistoryVisibilityInvited {
|
||||
return true
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ func HistoryVisibilityForRoom(authEvents []gomatrixserverlib.PDU) gomatrixserver
|
|||
return visibility
|
||||
}
|
||||
|
||||
func IsAnyUserOnServerWithMembership(ctx context.Context, db storage.RoomDatabase, serverName spec.ServerName, authEvents []gomatrixserverlib.PDU, wantMembership string) bool {
|
||||
func IsAnyUserOnServerWithMembership(ctx context.Context, querier api.QuerySenderIDAPI, serverName spec.ServerName, authEvents []gomatrixserverlib.PDU, wantMembership string) bool {
|
||||
for _, ev := range authEvents {
|
||||
if ev.Type() != spec.MRoomMember {
|
||||
continue
|
||||
|
@ -89,7 +89,11 @@ func IsAnyUserOnServerWithMembership(ctx context.Context, db storage.RoomDatabas
|
|||
continue
|
||||
}
|
||||
|
||||
userID, err := db.GetUserIDForSender(ctx, ev.RoomID(), spec.SenderID(*stateKey))
|
||||
validRoomID, err := spec.NewRoomID(ev.RoomID())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
userID, err := querier.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(*stateKey))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue