mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-10-09 20:55:06 +02:00
Allow admins to connect public credentials to connectors
This commit is contained in:
@@ -4,6 +4,7 @@ from sqlalchemy import select
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from sqlalchemy.sql.expression import or_
|
from sqlalchemy.sql.expression import or_
|
||||||
|
|
||||||
|
from danswer.auth.schemas import UserRole
|
||||||
from danswer.connectors.google_drive.constants import (
|
from danswer.connectors.google_drive.constants import (
|
||||||
DB_CREDENTIALS_DICT_SERVICE_ACCOUNT_KEY,
|
DB_CREDENTIALS_DICT_SERVICE_ACCOUNT_KEY,
|
||||||
)
|
)
|
||||||
@@ -39,6 +40,16 @@ def fetch_credential_by_id(
|
|||||||
) -> Credential | None:
|
) -> Credential | None:
|
||||||
stmt = select(Credential).where(Credential.id == credential_id)
|
stmt = select(Credential).where(Credential.id == credential_id)
|
||||||
if user:
|
if user:
|
||||||
|
# admins have access to all public credentials + credentials they own
|
||||||
|
if user.role == UserRole.ADMIN:
|
||||||
|
stmt = stmt.where(
|
||||||
|
or_(
|
||||||
|
Credential.user_id == user.id,
|
||||||
|
Credential.user_id.is_(None),
|
||||||
|
Credential.public_doc == True, # noqa: E712
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
stmt = stmt.where(
|
stmt = stmt.where(
|
||||||
or_(Credential.user_id == user.id, Credential.user_id.is_(None))
|
or_(Credential.user_id == user.id, Credential.user_id.is_(None))
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user