a
    Dg                     @   sJ   d Z ddlmZ ddlmZ ddlmZ ddlmZ	 G dd dej
ZdS )	a<  
Base model definitions for validating front-end user access to resources such as pages and
documents. These may be subclassed to accommodate specific models such as Page or Collection,
but the definitions here should remain generic and not depend on the base wagtail.models
module or specific models defined there.
    )settings)Group)models)gettext_lazyc                   @   s   e Zd ZdZdZdZdZeedfeedfeedfeedffZe	j
d	ed
Ze	j
edddeddZe	jeedddZdd Zdd ZG dd dZdS )BaseViewRestrictionnonepasswordgroupsloginZPublicz*Private, accessible with a shared passwordz*Private, accessible to any logged-in usersz/Private, accessible to users in specific groups   )
max_lengthchoiceszshared password   TzShared passwords should not be used to protect sensitive content. Anyone who has this password will be able to view the content.)verbose_namer   blank	help_text)r   r   c                    s   | j tjkr,|j| jg }| j|vrdS nZ| j tjkrF|jj	sdS n@| j tj
kr|jjs|jj  t fdd| j D sdS dS )NFc                 3   s   | ]}| v V  qd S )N ).0groupZcurrent_user_groupsr   _/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/models/view_restrictions.py	<genexpr>6       z5BaseViewRestriction.accept_request.<locals>.<genexpr>T)restriction_typer   PASSWORDsessionget$passed_view_restrictions_session_keyidLOGINuseris_authenticatedGROUPSZis_superuserr	   allany)selfrequestpassed_restrictionsr   r   r   accept_request&   s    
z"BaseViewRestriction.accept_requestc                 C   sR   t j|jv }|j| jg }| j|vr>|| j ||j| j< |sN|jd dS )zx
        Update the session data in the request to mark the user as having passed this
        view restriction
        r   N)	r   ZSESSION_COOKIE_NAMEZCOOKIESr   
setdefaultr   r   appendZ
set_expiry)r%   r&   Zhas_existing_sessionr'   r   r   r   mark_as_passed;   s    
z"BaseViewRestriction.mark_as_passedc                   @   s    e Zd ZdZedZedZdS )zBaseViewRestriction.MetaTzview restrictionzview restrictionsN)__name__
__module____qualname__Zabstract_r   Zverbose_name_pluralr   r   r   r   MetaN   s   r0   N)r,   r-   r.   NONEr   r"   r   r/   ZRESTRICTION_CHOICESr   Z	CharFieldr   r   ZManyToManyFieldr   r	   r(   r+   r0   r   r   r   r   r      s,   



r   N)__doc__Zdjango.confr   Zdjango.contrib.auth.modelsr   Z	django.dbr   Zdjango.utils.translationr   r/   ZModelr   r   r   r   r   <module>   s
   