
    ^h"              	           S r SSKJrJrJrJr  SSKJr  SSK7  S\	S\\
   S\4S jrS\
S	\\\   \\\\   4   4   4S
 jr SS\	S\\
   S	\4S jjrg)z
Auth Checks for Organizations
    )DictListOptionalTuple)status)*request_bodyuser_objectroutec           
         Uc  gU R                  SS5      nUS:X  ag  UR                  [        R                  R                  :w  a?  [        SUR                   3[        R                  R                  S[        R                  S9eUR                  [        R                  R                  :X  a  gU[        R                  R                  ;   Ga,  [        U5      u  pEUR                  c6  [        SU S3[        R                  R                  S[        R                  S9eUc2  [        S	[        R                  R                  S[        R                  S9eUR                  U5      nUc6  [        S
U S3[        R                  R                  S[        R                  S9eU[        R                  R                  :w  a>  [        SU SU SU SU 3[        R                  R                  S[        R                  S9egUS:X  a  [        U5      u  pEUR                  b  [        UR                  5      S:  a  Uc5  [        SU 3[        R                  R                  S[        R                  S9eUR                  U5      nU[        R                  R                  :w  a;  [        SU SU SU 3[        R                  R                  S[        R                  S9egggg)aF  
Role based access control checks only run if a user is part of an Organization

Organization Checks:
ONLY RUN IF user_object.organization_memberships is not None

1. Only Proxy Admins can access /organization/new
2. IF route is a LiteLLMRoutes.org_admin_only_routes, then check if user is an Org Admin for that organization

Norganization_idz/organization/newz8Only proxy admins can create new organizations. You are 	user_role)messagetypeparamcodezTried to access route=z` but you are not a member of any organization. Please contact the proxy admin to request access.zNPassed organization_id is None, please pass an organization_id in your requestzQYou do not have a role within the selected organization. Passed organization_id: z:. Please contact the organization admin to request access.z-You do not have the required role to perform z in Organization z. Your role is z	/team/newr   z|Passed organization_id is None, please specify the organization_id in your request. You are part of multiple organizations: z*You do not have the required role to call )getr   LitellmUserRolesPROXY_ADMINvalueProxyExceptionProxyErrorTypes
auth_errorr   HTTP_401_UNAUTHORIZEDLiteLLMRoutesorg_admin_only_routesget_user_organization_infoorganization_memberships	ORG_ADMINlen)r	   r
   r   passed_organization_id_user_organizations_user_organization_role_mappingr   _user_role_in_passed_orgs           e/home/james-whalen/.local/lib/python3.13/site-packages/litellm/proxy/auth/auth_checks_organization.py$organization_role_based_access_checkr&      sD     ,8,<,<=NPT,U##  $4$@$@$F$FF RS^ShShRij$//55!11	   0 < < B BB 33999&{3 	= //7 0  8X  Y$//55'11	  ") h$//55'11	  1P0S0S"1
	  k  mC  lD  D~  $//55'11	  (22888 GwN_`v_w  xG  HQ  GR  Rc  dz  c{  |$//55!11	  9 
+	 '{3 	= 00<K889A=%-$ [  \o  [p  q(3399+55	  (G'J'J&($ (+;+E+E+K+KK$H_w^x  yJ  Ka  Jb  c(3399%55	  L > = 
    returnc                     / n0 nU R                   bU  U R                    HE  nUR                  c  M  UR                  UR                  5        UR                  X#R                  '   MG     X4$ )an  
Helper function to extract user organization information.

Args:
    user_object (LiteLLM_UserTable): The user object containing organization memberships.

Returns:
    Tuple[List[str], Dict[str, Optional[LitellmUserRoles]]]: A tuple containing:
        - List of organization IDs the user is a member of
        - Dictionary mapping organization IDs to user roles
)r   r   appendr   )r
   r"   r#   _memberships       r%   r   r   r   sm     &(MO#++7&??K**6#**;+F+FGOZOdOd/0K0KL @
 ??r'   Nrequest_datac                    U R                  SS5      c  gUc  gUR                  c  gUR                   HO  nUR                  U R                  SS5      :X  d  M%  UR                  [        R
                  R                  :X  d  MO    g   g)zQ
Helper function to check if user is an org admin for the passed organization_id
r   NFT)r   r   r   r   r   r   r   )r,   r
   r+   s      r%   _user_is_org_adminr.      s     )408++3";;&&,*:*:;Ld*SS$$(8(B(B(H(HH <
 r'   )N)__doc__typingr   r   r   r   fastapir   litellm.proxy._typesdictLiteLLM_UserTablestrr&   r   r   boolr.    r'   r%   <module>r8      s    / .  "cc+,c cL@"@
49d3)9 ::;;<@8 04+, 
r'   