diff --git a/accessibility/models.py b/accessibility/models.py index fd2f19315..12552df69 100644 --- a/accessibility/models.py +++ b/accessibility/models.py @@ -18,5 +18,5 @@ class DefaultAccessibility(HorillaModel): filter = models.JSONField() exclude_all = models.BooleanField(default=False) employees = models.ManyToManyField( - Employee, blank=True, related_name="profile_edit_accessibility" + Employee, blank=True, related_name="default_accessibility" ) diff --git a/base/context_processors.py b/base/context_processors.py index 734f94e7e..0e874abfb 100644 --- a/base/context_processors.py +++ b/base/context_processors.py @@ -14,7 +14,12 @@ from django.utils.translation import gettext_lazy as _ from base.models import Company, TrackLateComeEarlyOut from base.urls import urlpatterns -from employee.models import Employee, EmployeeGeneralSetting, EmployeeWorkInformation +from employee.models import ( + Employee, + EmployeeGeneralSetting, + EmployeeWorkInformation, + ProfileEditFeature, +) from horilla import horilla_apps from horilla.decorators import hx_request_required, login_required, permission_required from horilla.methods import get_horilla_model_class @@ -284,3 +289,15 @@ def enable_late_come_early_out_tracking(request): tracking = TrackLateComeEarlyOut.objects.first() enable = tracking.is_enable if tracking else True return {"tracking": enable, "late_come_early_out_tracking": enable} + + +def enable_profile_edit(request): + from accessibility.accessibility import ACCESSBILITY_FEATURE + + profile_edit = ProfileEditFeature.objects.filter().first() + enable = True if profile_edit and profile_edit.is_enabled else False + if enable: + if not any(item[0] == "profile_edit" for item in ACCESSBILITY_FEATURE): + ACCESSBILITY_FEATURE.append(("profile_edit", _("Profile Edit Access"))) + + return {"profile_edit_enabled": enable} diff --git a/base/templates/base/audit_tag/employee_account_block_unblock.html b/base/templates/base/audit_tag/employee_account_block_unblock.html index 387cca63f..84221dd5b 100644 --- a/base/templates/base/audit_tag/employee_account_block_unblock.html +++ b/base/templates/base/audit_tag/employee_account_block_unblock.html @@ -1,20 +1,73 @@ -{% load i18n %} -{% csrf_token %} +{% load i18n %} {% csrf_token %}
-

{% trans 'Employee Account Block/Unblock' %}

+

+ {% trans 'Employee Account Restrictions' %} +

-
- {% csrf_token %} -
- - - +
+
+ + {% csrf_token %} +
+ + + +
+
+ +
+ +
-
- +
+
+ {% csrf_token %} +
+ + + +
+
+ +
+ +
- - +
diff --git a/base/urls.py b/base/urls.py index 5cbf0e676..c69635ec2 100644 --- a/base/urls.py +++ b/base/urls.py @@ -744,6 +744,11 @@ urlpatterns = [ views.enable_account_block_unblock, name="enable-account-block-unblock", ), + path( + "enable-profile-edit-feature", + views.enable_profile_edit_feature, + name="enable-profile-edit-feature", + ), path( "rwork-individual-view//", views.rotating_work_individual_view, diff --git a/base/views.py b/base/views.py index 2e297b60d..7e3a06e7a 100644 --- a/base/views.py +++ b/base/views.py @@ -37,6 +37,7 @@ from django.utils.translation import gettext as _ from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_http_methods +from accessibility.models import DefaultAccessibility from base.backends import ConfiguredEmailBackend from base.decorators import ( shift_request_change_permission, @@ -158,6 +159,7 @@ from employee.models import ( Employee, EmployeeGeneralSetting, EmployeeWorkInformation, + ProfileEditFeature, ) from horilla.decorators import ( delete_permission, @@ -4874,6 +4876,10 @@ def general_settings(request): AccountBlockUnblock.objects.exists() and AccountBlockUnblock.objects.first().is_enabled ) + enabled_profile_edit = ( + ProfileEditFeature.objects.exists() + and ProfileEditFeature.objects.first().is_enabled + ) history_tracking_instance = HistoryTrackingFields.objects.first() history_fields_form_initial = {} if history_tracking_instance and history_tracking_instance.tracking_fields: @@ -4906,6 +4912,7 @@ def general_settings(request): "history_fields_form": history_fields_form, "history_tracking_instance": history_tracking_instance, "enabled_block_unblock": enabled_block_unblock, + "enabled_profile_edit": enabled_profile_edit, "prefix_form": prefix_form, "companies": companies, "selected_company_id": selected_company_id, @@ -5100,6 +5107,44 @@ def enable_account_block_unblock(request): return HttpResponse(status=405) +from accessibility.accessibility import ACCESSBILITY_FEATURE + + +@login_required +@permission_required("employee.change_employee") +def enable_profile_edit_feature(request): + + if request.method == "POST": + enabled = request.POST.get("enable_profile_edit") == "on" + instance = ProfileEditFeature.objects.first() + feature = DefaultAccessibility.objects.filter(feature="profile_edit").first() + if instance: + instance.is_enabled = enabled + instance.save() + else: + ProfileEditFeature.objects.create(is_enabled=enabled) + + if enabled and not feature: + DefaultAccessibility.objects.create( + feature="profile_edit", filter={"feature": ["profile_edit"]} + ) + + if enabled: + if not any(item[0] == "profile_edit" for item in ACCESSBILITY_FEATURE): + ACCESSBILITY_FEATURE.append(("profile_edit", _("Profile Edit Access"))) + else: + ACCESSBILITY_FEATURE.pop() + + messages.success( + request, + _(f"Profile edit feature has been {'enabled' if enabled else 'disabled'}."), + ) + if request.META.get("HTTP_HX_REQUEST"): + return HttpResponse() + return redirect(general_settings) + return HttpResponse(status=405) + + @login_required def shift_select(request): page_number = request.GET.get("page") diff --git a/employee/accessibility.py b/employee/accessibility.py index e590fff12..fbc5a44ea 100644 --- a/employee/accessibility.py +++ b/employee/accessibility.py @@ -5,7 +5,3 @@ employee/accessibility.py from django.utils.translation import gettext_lazy as _ from accessibility.accessibility import ACCESSBILITY_FEATURE - -ACCESSBILITY_FEATURE += [ - ("profile_edit", _("Profile Edit Access")), -] diff --git a/employee/models.py b/employee/models.py index d388428bd..333554eb6 100644 --- a/employee/models.py +++ b/employee/models.py @@ -925,6 +925,15 @@ class EmployeeGeneralSetting(HorillaModel): objects = HorillaCompanyManager("company_id") +class ProfileEditFeature(HorillaModel): + """ + ProfileEditFeature + """ + + is_enabled = models.BooleanField(default=False) + objects = models.Manager() + + from accessibility.accessibility import ACCESSBILITY_FEATURE ACCESSBILITY_FEATURE.append(("gender_chart", "Can view Gender Chart")) diff --git a/employee/templates/employee_personal_info/employee_card.html b/employee/templates/employee_personal_info/employee_card.html index b0902b7d1..539694913 100644 --- a/employee/templates/employee_personal_info/employee_card.html +++ b/employee/templates/employee_personal_info/employee_card.html @@ -85,16 +85,18 @@ {% trans "Edit" %} {% endif %} - {% if perms.employee.change_employee or request.user|check_manager:emp %} -
  • - - {% if emp.profile_edit_accessibility.all %} - {% trans "Revoke Profile Edit Access" %} - {% else %} - {% trans "Add Profile Edit Access" %} - {% endif %} - -
  • + {% if profile_edit_enabled %} + {% if perms.employee.change_employee or request.user|check_manager:emp %} +
  • + + {% if emp.profile_edit_accessibility.all %} + {% trans "Revoke Profile Edit Access" %} + {% else %} + {% trans "Add Profile Edit Access" %} + {% endif %} + +
  • + {% endif %} {% endif %} {% if perms.employee.delete_employee %}
  • diff --git a/horilla/horilla_context_processors.py b/horilla/horilla_context_processors.py index 08322d991..8cbe4b77c 100644 --- a/horilla/horilla_context_processors.py +++ b/horilla/horilla_context_processors.py @@ -40,3 +40,6 @@ TEMPLATES[0]["OPTIONS"]["context_processors"].append( TEMPLATES[0]["OPTIONS"]["context_processors"].append( "base.context_processors.enable_late_come_early_out_tracking", ) +TEMPLATES[0]["OPTIONS"]["context_processors"].append( + "base.context_processors.enable_profile_edit", +)