def item_index(entityset_id): """See a list of all items in that are linked to this entity set. This gives entities that are judged negative and unsure alongside the positive matches returned by the subling `./entities` API. --- post: summary: Get all items in the entity set. parameters: - description: The entityset id. in: path name: entityset_id required: true schema: type: string example: 3a0d91ece2dce88ad3259594c7b642485235a048 responses: '200': content: application/json: schema: $ref: '#/components/schemas/EntitySetItemResponse' description: OK tags: - EntitySetItem """ entityset = get_entityset(entityset_id, request.authz.READ) result = DatabaseQueryResult(request, entityset.items(request.authz)) # The entityset is needed to check if the item is writeable in the serializer: result.results = [i.to_dict(entityset=entityset) for i in result.results] return EntitySetItemSerializer.jsonify_result(result)
def index(collection_id): collection = get_db_collection(collection_id) record_audit(Audit.ACT_COLLECTION, id=collection.id) parser = QueryParser(request.args, request.authz) q = Match.group_by_collection(collection.id, authz=request.authz) result = DatabaseQueryResult(request, q, parser=parser) return MatchCollectionsSerializer.jsonify_result(result)
def index(): """Returns a list of linkages for god entities --- get: summary: List linkages parameters: - description: >- Choose to filter for a specific role context. in: query name: "filter:context_id" schema: type: string responses: '200': description: OK content: application/json: schema: type: object allOf: - $ref: '#/components/schemas/QueryResponse' properties: results: type: array items: $ref: '#/components/schemas/Linkage' tags: - Linkage """ require(request.authz.logged_in) parser = QueryParser(request.args, request.authz) context_ids = parser.getintlist('filter:context_id') q = Linkage.by_authz(request.authz, context_ids=context_ids) result = DatabaseQueryResult(request, q, parser=parser) return LinkageSerializer.jsonify_result(result)
def collection(id): require(request.authz.logged_in) collection = get_db_collection(id) channel_name = channel(collection) query = Notification.by_channel(channel_name) result = DatabaseQueryResult(request, query) return NotificationSerializer.jsonify_result(result)
def index(): require(request.authz.logged_in) role = Role.by_id(request.authz.id) require(role is not None) query = Notification.by_role(role) result = DatabaseQueryResult(request, query, schema=NotificationSchema) return jsonify(result)
def matches(id, other_id): collection = get_db_collection(id) other = get_db_collection(other_id) parser = QueryParser(request.args, request.authz, limit=10) q = Match.find_by_collection(collection.id, other.id) result = DatabaseQueryResult(request, q, parser=parser, schema=MatchSchema) return jsonify(result)
def collection(id): require(request.authz.logged_in) collection = get_db_collection(id) channel_name = channel(collection) query = Notification.by_channel(channel_name) result = DatabaseQueryResult(request, query, schema=NotificationSchema) return jsonify(result)
def matches(collection_id, other_id): collection = get_db_collection(collection_id) other = get_db_collection(other_id) parser = QueryParser(request.args, request.authz) q = Match.find_by_collection(collection.id, other.id) result = DatabaseQueryResult(request, q, parser=parser) return MatchSerializer.jsonify_result(result)
def index(): """Get query logs for the user. --- get: summary: Get query logs description: Get query logs for the user responses: '200': description: OK content: application/json: schema: type: object allOf: - $ref: '#/components/schemas/QueryResponse' properties: results: type: array items: $ref: '#/components/schemas/QueryLog' tags: - Query Log """ require(request.authz.logged_in) parser = QueryParser(request.args, request.authz) q = QueryLog.query_log(role_id=request.authz.id) result = DatabaseQueryResult(request, q, parser=parser) return QueryLogSerializer.jsonify_result(result)
def index(): """Returns a list of alerts for the user. --- get: summary: List alerts responses: '200': content: application/json: schema: type: object allOf: - $ref: '#/components/schemas/QueryResponse' properties: results: type: array items: $ref: '#/components/schemas/Alert' description: OK tags: - Alert """ require(request.authz.logged_in) query = Alert.by_role_id(request.authz.id) result = DatabaseQueryResult(request, query) return AlertSerializer.jsonify_result(result)
def index(): """ --- get: summary: Get notifications description: Get all the notifications for the user responses: '200': content: application/json: schema: type: object allOf: - $ref: '#/components/schemas/QueryResponse' properties: results: type: array items: $ref: '#/components/schemas/Notification' description: OK tags: - Notification """ require(request.authz.logged_in) role = Role.by_id(request.authz.id) query = Notification.by_channels(get_role_channels(role), role) result = DatabaseQueryResult(request, query) return NotificationSerializer.jsonify_result(result)
def all(): parser = QueryParser(request.args, request.authz) q = Entity.all_ids(authz=request.authz) collection_ids = parser.getintlist('collection_id') if len(collection_ids): q = q.filter(Entity.collection_id.in_(collection_ids)) result = DatabaseQueryResult(request, q, parser=parser) return jsonify(result)
def index(): require(request.authz.logged_in) role = Role.by_id(request.authz.id) query = Notification.by_channels(get_role_channels(role), since=role.notified_at, exclude_actor_id=role.id) result = DatabaseQueryResult(request, query) return NotificationSerializer.jsonify_result(result)
def index(id): collection = get_db_collection(id) parser = QueryParser(request.args, request.authz, limit=10) q = Match.group_by_collection(collection.id, authz=request.authz) result = DatabaseQueryResult(request, q, parser=parser, schema=MatchCollectionsSchema) return jsonify(result)
def index(): parser = QueryParser(request.args, request.authz) q = Audit.query_log(role_id=request.authz.id, session_id=request.session_id) result = DatabaseQueryResult(request, q, parser=parser, schema=QueryLogSchema) return jsonify(result)
def matches(id, other_id): collection = get_db_collection(id) record_audit(Audit.ACT_COLLECTION, id=collection.id) other = get_db_collection(other_id) record_audit(Audit.ACT_COLLECTION, id=other.id) parser = QueryParser(request.args, request.authz) q = Match.find_by_collection(collection.id, other.id) result = DatabaseQueryResult(request, q, parser=parser, schema=MatchSchema) return jsonify(result)
def summary(id): collection = obj_or_404(Collection.by_id(id)) require(request.authz.can_read(collection.id)) parser = QueryParser(request.args, request.authz, limit=10) q = Match.group_by_collection(collection.id, authz=request.authz) result = DatabaseQueryResult(request, q, parser=parser, schema=MatchCollectionsSchema) return jsonify(result)
def index(): """Returns a list of entitysets for the role --- get: summary: List entitysets parameters: - description: The collection id. in: query name: 'filter:collection_id' required: true schema: minimum: 1 type: integer - description: The type of the entity set in: query name: 'filter:type' required: false schema: type: string - description: Quert string for searches in: query name: 'prefix' required: false schema: type: string responses: '200': content: application/json: schema: type: object allOf: - $ref: '#/components/schemas/QueryResponse' properties: results: type: array items: $ref: '#/components/schemas/EntitySet' description: OK tags: - EntitySet """ parser = QueryParser(request.args, request.authz) types = parser.filters.get("type") q = EntitySet.by_authz(request.authz, types=types, prefix=parser.prefix) q = q.order_by(EntitySet.updated_at.desc()) collection_ids = ensure_list(parser.filters.get("collection_id")) if len(collection_ids): q = q.filter(EntitySet.collection_id.in_(collection_ids)) result = DatabaseQueryResult(request, q, parser=parser) return EntitySetSerializer.jsonify_result(result)
def suggest(): require(request.authz.logged_in) parser = QueryParser(request.args, request.authz, limit=10) if parser.prefix is None or len(parser.prefix) < 3: # Do not return 400 because it's a routine event. return jsonify({ 'status': 'error', 'message': 'prefix filter is too short', 'results': [], 'total': 0 }) # this only returns users, not groups q = Role.by_prefix(parser.prefix) result = DatabaseQueryResult(request, q, parser=parser, schema=RoleSchema) return jsonify(result)
def suggest(): """ --- get: summary: Suggest users matching a search prefix description: >- For a given `prefix`, suggest matching user accounts. For security reasons, the prefix must be more than three characters long. parameters: - in: query name: prefix required: true schema: type: string responses: '200': description: OK content: application/json: schema: type: object allOf: - $ref: '#/components/schemas/QueryResponse' properties: results: type: array items: $ref: '#/components/schemas/Role' tags: - Role """ require(request.authz.logged_in) parser = QueryParser(request.args, request.authz, limit=10) if parser.prefix is None or len(parser.prefix) < 3: # Do not return 400 because it's a routine event. return jsonify({ "status": "error", "message": gettext("prefix filter is too short"), "results": [], "total": 0, }) # this only returns users, not groups exclude = ensure_list(parser.excludes.get("id")) q = Role.by_prefix(parser.prefix, exclude=exclude) result = DatabaseQueryResult(request, q, parser=parser) return RoleSerializer.jsonify_result(result)
def matches(collection_id, other_id): """ --- get: summary: Fetch cross-reference matches between collections description: >- Fetch cross-reference matches between 2 collections with ids `collection_id` and `other_id` parameters: - in: path name: collection_id required: true schema: type: integer - in: path name: other_id required: true schema: type: integer responses: '200': description: OK content: application/json: schema: type: object allOf: - $ref: '#/components/schemas/QueryResponse' properties: results: type: array items: $ref: '#/components/schemas/XrefMatch' tags: - Xref - Collection """ collection = get_db_collection(collection_id) other = get_db_collection(other_id) parser = QueryParser(request.args, request.authz) q = Match.find_by_collection(collection.id, other.id) result = DatabaseQueryResult(request, q, parser=parser) return MatchSerializer.jsonify_result(result)
def index(collection_id): """Returns a list of mappings for the collection and table. --- get: summary: List mappings parameters: - description: The collection id. in: path name: collection_id required: true schema: minimum: 1 type: integer - description: The table id. in: query name: table schema: type: string requestBody: responses: '200': content: application/json: schema: type: object allOf: - $ref: '#/components/schemas/QueryResponse' properties: results: type: array items: $ref: '#/components/schemas/Mapping' description: OK tags: - Collection - Mapping """ collection = get_db_collection(collection_id) parser = QueryParser(request.args, request.authz) table_id = first(parser.filters.get("table")) q = Mapping.by_collection(collection.id, table_id=table_id) result = DatabaseQueryResult(request, q, parser=parser) return MappingSerializer.jsonify_result(result)
def index(collection_id): """ --- get: summary: Fetch cross-reference summary description: >- Fetch cross-reference matches grouped by collection, for entities in the collection with id `collection_id` parameters: - in: path name: collection_id required: true schema: type: integer responses: '200': description: OK content: application/json: schema: type: object allOf: - $ref: '#/components/schemas/QueryResponse' properties: results: type: array items: $ref: '#/components/schemas/XrefCollection' tags: - Xref - Collection """ collection = get_db_collection(collection_id) parser = QueryParser(request.args, request.authz) q = Match.group_by_collection(collection.id, authz=request.authz) result = DatabaseQueryResult(request, q, parser=parser) return MatchCollectionsSerializer.jsonify_result(result)
def index(): """Returns a list of diagrams for the role --- get: summary: List diagrams parameters: - description: The collection id. in: query name: 'filter:collection_id' required: true schema: minimum: 1 type: integer responses: '200': content: application/json: schema: type: object allOf: - $ref: '#/components/schemas/QueryResponse' properties: results: type: array items: $ref: '#/components/schemas/Diagram' description: OK tags: - Diagram """ parser = QueryParser(request.args, request.authz) q = Diagram.by_authz(request.authz) collection_ids = ensure_list(parser.filters.get('collection_id')) if len(collection_ids): q = q.filter(Diagram.collection_id.in_(collection_ids)) result = DatabaseQueryResult(request, q) return DiagramSerializer.jsonify_result(result)
def entitysets(entity_id): """Returns a list of entitysets which the entity has references in --- get: summary: Shows EntitySets which reference the given entity description: >- Search for all entitysets which reference the given entity. The entity sets can be filtered based on it's collection id, label, type or the judgement of the entity within the set. parameters: - in: path name: entity_id required: true schema: type: string - in: query name: 'filter:type' description: Restrict to a EntitySets of a particular type required: false schema: items: type: string type: array - in: query name: 'filter:label' description: Restrict to a EntitySets with a particular label required: false schema: items: type: string type: array - in: query name: 'filter:judgement' description: Restrict to a specific profile judgement required: false schema: items: type: string type: array - in: query name: 'filter:collection_id' description: Restrict to entity sets within particular collections schema: items: type: string type: array responses: '200': content: application/json: schema: type: array items: $ref: '#/components/schemas/EntitySet' description: OK tags: - Entity - Profile """ entity = get_index_entity(entity_id, request.authz.READ) parser = QueryParser(request.args, request.authz) collection_ids = [ cid for cid in parser.filters.get("collection_id", []) if request.authz.can(cid, request.authz.READ) ] judgements = parser.filters.get("judgement") labels = parser.filters.get("label") types = parser.filters.get("type") if judgements is not None: judgements = list(map(Judgement, judgements)) if not collection_ids: collection_ids = request.authz.collections(request.authz.READ) entitysets = EntitySet.by_entity_id( entity["id"], collection_ids=collection_ids, judgements=judgements, types=types, labels=labels, ) result = DatabaseQueryResult(request, entitysets, parser=parser) return EntitySetSerializer.jsonify_result(result)
def index(): parser = QueryParser(request.args, request.authz) q = Audit.query_log(role_id=request.authz.id, session_id=request.session_id) result = DatabaseQueryResult(request, q, parser=parser) return QueryLogSerializer.jsonify_result(result)
def index(): require(request.authz.logged_in) parser = QueryParser(request.args, request.authz) q = QueryLog.query_log(role_id=request.authz.id) result = DatabaseQueryResult(request, q, parser=parser) return QueryLogSerializer.jsonify_result(result)
def index(): require(request.authz.logged_in) query = Alert.by_role_id(request.authz.id) result = DatabaseQueryResult(request, query) return AlertSerializer.jsonify_result(result)
def index(): require(request.authz.logged_in) query = Alert.by_role(request.authz.role) result = DatabaseQueryResult(request, query, schema=AlertSchema) return jsonify(result)
def index(): require(request.authz.logged_in) query = Alert.by_role_id(request.authz.id) result = DatabaseQueryResult(request, query, schema=AlertSchema) enable_cache(vary_user=True, vary=result.cache_key) return jsonify(result)