
    nj-                         d Z ddlmZ ddlmZ  G d dej
                        Z G d dej
                        Z G d d	ej
                        Zy
)z5
Custom DRF permission classes for accounting views.
    )permissions)Userc                       e Zd ZdZd Zy)IsAccountantz
    Allow access to users who have an active StaffProfile with role=ACCOUNTANT.
    Admin users (is_staff=True) also pass this check.
    c                 0   |j                   r|j                   j                  syt        |j                   t              r|j                   j                  ry	 |j                   j
                  }|j                  dk(  xr |j                  S # t        $ r Y yw xY wNFT
ACCOUNTANT	useris_authenticated
isinstancer   is_staffstaff_profilerole	is_active	Exceptionselfrequestviewprofiles       @/var/www/kalinger_portal/trust-backend/accounting/permissions.pyhas_permissionzIsAccountant.has_permission   su    ||7<<#@#@gllD)gll.C.C	ll00G<<</EG4E4EE 		   2B	 		BBN__name__
__module____qualname____doc__r        r   r   r   	   s    
r!   r   c                       e Zd ZdZd Zy)IsAccountantOrAdminzz
    Combined permission: Accountant OR Admin.
    Identical logic to IsAccountant because Admin is already included.
    c                 0   |j                   r|j                   j                  syt        |j                   t              r|j                   j                  ry	 |j                   j
                  }|j                  dk(  xr |j                  S # t        $ r Y yw xY wr   r
   r   s       r   r   z"IsAccountantOrAdmin.has_permission#   su    ||7<<#@#@gllD)gll.C.C	ll00G<<</EG4E4EE 		r   Nr   r    r!   r   r#   r#      s    
	r!   r#   c                       e Zd ZdZd Zy)IsAdminz4Restrict access to Admin users only (is_staff=True).c                     |j                   xrJ |j                   j                  xr2 t        |j                   t              xr |j                   j                  S )N)r   r   r   r   r   )r   r   r   s      r   r   zIsAdmin.has_permission2   sG    LL &--&7<<.& %%		
r!   Nr   r    r!   r   r&   r&   /   s
    >
r!   r&   N)	r   rest_frameworkr   django.contrib.auth.modelsr   BasePermissionr   r#   r&   r    r!   r   <module>r+      sH    ' +;-- (+44 $	
k(( 	
r!   