mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-19 17:54:18 -05:00
Merge pull request #2296 from matrix-org/erikj/dont_appserver_shar
Don't work out users who share room with appservice users
This commit is contained in:
commit
b668112320
@ -25,8 +25,8 @@ from synapse.http.site import SynapseSite
|
|||||||
from synapse.http.server import JsonResource
|
from synapse.http.server import JsonResource
|
||||||
from synapse.metrics.resource import MetricsResource, METRICS_PREFIX
|
from synapse.metrics.resource import MetricsResource, METRICS_PREFIX
|
||||||
from synapse.replication.slave.storage._base import BaseSlavedStore
|
from synapse.replication.slave.storage._base import BaseSlavedStore
|
||||||
from synapse.replication.slave.storage.events import SlavedEventStore
|
|
||||||
from synapse.replication.slave.storage.appservice import SlavedApplicationServiceStore
|
from synapse.replication.slave.storage.appservice import SlavedApplicationServiceStore
|
||||||
|
from synapse.replication.slave.storage.events import SlavedEventStore
|
||||||
from synapse.replication.slave.storage.registration import SlavedRegistrationStore
|
from synapse.replication.slave.storage.registration import SlavedRegistrationStore
|
||||||
from synapse.replication.tcp.client import ReplicationClientHandler
|
from synapse.replication.tcp.client import ReplicationClientHandler
|
||||||
from synapse.rest.client.v2_alpha import user_directory
|
from synapse.rest.client.v2_alpha import user_directory
|
||||||
|
@ -205,6 +205,10 @@ class UserDirectoyHandler(object):
|
|||||||
count += 1
|
count += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if self.store.get_if_app_services_interested_in_user(user_id):
|
||||||
|
count += 1
|
||||||
|
continue
|
||||||
|
|
||||||
for other_user_id in user_ids:
|
for other_user_id in user_ids:
|
||||||
if user_id == other_user_id:
|
if user_id == other_user_id:
|
||||||
continue
|
continue
|
||||||
@ -411,8 +415,10 @@ class UserDirectoyHandler(object):
|
|||||||
to_insert = set()
|
to_insert = set()
|
||||||
to_update = set()
|
to_update = set()
|
||||||
|
|
||||||
|
is_appservice = self.store.get_if_app_services_interested_in_user(user_id)
|
||||||
|
|
||||||
# First, if they're our user then we need to update for every user
|
# First, if they're our user then we need to update for every user
|
||||||
if self.is_mine_id(user_id):
|
if self.is_mine_id(user_id) and not is_appservice:
|
||||||
# Returns a map of other_user_id -> shared_private. We only need
|
# Returns a map of other_user_id -> shared_private. We only need
|
||||||
# to update mappings if for users that either don't share a room
|
# to update mappings if for users that either don't share a room
|
||||||
# already (aren't in the map) or, if the room is private, those that
|
# already (aren't in the map) or, if the room is private, those that
|
||||||
@ -443,7 +449,10 @@ class UserDirectoyHandler(object):
|
|||||||
if user_id == other_user_id:
|
if user_id == other_user_id:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if self.is_mine_id(other_user_id):
|
is_appservice = self.store.get_if_app_services_interested_in_user(
|
||||||
|
other_user_id
|
||||||
|
)
|
||||||
|
if self.is_mine_id(other_user_id) and not is_appservice:
|
||||||
shared_is_private = yield self.store.get_if_users_share_a_room(
|
shared_is_private = yield self.store.get_if_users_share_a_room(
|
||||||
other_user_id, user_id,
|
other_user_id, user_id,
|
||||||
)
|
)
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
from ._base import BaseSlavedStore
|
from ._base import BaseSlavedStore
|
||||||
from synapse.storage import DataStore
|
from synapse.storage import DataStore
|
||||||
from synapse.config.appservice import load_appservices
|
from synapse.config.appservice import load_appservices
|
||||||
|
from synapse.storage.appservice import _make_exclusive_regex
|
||||||
|
|
||||||
|
|
||||||
class SlavedApplicationServiceStore(BaseSlavedStore):
|
class SlavedApplicationServiceStore(BaseSlavedStore):
|
||||||
@ -25,6 +26,7 @@ class SlavedApplicationServiceStore(BaseSlavedStore):
|
|||||||
hs.config.server_name,
|
hs.config.server_name,
|
||||||
hs.config.app_service_config_files
|
hs.config.app_service_config_files
|
||||||
)
|
)
|
||||||
|
self.exclusive_user_regex = _make_exclusive_regex(self.services_cache)
|
||||||
|
|
||||||
get_app_service_by_token = DataStore.get_app_service_by_token.__func__
|
get_app_service_by_token = DataStore.get_app_service_by_token.__func__
|
||||||
get_app_service_by_user_id = DataStore.get_app_service_by_user_id.__func__
|
get_app_service_by_user_id = DataStore.get_app_service_by_user_id.__func__
|
||||||
@ -38,3 +40,6 @@ class SlavedApplicationServiceStore(BaseSlavedStore):
|
|||||||
get_appservice_state = DataStore.get_appservice_state.__func__
|
get_appservice_state = DataStore.get_appservice_state.__func__
|
||||||
set_appservice_last_pos = DataStore.set_appservice_last_pos.__func__
|
set_appservice_last_pos = DataStore.set_appservice_last_pos.__func__
|
||||||
set_appservice_state = DataStore.set_appservice_state.__func__
|
set_appservice_state = DataStore.set_appservice_state.__func__
|
||||||
|
get_if_app_services_interested_in_user = (
|
||||||
|
DataStore.get_if_app_services_interested_in_user.__func__
|
||||||
|
)
|
||||||
|
@ -27,6 +27,25 @@ from ._base import SQLBaseStore
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def _make_exclusive_regex(services_cache):
|
||||||
|
# We precompie a regex constructed from all the regexes that the AS's
|
||||||
|
# have registered for exclusive users.
|
||||||
|
exclusive_user_regexes = [
|
||||||
|
regex.pattern
|
||||||
|
for service in services_cache
|
||||||
|
for regex in service.get_exlusive_user_regexes()
|
||||||
|
]
|
||||||
|
if exclusive_user_regexes:
|
||||||
|
exclusive_user_regex = "|".join("(" + r + ")" for r in exclusive_user_regexes)
|
||||||
|
exclusive_user_regex = re.compile(exclusive_user_regex)
|
||||||
|
else:
|
||||||
|
# We handle this case specially otherwise the constructed regex
|
||||||
|
# will always match
|
||||||
|
exclusive_user_regex = None
|
||||||
|
|
||||||
|
return exclusive_user_regex
|
||||||
|
|
||||||
|
|
||||||
class ApplicationServiceStore(SQLBaseStore):
|
class ApplicationServiceStore(SQLBaseStore):
|
||||||
|
|
||||||
def __init__(self, hs):
|
def __init__(self, hs):
|
||||||
@ -36,21 +55,7 @@ class ApplicationServiceStore(SQLBaseStore):
|
|||||||
hs.hostname,
|
hs.hostname,
|
||||||
hs.config.app_service_config_files
|
hs.config.app_service_config_files
|
||||||
)
|
)
|
||||||
|
self.exclusive_user_regex = _make_exclusive_regex(self.services_cache)
|
||||||
# We precompie a regex constructed from all the regexes that the AS's
|
|
||||||
# have registered for exclusive users.
|
|
||||||
exclusive_user_regexes = [
|
|
||||||
regex.pattern
|
|
||||||
for service in self.services_cache
|
|
||||||
for regex in service.get_exlusive_user_regexes()
|
|
||||||
]
|
|
||||||
if exclusive_user_regexes:
|
|
||||||
exclusive_user_regex = "|".join("(" + r + ")" for r in exclusive_user_regexes)
|
|
||||||
self.exclusive_user_regex = re.compile(exclusive_user_regex)
|
|
||||||
else:
|
|
||||||
# We handle this case specially otherwise the constructed regex
|
|
||||||
# will always match
|
|
||||||
self.exclusive_user_regex = None
|
|
||||||
|
|
||||||
def get_app_services(self):
|
def get_app_services(self):
|
||||||
return self.services_cache
|
return self.services_cache
|
||||||
|
Loading…
Reference in New Issue
Block a user