
    htf                     r    d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d Zd Zd	 Z G d
 d      Zy)    )get_user_model)models)settings)ObjectPermissionChecker)get_content_type)WrongAppErrorc                 6    t        | t        j                        S )z8
    Returns ``True`` if given ``obj`` is supported
    )
isinstancer   Model)objs    [/var/www/html/software/conda/envs/higlass/lib/python3.12/site-packages/guardian/backends.pycheck_object_supportr   	   s     c6<<((    c                     | j                   sVt        j                  d| fS t               }|j                  t        j                  i} |j
                  j                  di |} d| fS )z
    Returns a tuple of checkresult and ``user_obj`` which should be used for
    permission checks

    Checks if the given user is supported. Anonymous users need explicit
    activation via ANONYMOUS_USER_NAME
    FT )is_authenticatedr   ANONYMOUS_USER_NAMEr   USERNAME_FIELDobjectsget)user_objUserlookups      r   check_user_supportr      sf     $$ ''/(?"%%x'C'CD#4<<##-f->r   c                 D    t        |      }t        |       \  }} |xr || fS )zL
    Combination of ``check_object_support`` and ``check_user_support``
    )r   r   )r   r   obj_supportuser_supports       r   check_supportr   )   s-     's+K/9L('<11r   c                   0    e Zd ZdZdZdZddZddZddZy)ObjectPermissionBackendTNc                      y Nr   )selfrequestusernamepasswords       r   authenticatez$ObjectPermissionBackend.authenticate7   s    r   c           	      ^   t        ||      \  }}|syd|v r{|j                  dd      \  }}||j                  j                  k7  rMt	        |      }||j                  k7  r3t        d|d|j                  j                  d|j                  d      t        |      }|j                  ||      S )ab  
        Returns ``True`` if given ``user_obj`` has ``perm`` for ``obj``. If no
        ``obj`` is given, ``False`` is returned.

        .. note::

           Remember, that if user is not *active*, all checks would return
           ``False``.

        Main difference between Django's ``ModelBackend`` is that we can pass
        ``obj`` instance here and ``perm`` doesn't have to contain
        ``app_label`` as it can be retrieved from given ``obj``.

        **Inactive user support**

        If user is authenticated but inactive at the same time, all checks
        always returns ``False``.
        F.   zPassed perm has app label of 'z!' while given obj has app label 'z+' and given objcontent_type has app label '')r   split_meta	app_labelr   r   r   has_perm)	r#   r   permr   supportr.   _ctypechecks	            r   r/   z ObjectPermissionBackend.has_perm:   s    * *(C8$;::c1-LIqCII/// )-/' *3CII4G4G)Z [ [
 (1~~dC((r   c                 p    t        ||      \  }}|s
t               S t        |      }|j                  |      S )za
        Returns a set of permission strings that the given ``user_obj`` has for ``obj``
        )r   setr   	get_perms)r#   r   r   r1   r4   s        r   get_all_permissionsz+ObjectPermissionBackend.get_all_permissionsb   s8    
 *(C85L'1s##r   )NNr"   )	__name__
__module____qualname__supports_object_permissionssupports_anonymous_usersupports_inactive_userr'   r/   r8   r   r   r   r    r    2   s$    "&"!&)P
$r   r    N)django.contrib.authr   	django.dbr   guardian.confr   guardian.corer   guardian.ctypesr   guardian.exceptionsr   r   r   r   r    r   r   r   <module>rE      s0    .  " 1 , -),2:$ :$r   