forked from horilla-opensource/horilla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecorators.py
68 lines (59 loc) · 2.27 KB
/
decorators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
decorator functions for base
"""
from django.contrib import messages
from django.http import HttpResponseRedirect
from .models import ShiftRequest, WorkTypeRequest
decorator_with_arguments = (
lambda decorator: lambda *args, **kwargs: lambda func: decorator(
func, *args, **kwargs
)
)
@decorator_with_arguments
def shift_request_change_permission(function=None, *args, **kwargs):
def check_permission(
request,
shift_request_id=None,
*args,
**kwargs,
):
"""
This method is used to check the employee can change a shift request or not
"""
shift_request = ShiftRequest.objects.get(id=shift_request_id)
if (
request.user.has_perm("base.change_shiftrequest")
or request.user.employee_get
== shift_request.employee_id.employee_work_info.reporting_manager_id
or request.user.employee_get == shift_request.employee_id
):
return function(request, *args, shift_request_id=shift_request_id, **kwargs)
messages.info(request, "You dont have permission.")
return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))
# return function(request, *args, **kwargs)
return check_permission
@decorator_with_arguments
def work_type_request_change_permission(function=None, *args, **kwargs):
def check_permission(
request,
work_type_request_id=None,
*args,
**kwargs,
):
"""
This method is used to check the employee can change a shift request or not
"""
work_type_request = WorkTypeRequest.objects.get(id=work_type_request_id)
if (
request.user.has_perm("base.change_worktyperequest")
or request.user.employee_get
== work_type_request.employee_id.employee_work_info.reporting_manager_id
or request.user.employee_get == work_type_request.employee_id
):
return function(
request, *args, work_type_request_id=work_type_request_id, **kwargs
)
messages.info(request, "You dont have permission.")
return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))
# return function(request, *args, **kwargs)
return check_permission