From 2c43e222bd57cbb1e278ff776f7a2aa2221ac1e8 Mon Sep 17 00:00:00 2001 From: mohit kumar singh Date: Tue, 14 Apr 2020 20:01:27 +0530 Subject: [PATCH] support non-exclusive namespaces for AS (#828) Signed-off-by: MohitKS5 Co-authored-by: Neil Alexander Co-authored-by: Kegsay --- clientapi/routing/register.go | 4 ++-- common/config/appservice.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/clientapi/routing/register.go b/clientapi/routing/register.go index 2de7b273..b67e68e1 100644 --- a/clientapi/routing/register.go +++ b/clientapi/routing/register.go @@ -362,7 +362,7 @@ func UsernameMatchesMultipleExclusiveNamespaces( // Check namespaces and see if more than one match matchCount := 0 for _, appservice := range cfg.Derived.ApplicationServices { - if appservice.IsInterestedInUserID(userID) { + if appservice.OwnsNamespaceCoveringUserId(userID) { if matchCount++; matchCount > 1 { return true } @@ -1000,7 +1000,7 @@ func RegisterAvailable( // Check if this username is reserved by an application service userID := userutil.MakeUserID(username, cfg.Matrix.ServerName) for _, appservice := range cfg.Derived.ApplicationServices { - if appservice.IsInterestedInUserID(userID) { + if appservice.OwnsNamespaceCoveringUserId(userID) { return util.JSONResponse{ Code: http.StatusBadRequest, JSON: jsonerror.UserInUse("Desired user ID is reserved by an application service."), diff --git a/common/config/appservice.go b/common/config/appservice.go index 7a43d48f..bf5f089b 100644 --- a/common/config/appservice.go +++ b/common/config/appservice.go @@ -98,6 +98,22 @@ func (a *ApplicationService) IsInterestedInUserID( return false } +// OwnsNamespaceCoveringUserId returns a bool on whether an application service's +// namespace is exclusive and includes the given user ID +func (a *ApplicationService) OwnsNamespaceCoveringUserId( + userID string, +) bool { + if namespaceSlice, ok := a.NamespaceMap["users"]; ok { + for _, namespace := range namespaceSlice { + if namespace.Exclusive && namespace.RegexpObject.MatchString(userID) { + return true + } + } + } + + return false +} + // IsInterestedInRoomAlias returns a bool on whether an application service's // namespace includes the given room alias func (a *ApplicationService) IsInterestedInRoomAlias(