
    ugQ                         d dl mZmZ d dlmZ d dlmZmZ d dlm	Z	 dede
deee   ee   f   fdZ	 	 ddede
d
ee   dee   deee   ee   f   f
dZy	)    )OptionalTuple)UserIdentity)DEFAULT_DATABASEDEFAULT_TENANT)ChromaAuthErroruser_identity4overwrite_singleton_tenant_database_access_from_authreturnc                     |syd}d}| j                   }| j                  }|r|dk7  r|}|rt        |      dk(  r|d   dk7  r|d   }||fS )a(  
    If settings.chroma_overwrite_singleton_tenant_database_access_from_auth
    is False, this function always returns (None, None).

    If settings.chroma_overwrite_singleton_tenant_database_access_from_auth
    is True, follows the following logic:
    - If the user only has access to a single tenant, this function will
        return that tenant as its first return value.
    - If the user only has access to a single database, this function will
        return that database as its second return value. If the user has
        access to multiple tenants and/or databases, including "*", this
        function will return None for the corresponding value(s).
    - If the user has access to multiple tenants and/or databases this
        function will return None for the corresponding value(s).
    NNN*   r   )tenant	databaseslen)r	   r
   r   databaseuser_tenantuser_databasess         Q/var/www/openai/venv/lib/python3.12/site-packages/chromadb/auth/utils/__init__.py(_singleton_tenant_database_if_applicabler      sj    & @FH&&K",,N{c)#n-2~a7HC7O!!$8    Nuser_provided_tenantuser_provided_databasec                     t        | |      \  }}|r|t        k7  r|r||k7  rt        |r|t        k7  r|r||k7  rt        |r	|t        k(  r|r|}|r	|t        k(  r|r|}||fS )N)r	   r
   )r   r   r   r   )r	   r
   r   r   
new_tenantnew_databases         r   maybe_set_tenant_and_databaser   (   s     	1#=q	 	 N2.."&6622 !$8N$J
)"&<@P&P
!-!777r   r   )typingr   r   chromadb.authr   chromadb.configr   r   chromadb.errorsr   boolstrr   r    r   r   <module>r&      s    " & < +:> 8C=(3-'(F +/,0	,8,8:>,8 #3-,8 %SM	,8
 8C=(3-'(,8r   