Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
pablonyx committed Dec 6, 2024
1 parent ab36a73 commit 0e40102
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 10 deletions.
7 changes: 5 additions & 2 deletions backend/danswer/auth/noauth_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ def load_no_auth_user_preferences(store: KeyValueStore) -> UserPreferences:
)


def fetch_no_auth_user(store: KeyValueStore) -> UserInfo:
def fetch_no_auth_user(
store: KeyValueStore, *, anonymous_user_enabled: bool | None = None
) -> UserInfo:
return UserInfo(
id="__no_auth_user__",
email="anonymous@danswer.ai",
is_active=True,
is_superuser=False,
is_verified=True,
role=UserRole.ADMIN,
role=UserRole.ADMIN if anonymous_user_enabled else UserRole.BASIC,
preferences=load_no_auth_user_preferences(store),
is_anonymous_user=anonymous_user_enabled,
)
4 changes: 2 additions & 2 deletions backend/danswer/server/manage/llm/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sqlalchemy.orm import Session

from danswer.auth.users import current_admin_user
from danswer.auth.users import current_user
from danswer.auth.users import current_second_level_limited_user
from danswer.db.engine import get_session
from danswer.db.llm import fetch_existing_llm_providers
from danswer.db.llm import fetch_provider
Expand Down Expand Up @@ -190,7 +190,7 @@ def set_provider_as_default(

@basic_router.get("/provider")
def list_llm_provider_basics(
user: User | None = Depends(current_user),
user: User | None = Depends(current_second_level_limited_user),
db_session: Session = Depends(get_session),
) -> list[LLMProviderDescriptor]:
return [
Expand Down
5 changes: 4 additions & 1 deletion backend/danswer/server/manage/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from danswer.auth.noauth_user import set_no_auth_user_preferences
from danswer.auth.schemas import UserRole
from danswer.auth.schemas import UserStatus
from danswer.auth.users import anonymous_user_enabled
from danswer.auth.users import current_admin_user
from danswer.auth.users import current_curator_or_admin_user
from danswer.auth.users import current_user
Expand Down Expand Up @@ -489,13 +490,15 @@ def verify_user_logged_in(
# NOTE: this does not use `current_user` / `current_admin_user` because we don't want
# to enforce user verification here - the frontend always wants to get the info about
# the current user regardless of if they are currently verified

if user is None:
# if auth type is disabled, return a dummy user with preferences from
# the key-value store
if AUTH_TYPE == AuthType.DISABLED:
store = get_kv_store()
return fetch_no_auth_user(store)
if anonymous_user_enabled():
store = get_kv_store()
return fetch_no_auth_user(store, anonymous_user_enabled=True)

raise BasicAuthenticationError(detail="User Not Authenticated")
if user.oidc_expiry and user.oidc_expiry < datetime.now(timezone.utc):
Expand Down
4 changes: 2 additions & 2 deletions backend/danswer/server/query_and_chat/chat_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def update_chat_session_model(
def get_chat_session(
session_id: UUID,
is_shared: bool = False,
user: User | None = Depends(current_user),
user: User | None = Depends(current_second_level_limited_user),
db_session: Session = Depends(get_session),
) -> ChatSessionDetailResponse:
user_id = user.id if user is not None else None
Expand Down Expand Up @@ -313,7 +313,7 @@ def is_connected_sync() -> bool:
def handle_new_chat_message(
chat_message_req: CreateChatMessageRequest,
request: Request,
user: User | None = Depends(current_limited_user),
user: User | None = Depends(current_second_level_limited_user),
_: None = Depends(check_token_rate_limits),
is_connected_func: Callable[[], bool] = Depends(is_connected),
) -> StreamingResponse:
Expand Down
1 change: 1 addition & 0 deletions web/src/app/chat/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,7 @@ export function ChatPage({
currentChatSession={selectedChatSession}
documentSidebarToggled={documentSidebarToggled}
llmOverrideManager={llmOverrideManager}
hideUserDropdown={user?.is_anonymous_user}
/>
)}

Expand Down
13 changes: 10 additions & 3 deletions web/src/components/chat_search/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function FunctionalHeader({
llmOverrideManager,
documentSidebarToggled,
toggleUserSettings,
hideUserDropdown,
}: {
reset?: () => void;
page: pageType;
Expand All @@ -38,6 +39,7 @@ export default function FunctionalHeader({
onAssistantChange?: (assistant: Persona) => void;
llmOverrideManager?: LlmOverrideManager;
toggleUserSettings?: () => void;
hideUserDropdown?: boolean;
}) {
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
Expand Down Expand Up @@ -119,9 +121,14 @@ export default function FunctionalHeader({
<FiShare2 size="18" />
</div>
)}
<div className="mobile:hidden flex my-auto">
<UserDropdown page={page} toggleUserSettings={toggleUserSettings} />
</div>
{!hideUserDropdown && (
<div className="mobile:hidden flex my-auto">
<UserDropdown
page={page}
toggleUserSettings={toggleUserSettings}
/>
</div>
)}
<Link
className="desktop:hidden my-auto"
href={
Expand Down
5 changes: 5 additions & 0 deletions web/src/components/context/AssistantsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,15 @@ export const AssistantsProvider: React.FC<{
finalAssistants,
ownedButHiddenAssistants,
} = useMemo(() => {
console.log("claaassifying assistants", assistants);
// console.log(assistants);

const { visibleAssistants, hiddenAssistants } = classifyAssistants(
user,
assistants
);
console.log("visibleAssistants", visibleAssistants);
console.log("hiddenAssistants", hiddenAssistants);

const finalAssistants = user
? orderAssistantsForUser(visibleAssistants, user)
Expand Down
1 change: 1 addition & 0 deletions web/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface User {
oidc_expiry?: Date;
is_cloud_superuser?: boolean;
organization_name: string | null;
is_anonymous_user?: boolean;
}

export interface MinimalUserSnapshot {
Expand Down

0 comments on commit 0e40102

Please sign in to comment.