o
    Yhn                     @   sF   d dl mZ d dlmZ d dlmZ d dlmZ dddZdd	 Z	d
S )    wraps)HttpResponseForbidden)user_passes_test)render403.htmlc                    s    fdd}|S )a   
    Decorator that checks permissions and renders a custom 403 template if denied.
    
    Args:
        permission_codename (str): The permission to check (format: 'app_label.permission_codename')
        template_name (str): Path to your custom 403 template (default: '403.html')
    c                    s   t   fdd}|S )Nc                    s8   | j  s
| j jr| g|R i |S t| ddS )N  status)userhas_permis_superuserr   requestargskwargs)permission_codenametemplate_name	view_func A/var/www/html/mimamsha/mimansha/apps/mimansha_main/permissions.py_wrapped_view   s   z=permission_required.<locals>.decorator.<locals>._wrapped_viewr   r   r   r   r   r   r   	decorator   s   z&permission_required.<locals>.decoratorr   )r   r   r   r   r   r   permission_required   s   r   c                    s   t   fdd}|S )z
    Decorator that checks if user is a superuser.
    Returns 403 Forbidden for all non-superusers (authenticated or not).
    c                    s4   | j jr| j jst| dddS  | g|R i |S )Nr   r   r	   )r   is_authenticatedr   r   r   r   r   r   r      s   z)superuser_required.<locals>._wrapped_viewr   r   r   r   r   superuser_required   s   r   N)r   )
	functoolsr   django.httpr   django.contrib.auth.decoratorsr   django.shortcutsr   r   r   r   r   r   r   <module>   s   
