예제 #1
0
    def get_logs(page, limit, search, session=None):
        if not is_admin():
            raise AuthorizationException()
        logs = session.query(ReplayLog).order_by(desc(ReplayLog.id))
        if search is not None:
            search = f"%{search}%"
            logs = logs.filter(or_(
                ReplayLog.uuid.like(search),
                ReplayLog.game.like(search),
                ReplayLog.error_type.like(search),
                ReplayLog.log.like(search),
                ReplayLog.params.like(search)
            ))

        return {
            'logs': [
                {
                    'id': log.id,
                    'uuid': log.uuid,
                    'game': log.game,
                    'errorType': log.error_type,
                    'log': log.log,
                    'params': log.params,
                    'result': log.result.value

                } for log in logs[page * limit: (page + 1) * limit]
            ],
            'count': logs.count()
        }
예제 #2
0
def update_self(code):
    if code != update_code or not is_admin():
        raise AuthorizationException()

    script = os.path.join(BASE_FOLDER, 'update_run.sh')
    if update_code == 1234 or is_local_dev():
        subprocess.call([script, 'test'])
    else:
        subprocess.call([script])
예제 #3
0
 def rename_entry(uuid, name, session=None):
     current_user = UserManager.get_current_user().platformid
     entry: GroupEntry = session.query(GroupEntry).filter(
         GroupEntry.uuid == uuid).first()
     if entry.owner != current_user:
         raise AuthorizationException()
     entry.name = name
     session.add(entry)
     session.commit()
     return entry.uuid
예제 #4
0
 def delete_entry(uuid, session=None):
     current_user = UserManager.get_current_user().platformid
     entry = session.query(GroupEntry).filter(
         GroupEntry.uuid == uuid).first()
     if entry.owner != current_user:
         raise AuthorizationException()
     descendants = session.query(GroupEntry).filter(
         GroupEntry.path.descendant_of(entry.path)).all()
     for desc in descendants:
         session.delete(desc)
     session.delete(entry)
     session.commit()
     return entry.uuid
예제 #5
0
 def add_subgroup(parent_uuid, name=None, session=None):
     current_user = UserManager.get_current_user().platformid
     parent = session.query(GroupEntry).filter(
         GroupEntry.uuid == parent_uuid).first()
     if parent.owner != current_user:
         raise AuthorizationException()
     entry = GroupEntry(engine=session.get_bind(),
                        name=name,
                        owner=parent.owner,
                        type=GroupEntryType.group,
                        parent=parent)
     session.add(entry)
     session.commit()
     return entry.uuid
예제 #6
0
    def change_replay_visibility(game_hash: str,
                                 visibility: GameVisibilitySetting,
                                 user_id='',
                                 release_date=None) -> 'ReplayVisibility':
        can_change = PlayerWrapper.have_permission_to_change_game(game_hash, user_id)
        if can_change:
            try:
                apply_game_visibility_explicit(user_id, visibility, release_date, game_hash)
            except CalculatedError as e:
                log_error(e)
                raise e
        else:
            log_error(AuthorizationException())

        return ReplayVisibility(game_hash, visibility)
예제 #7
0
    def create(name, owner=None, session=None):
        if owner is None:
            current_user = UserManager.get_current_user()
            if current_user is not None:
                owner = current_user.platformid
            else:
                raise AuthorizationException()

        entry = GroupEntry(engine=session.get_bind(),
                           name=name,
                           owner=owner,
                           type=GroupEntryType.group)
        session.add(entry)
        session.commit()
        return entry.uuid
예제 #8
0
    def remove_group_from_user(id_: str, group: int, session=None):
        if not is_admin(
        ):  # putting this here so that it *can't* be run without being admin from anywhere
            raise AuthorizationException()

        player = session.query(Player).filter(
            Player.platformid == id_).one_or_none()
        if player is None:
            raise PlayerNotFound()
        if player.groups is None:
            raise CalculatedError(400, "Player groups is None")
        if group not in player.groups:
            raise CalculatedError(400, "Group is not assigned to user")

        player.groups.remove(group)
        # SQLAlchemy needs this flag to be set to actually update the DB for whatever reason
        flag_modified(player, "groups")
        session.add(player)
        session.commit()
        return jsonify({"status": "Success", "groups": player.groups})
예제 #9
0
def apply_game_visibility(query_params=None, game_id=None, game_exists=True) -> Exception:
    if query_params is None:
        return None
    if 'visibility' not in query_params:
        return None

    player_id = query_params['player_id']
    visibility = query_params['visibility']
    try:
        release_date = query_params['release_date']
    except KeyError:
        release_date = None

    try:
        can_change = PlayerWrapper.have_permission_to_change_game(game_id, player_id)
    except ReplayNotFound:
        can_change = not game_exists

    if can_change:
        return apply_game_visibility_explicit(player_id, visibility, release_date, game_id)
    raise AuthorizationException()
예제 #10
0
    def add_group_to_user(id_: str, group: int, session=None):
        if not is_admin(
        ):  # putting this here so that it *can't* be run without being admin from anywhere
            raise AuthorizationException()

        player = session.query(Player).filter(
            Player.platformid == id_).one_or_none()
        if player is None:
            raise PlayerNotFound()

        if player.groups is None:
            player.groups = []

        if group in player.groups:
            raise CalculatedError(400, "Group is already assigned to user")

        player.groups.append(group)
        flag_modified(player, "groups")
        session.add(player)
        session.commit()
        return jsonify({"status": "Success"})
예제 #11
0
 def add_game(parent_uuid, game, name=None, session=None):
     current_user = UserManager.get_current_user().platformid
     parent = session.query(GroupEntry).filter(
         GroupEntry.uuid == parent_uuid).first()
     if parent is None:
         raise ReplayNotFound()
     if parent.owner != current_user:
         raise AuthorizationException()
     game_obj = session.query(Game).filter(Game.hash == game).first()
     if game_obj is None:
         game_obj: Game = session.query(Game).filter(
             Game.replay_id == game).first()
         if game_obj is not None:
             game = game_obj.hash
     entry = GroupEntry(engine=session.get_bind(),
                        name=name,
                        game=game,
                        owner=parent.owner,
                        type=GroupEntryType.game,
                        parent=parent)
     session.add(entry)
     session.commit()
     return entry.uuid
예제 #12
0
def apply_game_visibility(query_params=None,
                          game_id=None,
                          game_exists=True,
                          proto_game=None) -> Exception:

    # if it is a custom lobby we should try and fake it being a private game so scrims are not published.
    if (not game_exists and proto_game is not None and
            proto_game.game_metadata.playlist == Playlist.CUSTOM_LOBBY.value
            and query_params is not None and 'player_id' in query_params):
        query_params = {
            'player_id': query_params['player_id'],
            'visibility': GameVisibilitySetting.PRIVATE
        }

    if query_params is None:
        return None
    if 'visibility' not in query_params:
        return None

    player_id = query_params['player_id']
    visibility = query_params['visibility']
    try:
        release_date = query_params['release_date']
    except KeyError:
        release_date = None

    try:
        can_change = PlayerWrapper.have_permission_to_change_game(
            game_id, player_id)
    except ReplayNotFound:
        can_change = not game_exists

    if can_change:
        return apply_game_visibility_explicit(player_id, visibility,
                                              release_date, game_id)
    raise AuthorizationException()