def test_delete_expired(self): q = Export.by_role_id(self.role_email.id) assert q.count() == 3, q.count() delete_expired_exports() q = Export.by_role_id(self.role_email.id) assert q.count() == 1, q.count() exp1 = Export.by_id(self.export1.id, deleted=False) assert exp1 is not None assert exp1.deleted is False exp2 = Export.by_id(self.export2.id, deleted=True) assert exp2 is not None assert exp2.deleted is True path = archive.load_file(self.export1.content_hash) assert path is not None assert path.exists() exp1.expires_at = datetime.utcnow() + timedelta(days=-1) db.session.add(exp1) db.session.commit() delete_expired_exports() q = Export.by_role_id(self.role_email.id) assert q.count() == 0, q.count() exp1 = Export.by_id(self.export1.id, deleted=True) assert exp1 is not None assert exp1.deleted is True path = archive.load_file(self.export1.content_hash) assert path is not None, path path = archive.load_file(self.export3.content_hash) assert path is None, path
def index(): """Returns a list of exports for the user. --- get: summary: List exports responses: '200': content: application/json: schema: type: object allOf: - $ref: '#/components/schemas/QueryResponse' properties: results: type: array items: $ref: '#/components/schemas/Export' description: OK tags: - Export """ require(request.authz.logged_in) query = Export.by_role_id(request.authz.id) result = DatabaseQueryResult(request, query) return ExportSerializer.jsonify_result(result)
def get_deep_role(role): authz = Authz.from_role(role) alerts = Alert.by_role_id(role.id).count() exports = Export.by_role_id(role.id).count() casefiles = Collection.all_casefiles(authz=authz).count() entitysets = EntitySet.type_counts(authz=authz) return { "counts": { "alerts": alerts, "entitysets": entitysets, "casefiles": casefiles, "exports": exports, }, "shallow": False, }