| Server IP : 65.108.144.40 / Your IP : 216.73.217.165 Web Server : Apache/2.4.52 (Ubuntu) System : Linux ubuntu-8gb-hel1-1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 User : dev ( 1000) PHP Version : 8.2.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/erp/recruitment/__pycache__/ |
Upload File : |
o
hͦh � @ s� d Z ddlmZ ddlmZ ddlmZmZ ddlm Z m
Z
ddlmZ ddl
mZmZ dd � Zed
d� �Zedd
� �Zdd� ZdS )zX
decorators.py
Custom decorators for permission and manager checks in the application.
� ��wraps)�messages)�HttpResponse�HttpResponseRedirect)�redirect�render)�Employee)�Recruitment�Stagec s � fdd�}|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 s � ��fdd�}|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 s �| g� �R 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�kwargsr �&/var/www/erp/recruitment/decorators.py�
inner_wrapper* s z@decorator_with_arguments.<locals>.wrapper.<locals>.inner_wrapperr )r r r �r )r r r �wrapper s
z)decorator_with_arguments.<locals>.wrapperr )r r r r r �decorator_with_arguments s r c � � �fdd�}|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 s� | j }tjj|d��� }tjj|d��� ptjj|d��� }|���s%|r0� | g|�R i |��S t �
| d� | j�dd�}d|� d�}d }|| j�
� v rQt| 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�permr r � _functionL s
�
z$manager_can_enter.<locals>._functionr �r5 r6 r7 r r4 r �manager_can_enter<