def check_can_change_room_list(self, room_id, user): """Check if the user is allowed to edit the room's entry in the published room list. Args: room_id (str) user (UserID) """ is_admin = yield self.is_server_admin(user) if is_admin: defer.returnValue(True) user_id = user.to_string() yield self.check_joined_room(room_id, user_id) # We currently require the user is a "moderator" in the room. We do this # by checking if they would (theoretically) be able to change the # m.room.aliases events power_level_event = yield self.state.get_current_state( room_id, EventTypes.PowerLevels, "") auth_events = {} if power_level_event: auth_events[(EventTypes.PowerLevels, "")] = power_level_event send_level = event_auth.get_send_level(EventTypes.Aliases, "", auth_events) user_level = event_auth.get_user_power_level(user_id, auth_events) if user_level < send_level: raise AuthError( 403, "This server requires you to be a moderator in the room to" " edit its room list entry")
async def check_can_change_room_list(self, room_id: str, user: UserID) -> bool: """Determine whether the user is allowed to edit the room's entry in the published room list. Args: room_id user """ is_admin = await self.is_server_admin(user) if is_admin: return True user_id = user.to_string() await self.check_user_in_room(room_id, user_id) # We currently require the user is a "moderator" in the room. We do this # by checking if they would (theoretically) be able to change the # m.room.canonical_alias events power_level_event = await self.state.get_current_state( room_id, EventTypes.PowerLevels, "") auth_events = {} if power_level_event: auth_events[(EventTypes.PowerLevels, "")] = power_level_event send_level = event_auth.get_send_level(EventTypes.CanonicalAlias, "", power_level_event) user_level = event_auth.get_user_power_level(user_id, auth_events) return user_level >= send_level
def check_can_change_room_list(self, room_id, user): """Check if the user is allowed to edit the room's entry in the published room list. Args: room_id (str) user (UserID) """ is_admin = yield self.is_server_admin(user) if is_admin: defer.returnValue(True) user_id = user.to_string() yield self.check_joined_room(room_id, user_id) # We currently require the user is a "moderator" in the room. We do this # by checking if they would (theoretically) be able to change the # m.room.aliases events power_level_event = yield self.state.get_current_state( room_id, EventTypes.PowerLevels, "" ) auth_events = {} if power_level_event: auth_events[(EventTypes.PowerLevels, "")] = power_level_event send_level = event_auth.get_send_level( EventTypes.Aliases, "", power_level_event, ) user_level = event_auth.get_user_power_level(user_id, auth_events) if user_level < send_level: raise AuthError( 403, "This server requires you to be a moderator in the room to" " edit its room list entry" )