diff options
author | Andrew Morgan <andrew@amorgan.xyz> | 2021-12-09 18:37:50 +0000 |
---|---|---|
committer | Andrew Morgan <andrew@amorgan.xyz> | 2021-12-09 18:37:50 +0000 |
commit | b4336fc9e06890967c7ecaf739d7cc1513e05ce9 (patch) | |
tree | fbbd6e725b3da1a69e18b4167aba62d4a31e65f7 | |
parent | Support sending device lists everywhere; needs cleaning up (diff) | |
download | synapse-b4336fc9e06890967c7ecaf739d7cc1513e05ce9.tar.xz |
squash into 'and use everywhere'
-rw-r--r-- | synapse/api/auth.py | 2 | ||||
-rw-r--r-- | synapse/appservice/__init__.py | 10 | ||||
-rw-r--r-- | synapse/appservice/api.py | 2 | ||||
-rw-r--r-- | synapse/handlers/appservice.py | 6 | ||||
-rw-r--r-- | synapse/handlers/message.py | 2 | ||||
-rw-r--r-- | synapse/handlers/register.py | 4 | ||||
-rw-r--r-- | synapse/rest/client/login.py | 2 | ||||
-rw-r--r-- | tests/api/test_auth.py | 4 | ||||
-rw-r--r-- | tests/handlers/test_appservice.py | 4 |
9 files changed, 18 insertions, 18 deletions
diff --git a/synapse/api/auth.py b/synapse/api/auth.py index 2b73c66071..44883c6663 100644 --- a/synapse/api/auth.py +++ b/synapse/api/auth.py @@ -263,7 +263,7 @@ class Auth: if app_service.sender == user_id: pass # Check to make sure the app service is allowed to control the user - elif not app_service.is_user_in_namespace(user_id): + elif not app_service.is_interested_in_user(user_id): raise AuthError( 403, "Application service cannot masquerade as this user (%s)." % user_id, diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index 382b174d81..09d49471ba 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -167,7 +167,7 @@ class ApplicationService: # check joined member events for user_id in member_list: - if self.is_user_in_namespace(user_id): + if self.is_interested_in_user(user_id): return True return False @@ -193,7 +193,7 @@ class ApplicationService: # User is the appservice's sender_localpart user user_id == self.sender # User is in a defined namespace - or self.is_user_in_namespace(user_id) + or self.is_interested_in_user(user_id) ) @cached(num_args=1, cache_context=True) @@ -259,11 +259,11 @@ class ApplicationService: # Check if we're interested in this user by namespace (or if they're the # sender_localpart user) - if self.is_user_in_namespace(event.sender): + if self.is_interested_in_user(event.sender): return True # or, if this is a membership event, the user it references by namespace - if event.type == EventTypes.Member and self.is_user_in_namespace( + if event.type == EventTypes.Member and self.is_interested_in_user( event.state_key ): return True @@ -292,7 +292,7 @@ class ApplicationService: True if this service would like to know about presence for this user. """ # Find all the rooms the sender is in - if self.is_user_in_namespace(user_id.to_string()): + if self.is_interested_in_user(user_id.to_string()): return True room_ids = await store.get_rooms_for_user(user_id.to_string()) diff --git a/synapse/appservice/api.py b/synapse/appservice/api.py index 0b504b3fc8..3ae59c7a04 100644 --- a/synapse/appservice/api.py +++ b/synapse/appservice/api.py @@ -308,7 +308,7 @@ class ApplicationServiceApi(SimpleHttpClient): e.membership == Membership.INVITE or e.membership == Membership.KNOCK ) - and service.is_user_in_namespace(e.state_key) + and service.is_interested_in_user(e.state_key) ), ) for e in events diff --git a/synapse/handlers/appservice.py b/synapse/handlers/appservice.py index 91de1f6652..3dc0d89530 100644 --- a/synapse/handlers/appservice.py +++ b/synapse/handlers/appservice.py @@ -522,7 +522,7 @@ class ApplicationServicesHandler: if isinstance(user, UserID): user = user.to_string() - if service.is_user_in_namespace(user): + if service.is_interested_in_user(user): users_appservice_is_interested_in.append(user) if not users_appservice_is_interested_in: @@ -636,7 +636,7 @@ class ApplicationServicesHandler: True if the application service is interested in the user's device lists, False otherwise. """ - if appservice.is_user_in_namespace(user_id): + if appservice.is_interested_in_user(user_id): return True # FIXME: This is quite an expensive check. This method is called per device @@ -775,7 +775,7 @@ class ApplicationServicesHandler: def _get_services_for_user(self, user_id: str) -> List[ApplicationService]: services = self.store.get_app_services() - return [s for s in services if (s.is_user_in_namespace(user_id))] + return [s for s in services if (s.is_interested_in_user(user_id))] def _get_services_for_3pn(self, protocol: str) -> List[ApplicationService]: services = self.store.get_app_services() diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index c385813493..87f671708c 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -280,7 +280,7 @@ class MessageHandler: # is a user in the room that the AS is "interested in" if requester.app_service and user_id not in users_with_profile: for uid in users_with_profile: - if requester.app_service.is_user_in_namespace(uid): + if requester.app_service.is_interested_in_user(uid): break else: # Loop fell through, AS has no interested users in room diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py index ab3d5c9456..f08a516a75 100644 --- a/synapse/handlers/register.py +++ b/synapse/handlers/register.py @@ -615,7 +615,7 @@ class RegistrationHandler: service = self.store.get_app_service_by_token(as_token) if not service: raise AuthError(403, "Invalid application service token.") - if not service.is_user_in_namespace(user_id): + if not service.is_interested_in_user(user_id): raise SynapseError( 400, "Invalid user localpart for this application service.", @@ -650,7 +650,7 @@ class RegistrationHandler: interested_services = [ s for s in services - if s.is_user_in_namespace(user_id) and s != allowed_appservice + if s.is_interested_in_user(user_id) and s != allowed_appservice ] for service in interested_services: if service.is_exclusive_user(user_id): diff --git a/synapse/rest/client/login.py b/synapse/rest/client/login.py index abb9d49f9f..f9994658c4 100644 --- a/synapse/rest/client/login.py +++ b/synapse/rest/client/login.py @@ -249,7 +249,7 @@ class LoginRestServlet(RestServlet): else: qualified_user_id = UserID(user, self.hs.hostname).to_string() - if not appservice.is_user_in_namespace(qualified_user_id): + if not appservice.is_interested_in_user(qualified_user_id): raise LoginError(403, "Invalid access_token", errcode=Codes.FORBIDDEN) return await self._complete_login( diff --git a/tests/api/test_auth.py b/tests/api/test_auth.py index 0693da1cf6..3aa9ba3c43 100644 --- a/tests/api/test_auth.py +++ b/tests/api/test_auth.py @@ -178,7 +178,7 @@ class AuthTestCase(unittest.HomeserverTestCase): app_service = Mock( token="foobar", url="a_url", sender=self.test_user, ip_range_whitelist=None ) - app_service.is_user_in_namespace = Mock(return_value=True) + app_service.is_interested_in_user = Mock(return_value=True) self.store.get_app_service_by_token = Mock(return_value=app_service) # This just needs to return a truth-y value. self.store.get_user_by_id = simple_async_mock({"is_guest": False}) @@ -199,7 +199,7 @@ class AuthTestCase(unittest.HomeserverTestCase): app_service = Mock( token="foobar", url="a_url", sender=self.test_user, ip_range_whitelist=None ) - app_service.is_user_in_namespace = Mock(return_value=False) + app_service.is_interested_in_user = Mock(return_value=False) self.store.get_app_service_by_token = Mock(return_value=app_service) self.store.get_user_by_access_token = simple_async_mock(None) diff --git a/tests/handlers/test_appservice.py b/tests/handlers/test_appservice.py index 9a84ff78d2..42b2de0927 100644 --- a/tests/handlers/test_appservice.py +++ b/tests/handlers/test_appservice.py @@ -78,7 +78,7 @@ class AppServiceHandlerTestCase(unittest.TestCase): def test_query_user_exists_unknown_user(self): user_id = "@someone:anywhere" services = [self._mkservice(is_interested=True)] - services[0].is_user_in_namespace.return_value = True + services[0].is_interested_in_user.return_value = True self.mock_store.get_app_services.return_value = services self.mock_store.get_user_by_id.return_value = make_awaitable(None) @@ -95,7 +95,7 @@ class AppServiceHandlerTestCase(unittest.TestCase): def test_query_user_exists_known_user(self): user_id = "@someone:anywhere" services = [self._mkservice(is_interested=True)] - services[0].is_user_in_namespace.return_value = True + services[0].is_interested_in_user.return_value = True self.mock_store.get_app_services.return_value = services self.mock_store.get_user_by_id.return_value = make_awaitable({"name": user_id}) |