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

Custom decorators for permission and manager checks in the application.
    )messages)HttpResponseHttpResponseRedirect)render)Employee)OnboardingStageOnboardingTask)Recruitmentc                       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/onboarding/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 )W
    This method is used to check permission of employee for enter to the function
    c                    | j                   }t        j                  j                  |      j	                         }t
        j                  j                  |      j                         xsP t        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 Nemployee_user_id)employee_idrecruitment_managersYou dont have permission.HTTP_REFERER/ <script>window.location.href = "
"</script>HTTP_HX_REQUESTdecorator_404.html)userr   objectsfilterfirstr	   existsr   r
   has_permr   infoMETAgetkeysr   r   requestr   r   r(   employee
is_managerprevious_urlscriptkeyfunctionperms            r   	_functionz(all_manager_can_enter.<locals>._functionA   s!   ||##**D*AGGI""))h)?FFH R&&--(-C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   all_manager_can_enterr=   ;   s    $$ r   c                       fd}|S )r   c                 0   | j                   }t        j                  j                  |      j	                         }t
        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 r   )r(   r   r)   r*   r+   r   r
   r,   r-   r   r.   r/   r0   r1   r   r   r2   s            r   r;   z*stage_manager_can_enter.<locals>._function\   s    ||##**D*AGGI##**x*@ R""))x)HOOQ 	 ==*G5d5f55g:;||''<3L>L',,##%%'#788F##r   r   r<   s   `` r   stage_manager_can_enterr@   V   s    $" r   c                       fd}|S )r   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 )
Nr   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>._functionv   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_enterrC   p   s    $ r   N)__doc__django.contribr   django.httpr   r   django.shortcutsr   employee.modelsr   onboarding.modelsr   r	   recruitment.modelsr
   r   r=   r@   rC   r   r   r   <module>rK      s`    $ : # $ = *(V  4  2  r   