Beispiel #1
0
def get_deck(deck_id):
    """loads deck"""
    deck = get_deck_or_abort(deck_id)
    coach = current_coach()

    if (not deck.commited and
            not (coach.id == deck.tournament_signup.coach.id or coach.short_name() == "TomasT")):
        raise InvalidUsage("Deck not commited, only owner can display it!", status_code=403)

    # is committed
    if (deck.tournament_signup.tournament.phase == "deck_building" and
            not (coach.id == deck.tournament_signup.coach.id or
                 coach.short_name() == deck.tournament_signup.tournament.admin or
                 coach.short_name() == "TomasT")
       ):
        raise InvalidUsage(
            "Only owner and admin can see display commited deck in the Deck Building phase!",
            status_code=403
        )

    # any other phase only tournament admin or tournament signees can see it
    coach_ids = [ts.coach_id for ts in deck.tournament_signup.tournament.tournament_signups]
    if (coach.id not in coach_ids and
            not (coach.short_name() == deck.tournament_signup.tournament.admin or
                 coach.short_name() == "TomasT")
       ):
        raise InvalidUsage(
            "Only tournament participants or admin can display the decks!",
            status_code=403
        )
    return deck_response(deck)
Beispiel #2
0
 def wrapper_superadmin(*args, **kwargs):
     coach = current_coach()
     if not coach:
         raise InvalidUsage("Coach not found", status_code=403)
     if not coach.super_admin:
         raise InvalidUsage("Coach does not have superadmin role",
                            status_code=403)
     return func(*args, **kwargs)
Beispiel #3
0
def level_hc(coach_id):
    """get coach with detailed info"""
    coach = Coach.query.get(coach_id)
    if coach is None:
        abort(404)
    if coach != current_coach():
        raise InvalidUsage("Unauthorized access!!!!", status_code=403)
    try:
        hc_service.level(coach)
        result = high_command_schema.dump(coach.high_command)
    except (TransactionError, hc_service.HighCommandError) as exc:
        raise InvalidUsage(str(exc), status_code=403)
    return jsonify(result.data)
Beispiel #4
0
def tournament_close(tournament_id):
    """Close tournaments and award prizes"""
    try:
        tourn = Tournament.query.get(tournament_id)
        coach = current_coach()
        #prizes
        for prize in request.get_json():
            tmp_coach = Coach.query.options(raiseload(Coach.cards),
                                            raiseload(Coach.packs)).get(
                                                prize['coach'])

            reason = prize['reason'] + " by " + coach.short_name()
            TransactionService.process(tmp_coach,
                                       int(prize['amount']) * -1, reason)

        TournamentService.close_tournament(tourn)

        result = tournament_schema.dump(tourn)
        return jsonify(result.data)
    except (RegistrationError, TransactionError) as exc:
        raise InvalidUsage(str(exc), status_code=403)
Beispiel #5
0
 def is_accessible(self):
     return current_coach() and current_coach().short_name() == "TomasT"
Beispiel #6
0
def can_edit_deck(deck):
    """Checks if deck belongs to the current coach, otherwise raises InvalidUsage"""
    if deck.tournament_signup.coach != current_coach():
        raise InvalidUsage("Unauthorized access!!!!", status_code=403)
    return True
Beispiel #7
0
 def wrapper_registered(*args, **kwargs):
     coach = current_coach()
     if not coach:
         raise InvalidUsage("Coach not found", status_code=403)
     kwargs['coach'] = coach
     return func(*args, **kwargs)