Skip to content

Commit

Permalink
Respect ban membership
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Mar 16, 2015
1 parent d517406 commit ab82294
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions synapse/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def is_membership_change_allowed(self, event, auth_events):
target = auth_events.get(key)

target_in_room = target and target.membership == Membership.JOIN
target_banned = target and target.membership == Membership.BAN

key = (EventTypes.JoinRules, "", )
join_rule_event = auth_events.get(key)
Expand Down Expand Up @@ -194,6 +195,7 @@ def is_membership_change_allowed(self, event, auth_events):
{
"caller_in_room": caller_in_room,
"caller_invited": caller_invited,
"target_banned": target_banned,
"target_in_room": target_in_room,
"membership": membership,
"join_rule": join_rule,
Expand All @@ -202,6 +204,11 @@ def is_membership_change_allowed(self, event, auth_events):
}
)

if ban_level:
ban_level = int(ban_level)
else:
ban_level = 50 # FIXME (erikj): What should we do here?

if Membership.INVITE == membership:
# TODO (erikj): We should probably handle this more intelligently
# PRIVATE join rules.
Expand All @@ -212,6 +219,10 @@ def is_membership_change_allowed(self, event, auth_events):
403,
"%s not in room %s." % (event.user_id, event.room_id,)
)
elif target_banned:
raise AuthError(
403, "%s is banned from the room" % (target_user_id,)
)
elif target_in_room: # the target is already in the room.
raise AuthError(403, "%s is already in the room." %
target_user_id)
Expand All @@ -221,6 +232,8 @@ def is_membership_change_allowed(self, event, auth_events):
# joined: It's a NOOP
if event.user_id != target_user_id:
raise AuthError(403, "Cannot force another user to join.")
elif target_banned:
raise AuthError(403, "You are banned from this room")
elif join_rule == JoinRules.PUBLIC:
pass
elif join_rule == JoinRules.INVITE:
Expand All @@ -238,6 +251,10 @@ def is_membership_change_allowed(self, event, auth_events):
403,
"%s not in room %s." % (target_user_id, event.room_id,)
)
elif target_banned and user_level < ban_level:
raise AuthError(
403, "You cannot unban user &s." % (target_user_id,)
)
elif target_user_id != event.user_id:
if kick_level:
kick_level = int(kick_level)
Expand All @@ -249,11 +266,6 @@ def is_membership_change_allowed(self, event, auth_events):
403, "You cannot kick user %s." % target_user_id
)
elif Membership.BAN == membership:
if ban_level:
ban_level = int(ban_level)
else:
ban_level = 50 # FIXME (erikj): What should we do here?

if user_level < ban_level:
raise AuthError(403, "You don't have permission to ban")
else:
Expand Down

0 comments on commit ab82294

Please sign in to comment.