<!-- .github/pull_request_template.md --> ## Description Unified dataset resolution mechanisms across cognee ## Type of Change <!-- Please check the relevant option --> - [ ] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [x] Code refactoring - [ ] Performance improvement - [ ] Other (please specify): ## Pre-submission Checklist <!-- Please check all boxes that apply before submitting your PR --> - [ ] **I have tested my changes thoroughly before submitting this PR** - [ ] **This PR contains minimal changes necessary to address the issue/feature** - [ ] My code follows the project's coding standards and style guidelines - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have added necessary documentation (if applicable) - [ ] All new and existing tests pass - [ ] I have searched existing PRs to ensure this change hasn't been submitted already - [ ] I have linked any relevant issues in the description - [ ] My commits have clear and descriptive messages ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin.
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from uuid import UUID
|
|
from typing import Optional
|
|
|
|
from cognee.modules.users.models import User
|
|
from cognee.modules.pipelines.layers.resolve_authorized_user_datasets import (
|
|
resolve_authorized_user_datasets,
|
|
)
|
|
|
|
|
|
async def resolve_authorized_user_dataset(
|
|
dataset_name: str, dataset_id: Optional[UUID] = None, user: Optional[User] = None
|
|
):
|
|
"""
|
|
Function handles creation and dataset authorization if dataset already exist for Cognee.
|
|
Verifies that provided user has necessary permission for provided Dataset.
|
|
If Dataset does not exist creates the Dataset and gives permission for the user creating the dataset.
|
|
|
|
Args:
|
|
dataset_name: Name of the dataset.
|
|
dataset_id: Id of the dataset.
|
|
user: Cognee User request is being processed for, if None default user will be used.
|
|
|
|
Returns:
|
|
Tuple[User, Dataset]: A tuple containing the user and the authorized dataset.
|
|
"""
|
|
|
|
user, authorized_datasets = await resolve_authorized_user_datasets(
|
|
datasets=dataset_id if dataset_id else dataset_name, user=user
|
|
)
|
|
|
|
return user, authorized_datasets[0]
|