
    \j
                     (    d dl mZmZ  G d d      Zy)    )ImproperlyConfiguredPermissionDeniedc                   4     e Zd ZdZdddddddZ fdZ xZS )	AutoPermissionViewSetMixinaM  
    Enforces object-level permissions in ``rest_framework.viewsets.ViewSet``,
    deriving the permission type from the particular action to be performed..

    As with ``rules.contrib.views.AutoPermissionRequiredMixin``, this only works when
    model permissions are registered using ``rules.contrib.models.RulesModelMixin``.
    adddeleteNchangeview)createdestroylistpartial_updateretrieveupdatec                 L   t        |   |i | | j                  j                  sy	 | j                  j                  j                         | j                  vrt        t        | | j                  j                  j                               }	 | j                  | j                     }|yd}| j                         }|j                  |v r|j                   r/| j#                         }n| j                  dvr| j#                         }| j%                         j&                  j)                  |      }| j                  j                  j+                  ||      st,        y# t        $ r Y yw xY w# t        $ r0 t        dj                  | j                  | j                              w xY w)z<Ensures user has permission to perform the requested action.NzyAutoPermissionViewSetMixin tried to authorize a request with the {!r} action, but permission_type_map only contains: {!r})r   r   )superinitialrequestusermethodlowerhttp_method_namesAttributeErrorgetattrpermission_type_mapactionKeyErrorr   formatget_extra_actions__func__detail
get_objectget_querysetmodelget_permhas_permr   )	selfargskwargshandler	perm_typeobjextra_actionsperm	__class__s	           F/root/env/lib/python3.12/site-packages/rules/contrib/rest_framework.pyr   z"AutoPermissionViewSetMixin.initial    sy   ((||  	||""((*$2H2HH$$dDLL$7$7$=$=$?@G
	00=I  ..0},~~oo'[[ 22//#C   "((11)<||  ))$4"" 5;  		  	&KKQ6KK!9!9L 	s   A$E E* 	E'&E'*9F#)__name__
__module____qualname____doc__r   r   __classcell__)r/   s   @r0   r   r      s.    & "+# +#    r   N)django.core.exceptionsr   r   r    r6   r0   <module>r9      s    IG# G#r6   