From 0467357c8c89dbc359d21259c3af1571ac0fc291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Rodr=C3=ADguez?= Date: Tue, 5 Sep 2023 16:36:09 -0400 Subject: [PATCH] add denylist for allow_invited --- .../src/uplink_synapse_module/student_only_rooms.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/uplink_synapse_module/src/uplink_synapse_module/student_only_rooms.py b/uplink_synapse_module/src/uplink_synapse_module/student_only_rooms.py index 249d9f0..d4f838f 100644 --- a/uplink_synapse_module/src/uplink_synapse_module/student_only_rooms.py +++ b/uplink_synapse_module/src/uplink_synapse_module/student_only_rooms.py @@ -20,6 +20,9 @@ @dataclass_json @dataclass class Config: + # Inviters to ignore the following list for + deny_inviters: list[str] + # Allow invited users to join allow_invited: bool = True @@ -59,6 +62,12 @@ async def is_mit_student(self, user: str) -> bool: affiliation = await self.get_affiliation(user) print(f"[uplink_synapse_module] {user}'s affiliation is {affiliation}") return affiliation == 'student@mit.edu' + + async def who_invited(self, user: str, room: str) -> bool: + event_key = ('m.room.member', user) + state = await self.api.get_room_state(room, [event_key]) + invitation = state[event_key] + return invitation.sender async def user_may_join_room(self, user: str, room: str, is_invited: bool): # We are choosing to use the empty string as state key since we don't need one @@ -72,7 +81,8 @@ async def user_may_join_room(self, user: str, room: str, is_invited: bool): print("[uplink_synapse_module] user_may_join_room called on", user, "and", room) # Allow invited users to join if the config says so - if self.config.allow_invited and is_invited: + if self.config.allow_invited and is_invited \ + and await self.who_invited(user, room) not in self.config.deny_inviters: print("[uplink_synapse_module]", "user was invited, accepting") return NOT_SPAM if await self.is_mit_student(user):