
    vgN                         d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	m
Z
 ddlmZ ddlmZmZ d Zed	        Zed
        Zd Zy)zX
decorators.py

Custom decorators for permission and manager checks in the application.
    wraps)messages)HttpResponseHttpResponseRedirect)redirectrender)Employee)RecruitmentStagec                       fd}|S )z
    Decorator that allows decorators to accept arguments and keyword arguments.

    Args:
        decorator (function): The decorator function to be wrapped.

    Returns:
        function: The wrapper function.

    c                        fd}|S )a  
        Wrapper function that captures the arguments and keyword arguments.

        Args:
            *args: Variable length argument list.
            **kwargs: Arbitrary keyword arguments.

        Returns:
            function: The inner wrapper function.

        c                      | gi S )z
            Inner wrapper function that applies the decorator to the function.

            Args:
                func (function): The function to be decorated.

            Returns:
                function: The decorated function.

             )funcargs	decoratorkwargss    */var/www/horilla/recruitment/decorators.pyinner_wrapperz@decorator_with_arguments.<locals>.wrapper.<locals>.inner_wrapper*   s     T3D3F33    r   )r   r   r   r   s   `` r   wrapperz)decorator_with_arguments.<locals>.wrapper   s    	4 r   r   )r   r   s   ` r   decorator_with_argumentsr      s    8 Nr   c                       fd}|S )z
    Decorator that checks if the user has the specified permission or is a manager.

    Args:
        perm (str): The permission to check.

    Returns:
        function: The decorated function.

    Raises:
        None

    c                 L   | j                   }t        j                  j                  |      j	                         }t
        j                  j                  |      j                         xs. t        j                  j                  |      j                         }|j                  
      s|r 	| g|i |S t        j                  | d       | j                  j                  dd      }d| d}d	}|| j                  j                         v rt        | d
      S t        |      S )aR  
        Inner function that performs the permission and manager check.

        Args:
            request (HttpRequest): The request object.
            *args: Variable length argument list.
            **kwargs: Arbitrary keyword arguments.

        Returns:
            HttpResponse: The response from the decorated function.

        employee_user_id)stage_managersrecruitment_managersYou dont have permission.HTTP_REFERER/ <script>window.location.href = "
"</script>HTTP_HX_REQUESTdecorator_404.html)userr
   objectsfilterfirstr   existsr   has_permr   infoMETAgetkeysr	   r   requestr   r   r(   employee
is_managerprevious_urlscriptkeyfunctionperms            r   	_functionz$manager_can_enter.<locals>._functionL   s    ||##**D*AGGIMM   9@@B R""))x)HOOQ 	 ==*G5d5f55g:;||''<3L>L',,##%%'#788F##r   r   r9   r:   r;   s   `` r   manager_can_enterr=   <   s     $: r   c                       fd}|S )z
    Decorator that checks if the user has the specified permission or is a recruitment manager.

    Args:
        perm (str): The permission to check.

    Returns:
        function: The decorated function.

    Raises:
        None

    c                    | j                   }t        j                  j                  |      j	                         }t
        j                  j                  |      j                         }|j                  
      s|r 	| g|i |S t        j                  | d       | j                  j                  dd      }d| d}d}|| j                  j                         v rt        | d	      S t        |      S )
aQ  
        Inner function that performs the permission and manager check.

        Args:
            request (HttpRequest): The request object.
            *args: Variable length argument list.
            **kwargs: Arbitrary keyword arguments.

        Returns:
            HttpResponse: The response from the decorated function.
        r   r   r!   r"   r#   r$   r%   r&   r'   )r(   r
   r)   r*   r+   r   r,   r-   r   r.   r/   r0   r1   r	   r   r2   s            r   r;   z0recruitment_manager_can_enter.<locals>._function|   s     ||##**D*AGGI ((//X/NUUW
==*G5d5f55g:;||''<3L>L',,##%%'#788F##r   r   r<   s   `` r   recruitment_manager_can_enterr@   l   s     $2 r   c                 .     t                fd       }|S )Nc                    | j                   j                  d      r | g|i |S | j                   r~| j                   j                  rh| j                   j                  j                  j                         s.| j                   j                  j                  j                         r | g|i |S d| j                  v r | g|i |S t        d      S )Nzrecruitment.view_candidatecandidate_idzcandidate-login)	r(   r-   is_authenticatedemployee_get	stage_setr,   recruitment_setsessionr   )r3   r   r   	view_funcs      r   _wrapped_viewz/candidate_login_required.<locals>._wrapped_view   s     <<  !=>W6t6v66<<||,,LL--77>>@||00@@GGI$W>t>v>>W__,W6t6v66)**r   r   )rI   rJ   s   ` r   candidate_login_requiredrK      s"    
9+ +  r   N)__doc__	functoolsr   django.contribr   django.httpr   r   django.shortcutsr   r	   employee.modelsr
   recruitment.modelsr   r   r   r=   r@   rK   r   r   r   <module>rS      sS     # : - $ 1(V , ,^ ( (Vr   