def ban_user(): form = request.get_json() target = form['target'] target_uuid = form['target_uuid'] user_uuid = form['user_uuid'] duration = form['duration'] try: user_manager.ban_user(user_uuid, target_uuid, duration, target) except ValidationException as e: return api_response(400, message='invalid duration: %s' % str(e)) except UnknownBanTypeException as e: return api_response(400, message='could not ban user: %s' % str(e)) except Exception as e: logger.exception(traceback.format_exc()) return api_response(400, message=str(e)) try: user = user_manager.get_user(user_uuid) user['name'] = utils.b64d(user['name']) user['duration'] = duration except NoSuchUserException: return api_response(400, message="No such user.") if target == 'channel': user['channel'] = { 'uuid': target_uuid, 'name': channel_manager.name_for_uuid(target_uuid) } elif target == 'room': user['room'] = { 'uuid': target_uuid, 'name': room_manager.name_for_uuid(target_uuid) } return api_response(200, user)
def add_room_moderator(room_uuid: str): form = request.get_json() user_uuid = form['moderator'] if is_blank(user_uuid): return api_response(400, message='Blank user id is not allowed.') try: user = user_manager.get_user(user_uuid) user['name'] = utils.b64d(user['name']) except NoSuchUserException: return api_response(400, message='No Such User.') user_manager.add_room_moderator(room_uuid, user_uuid) return api_response(200, user)
def get_user(user_uuid: str): try: user = user_manager.get_user(user_uuid) except NoSuchUserException: return api_response(400, message='No Such User.') return api_response(200, user)
def user(user_uuid: str): return render_template('user.html', user=user_manager.get_user(user_uuid))