summary refs log tree commit diff
path: root/synapse/event_auth.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2018-06-14 12:28:36 +0100
committerRichard van der Hoff <richard@matrix.org>2018-06-14 12:38:09 +0100
commit5c9afd6f80cf04367fe9b02c396af9f85e02a611 (patch)
treefc4f86acc126c9498c130f80a7916d5db78b10e7 /synapse/event_auth.py
parentClarify interface for event_auth (diff)
downloadsynapse-5c9afd6f80cf04367fe9b02c396af9f85e02a611.tar.xz
Make default state_default 50
Make it so that, before there is a power-levels event in the room, you need a
power level of at least 50 to send state.

Partially addresses https://github.com/matrix-org/matrix-doc/issues/1192
Diffstat (limited to 'synapse/event_auth.py')
-rw-r--r--synapse/event_auth.py34
1 files changed, 14 insertions, 20 deletions
diff --git a/synapse/event_auth.py b/synapse/event_auth.py
index 36a48870a0..f512d88145 100644
--- a/synapse/event_auth.py
+++ b/synapse/event_auth.py
@@ -370,28 +370,22 @@ def get_send_level(etype, state_key, power_levels_event):
         int: power level required to send this event.
     """
 
-    send_level_event = power_levels_event  # todo: rename refs below
-    send_level = None
-    if send_level_event:
-        send_level = send_level_event.content.get("events", {}).get(
-            etype
-        )
-        if send_level is None:
-            if state_key is not None:
-                send_level = send_level_event.content.get(
-                    "state_default", 50
-                )
-            else:
-                send_level = send_level_event.content.get(
-                    "events_default", 0
-                )
-
-    if send_level:
-        send_level = int(send_level)
+    if power_levels_event:
+        power_levels_content = power_levels_event.content
     else:
-        send_level = 0
+        power_levels_content = {}
+
+    # see if we have a custom level for this event type
+    send_level = power_levels_content.get("events", {}).get(etype)
+
+    # otherwise, fall back to the state_default/events_default.
+    if send_level is None:
+        if state_key is not None:
+            send_level = power_levels_content.get("state_default", 50)
+        else:
+            send_level = power_levels_content.get("events_default", 0)
 
-    return send_level
+    return int(send_level)
 
 
 def _can_send_event(event, auth_events):