Ejemplo n.º 1
0
async def get_user_info(request: Request):

    user = user_info(request)
    groups = get_all_individual_groups(user["memberof"])
    groups = [Group(id=private_group_id(user), path="private")] + \
             [Group(id=str(to_group_id(g)), path=g) for g in groups if g]

    return User(name=user['preferred_username'], groups=groups)
Ejemplo n.º 2
0
async def get_groups(request: Request):

    user = user_info(request)
    groups = get_all_individual_groups(user["memberof"])
    groups = [Group(id=private_group_id(user), path="private")] + \
             [Group(id=str(to_group_id(g)), path=g) for g in groups if g]

    return GroupsResponse(groups=groups)
Ejemplo n.º 3
0
async def get_group_from_drive(
        user: Dict[str, Any],
        drive_id: str,
        doc_dbs: Any,
        headers) -> str:

    groups = get_all_individual_groups(user["memberof"])
    group_id0, group_id1 = await asyncio.gather(
        get_group("drive_id", drive_id, groups, doc_dbs.drives_db, headers),
        get_group("drive_id", drive_id, groups, doc_dbs.deleted_db, headers)
        )
    return group_id0 or group_id1
Ejemplo n.º 4
0
async def get_group_from_item(
        user: Dict[str, Any],
        item_id: str,
        doc_dbs: Any,
        headers
        ) -> str:

    groups = get_all_individual_groups(user["memberof"])
    group_id0, group_id1 = await asyncio.gather(
        get_group("folder_id", item_id, groups, doc_dbs.items_db, headers),
        get_group("entity_id", item_id, groups, doc_dbs.deleted_db, headers)
        )
    return group_id0 or group_id1
Ejemplo n.º 5
0
    async def sync_asset_metadata(self, request: Request, raw_id: str,
                                  metadata: AssetMeta, headers):

        docdb = self.client.docdb
        user = user_info(request)
        groups = get_all_individual_groups(user["memberof"])
        owner = await get_group("file_id", raw_id, groups, docdb, headers)
        doc = await docdb.get_document(partition_keys={"file_id": raw_id},
                                       clustering_keys={},
                                       owner=owner,
                                       headers=headers)

        if metadata.name:
            doc['file_name'] = metadata.name

        await docdb.create_document(doc=doc, owner=self.owner, headers=headers)
        return doc
Ejemplo n.º 6
0
async def list_projects(
        request: Request,
        configuration: Configuration = Depends(get_configuration)
        ):

    headers = generate_headers_downstream(request.headers)
    doc_db = configuration.doc_db
    user = user_info(request)
    groups = get_all_individual_groups(user["memberof"])
    requests = [doc_db.query(query_body=QueryBody(query=Query()), owner=group, headers=headers)
                for group in groups]
    projects = await asyncio.gather(*requests)
    flatten_groups = list(flatten([len(project["documents"])*[groups[i]] for i, project in enumerate(projects)]))
    flatten_projects = list(flatten([project["documents"] for project in projects]))

    snippets = [ProjectSnippet(name=r["name"], id=r["project_id"], description=r["description"],
                               fluxPacks=r["packages"])
                for r, group in zip(flatten_projects, flatten_groups)]

    return Projects(projects=snippets)
Ejemplo n.º 7
0
async def delete_project(
        request: Request,
        project_id: str,
        configuration: Configuration = Depends(get_configuration)):

    headers = generate_headers_downstream(request.headers)
    doc_db = configuration.doc_db
    user = user_info(request)
    groups = get_all_individual_groups(user["memberof"])
    group = await get_group("project_id", project_id, groups, doc_db, headers)

    if group == -1:
        raise HTTPException(status_code=404, detail="delete_project: project not found")

    check_permission_or_raise(group, user["memberof"])

    base_path = f"projects/{project_id}"
    storage = configuration.storage
    await doc_db.delete_document(doc={"project_id": project_id}, owner=group, headers=headers)
    await storage.delete_group(prefix=base_path, owner=group, headers=headers)

    return {"status": "deleted", "projectId": project_id}