forked from danswer-ai/danswer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
2,072 additions
and
474 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
backend/alembic/versions/a3bfd0d64902_add_chosen_assistants_to_user_table.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Add chosen_assistants to User table | ||
Revision ID: a3bfd0d64902 | ||
Revises: ec85f2b3c544 | ||
Create Date: 2024-05-26 17:22:24.834741 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "a3bfd0d64902" | ||
down_revision = "ec85f2b3c544" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.add_column( | ||
"user", | ||
sa.Column("chosen_assistants", postgresql.ARRAY(sa.Integer()), nullable=True), | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_column("user", "chosen_assistants") |
This file contains 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from collections.abc import Mapping | ||
from typing import Any | ||
from typing import cast | ||
|
||
from danswer.auth.schemas import UserRole | ||
from danswer.dynamic_configs.store import ConfigNotFoundError | ||
from danswer.dynamic_configs.store import DynamicConfigStore | ||
from danswer.server.manage.models import UserInfo | ||
from danswer.server.manage.models import UserPreferences | ||
|
||
|
||
NO_AUTH_USER_PREFERENCES_KEY = "no_auth_user_preferences" | ||
|
||
|
||
def set_no_auth_user_preferences( | ||
store: DynamicConfigStore, preferences: UserPreferences | ||
) -> None: | ||
store.store(NO_AUTH_USER_PREFERENCES_KEY, preferences.dict()) | ||
|
||
|
||
def load_no_auth_user_preferences(store: DynamicConfigStore) -> UserPreferences: | ||
try: | ||
preferences_data = cast( | ||
Mapping[str, Any], store.load(NO_AUTH_USER_PREFERENCES_KEY) | ||
) | ||
return UserPreferences(**preferences_data) | ||
except ConfigNotFoundError: | ||
return UserPreferences(chosen_assistants=None) | ||
|
||
|
||
def fetch_no_auth_user(store: DynamicConfigStore) -> UserInfo: | ||
return UserInfo( | ||
id="__no_auth_user__", | ||
email="anonymous@danswer.ai", | ||
is_active=True, | ||
is_superuser=False, | ||
is_verified=True, | ||
role=UserRole.ADMIN, | ||
preferences=load_no_auth_user_preferences(store), | ||
) |
This file contains 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 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 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 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 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 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 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.