Exemplo n.º 1
0
def update_product(admin, product_id):
    """
    Update the product with the given id.

    :param admin:      Is the administrator user, determined by @adminRequired.
    :param product_id: Is the product id.

    :return:           A message that the update was successful and a list of all updated fields.
    """
    return generic_update(Product, product_id, json_body(), admin)
Exemplo n.º 2
0
def update_stocktaking(admin, stocktaking_id):
    """
    Update the stocktaking with the given id.

    :param admin:          Is the administrator user, determined by @adminRequired.
    :param stocktaking_id: Is the stocktaking id.

    :return:               A message that the update was successful and a list of all updated fields.
    """
    return generic_update(Stocktaking, stocktaking_id, json_body(), admin)
Exemplo n.º 3
0
def update_replenishment(admin, replenishment_id):
    """
    Update the replenishment with the given id.

    :param admin:            Is the administrator user, determined by @adminRequired.
    :param replenishment_id: Is the replenishment id.

    :return:                 A message that the update was successful and a list of all updated fields.
    """
    return generic_update(Replenishment, replenishment_id, json_body(), admin)
Exemplo n.º 4
0
def update_user(admin, user_id):
    """
    Update the user with the given id.

    :param admin:   Is the administrator user, determined by @adminRequired.
    :param user_id: Is the user id.

    :return:        A message that the update was successful and a list of all updated fields.
    """
    # Get the update data
    data = json_body()

    # Query the user. If he/she is not verified yet, there *must* be a
    # rank_id given in the update data.
    user = User.query.filter(User.id == user_id).first()
    if not user:
        raise exc.EntryNotFound()

    if not user.is_verified and 'rank_id' not in data:
        raise exc.UserIsNotVerified()

    # The password pre-check must be done here...
    if 'password' in data:
        # The repeat password must be there, too!
        if 'password_repeat' not in data:
            raise exc.DataIsMissing()

        # Both must be strings
        if not all([isinstance(x, str) for x in [data['password'], data['password_repeat']]]):
            raise exc.WrongType()

        # Passwords must match
        if data['password'] != data['password_repeat']:
            raise exc.PasswordsDoNotMatch()

        # Minimum password length
        if len(data['password']) < app.config['MINIMUM_PASSWORD_LENGTH']:
            raise exc.PasswordTooShort()

        # Convert the password into a salted hash
        # DONT YOU DARE TO REMOVE THIS LINE
        data['password'] = bcrypt.generate_password_hash(data['password'])
        # DONT YOU DARE TO REMOVE THIS LINE

        # All fine, delete repeat_password from the dict and do the rest of the update
        del data['password_repeat']

    return generic_update(User, user_id, data, admin)