Пример #1
0
def create_admin():
    admin_username = app.config["ADMIN_USERNAME"]
    admin = User.query.filter_by(username=admin_username).one_or_none()
    if not admin:
        admin = User.create(admin_username, app.config["ADMIN_PWD"])
    if not admin.is_admin():
        admin.add_role(Role.get_admin())
Пример #2
0
def home():
    nonAdminRoles = list(
        filter(lambda role: role != Role.get_admin(), Role.get_all()))
    columns = ["Naam"] + list(
        map(lambda role: role.translate().capitalize(),
            nonAdminRoles)) + ["Acties"]

    users = list(filter(lambda user: not user.is_admin(), User.get_all()))
    rolesPerUser = {
        user: list(map(lambda r: r in user.get_roles(), nonAdminRoles))
        for user in users
    }
    return render_template('usermanagement.html',
                           title="User Management",
                           columns=columns,
                           users=users,
                           rolesPerUser=rolesPerUser,
                           roles=list(map(lambda role: role.id,
                                          nonAdminRoles)))
Пример #3
0
def set_role():
    user = User.get(request.form['id'])
    role = Role.get(request.form['role'])
    enableDisable = strtobool(request.form['enable'])
    if user is None:
        abort(400, "An invalid user was given!")
    if role is None:
        abort(400, "An invalid role was given!")

    if enableDisable:
        user.add_role(role)
    else:
        user.remove_role(role)
    db.session.commit()
    return ("", http.HTTPStatus.NO_CONTENT)
Пример #4
0
        abort(400, "Some passed products are invalid!")

    amounts = request.form.getlist('amounts[]')
    if any((not is_float(a) for a in amounts)):
        abort(400, "Some passed amounts are invalid!")

    remarks = request.form['remarks']
    Order.create(beerPub, user, products, list(map(float, amounts)), table,
                 paid_at_order, remarks)
    db.session.commit()
    return ("", http.HTTPStatus.NO_CONTENT)


@order_blueprint.route('/newwaiterorder', methods=['POST'])
@login_required
@roles_required(Role.get_waiter_id())
def new_waiter_order():
    return new_order(current_user.user, True)


@order_blueprint.route('/newcashdeskorder', methods=['POST'])
@login_required
@roles_required(Role.get_cash_desk_id())
def new_cash_desk_order():
    return new_order(current_user.user, False)


@order_blueprint.route('/deleteorder', methods=['POST'])
@login_required
@roles_required(Role.get_cash_desk_id())
def delete_order():
Пример #5
0
from flask import Blueprint, request, jsonify, abort
from flask_login import login_required
import http
from app.common.loginutils import admin_required, any_role_required
from app.models.beer_pub import BeerPub
from app.models.product.product import Product
from app.models.user.role import Role
import jsonpickle
from utils.date_utils import to_date
from app import db
from .blueprint import pubmanagement_blueprint

@pubmanagement_blueprint.route('/activebeerpub', methods=['GET'])
@login_required
@any_role_required(Role.get_waiter_id(), Role.get_cash_desk_id())
def active_beer_pub():
    beer_pub = BeerPub.get_active()
    if beer_pub is None:
        return jsonify()
    return jsonify(id=beer_pub.id)

@pubmanagement_blueprint.route('/createbeerpub', methods=['POST'])
@login_required
@admin_required
def create_beer_pub():
    start_date = to_date(request.form['startDate'])
    end_date = to_date(request.form['endDate'])
    if end_date < start_date:
        abort(400, "Start date cannot be before end date!")

    beer_pub = BeerPub.create(start_date, end_date)
Пример #6
0
def admin_role_id():
    return jsonify(id=Role.get_admin_id())
Пример #7
0
def cash_desk_role_id():
    return jsonify(id=Role.get_cash_desk_id())
Пример #8
0
def waiter_role_id():
    return jsonify(id=Role.get_waiter_id())