예제 #1
0
async def get_default_user_drive(
    request: Request,
    configuration: Configuration = Depends(get_configuration)):
    user = user_info(request)
    return await get_default_drive(request=request,
                                   group_id=private_group_id(user),
                                   configuration=configuration)
예제 #2
0
파일: utils.py 프로젝트: youwol/py-youwol
def get_raw_record_permissions(request: Request, group_id: str):
    user = user_info(request)
    allowed_groups = get_user_group_ids(user)
    return {
        "read": group_id in allowed_groups,
        "write": group_id in allowed_groups
    }
예제 #3
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)
예제 #4
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)
예제 #5
0
파일: utils.py 프로젝트: youwol/py-youwol
async def ensure_query_permission(
        request: Request,
        docdb: DocDb,
        key: str,
        value: str,
        max_count: int,
        configuration: Configuration
        ):

    headers = generate_headers_downstream(request.headers)
    user = user_info(request)
    allowed_groups = get_user_group_ids(user)
    r = await docdb.query(query_body=f"{key}={value}#{max_count}", owner=configuration.public_owner, headers=headers)

    return [d for d in r["documents"] if d['group_id'] in allowed_groups]
예제 #6
0
파일: data.py 프로젝트: youwol/py-youwol
    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
예제 #7
0
파일: utils.py 프로젝트: youwol/py-youwol
async def ensure_query_permission(request: Request, query: QueryBody,
                                  scope: str, configuration: Configuration):

    # there is no restriction on access asset 'metadata' for now
    # ensure_group_permission(request=request, group_id=asset["group_id"])
    # ensure_group_permission(request=request, group_id=query.groupId)

    headers = generate_headers_downstream(request.headers)
    doc_db = configuration.doc_db_asset

    r = await doc_db.query(query_body=query,
                           owner=configuration.public_owner,
                           headers=headers)
    user = user_info(request)
    allowed_groups = get_user_group_ids(user)
    if 'w' in scope:
        return [d for d in r["documents"] if d["group_id"] in allowed_groups]
    return r["documents"]
예제 #8
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)
예제 #9
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}
예제 #10
0
async def put_story(request: Request,
                    body: PutStoryBody,
                    configuration: Configuration = Depends(get_configuration)):
    user = user_info(request)
    story_id = body.storyId if body.storyId else str(uuid.uuid4())
    headers = generate_headers_downstream(request.headers)
    doc_db_stories = configuration.doc_db_stories
    doc_db_docs = configuration.doc_db_documents
    storage = configuration.storage
    root_doc_id = "root_" + story_id

    await asyncio.gather(
        doc_db_stories.create_document(doc={
            "story_id": story_id,
            "authors": [user['sub']],
            "root_document_id": root_doc_id
        },
                                       owner=Configuration.default_owner,
                                       headers=headers),
        doc_db_docs.create_document(doc={
            "document_id": root_doc_id,
            "parent_document_id": story_id,
            "story_id": story_id,
            "content_id": root_doc_id,
            "title": body.title,
            "position": position_start(),
            "complexity_order": 0,
        },
                                    owner=Configuration.default_owner,
                                    headers=headers),
        storage.post_object(path=root_doc_id,
                            content="You can start writing your story :)",
                            content_type=Configuration.text_content_type,
                            owner=Configuration.default_owner,
                            headers=headers))
    return StoryResp(storyId=story_id,
                     title=body.title,
                     authors=[user['sub']],
                     rootDocumentId=root_doc_id)