コード例 #1
0
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)
コード例 #2
0
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)
コード例 #3
0
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)
コード例 #4
0
ファイル: xref_api.py プロジェクト: vishalbelsare/aleph
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)
コード例 #5
0
ファイル: querylog_api.py プロジェクト: x0rzkov/aleph
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)
コード例 #6
0
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)
コード例 #7
0
ファイル: xref_api.py プロジェクト: tpreusse/aleph
def matches(id, other_id):
    collection = obj_or_404(Collection.by_id(id))
    require(request.authz.can_read(collection.id))
    require(request.authz.can_read(other_id))
    parser = QueryParser(request.args, request.authz, limit=10)
    q = Match.find_by_collection(collection.id, other_id)
    result = MatchQueryResult(request, q, parser=parser, schema=MatchSchema)
    return jsonify(result)
コード例 #8
0
ファイル: xref_api.py プロジェクト: public-people/aleph
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)
コード例 #9
0
ファイル: audit_api.py プロジェクト: nt0z/aleph
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)
コード例 #10
0
ファイル: xref_api.py プロジェクト: jbaehne/aleph
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)
コード例 #11
0
ファイル: xref_api.py プロジェクト: tpreusse/aleph
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)
コード例 #12
0
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)
コード例 #13
0
ファイル: roles_api.py プロジェクト: DtorrX/aleph
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)
コード例 #14
0
ファイル: roles_api.py プロジェクト: wayne9qiu/aleph
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)
コード例 #15
0
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)
コード例 #16
0
ファイル: xref_api.py プロジェクト: we1l1n/aleph
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)
コード例 #17
0
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)
コード例 #18
0
ファイル: xref_api.py プロジェクト: we1l1n/aleph
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)
コード例 #19
0
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)
コード例 #20
0
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)
コード例 #21
0
def generate_matches_sheet(workbook,
                           sheet,
                           collection,
                           match_collection,
                           authz,
                           links=True,
                           one_sheet=False,
                           offset=0,
                           limit=1000):
    from aleph.views.serializers import MatchSchema

    if one_sheet:
        sheet_label = "All matches (top %s per collection)" % limit
    else:
        sheet_label = "%s (top %s)" % (match_collection.label, limit)

    sheet.set_zoom(125)
    parser = QueryParser({}, authz, limit=limit)
    q_match = Match.find_by_collection(collection.id, match_collection.id)
    matches = MatchQueryResult({}, q_match, parser=parser, schema=MatchSchema)

    if offset < 3:

        sheet.write(0, 0, '', workbook.header_format)
        sheet.write(1, 0, 'Score', workbook.header_format)
        sheet.merge_range(0, 1, 0, 4, collection.label, workbook.header_format)
        sheet.write(1, 1, 'Name', workbook.header_format)
        sheet.write(1, 2, 'Type', workbook.header_format)
        sheet.write(1, 3, 'Country', workbook.header_format)
        sheet.write(1, 4, 'Source URL', workbook.header_format)
        sheet.merge_range(0, 5, 0, 8, sheet_label, workbook.header_format)
        sheet.write(1, 5, 'Name', workbook.header_format)
        sheet.write(1, 6, 'Type', workbook.header_format)
        sheet.write(1, 7, 'Country', workbook.header_format)
        if one_sheet:
            sheet.write(1, 8, 'Collection', workbook.header_format)

        sheet.freeze_panes(2, 0)
        sheet.autofilter(1, 1, 2 + len(matches.results), 8)

    widths = {}
    for row, result in enumerate(matches.results, offset):
        sheet.write_number(row, 0, int(result.score))
        name = result.entity.get('name')
        widths[1] = max(widths.get(1, 0), len(name))
        if links:
            url = entity_url(result.entity_id)
            sheet.write_url(row, 1, url, workbook.link_format, name)
        else:
            sheet.write_string(row, 1, name)
        schema = model.get(result.entity['schema'])
        sheet.write_string(row, 2, schema.label)
        countries = ', '.join(sorted(result.entity.get('countries', [])))
        sheet.write_string(row, 3, countries.upper())
        ent_props = result.entity.get('properties', {})
        if (ent_props.get('sourceUrl') is not None):
            source_url = ', '.join(ent_props.get('sourceUrl'))
        else:
            source_url = ''
        sheet.write_string(row, 4, source_url)

        name = result.match.get('name')
        widths[5] = max(widths.get(5, 0), len(name))
        if links:
            url = entity_url(result.match_id)
            sheet.write_url(row, 5, url, workbook.link_format, name)
        else:
            sheet.write_string(row, 5, name)
        schema = model.get(result.match['schema'])
        sheet.write_string(row, 6, schema.label)
        countries = ', '.join(sorted(result.match.get('countries', [])))
        sheet.write_string(row, 7, countries.upper())
        if one_sheet:
            sheet.write_string(row, 8, match_collection.label)

    for idx, max_len in widths.items():
        max_len = min(70, max(7, max_len + 1))
        sheet.set_column(idx, idx, float(max_len))

    return sheet
コード例 #22
0
ファイル: profiles_api.py プロジェクト: sunu/aleph
def expand(profile_id):
    """
    ---
    get:
      summary: Expand the profile to get its adjacent entities
      description: >-
        Get the property-wise list of entities adjacent to the entities that
        are part of the profile `profile_id`.
      parameters:
      - in: path
        name: profile_id
        required: true
        schema:
          type: string
      - description: properties to filter on
        in: query
        name: 'filter:property'
        schema:
          type: string
      - in: query
        description: number of entities to return per property
        name: limit
        schema:
          type: number
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                allOf:
                - $ref: '#/components/schemas/QueryResponse'
                properties:
                  results:
                    type: array
                    items:
                      $ref: '#/components/schemas/EntityExpand'
      tags:
      - Profile
    """
    profile = obj_or_404(get_profile(profile_id, authz=request.authz))
    require(request.authz.can(profile.get("collection_id"),
                              request.authz.READ))
    tag_request(collection_id=profile.get("collection_id"))
    parser = QueryParser(request.args,
                         request.authz,
                         max_limit=MAX_EXPAND_ENTITIES)
    properties = parser.filters.get("property")
    results = expand_proxies(
        profile.get("proxies"),
        properties=properties,
        authz=request.authz,
        limit=parser.limit,
    )
    result = {
        "status": "ok",
        "total": sum(result["count"] for result in results),
        "results": results,
    }
    return jsonify(result)