
    Jiy                     "    d dl mZ d dlmZ d Zy)    )APIException)UserCompanyRoleRepositoryc                 X   t               }|j                  |       st        d      | j                  j	                  d      }|j                         st        d      | j                  r| j                  j                  s)|j                         | _        | j                  dg       yy)	zm
    Ensures user has role and active company.
    Call this ONLY after authentication (password + 2FA).
    z2Please ask your dealership admin to assign a role.)detailT)	is_activezINo active companies found for this user. Please contact dealership admin.active_company)update_fieldsN)
r   has_roler   	companiesfilterexistsr   r   firstsave)userrepoactive_companiess      H/var/www/html/dp2/backend_v2.1/server/apps/core/services/auth_context.pyvalidate_user_contextr      s    
 %&D==G
 	
 ~~,,t,<""$6
 	

 d&9&9&C&C.446		!1 2	3 'D    N)rest_framework.exceptionsr   apps.permissions.repositoriesr   r    r   r   <module>r      s    2 C4r   