
    si                         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mZmZ e	dd       Ze	d        Ze	d	        Ze	d
        Zy)zq
offboarding/decorators.py

This module is used to write custom authentication decorators for offboarding module
    )messages)HttpResponseHttpResponseRedirect)render)decorator_with_arguments)OffboardingOffboardingGeneralSettingOffboardingStageOffboardingTaskc                       fd}|S )Nc                      j                   j                  }}d}t        |t        t        t
        f      s|g}t         fd|D              }|s
st        j                  j                  |      j                         t        j                  j                  |      j                         z  t        j                  j                  |      j                         z  r 	 g|i |S t        j                   d        j                  j!                  dd      }d| d}d	}| j                  j#                         v rt%         d
      S t'        |      S )NFc              3   T   K   | ]  }j                   j                  |       ! y w)N)userhas_perm).0permrequests     :/var/www/python-projects/worksol/offboarding/decorators.py	<genexpr>z;any_manager_can_enter.<locals>._function.<locals>.<genexpr>   s      QTW\\2248Qs   %(managerszYou don't have permission.HTTP_REFERER/ <script>window.location.href = "
"</script>HTTP_HX_REQUESTdecorator_404.html)r   employee_get
isinstancelisttuplesetanyr   objectsfilterexistsr
   r   r   infoMETAgetkeysr   r   )r   argskwargsemployeepermissionshas_permissionprevious_urlscriptkeyfunctionoffboarding_employee_can_enterr   s   `        r   	_functionz(any_manager_can_enter.<locals>._function   s3   <<,,+eS'9:&-KQ[QQ-##**H*=DDF"**1181DKKMN!))00(0CJJLM
 G5d5f55MM'#?@"<<++NC@L7~ZPF#Cgll''))g';<<''     )r3   r   r4   r5   s   ``` r   any_manager_can_enterr8      s    (4 r6   c                       fd}|S )Nc                    | j                   j                  }| j                   j                        s.t        j                  j                  |      j                         r | g|i |S t        j                  | d       | j                  j                  dd      }d| d}d}|| j                  j                         v rt        | d      S t        |      S )	Nr   You dont have permission.r   r   r   r   r   r   )r   r   r   r   r$   r%   r&   r   r'   r(   r)   r*   r   r   )	r   r+   r,   r-   r0   r1   r2   r3   r   s	          r   r5   z0offboarding_manager_can_enter.<locals>._function5   s    <<,,LL!!$'""))8)<CCEG5d5f55MM'#>?"<<++NC@L7~ZPF#Cgll''))g';<<''r6   r7   r3   r   r5   s   `` r   offboarding_manager_can_enterr=   3   s    (  r6   c                       fd}|S )Nc                    | j                   j                  }| j                   j                        s\t        j                  j                  |      j                         s.t        j                  j                  |      j                         r | g|i |S t        j                  | d       | j                  j                  dd      }d}|| j                  j                         v rt        | d      S d| d}t        |      S )	Nr   r;   r   r   r   r   r   r   )r   r   r   r   r$   r%   r&   r
   r   r'   r(   r)   r*   r   r   )	r   r+   r,   r-   r0   r2   r1   r3   r   s	          r   r5   z9offboarding_or_stage_manager_can_enter.<locals>._functionJ   s    <<,,LL!!$'""))8)<CCE''...AHHJG5d5f55MM'#>?"<<++NC@L#Cgll''))g';<<7~ZPF''r6   r7   r<   s   `` r   &offboarding_or_stage_manager_can_enterr@   H   s    (" r6   c                       fd}|S )Nc                 P   t         j                  j                         }t        |d      }|r 	| g|i |S t	        j
                  | d       | j                  j                  dd      }d}|| j                  j                         v rt        | d      S d| d}t        |      S )	NFz&Feature is not enabled on the settingsr   r   r   r   r   r   )r	   r$   firstgetattrr   r'   r(   r)   r*   r   r   )
r   r+   r,   general_settingenabledr0   r2   r1   feature_namer3   s
           r   r5   z(check_feature_enabled.<locals>._function`   s    3;;AAC/<?G5d5f55gGH||''<',,##%%'#7883L>LF##r6   r7   )r3   rG   r5   s   `` r   check_feature_enabledrH   ^   s    $ r6   N)F)__doc__django.contribr   django.httpr   r   django.shortcutsr   horilla.decoratorsr   offboarding.modelsr   r	   r
   r   r8   r=   r@   rH   r7   r6   r   <module>rO      sr    $ : # 7   <  (  *  r6   