def ingest_upload(collection_id): collection = obj_or_404(Collection.by_id(collection_id)) request.authz.require(request.authz.collection_write(collection.id)) log_event(request) try: meta = json.loads(request.form.get('meta', '{}')) meta['crawler_id'] = 'user_upload:%s' % request.authz.role.id meta['crawler_run'] = make_textid() except Exception as ex: raise BadRequest(unicode(ex)) metas = [] for storage in request.files.values(): file_meta = meta.copy() file_meta['mime_type'] = storage.mimetype file_meta['file_name'] = storage.filename file_meta['source_path'] = storage.filename validate(file_meta, 'metadata.json#') file_meta = Metadata.from_data(file_meta) sec_fn = os.path.join(upload_folder, secure_filename(storage.filename)) storage.save(sec_fn) ingest_file(collection_id, file_meta, sec_fn, move=True, queue=USER_QUEUE, routing_key=USER_ROUTING_KEY) metas.append(file_meta) return jsonify({'status': 'ok', 'metadata': metas})
def create(cls, data, role): validate(data, 'alert.json#') alert = cls() alert.role_id = role.id alert.query_text = data.get('query_text') if alert.query_text is not None: alert.query_text = alert.query_text.strip() alert.query_text = alert.query_text or None alert.entity_id = data.get('entity_id') or None alert.custom_label = data.get('label') alert.update() return alert
def permissions_update(collection): request.authz.require(request.authz.collection_write(collection)) data = request_data() validate(data, 'permission.json#') role = Role.all().filter(Role.id == data['role']).first() collection = Collection.by_id(collection) if role is None or collection is None: raise BadRequest() request.authz.require(check_visible(role)) perm = update_permission(role, collection, data['read'], data['write']) log_event(request) return jsonify({'status': 'ok', 'updated': perm})
def update(self, data): validate(data, self._schema) creator_id = data.get('creator_id') if creator_id is not None and creator_id != self.creator_id: role = Role.by_id(creator_id) if role is not None and role.type == Role.USER: self.creator_id = role.id Permission.grant_collection(self.id, role, True, True) self.label = data.get('label') self.summary = data.get('summary', self.summary) self.category = data.get('category', self.category) self.managed = data.get('managed') self.private = data.get('private') self.countries = data.pop('countries', [])
def update(self, data): validate(data, self._schema) self.name = data.get('name', self.name) self.email = data.get('email', self.email)
def update(self, data): validate(data, self._schema) meta = self.meta meta.update(data, safe=True) self.meta = meta db.session.add(self)