Esempio n. 1
0
def update_blackout(blackout_id):
    if not request.json:
        raise ApiError('nothing to change', 400)

    if not current_app.config['AUTH_REQUIRED']:
        blackout = Blackout.find_by_id(blackout_id)
    elif Scope.admin in g.scopes or Scope.admin_blackouts in g.scopes:
        blackout = Blackout.find_by_id(blackout_id)
    else:
        blackout = Blackout.find_by_id(blackout_id, g.customers)

    if not blackout:
        raise ApiError('not found', 404)

    update = request.json
    update['user'] = g.login
    update['customer'] = assign_customer(wanted=update.get('customer'), permission=Scope.admin_blackouts)

    write_audit_trail.send(current_app._get_current_object(), event='blackout-updated', message='', user=g.login,
                           customers=g.customers, scopes=g.scopes, resource_id=blackout.id, type='blackout',
                           request=request)

    updated = blackout.update(**update)
    if updated:
        return jsonify(status='ok', blackout=updated.serialize)
    else:
        raise ApiError('failed to update blackout', 500)
Esempio n. 2
0
def get_blackout(blackout_id):
    blackout = Blackout.find_by_id(blackout_id)

    if blackout:
        return jsonify(status='ok', total=1, blackout=blackout.serialize)
    else:
        raise ApiError('not found', 404)
Esempio n. 3
0
def delete_blackout(blackout_id):
    customer = g.get('customer', None)
    blackout = Blackout.find_by_id(blackout_id, customer)

    if not blackout:
        raise ApiError("not found", 404)

    if blackout.delete():
        return jsonify(status="ok")
    else:
        raise ApiError("failed to delete blackout", 500)
Esempio n. 4
0
def delete_blackout(blackout_id):
    customer = g.get('customer', None)
    blackout = Blackout.find_by_id(blackout_id, customer)

    if not blackout:
        raise ApiError("not found", 404)

    if blackout.delete():
        return jsonify(status="ok")
    else:
        raise ApiError("failed to delete blackout", 500)
Esempio n. 5
0
def delete_blackout(blackout_id):
    customer = g.get('customer', None)
    blackout = Blackout.find_by_id(blackout_id, customer)

    if not blackout:
        raise ApiError('not found', 404)

    write_audit_trail.send(current_app._get_current_object(), event='blackout-deleted', message='', user=g.login,
                           customers=g.customers, scopes=g.scopes, resource_id=blackout.id, type='blackout', request=request)

    if blackout.delete():
        return jsonify(status='ok')
    else:
        raise ApiError('failed to delete blackout', 500)
Esempio n. 6
0
def update_blackout(blackout_id):
    if not request.json:
        raise ApiError('nothing to change', 400)

    blackout = Blackout.find_by_id(blackout_id)

    if not blackout:
        raise ApiError('not found', 404)

    write_audit_trail.send(current_app._get_current_object(),
                           event='blackout-updated',
                           message='',
                           user=g.user,
                           customers=g.customers,
                           scopes=g.scopes,
                           resource_id=blackout.id,
                           type='blackout',
                           request=request)

    if blackout.update(**request.json):
        return jsonify(status='ok')
    else:
        raise ApiError('failed to update blackout', 500)