[FIX] BASE: Fixed the issue in company change from the employee individual view, and removed the unwanted permissions from settings page

This commit is contained in:
Horilla
2024-12-02 10:16:25 +05:30
parent 983b469827
commit aa2c524bdc
3 changed files with 166 additions and 16 deletions

View File

@@ -4,13 +4,17 @@ context_processor.py
This module is used to register context processor`
"""
import re
from django.apps import apps
from django.contrib import messages
from django.http import HttpResponse
from django.urls import path
from django.urls import path, reverse
from django.utils.translation import gettext_lazy as _
from base.models import Company, TrackLateComeEarlyOut
from base.urls import urlpatterns
from employee.models import EmployeeGeneralSetting
from employee.models import Employee, EmployeeGeneralSetting, EmployeeWorkInformation
from horilla import horilla_apps
from horilla.decorators import hx_request_required, login_required, permission_required
from horilla.methods import get_horilla_model_class
@@ -30,6 +34,15 @@ class AllCompany:
id = None
def get_last_section(path):
# Remove any trailing slash and split the path
segments = path.strip("/").split("/")
# Get the last section (the ID)
last_section = segments[-1] if segments else None
return last_section
def get_companies(request):
"""
This method will return the history additional field form
@@ -77,6 +90,44 @@ def update_selected_company(request):
else AllCompany()
)
)
previous_path = request.GET.get("next", "/")
# Define the regex pattern for the path
pattern = r"^/employee/employee-view/\d+/$"
# Check if the previous path matches the pattern
if company_id != "all":
if re.match(pattern, previous_path):
employee_id = get_last_section(previous_path)
employee = Employee.objects.filter(id=employee_id).first()
if (
not EmployeeWorkInformation.objects.filter(
employee_id=employee_id
).exists()
or employee.employee_work_info.company_id != company
):
text = "Other Company"
if (
company_id
== request.user.employee_get.employee_work_info.company_id
):
text = "My Company"
if company_id == "all":
text = "All companies"
company = {
"company": company.company,
"icon": company.icon.url,
"text": text,
"id": company.id,
}
messages.error(
request, _("Employee is not working in the selected company.")
)
request.session["selected_company_instance"] = company
return HttpResponse(
f"""
<script>window.location.href = `{reverse("employee-view")}`</script>
"""
)
text = "Other Company"
if company_id == request.user.employee_get.employee_work_info.company_id:

View File

@@ -10,7 +10,7 @@
<ul class="oh-dropdown__items">
{% for company in all_companies %}
<li class="oh-dropdown__item">
<a hx-get="{% url 'update-selected-company' %}?company_id={{company.0}}"class="oh-dropdown__link">
<a hx-get="{% url 'update-selected-company' %}?company_id={{company.0}}&next={{ request.path }}"class="oh-dropdown__link">
<img src="{{company.2}}" class="oh-dropdown__lang-icon" style="border-radius: 50%;" />
{{company.1}}
{% if company.3 %}

View File

@@ -3083,17 +3083,73 @@ def employee_permission_assign(request):
).distinct()
context["show_assign"] = True
permissions = []
horilla_apps = APPS
horilla_apps = [
"base",
"recruitment",
"employee",
"leave",
"pms",
"onboarding",
"asset",
"attendance",
"payroll",
"auth",
"offboarding",
"horilla_documents",
"helpdesk",
]
installed_apps = [app for app in settings.INSTALLED_APPS if app in horilla_apps]
no_permission_models = [
"historicalbonuspoint",
"assetreport",
"assetdocuments",
"returnimages",
"holiday",
"companyleave",
"historicalavailableleave",
"historicalleaverequest",
"historicalleaveallocationrequest",
"leaverequestconditionapproval",
"historicalcompensatoryleaverequest",
"employeepastleaverestrict",
"overrideleaverequests",
"historicalrotatingworktypeassign",
"employeeshiftday",
"historicalrotatingshiftassign",
"historicalworktyperequest",
"historicalshiftrequest",
"multipleapprovalmanagers",
"attachment",
"announcementview",
"emaillog",
"driverviewed",
"dashboardemployeecharts",
"attendanceallowedip",
"tracklatecomeearlyout",
"historicalcontract",
"overrideattendance",
"overrideleaverequest",
"overrideworkinfo",
"multiplecondition",
"historicalpayslip",
"reimbursementmultipleattachment",
"historicalcontract",
"overrideattendance",
"overrideleaverequest",
"workrecord",
"historicalticket",
]
for app_name in installed_apps:
app_models = []
for model in get_models_in_app(app_name):
app_models.append(
{
"verbose_name": model._meta.verbose_name.capitalize(),
"model_name": model._meta.model_name,
}
)
if model._meta.model_name not in no_permission_models:
app_models.append(
{
"verbose_name": model._meta.verbose_name.capitalize(),
"model_name": model._meta.model_name,
}
)
permissions.append(
{"app": app_name.capitalize().replace("_", " "), "app_models": app_models}
)
@@ -3178,15 +3234,58 @@ def permission_table(request):
permissions = []
apps = APPS
form = AssignPermission()
no_permission_models = [
"historicalbonuspoint",
"assetreport",
"assetdocuments",
"returnimages",
"holiday",
"companyleave",
"historicalavailableleave",
"historicalleaverequest",
"historicalleaveallocationrequest",
"leaverequestconditionapproval",
"historicalcompensatoryleaverequest",
"employeepastleaverestrict",
"overrideleaverequests",
"historicalrotatingworktypeassign",
"employeeshiftday",
"historicalrotatingshiftassign",
"historicalworktyperequest",
"historicalshiftrequest",
"multipleapprovalmanagers",
"attachment",
"announcementview",
"emaillog",
"driverviewed",
"dashboardemployeecharts",
"attendanceallowedip",
"tracklatecomeearlyout",
"historicalcontract",
"overrideattendance",
"overrideleaverequest",
"overrideworkinfo",
"multiplecondition",
"historicalpayslip",
"reimbursementmultipleattachment",
"historicalcontract",
"overrideattendance",
"overrideleaverequest",
"workrecord",
"historicalticket",
]
for app_name in apps:
app_models = []
for model in get_models_in_app(app_name):
app_models.append(
{
"verbose_name": model._meta.verbose_name.capitalize(),
"model_name": model._meta.model_name,
}
)
if model not in no_permission_models:
app_models.append(
{
"verbose_name": model._meta.verbose_name.capitalize(),
"model_name": model._meta.model_name,
}
)
permissions.append({"app": app_name.capitalize(), "app_models": app_models})
if request.method == "POST":
form = AssignPermission(request.POST)