Skip to content

Commit

Permalink
add denylist for allow_invited
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrc52 committed Sep 5, 2023
1 parent 7fbfd95 commit 0467357
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 == '[email protected]'

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
Expand All @@ -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):
Expand Down

0 comments on commit 0467357

Please sign in to comment.