def create(): authz.require(authz.logged_in()) data = request.get_json() validate(data, alerts_schema) alert = Alert(user_id=current_user.id, query=data['query'], label=data.get('custom_label', data['query']), checking_interval=int(data.get('checking_interval', 9))) db.session.add(alert) db.session.commit() return view(alert.id)
def permissions_save(watchlist=None, source=None): if watchlist is not None: authz.require(authz.watchlist_write(watchlist)) if source is not None: authz.require(authz.source_write(source)) resource_type = Permission.WATCHLIST if watchlist else Permission.SOURCE resource_id = watchlist or source data = request_data() validate(data, permissions_schema) role = db.session.query(Role).filter(Role.id == data['role']).first() if role is None: raise BadRequest() permission = Permission.grant_resource(resource_type, resource_id, role, data['read'], data['write']) db.session.commit() return jsonify({ 'status': 'ok', 'updated': permission })
def create(): ''' should also handle update''' authz.require(authz.logged_in()) data = request.get_json() print(data) validate(data, alerts_schema) if data['alert_id']: # UPDATE alert_id = int(data['alert_id']) alert = obj_or_404(Alert.by_id(alert_id)) authz.require(alert.user_id == current_user.id) alert.query = data['query'] alert.label = data.get('custom_label', data['query']) alert.checking_interval=int(data.get('checking_interval', 9)) else: # CREATE alert = Alert( user_id = current_user.id, query=data['query'], label=data.get('custom_label', data['query']), checking_interval=int(data.get('checking_interval', 9)) ) db.session.add(alert) db.session.commit() return view(alert.id)