
    h#                     j   d Z ddlmZ ddlmZ dZ G d d      Z G d de      Z G d	 d
e      Z G d d      Z	 G d d      Z
 G d d      Z G d dee      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d  d!e      Z G d" d#e      Zy$)%z2
Provides a set of pluggable permission policies.
    )Http404)
exceptions)GETHEADOPTIONSc                   *    e Zd Zd Zd Zd Zd Zd Zy)OperationHolderMixinc                 $    t        t        | |      S NOperandHolderANDselfothers     ]/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/rest_framework/permissions.py__and__zOperationHolderMixin.__and__   s    S$..    c                 $    t        t        | |      S r   r   ORr   s     r   __or__zOperationHolderMixin.__or__   s    Ru--r   c                 $    t        t        ||       S r   r   r   s     r   __rand__zOperationHolderMixin.__rand__   s    S%..r   c                 $    t        t        ||       S r   r   r   s     r   __ror__zOperationHolderMixin.__ror__   s    R--r   c                 "    t        t        |       S r   )SingleOperandHolderNOT)r   s    r   
__invert__zOperationHolderMixin.__invert__   s    "3--r   N)__name__
__module____qualname__r   r   r   r   r     r   r   r	   r	      s    /./..r   r	   c                       e Zd Zd Zd Zy)r   c                      || _         || _        y r   )operator_class	op1_class)r   r'   r(   s      r   __init__zSingleOperandHolder.__init__   s    ,"r   c                 H     | j                   |i |}| j                  |      S r   )r(   r'   )r   argskwargsop1s       r   __call__zSingleOperandHolder.__call__!   s(    dnnd-f-""3''r   Nr!   r"   r#   r)   r.   r$   r   r   r   r      s    #(r   r   c                       e Zd Zd Zd Zy)r   c                 .    || _         || _        || _        y r   )r'   r(   	op2_class)r   r'   r(   r2   s       r   r)   zOperandHolder.__init__'   s    ,""r   c                 n     | j                   |i |} | j                  |i |}| j                  ||      S r   )r(   r2   r'   )r   r+   r,   r-   op2s        r   r.   zOperandHolder.__call__,   s?    dnnd-f-dnnd-f-""3,,r   Nr/   r$   r   r   r   r   &   s    #
-r   r   c                       e Zd Zd Zd Zd Zy)r   c                      || _         || _        y r   r-   r4   r   r-   r4   s      r   r)   zAND.__init__3       r   c                 v    | j                   j                  ||      xr | j                  j                  ||      S r   r-   has_permissionr4   r   requestviews      r   r<   zAND.has_permission7   4    HH##GT2 3HH##GT2	
r   c                 z    | j                   j                  |||      xr | j                  j                  |||      S r   r-   has_object_permissionr4   r   r>   r?   objs       r   rC   zAND.has_object_permission=   8    HH**7D#> ?HH**7D#>	
r   Nr!   r"   r#   r)   r<   rC   r$   r   r   r   r   2       

r   r   c                       e Zd Zd Zd Zd Zy)r   c                      || _         || _        y r   r7   r8   s      r   r)   zOR.__init__E   r9   r   c                 v    | j                   j                  ||      xs | j                  j                  ||      S r   r;   r=   s      r   r<   zOR.has_permissionI   r@   r   c                 z    | j                   j                  |||      xs | j                  j                  |||      S r   rB   rD   s       r   rC   zOR.has_object_permissionO   rF   r   NrG   r$   r   r   r   r   D   rH   r   r   c                       e Zd Zd Zd Zd Zy)r   c                     || _         y r   )r-   )r   r-   s     r   r)   zNOT.__init__W   s	    r   c                 <    | j                   j                  ||       S r   )r-   r<   r=   s      r   r<   zNOT.has_permissionZ   s    88**7D999r   c                 >    | j                   j                  |||       S r   )r-   rC   rD   s       r   rC   zNOT.has_object_permission]   s    8811'4EEEr   NrG   r$   r   r   r   r   V   s    :Fr   r   c                       e Zd Zy)BasePermissionMetaclassN)r!   r"   r#   r$   r   r   rR   rR   a   s    r   rR   c                       e Zd ZdZd Zd Zy)BasePermissionzH
    A base class from which all permission classes should inherit.
    c                      yzL
        Return `True` if permission is granted, `False` otherwise.
        Tr$   r=   s      r   r<   zBasePermission.has_permissionj        r   c                      yrV   r$   rD   s       r   rC   z$BasePermission.has_object_permissionp   rW   r   N)r!   r"   r#   __doc__r<   rC   r$   r   r   rT   rT   e   s    r   rT   )	metaclassc                       e Zd ZdZd Zy)AllowAnyz
    Allow any access.
    This isn't strictly required, since you could use an empty
    permission_classes list, but it's useful because it makes the intention
    more explicit.
    c                      y)NTr$   r=   s      r   r<   zAllowAny.has_permission   s    r   Nr!   r"   r#   rY   r<   r$   r   r   r\   r\   w   s    r   r\   c                       e Zd ZdZd Zy)IsAuthenticatedz4
    Allows access only to authenticated users.
    c                 \    t        |j                  xr |j                  j                        S r   )booluseris_authenticatedr=   s      r   r<   zIsAuthenticated.has_permission   s     GLLBW\\%B%BCCr   Nr^   r$   r   r   r`   r`      s    Dr   r`   c                       e Zd ZdZd Zy)IsAdminUserz,
    Allows access only to admin users.
    c                 \    t        |j                  xr |j                  j                        S r   )rb   rc   is_staffr=   s      r   r<   zIsAdminUser.has_permission   s     GLL:W\\%:%:;;r   Nr^   r$   r   r   rf   rf      s    <r   rf   c                       e Zd ZdZd Zy)IsAuthenticatedOrReadOnlyzL
    The request is authenticated as a user, or is a read-only request.
    c                     t        |j                  t        v xs$ |j                  xr |j                  j                        S r   )rb   methodSAFE_METHODSrc   rd   r=   s      r   r<   z(IsAuthenticatedOrReadOnly.has_permission   s9    NNl* *LL *LL))
 	
r   Nr^   r$   r   r   rj   rj      s    
r   rj   c                   B    e Zd ZdZg g g dgdgdgdgdZdZd Zd Zd	 Zy
)DjangoModelPermissionsa}  
    The request is authenticated using `django.contrib.auth` permissions.
    See: https://docs.djangoproject.com/en/dev/topics/auth/#permissions

    It ensures that the user is authenticated, and has the appropriate
    `add`/`change`/`delete` permissions on the model.

    This permission can only be applied against view classes that
    provide a `.queryset` attribute.
     %(app_label)s.add_%(model_name)s#%(app_label)s.change_%(model_name)s#%(app_label)s.delete_%(model_name)sr   r   r   POSTPUTPATCHDELETETc                     |j                   j                  |j                   j                  d}|| j                  vrt	        j
                  |      | j                  |   D cg c]  }||z  	 c}S c c}w )z
        Given a model and an HTTP method, return the list of permission
        codes that the user is required to have.
        	app_label
model_name_metarz   r{   	perms_mapr   MethodNotAllowedr   rl   	model_clsr,   perms        r   get_required_permissionsz/DjangoModelPermissions.get_required_permissions   se     #22#//44

 '--f55*...*@A$vAAA   "A1c                 4   t        |d      s7t        |dd       *J dj                  | j                  j                               t        |d      r>|j                         }|*J dj                  |j                  j                               |S |j                  S )Nget_querysetquerysetz[Cannot apply {} on a view that does not set `.queryset` or have a `.get_queryset()` method.z{}.get_queryset() returned None)hasattrgetattrformat	__class__r!   r   r   )r   r?   r   s      r   	_querysetz DjangoModelPermissions._queryset   s    t^,tZ.:	*>
&((
)		* ; 4(((*H' 1889P9PQ' O}}r   c                     t        |dd      ry|j                  r"|j                  j                  s| j                  ry| j	                  |      }| j                  |j                  |j                        }|j                  j                  |      S )N_ignore_model_permissionsFT)	r   rc   rd   authenticated_users_onlyr   r   rl   model	has_perms)r   r>   r?   r   permss        r   r<   z%DjangoModelPermissions.has_permission   sp     44e<||||,,1N1N>>$'--gnnhnnM||%%e,,r   N)	r!   r"   r#   rY   r~   r   r   r   r<   r$   r   r   ro   ro      sI    	 34567889I  $B-r   ro   c                       e Zd ZdZdZy)$DjangoModelPermissionsOrAnonReadOnlyzj
    Similar to DjangoModelPermissions, except that anonymous users are
    allowed read-only access.
    FN)r!   r"   r#   rY   r   r$   r   r   r   r      s      %r   r   c                   8    e Zd ZdZg g g dgdgdgdgdZd Zd Zy)	DjangoObjectPermissionsa  
    The request is authenticated using Django's object-level permissions.
    It requires an object-permissions-enabled backend, such as Django Guardian.

    It ensures that the user is authenticated, and has the appropriate
    `add`/`change`/`delete` permissions on the object using .has_perms.

    This permission can only be applied against view classes that
    provide a `.queryset` attribute.
    rp   rq   rr   rs   c                     |j                   j                  |j                   j                  d}|| j                  vrt	        j
                  |      | j                  |   D cg c]  }||z  	 c}S c c}w )Nry   r|   r   s        r   get_required_object_permissionsz7DjangoObjectPermissions.get_required_object_permissions  sc    "22#//44

 '--f55*...*@A$vAAAr   c                 8   | j                  |      }|j                  }|j                  }| j                  |j                  |      }|j                  ||      sC|j                  t        v rt        | j                  d|      }|j                  ||      st        yy)Nr   FT)r   r   rc   r   rl   r   rm   r   )	r   r>   r?   rE   r   r   rc   r   
read_permss	            r   rC   z-DjangoObjectPermissions.has_object_permission  s    >>$'NN	||44W^^YO~~eS)
 ~~- ==eYOJ>>*c2 r   N)r!   r"   r#   rY   r~   r   rC   r$   r   r   r   r      s<    	 34567889I	Br   r   N)rY   django.httpr   rest_frameworkr   rm   r	   r   r   r   r   r   typerR   rT   r\   r`   rf   rj   ro   r   r   r$   r   r   <module>r      s      %). ."(. (	-( 	-
 
$
 
$F F	2D 	6 $	~ 	Dn D<. <

 

F-^ F-R%+A %94 9r   