-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor: Enable multi user mode by default if graph and vector db pr… #1695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
fb7e74e
refactor: Enable multi user mode by default if graph and vector db pr…
dexters1 6a7660a
refactor: Return logs folder
dexters1 6572cf5
refactor: use boolean instead of string
dexters1 858ae99
Merge branch 'dev' into enable-multi-user-mode-default
dexters1 d1581e9
refactor: disable permissions for code graph example
dexters1 82eb6e4
Merge branch 'enable-multi-user-mode-default' of github.com:topoteret…
dexters1 eec96e4
refactor: fix search result for library test
dexters1 8d4eed6
Merge branch 'dev' into enable-multi-user-mode-default
dexters1 ee0ecd5
refactor: Rewrite tests to work with multi-user mode by default
dexters1 50977db
Merge branch 'enable-multi-user-mode-default' of github.com:topoteret…
dexters1 9d8430c
refactor: Update unit tests for require auth
dexters1 e061f34
fix: Resolve issue with dataset names for example
dexters1 45bb313
fix: Use same dataset name accross cognee calls
dexters1 1b48327
fix: disable backend access control for rel db test
dexters1 3c09433
fix: Resolve docling test
dexters1 00a1fe7
fix: Use multi-user mode search
dexters1 4c8b821
fix: resolve test failing
dexters1 f368a1a
fix: set tests to not use multi-user mode
dexters1 baac009
Merge branch 'dev' into enable-multi-user-mode-default
dexters1 2ab2cff
chore: update test_search_db to work with all graph providers
dexters1 c81d06d
Update cognee/context_global_variables.py
dexters1 53521c2
Update cognee/context_global_variables.py
dexters1 46c5097
refactor: Rename access control functions
dexters1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
| from uuid import UUID | ||
|
|
||
| from cognee.base_config import get_base_config | ||
| from cognee.infrastructure.databases.vector.config import get_vectordb_context_config | ||
| from cognee.infrastructure.databases.graph.config import get_graph_context_config | ||
| from cognee.infrastructure.databases.utils import get_or_create_dataset_database | ||
| from cognee.infrastructure.files.storage.config import file_storage_config | ||
| from cognee.modules.users.methods import get_user | ||
|
|
@@ -14,11 +16,50 @@ | |
| graph_db_config = ContextVar("graph_db_config", default=None) | ||
| session_user = ContextVar("session_user", default=None) | ||
|
|
||
| vector_dbs_with_multi_user_support = ["lancedb"] | ||
| graph_dbs_with_multi_user_support = ["kuzu"] | ||
|
|
||
|
|
||
| async def set_session_user_context_variable(user): | ||
| session_user.set(user) | ||
|
|
||
|
|
||
| def check_multi_user_support(): | ||
| graph_db_config = get_graph_context_config() | ||
| vector_db_config = get_vectordb_context_config() | ||
| if ( | ||
| graph_db_config["graph_database_provider"] in graph_dbs_with_multi_user_support | ||
| and vector_db_config["vector_db_provider"] in vector_dbs_with_multi_user_support | ||
| ): | ||
| return True | ||
| else: | ||
| return False | ||
dexters1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def check_backend_access_control_mode(): | ||
|
||
| backend_access_control = os.environ.get("ENABLE_BACKEND_ACCESS_CONTROL", None) | ||
| if backend_access_control is None: | ||
| # If backend access control is not defined in environment variables, | ||
| # enable it by default if graph and vector DBs can support it, otherwise disable it | ||
| multi_user_support = check_multi_user_support() | ||
| if multi_user_support: | ||
| return True | ||
| else: | ||
| return False | ||
dexters1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| elif backend_access_control.lower() == "true": | ||
| # If enabled, ensure that the current graph and vector DBs can support it | ||
| multi_user_support = check_multi_user_support() | ||
| if not multi_user_support: | ||
| raise EnvironmentError( | ||
| "ENABLE_BACKEND_ACCESS_CONTROL is set to true but the current graph and/or vector databases do not support multi-user access control. Please use supported databases or disable backend access control." | ||
| ) | ||
| else: | ||
dexters1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return True | ||
| else: | ||
dexters1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # If explicitly disabled, return false | ||
| return False | ||
|
|
||
|
|
||
| async def set_database_global_context_variables(dataset: Union[str, UUID], user_id: UUID): | ||
| """ | ||
| If backend access control is enabled this function will ensure all datasets have their own databases, | ||
|
|
@@ -40,7 +81,7 @@ async def set_database_global_context_variables(dataset: Union[str, UUID], user_ | |
|
|
||
| base_config = get_base_config() | ||
|
|
||
| if not os.getenv("ENABLE_BACKEND_ACCESS_CONTROL", "false").lower() == "true": | ||
| if not check_backend_access_control_mode(): | ||
| return | ||
|
|
||
| user = await get_user(user_id) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.