def list_customers(): query = qb.customers.from_params(request.args, customers=g.customers) total = Customer.count(query) paging = Page.from_params(request.args, total) customers = [ c for c in Customer.find_all( query, page=paging.page, page_size=paging.page_size) if Scope.admin in g.scopes or Scope.admin_customers in g.scopes or c.customer in g.customers ] if customers: return jsonify( status='ok', page=paging.page, pageSize=paging.page_size, pages=paging.pages, more=paging.has_more, customers=[customer.serialize for customer in customers], total=total) else: return jsonify(status='ok', page=paging.page, pageSize=paging.page_size, pages=paging.pages, more=paging.has_more, message='not found', customers=[], total=0)
def get_customer(customer_id): customer = Customer.find_by_id(customer_id) if customer: return jsonify(status='ok', total=1, customer=customer.serialize) else: raise ApiError('not found', 404)
def create_customer(): try: customer = Customer.parse(request.json) except ValueError as e: raise ApiError(str(e), 400) try: customer = customer.create() except Exception as e: raise ApiError(str(e), 500) admin_audit_trail.send(current_app._get_current_object(), event='customer-created', message='', user=g.login, customers=g.customers, scopes=g.scopes, resource_id=customer.id, type='customer', request=request) if customer: return jsonify(status='ok', id=customer.id, customer=customer.serialize), 201 else: raise ApiError('create customer lookup failed', 500)
def get_customer(customer_id): customer = Customer.find_by_id(customer_id) if Scope.admin in g.scopes or Scope.admin_customers in g.scopes or customer.customer in g.customers: return jsonify(status='ok', total=1, customer=customer.serialize) else: raise ApiError('not found', 404)
def get_customer(customer_id): customer = Customer.find_by_id(customer_id) if Scope.admin in g.scopes or Scope.admin_customers in g.scopes or customer.customer in g.customers: return jsonify(status='ok', total=1, customer=customer.serialize) else: raise ApiError('not found', 404)
def get_customers(login: str, groups: List[str]) -> List[str]: if current_app.config['CUSTOMER_VIEWS']: try: return Customer.lookup(login, groups) except NoCustomerMatch as e: raise ApiError(str(e), 403) else: return []
def get_customer(login, groups): if current_app.config['CUSTOMER_VIEWS']: try: return Customer.lookup(login, groups) except NoCustomerMatch as e: raise ApiError(str(e), 403) else: return
def delete_customer(customer_id): customer = Customer.find_by_id(customer_id) if not customer: raise ApiError("not found", 404) if customer.delete(): return jsonify(status="ok") else: raise ApiError("failed to delete customer", 500)
def delete_customer(customer_id): customer = Customer.find_by_id(customer_id) if not customer: raise ApiError("not found", 404) if customer.delete(): return jsonify(status="ok") else: raise ApiError("failed to delete customer", 500)
def delete_customer(customer_id): customer = Customer.find_by_id(customer_id) if not customer: raise ApiError('not found', 404) if customer.delete(): return jsonify(status='ok') else: raise ApiError('failed to delete customer', 500)
def list_customers(): query = qb.from_params(request.args) customers = Customer.find_all(query) if customers: return jsonify( status="ok", customers=[customer.serialize for customer in customers], total=len(customers)) else: return jsonify(status="ok", message="not found", customers=[], total=0)
def delete_customer(customer_id): customer = Customer.find_by_id(customer_id) if not customer: raise ApiError('not found', 404) admin_audit_trail.send(current_app._get_current_object(), event='customer-deleted', message='', user=g.user, customers=g.customers, scopes=g.scopes, resource_id=customer.id, type='customer', request=request) if customer.delete(): return jsonify(status='ok') else: raise ApiError('failed to delete customer', 500)
def delete_customer(customer_id): customer = Customer.find_by_id(customer_id) if not customer: raise ApiError('not found', 404) admin_audit_trail.send(current_app._get_current_object(), event='customer-deleted', message='', user=g.login, customers=g.customers, scopes=g.scopes, resource_id=customer.id, type='customer', request=request) if customer.delete(): return jsonify(status='ok') else: raise ApiError('failed to delete customer', 500)
def list_customers(): query = qb.from_params(request.args, customers=g.customers) customers = [ c for c in Customer.find_all(query) if Scope.admin in g.scopes or Scope.admin_customers in g.scopes or c.customer in g.customers ] if customers: return jsonify( status='ok', customers=[customer.serialize for customer in customers], total=len(customers)) else: return jsonify(status='ok', message='not found', customers=[], total=0)
def create_customer(): try: customer = Customer.parse(request.json) except ValueError as e: raise ApiError(str(e), 400) try: customer = customer.create() except Exception as e: raise ApiError(str(e), 500) if customer: return jsonify(status="ok", id=customer.id, customer=customer.serialize), 201 else: raise ApiError("create customer lookup failed", 500)
def list_customers(): query = qb.from_params(request.args) customers = Customer.find_all(query) if customers: return jsonify( status="ok", customers=[customer.serialize for customer in customers], total=len(customers) ) else: return jsonify( status="ok", message="not found", customers=[], total=0 )
def create_customer(): try: customer = Customer.parse(request.json) except ValueError as e: raise ApiError(str(e), 400) try: customer = customer.create() except Exception as e: raise ApiError(str(e), 500) if customer: return jsonify(status="ok", id=customer.id, customer=customer.serialize), 201 else: raise ApiError("create customer lookup failed", 500)
def create_customer(): try: customer = Customer.parse(request.json) except ValueError as e: raise ApiError(str(e), 400) try: customer = customer.create() except Exception as e: raise ApiError(str(e), 500) admin_audit_trail.send(current_app._get_current_object(), event='customer-created', message='', user=g.login, customers=g.customers, scopes=g.scopes, resource_id=customer.id, type='customer', request=request) if customer: return jsonify(status='ok', id=customer.id, customer=customer.serialize), 201 else: raise ApiError('create customer lookup failed', 500)
def list_customers(): query = qb.from_params(request.args, customers=g.customers) customers = [ c for c in Customer.find_all(query) if Scope.admin in g.scopes or Scope.admin_customers in g.scopes or c.customer in g.customers ] if customers: return jsonify( status='ok', customers=[customer.serialize for customer in customers], total=len(customers) ) else: return jsonify( status='ok', message='not found', customers=[], total=0 )
def update_customer(customer_id): if not request.json: raise ApiError('nothing to change', 400) customer = Customer.find_by_id(customer_id) if not customer: raise ApiError('not found', 404) admin_audit_trail.send(current_app._get_current_object(), event='customer-updated', message='', user=g.login, customers=g.customers, scopes=g.scopes, resource_id=customer.id, type='customer', request=request) if customer.update(**request.json): return jsonify(status='ok') else: raise ApiError('failed to update customer', 500)