summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorLuke Barnard <lukeb@openmarket.com>2016-10-20 12:04:54 +0100
committerLuke Barnard <lukeb@openmarket.com>2016-10-20 12:04:54 +0100
commitf09db236b1867a20ef1328af40a2422bca35944e (patch)
treefbb76e62a298621c517934d6a8c32943509e6c31 /synapse
parentflake8 (diff)
downloadsynapse-f09db236b1867a20ef1328af40a2422bca35944e.tar.xz
as_user->app_service, less redundant comments, better positioned comments
Diffstat (limited to '')
-rw-r--r--synapse/api/auth.py6
-rw-r--r--synapse/handlers/_base.py9
-rw-r--r--synapse/types.py10
3 files changed, 11 insertions, 14 deletions
diff --git a/synapse/api/auth.py b/synapse/api/auth.py
index 5fc0150bdc..154af6728a 100644
--- a/synapse/api/auth.py
+++ b/synapse/api/auth.py
@@ -603,11 +603,11 @@ class Auth(object):
         """
         # Can optionally look elsewhere in the request (e.g. headers)
         try:
-            user_id, as_user = yield self._get_appservice_user_id(request)
+            user_id, app_service = yield self._get_appservice_user_id(request)
             if user_id:
                 request.authenticated_entity = user_id
                 defer.returnValue(
-                    synapse.types.create_requester(user_id, as_user=as_user)
+                    synapse.types.create_requester(user_id, app_service=app_service)
                 )
 
             access_token = get_access_token_from_request(
@@ -646,7 +646,7 @@ class Auth(object):
             request.authenticated_entity = user.to_string()
 
             defer.returnValue(synapse.types.create_requester(
-                user, token_id, is_guest, device_id, as_user=as_user))
+                user, token_id, is_guest, device_id, app_service=app_service))
         except KeyError:
             raise AuthError(
                 self.TOKEN_NOT_FOUND_HTTP_STATUS, "Missing access token.",
diff --git a/synapse/handlers/_base.py b/synapse/handlers/_base.py
index ba62746214..90f96209f8 100644
--- a/synapse/handlers/_base.py
+++ b/synapse/handlers/_base.py
@@ -57,17 +57,14 @@ class BaseHandler(object):
         time_now = self.clock.time()
         user_id = requester.user.to_string()
 
-        # Disable rate limiting of users belonging to any AS that is configured
-        # not to be rate limited in its registration file (rate_limited: true|false).
         # The AS user itself is never rate limited.
-
         app_service = self.store.get_app_service_by_user_id(user_id)
         if app_service is not None:
             return  # do not ratelimit app service senders
 
-        if requester.as_user and not requester.as_user.is_rate_limited():
-            # do not ratelimit users of which a non-rate-limited AS is
-            # acting on behalf
+        # Disable rate limiting of users belonging to any AS that is configured
+        # not to be rate limited in its registration file (rate_limited: true|false).
+        if requester.app_service and not requester.app_service.is_rate_limited():
             return
 
         allowed, time_allowed = self.ratelimiter.send_message(
diff --git a/synapse/types.py b/synapse/types.py
index 35e05b9c41..2b8afa9aab 100644
--- a/synapse/types.py
+++ b/synapse/types.py
@@ -19,7 +19,7 @@ from collections import namedtuple
 
 
 Requester = namedtuple("Requester",
-                       ["user", "access_token_id", "is_guest", "device_id", "as_user"])
+                       ["user", "access_token_id", "is_guest", "device_id", "app_service"])
 """
 Represents the user making a request
 
@@ -29,12 +29,12 @@ Attributes:
         request, or None if it came via the appservice API or similar
     is_guest (bool):  True if the user making this request is a guest user
     device_id (str|None):  device_id which was set at authentication time
-    as_user (ApplicationService|None):  the AS requesting on behalf of the user
+    app_service (ApplicationService|None):  the AS requesting on behalf of the user
 """
 
 
 def create_requester(user_id, access_token_id=None, is_guest=False,
-                     device_id=None, as_user=None):
+                     device_id=None, app_service=None):
     """
     Create a new ``Requester`` object
 
@@ -44,14 +44,14 @@ def create_requester(user_id, access_token_id=None, is_guest=False,
             request, or None if it came via the appservice API or similar
         is_guest (bool):  True if the user making this request is a guest user
         device_id (str|None):  device_id which was set at authentication time
-        as_user (ApplicationService|None):  the AS requesting on behalf of the user
+        app_service (ApplicationService|None):  the AS requesting on behalf of the user
 
     Returns:
         Requester
     """
     if not isinstance(user_id, UserID):
         user_id = UserID.from_string(user_id)
-    return Requester(user_id, access_token_id, is_guest, device_id, as_user)
+    return Requester(user_id, access_token_id, is_guest, device_id, app_service)
 
 
 def get_domain_from_id(string):