Exemple #1
0
def get_coach(coach_id):
    """get coach with detailed info"""
    coach = Coach.query.options(selectinload(Coach.packs)).get(coach_id)
    if coach is None:
        abort(404)
    result = coach_schema.dump(coach)
    if not owning_coach(coach):
        CardHelper.censor_cards(result.data['cards'])
    return etagjsonify(result.data)
Exemple #2
0
def new_coach():
    """creates new coach"""
    try:
        user = current_user()
        name = user['username'] + "#" + user['discriminator']
        coach = CoachService.new_coach(name, user['id'])
    except TransactionError as exc:
        raise InvalidUsage(str(exc), status_code=403)

    result = coach_schema.dump(coach)
    return jsonify(result.data)
Exemple #3
0
def update_coach(coach_id):
    """Update coaches bb2 name"""
    coach = Coach.query.options(selectinload(Coach.packs)).get(coach_id)
    if coach is None:
        abort(404)

    bb2_name = request.get_json()['name']
    coach.bb2_name = bb2_name
    db.session.commit()
    result = coach_schema.dump(coach)
    return jsonify(result.data)
Exemple #4
0
def me():
    """returns user from session"""
    user = session.get('discord_user', {'code':0})
    if current_user():
        coach = Coach.query.with_deleted().options(selectinload(Coach.packs)).filter_by(disc_id=current_user()['id']).one_or_none()
        result = coach_schema.dump(coach)
        coach_data = result.data
    else:
        coach_data = {}
    cuser = deepcopy(user)
    cuser['coach'] = coach_data
    return jsonify(user=cuser)
Exemple #5
0
def activate_coach(coach_id, **kwargs):
    """Activates coach"""
    coach = kwargs['coach']
    if coach is None:
        abort(404)
    if not owning_coach(coach):
        raise InvalidUsage("Unauthorized access!!!!", status_code=403)
    try:
        card_ids = request.get_json()['card_ids']
        CoachService.activate_coach(coach=coach, card_ids=card_ids)
    except (ValueError, TypeError, TransactionError) as exc:
        raise InvalidUsage(str(exc), status_code=403)
    result = coach_schema.dump(coach)
    return jsonify(result.data)
Exemple #6
0
def update_coach(coach_id):
    if not current_user():
        raise InvalidUsage('You are not authenticated', status_code=401)
    
    tcoach = Coach.query.filter_by(disc_id=current_user()['id']).one_or_none()
    if not tcoach:
        raise InvalidUsage("Coach not found", status_code=403)
    if not tcoach.web_admin:
        raise InvalidUsage("Coach does not have webadmin role", status_code=403)    

    coach = Coach.query.get(coach_id)
    if coach is None:
        abort(404)

    bb2_name = request.get_json()['name']
    coach.bb2_name=bb2_name
    db.session.commit()
    result = coach_schema.dump(coach)
    return jsonify(result.data)
Exemple #7
0
def get_coach(coach_id):
    coach = Coach.query.get(coach_id)
    if coach is None:
        abort(404)
    result = coach_schema.dump(coach)
    return jsonify(result.data)