[UPDT] OFFBOARDING: User level updates
This commit is contained in:
@@ -4,24 +4,28 @@ offboarding/decorators.py
|
||||
This module is used to write custom authentication decorators for offboarding module
|
||||
"""
|
||||
from django.contrib import messages
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from horilla.decorators import decorator_with_arguments
|
||||
from offboarding.models import Offboarding, OffboardingStage, OffboardingTask
|
||||
|
||||
|
||||
@decorator_with_arguments
|
||||
def any_manager_can_enter(function, perm):
|
||||
def any_manager_can_enter(function, perm, offboarding_employee_can_enter=False):
|
||||
def _function(request, *args, **kwargs):
|
||||
employee = request.user.employee_get
|
||||
if request.user.has_perm(perm) or (
|
||||
Offboarding.objects.filter(managers=employee).exists()
|
||||
| OffboardingStage.objects.filter(managers=employee).exists()
|
||||
| OffboardingTask.objects.filter(managers=employee).exists()
|
||||
if (
|
||||
request.user.has_perm(perm)
|
||||
or offboarding_employee_can_enter
|
||||
or (
|
||||
Offboarding.objects.filter(managers=employee).exists()
|
||||
| OffboardingStage.objects.filter(managers=employee).exists()
|
||||
| OffboardingTask.objects.filter(managers=employee).exists()
|
||||
)
|
||||
):
|
||||
return function(request, *args, **kwargs)
|
||||
else:
|
||||
messages.info(request, "You dont have permission.")
|
||||
return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))
|
||||
return HttpResponse("<script>window.location.reload()</script>")
|
||||
|
||||
return _function
|
||||
|
||||
@@ -37,7 +41,7 @@ def offboarding_manager_can_enter(function, perm):
|
||||
return function(request, *args, **kwargs)
|
||||
else:
|
||||
messages.info(request, "You dont have permission.")
|
||||
return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))
|
||||
return HttpResponse("<script>window.location.reload()</script>")
|
||||
|
||||
return _function
|
||||
|
||||
@@ -54,6 +58,6 @@ def offboarding_or_stage_manager_can_enter(function, perm):
|
||||
return function(request, *args, **kwargs)
|
||||
else:
|
||||
messages.info(request, "You dont have permission.")
|
||||
return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))
|
||||
return HttpResponse("<script>window.location.reload()</script>")
|
||||
|
||||
return _function
|
||||
|
||||
@@ -40,4 +40,4 @@
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
</ol>
|
||||
@@ -12,53 +12,57 @@
|
||||
<div class="oh-tabs">
|
||||
<ul class="oh-tabs__tablist">
|
||||
{% for offboarding in offboardings %}
|
||||
<li class="oh-tabs__tab" onclick="localStorage.setItem('activeTabOffboarding',$(this).attr('data-target'));" data-target="#Offboarding{{ offboarding.id }}">
|
||||
{{ offboarding.title }}
|
||||
<div class="d-flex">
|
||||
<div class="oh-tabs__input-badge-container">
|
||||
<span class="oh-badge oh-badge--secondary oh-badge--small oh-badge--round ms-2 mr-2" id="recruitmentCandidateCount1" title="{{ offboarding.offboardingstage_set.all|length }} Stages" onclick="event.stopPropagation()">
|
||||
{{ offboarding.offboardingstage_set.all|length }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="oh-dropdown" x-data="{open: false}">
|
||||
<button class="oh-btn oh-stop-prop oh-btn--transparent oh-accordion-meta__btn" @click="open = !open" @click.outside="open = false" title="Actions">
|
||||
<ion-icon name="ellipsis-vertical" role="img" class="md hydrated" aria-label="ellipsis vertical"></ion-icon>
|
||||
</button>
|
||||
<div class="oh-dropdown__menu oh-dropdown__menu--right" x-show="open" style="display: none;">
|
||||
<ul class="oh-dropdown__items">
|
||||
{% if perms.offboarding.change_offboarding or request.user.employee_get|is_offboarding_manager %}
|
||||
<li class="oh-dropdown__item">
|
||||
<a hx-get="{% url "create-offboarding" %}?instance_id={{offboarding.id}}" hx-target="#offboardingModalBody" data-toggle="oh-modal-toggle" data-target="#offboardingModal" class="oh-dropdown__link">{% trans "Edit" %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if perms.offboarding.delete_offboarding %}
|
||||
<li class="oh-dropdown__item">
|
||||
<form action="{% url "delete-offboarding" %}" onsubmit="return confirm('Are you sure you want to delete this offboarding?');" method="post">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="oh-dropdown__link oh-dropdown__link--danger">
|
||||
{% trans "Delete" %}
|
||||
</button>
|
||||
</form>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% if perms.offboarding.view_offboarding or request.user.employee_get|is_in_offboarding:offboarding %}
|
||||
<li class="oh-tabs__tab" onclick="localStorage.setItem('activeTabOffboarding',$(this).attr('data-target'));" data-target="#Offboarding{{ offboarding.id }}">
|
||||
{{ offboarding.title }}
|
||||
<div class="d-flex">
|
||||
<div class="oh-tabs__input-badge-container">
|
||||
<span class="oh-badge oh-badge--secondary oh-badge--small oh-badge--round ms-2 mr-2" id="recruitmentCandidateCount1" title="{{ offboarding.offboardingstage_set.all|length }} Stages" onclick="event.stopPropagation()">
|
||||
{{ offboarding.offboardingstage_set.all|length }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<div class="oh-dropdown" x-data="{open: false}">
|
||||
<button class="oh-btn oh-stop-prop oh-btn--transparent oh-accordion-meta__btn" @click="open = !open" @click.outside="open = false" title="Actions">
|
||||
<ion-icon name="ellipsis-vertical" role="img" class="md hydrated" aria-label="ellipsis vertical"></ion-icon>
|
||||
</button>
|
||||
<div class="oh-dropdown__menu oh-dropdown__menu--right" x-show="open" style="display: none;">
|
||||
<ul class="oh-dropdown__items">
|
||||
{% if perms.offboarding.change_offboarding or request.user.employee_get|is_offboarding_manager %}
|
||||
<li class="oh-dropdown__item">
|
||||
<a hx-get="{% url "create-offboarding" %}?instance_id={{offboarding.id}}" hx-target="#offboardingModalBody" data-toggle="oh-modal-toggle" data-target="#offboardingModal" class="oh-dropdown__link">{% trans "Edit" %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if perms.offboarding.delete_offboarding %}
|
||||
<li class="oh-dropdown__item">
|
||||
<form action="{% url "delete-offboarding" %}" onsubmit="return confirm('Are you sure you want to delete this offboarding?');" method="post">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="oh-dropdown__link oh-dropdown__link--danger">
|
||||
{% trans "Delete" %}
|
||||
</button>
|
||||
</form>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<div class="oh-tabs__contents">
|
||||
{% for offboarding in offboardings %}
|
||||
<div class="oh-tabs__content" id="Offboarding{{ offboarding.id }}">
|
||||
{% if perms.offboarding.add_offboardingstage or request.user.employee_get|any_manager %}
|
||||
<a hx-get="{% url 'create-offboarding-stage' %}?offboarding_id={{offboarding.id}}" style="width: 100px;" hx-target="#offboardingModalBody" data-toggle="oh-modal-toggle" data-target="#offboardingModal" class="mb-3 oh-btn oh-btn--secondary">
|
||||
<ion-icon name="add-outline"></ion-icon>
|
||||
{% trans 'Stage' %}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% include "offboarding/stage/stages.html" %}
|
||||
</div>
|
||||
{% if perms.offboarding.view_offboarding or request.user.employee_get|is_in_offboarding:offboarding %}
|
||||
<div class="oh-tabs__content" id="Offboarding{{ offboarding.id }}">
|
||||
{% if perms.offboarding.add_offboardingstage or request.user.employee_get|any_manager %}
|
||||
<a hx-get="{% url 'create-offboarding-stage' %}?offboarding_id={{offboarding.id}}" style="width: 100px;" hx-target="#offboardingModalBody" data-toggle="oh-modal-toggle" data-target="#offboardingModal" class="mb-3 oh-btn oh-btn--secondary">
|
||||
<ion-icon name="add-outline"></ion-icon>
|
||||
{% trans 'Stage' %}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% include "offboarding/stage/stages.html" %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -62,7 +62,9 @@
|
||||
<div class="oh-sticky-table__th">{% trans "Notice Period" %}</div>
|
||||
<div class="oh-sticky-table__th">{% trans "Start Date" %}</div>
|
||||
<div class="oh-sticky-table__th">{% trans "End Date" %}</div>
|
||||
{% if request.user.employee_get|is_any_stage_manager or perms.offboarding.change_offboarding or perms.offboarding.change_offboardingemployee %}
|
||||
<div class="oh-sticky-table__th">{% trans "Stage" %}</div>
|
||||
{% endif %}
|
||||
<div class="oh-sticky-table__th">{% trans "Options" %}</div>
|
||||
{% for task in stage.offboardingtask_set.all %}
|
||||
<div class="oh-sticky-table__th" style="width: 200px;" hx-get="{% url "offboarding-add-task" %}?stage_id={{stage.id}}&instance_id={{task.id}}" hx-target="#offboardingModalBody" data-toggle="oh-modal-toggle" data-target="#offboardingModal">
|
||||
|
||||
@@ -6,10 +6,12 @@ This page is used to write custom template filters.
|
||||
|
||||
from django.template.defaultfilters import register
|
||||
from django import template
|
||||
from employee.models import Employee
|
||||
|
||||
from offboarding.models import (
|
||||
EmployeeTask,
|
||||
Offboarding,
|
||||
OffboardingEmployee,
|
||||
OffboardingStage,
|
||||
OffboardingTask,
|
||||
)
|
||||
@@ -19,7 +21,7 @@ register = template.Library()
|
||||
|
||||
|
||||
@register.filter(name="stages")
|
||||
def stages(stages_dict, stage):
|
||||
def stages(stages_dict: dict, stage: OffboardingStage):
|
||||
"""
|
||||
This method will return stage drop accordingly to the offboarding
|
||||
"""
|
||||
@@ -32,7 +34,7 @@ def stages(stages_dict, stage):
|
||||
|
||||
|
||||
@register.filter(name="have_task")
|
||||
def have_task(task, employee):
|
||||
def have_task(task: OffboardingTask, employee: Employee):
|
||||
"""
|
||||
used to check the task is for the employee
|
||||
"""
|
||||
@@ -40,7 +42,7 @@ def have_task(task, employee):
|
||||
|
||||
|
||||
@register.filter(name="get_assigned_task")
|
||||
def get_assigned_tak(employee, task):
|
||||
def get_assigned_tak(employee: Employee, task: OffboardingTask):
|
||||
"""
|
||||
This method is used to filterout the assigned task
|
||||
"""
|
||||
@@ -51,7 +53,7 @@ def get_assigned_tak(employee, task):
|
||||
|
||||
|
||||
@register.filter(name="any_manager")
|
||||
def any_manager(employee):
|
||||
def any_manager(employee: Employee):
|
||||
"""
|
||||
This method is used to check the employee is in managers
|
||||
employee: Employee model instance
|
||||
@@ -64,8 +66,58 @@ def any_manager(employee):
|
||||
|
||||
|
||||
@register.filter(name="is_offboarding_manager")
|
||||
def is_offboarding_manager(employee):
|
||||
def is_offboarding_manager(employee: Employee):
|
||||
"""
|
||||
This method is used to check the employee is manager of any offboarding
|
||||
"""
|
||||
return Offboarding.objects.filter(managers=employee).exists()
|
||||
|
||||
|
||||
@register.filter(name="is_offboarding_employee")
|
||||
def is_offboarding_employee(employee: Employee):
|
||||
"""
|
||||
This method is used to check the employee is in offboarding employee
|
||||
"""
|
||||
return OffboardingEmployee.objects.filter(employee_id=employee).exists()
|
||||
|
||||
|
||||
@register.filter("is_in_managers")
|
||||
def is_in_managers(employee: Employee, instance: object):
|
||||
"""
|
||||
This method is used to check the employee in the managers or not
|
||||
"""
|
||||
is_in_managers = False
|
||||
if isinstance(instance, (Offboarding, OffboardingStage)):
|
||||
# checking in offboarding managers
|
||||
is_in_managers = instance.managers.filter(employee_id=employee).exists()
|
||||
if isinstance(instance, OffboardingEmployee):
|
||||
# also checking in the offboarding employee
|
||||
is_in_managers = is_in_managers | (employee == instance.employee_id)
|
||||
return is_in_managers
|
||||
|
||||
|
||||
@register.filter("is_in_offboarding")
|
||||
def is_in_offboarding(employee: Employee, offboarding: Offboarding):
|
||||
"""
|
||||
This method is used to check the employee in the offboarding or not
|
||||
"""
|
||||
return (
|
||||
(employee in offboarding.managers.all())
|
||||
or OffboardingStage.objects.filter(
|
||||
offboarding_id=offboarding, managers=employee
|
||||
).exists()
|
||||
or OffboardingEmployee.objects.filter(
|
||||
stage_id__offboarding_id=offboarding, employee_id=employee
|
||||
).exists()
|
||||
)
|
||||
|
||||
|
||||
@register.filter("is_any_stage_manager")
|
||||
def is_any_stage_manager(employee):
|
||||
"""
|
||||
This method is used to to check any stage manager
|
||||
"""
|
||||
return (
|
||||
OffboardingStage.objects.filter(managers=employee).exists()
|
||||
| Offboarding.objects.filter(managers=employee).exists()
|
||||
)
|
||||
|
||||
@@ -735,7 +735,7 @@
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
{% if perms.offboarding.view_offboarding or request.user.employee_get|any_manager %}
|
||||
{% if perms.offboarding.view_offboarding or request.user.employee_get|any_manager or request.user.employee_get|is_offboarding_employee %}
|
||||
<li
|
||||
class="oh-sidebar__menu-item"
|
||||
x-data="{ isOpen: getOpenState('OffboardingNav') }"
|
||||
|
||||
Reference in New Issue
Block a user