[UPDT] HORILLA: Permission updations in views

This commit is contained in:
Horilla
2025-12-03 14:50:33 +05:30
parent d0fb75442b
commit 6ede82ce60
17 changed files with 200 additions and 169 deletions

View File

@@ -10,7 +10,7 @@ from horilla_views.generic.cbv.views import HorillaDetailedView, HorillaListView
@method_decorator(login_required, name="dispatch")
@method_decorator(permission_required("asset.view_assetlot"), name="dispatch")
@method_decorator(permission_required("asset.view_asset"), name="dispatch")
class AssetListView(HorillaListView):
"""
list view for batch number

View File

@@ -40,7 +40,7 @@
{% endif %}
{% endif %}
{% if perms.asset.add_asset %}
{% if perms.asset.change_asset %}
<a
class="oh-btn oh-btn--light-bkg w-100 flex-1"
data-toggle="oh-modal-toggle"

View File

@@ -4,7 +4,7 @@
{% if instance.asset_request_status == 'Requested' %}
<div class="oh-btn-group">
<a
class="oh-btn oh-btn--success w-100"
class="oh-btn oh-btn--success w-50"
role="button123"
data-toggle="oh-modal-toggle"
data-target="#objectCreateModal"

View File

@@ -2,60 +2,63 @@
<div>
<div class="oh-btn-group">
{% if instance.asset_request_status == "Approved" %}
<a
class="oh-btn oh-btn--light-bkg oh-btn--disabled w-100"
title="{% trans 'Edit' %}"
>
<ion-icon
name="create-outline"
role="img"
class="md hydrated"
aria-label="create outline"
></ion-icon>
</a>
{% else %}
<a
class="oh-btn oh-btn--light-bkg w-100"
title="{% trans 'Edit' %}"
data-toggle="oh-modal-toggle"
data-target="#genericModal"
hx-put="{% url 'asset-request-update' instance.id %}"
hx-target="#genericModalBody"
>
<ion-icon
name="create-outline"
role="img"
class="md hydrated"
aria-label="create outline"
></ion-icon>
</a>
{% if perms.asset.change_assetrequest or request.user.employee_get == instance.requested_employee_id %}
{% if instance.asset_request_status == "Approved" %}
<a
class="oh-btn oh-btn--light-bkg oh-btn--disabled w-100"
title="{% trans 'Edit' %}"
>
<ion-icon
name="create-outline"
role="img"
class="md hydrated"
aria-label="create outline"
></ion-icon>
</a>
{% else %}
<a
class="oh-btn oh-btn--light-bkg w-100"
title="{% trans 'Edit' %}"
data-toggle="oh-modal-toggle"
data-target="#genericModal"
hx-put="{% url 'asset-request-update' instance.id %}"
hx-target="#genericModalBody"
>
<ion-icon
name="create-outline"
role="img"
class="md hydrated"
aria-label="create outline"
></ion-icon>
</a>
{% endif %}
{% endif %}
{% if instance.asset_request_status == "Approved" %}
<a
class="oh-btn oh-btn--light-bkg oh-btn--danger-outline oh-btn--disabled w-100"
title="{% trans 'Delete' %}"
>
<ion-icon
name="trash-outline"
role="img"
class="md hydrated"
></ion-icon>
</a>
{% else %}
<a
class="oh-btn oh-btn--light-bkg oh-btn--danger-outline w-100"
title="{% trans 'Delete' %}"
hx-confirm="{% trans 'Do you want to delete this Allocation?' %}"
hx-post="{% url 'asset-request-delete' instance.id %}"
>
<ion-icon
name="trash-outline"
role="img"
class="md hydrated"
></ion-icon>
</a>
{% if perms.asset.delete_assetrequest %}
{% if instance.asset_request_status == "Approved" %}
<a
class="oh-btn oh-btn--light-bkg oh-btn--danger-outline oh-btn--disabled w-100"
title="{% trans 'Delete' %}"
>
<ion-icon
name="trash-outline"
role="img"
class="md hydrated"
></ion-icon>
</a>
{% else %}
<a
class="oh-btn oh-btn--light-bkg oh-btn--danger-outline w-100"
title="{% trans 'Delete' %}"
hx-confirm="{% trans 'Do you want to delete this Allocation?' %}"
hx-post="{% url 'asset-request-delete' instance.id %}"
>
<ion-icon
name="trash-outline"
role="img"
class="md hydrated"
></ion-icon>
</a>
{% endif %}
{% endif %}
</div>
</div>

View File

@@ -46,7 +46,7 @@ class CompanyleaveListView(HorillaListView):
self.search_url = reverse("company-leave-filter")
self.view_id = "companyleavedelete"
if self.request.user.has_perm("base.view_companyleave"):
if self.request.user.has_perm("base.view_companyleaves"):
self.action_method = "company_leave_actions"
if self.request.user.has_perm("base.view_company"):
@@ -84,7 +84,7 @@ class CompanyLeaveNavView(HorillaNavView):
def __init__(self, **kwargs: Any) -> None:
super().__init__(**kwargs)
self.search_url = reverse("company-leave-filter")
if self.request.user.has_perm("base.add_companyleave"):
if self.request.user.has_perm("base.add_companyleaves"):
self.create_attrs = f"""
hx-get="{reverse_lazy('company-leave-creation')}"
hx-target="#genericModalBody"
@@ -117,7 +117,6 @@ class CompanyLeaveDetailView(HorillaDetailedView):
@method_decorator(login_required, name="dispatch")
@method_decorator(permission_required("base.add_companyleave"), name="dispatch")
class CompanyleaveFormView(HorillaFormView):
"""
form view for create button

View File

@@ -47,7 +47,9 @@ class HolidayListView(HorillaListView):
super().__init__(**kwargs)
self.search_url = reverse("holiday-filter")
self.view_id = "holidaydelete"
if self.request.user.has_perm("base.add_holiday"):
if self.request.user.has_perm(
"base.change_holidays"
) or self.request.user.has_perm("base.delete_holidays"):
self.action_method = "holidays_actions"
columns = [
@@ -84,7 +86,7 @@ class HolidayNavView(HorillaNavView):
def __init__(self, **kwargs: Any) -> None:
super().__init__(**kwargs)
self.search_url = reverse("holiday-filter")
if self.request.user.has_perm("base.add_holiday"):
if self.request.user.has_perm("base.add_holidays"):
self.create_attrs = f"""
hx-get="{reverse_lazy('holiday-creation')}"
hx-target="#genericModalBody"
@@ -172,7 +174,6 @@ class HolidayExport(TemplateView):
@method_decorator(login_required, name="dispatch")
@method_decorator(permission_required("leave.add_holidays"), name="dispatch")
class HolidayFormView(HorillaFormView):
"""
form view for create button

View File

@@ -1,12 +1,12 @@
{% load i18n static %}
{% if perms.leave.change_companyleave or perms.leave.delete_companyleave %}
{% if perms.base.change_companyleaves or perms.base.delete_companyleaves %}
<div onclick="event.stopPropagation();" class="oh-btn-group">
{% if perms.leave.change_companyleave %}
{% if perms.base.change_companyleaves %}
<button class="oh-btn oh-btn--light-bkg w-100" title="{% trans 'Edit' %}" data-toggle="oh-modal-toggle"
data-target="#genericModal" hx-get="{% url 'company-leave-update' instance.id %}?instance_ids={{instance.ordered_ids}}"
hx-target="#genericModalBody"><ion-icon name="create-outline"></ion-icon></button>
{% endif %}
{% if perms.leave.delete_companyleave %}
{% if perms.base.delete_companyleaves %}
<a class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100"
hx-confirm="{% trans 'Are you sure you want to delete ?' %}"
hx-post="{% url 'company-leave-delete' instance.id %}"

View File

@@ -1,26 +1,26 @@
{% load basefilters i18n %}
<div class="oh-btn-group">
{% if perms.leave.change_companyleave or perms.leave.delete_companyleave %}
{% if perms.leave.change_companyleave %}
{% if perms.base.change_companyleaves or perms.base.delete_companyleaves %}
{% if perms.base.change_companyleaves %}
<a
hx-get="{% url 'company-leave-update' instance.id %}"
hx-target="#genericModalBody"
data-toggle="oh-modal-toggle"
data-target="#genericModal"
class="oh-btn oh-btn--info w-50"
class="oh-btn oh-btn--info w-100"
>
<ion-icon name="create-outline"></ion-icon>
{% trans 'Edit' %}
</a>
{% endif %}
{% if perms.leave.delete_companyleave %}
{% if perms.base.delete_companyleaves %}
<a
hx-post="{% url 'company-leave-delete' instance.id %}"
hx-target="#listContainer"
hx-confirm="{% trans 'Are you sure you want to delete ?' %}"
class="oh-btn oh-btn--secondary w-50"
class="oh-btn oh-btn--secondary w-100"
>
<ion-icon
name="trash-outline"

View File

@@ -1,7 +1,7 @@
{% load basefilters i18n %}
<div class="oh-btn-group w-100">
{% if perms.leave.change_holiday %}
{% if perms.base.change_holidays %}
<a
hx-get="{% url 'holiday-update' instance.id %}?{{pd}}"
hx-target="#genericModalBody"
@@ -14,7 +14,7 @@
</a>
{% endif %}
{% if perms.leave.delete_holiday %}
{% if perms.base.delete_holidays %}
<a
hx-post="{% url 'holiday-delete' instance.id %}"
hx-target="#holidaydelete"

View File

@@ -1,6 +1,6 @@
{% load i18n %}
<div onclick="event.stopPropagation();" class="oh-btn-group">
{% if perms.leave.change_holiday %}
{% if perms.base.change_holidays %}
<button
class="oh-btn oh-btn--light-bkg w-100"
title="{% trans 'Edit' %}"
@@ -11,8 +11,6 @@
>
<ion-icon name="create-outline"></ion-icon>
</button>
{% endif %}
{% if perms.leave.change_holiday %}
<button
class="oh-btn oh-btn--light-bkg w-100"
title="{% trans 'Duplicate' %}"
@@ -24,7 +22,7 @@
<ion-icon name="copy-outline"></ion-icon>
</button>
{% endif %}
{% if perms.leave.delete_holiday %}
{% if perms.base.delete_holidays %}
<a
class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100"
id="delete-link"

View File

@@ -17,7 +17,6 @@ from horilla_views.generic.cbv.views import HorillaFormView
@method_decorator(login_required, name="dispatch")
@method_decorator(permission_required("helpdesk.add_faqcategory"), name="dispatch")
class FaqCategoryCreateFormView(HorillaFormView):
"""
form view for create and update faq categories

View File

@@ -1,30 +1,45 @@
{% load i18n %}
{% load i18n %}{% load basefilters %}
{% is_manager_of request.user instance as can_manage %}
<div onclick="event.stopPropagation()">
<div class="oh-btn-group">
{% if instance.status == 'requested' %}
<button
class="oh-btn oh-btn--light-bkg w-50"
title="{% trans 'Edit' %}"
data-toggle="oh-modal-toggle"
data-target="#genericModal"
hx-get="{% url 'leave-allocation-request-update' instance.id %}?instance_ids={{instance.ordered_ids}}"
hx-target="#genericModalBody">
<ion-icon name="create-outline"></ion-icon>
</button>
{% if perms.leave.change_leaveallocationrequest or request.user.employee_get == instance.employee_id or can_manage %}
{% if instance.status == 'requested' %}
<button
class="oh-btn oh-btn--light-bkg w-50"
title="{% trans 'Edit' %}"
data-toggle="oh-modal-toggle"
data-target="#genericModal"
hx-get="{% url 'leave-allocation-request-update' instance.id %}?instance_ids={{instance.ordered_ids}}"
hx-target="#genericModalBody">
<ion-icon name="create-outline"></ion-icon>
</button>
{% else %}
<button
class="oh-btn oh-btn--light-bkg w-50" disabled>
<ion-icon name="create-outline" ></ion-icon>
</button>
{% endif %}
{% else %}
<button
class="oh-btn oh-btn--light-bkg w-50" disabled>
<ion-icon name="create-outline" ></ion-icon>
</button>
{% endif %}
{% if instance.status == 'requested' %}
<button class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-50" id="delete-link"
hx-confirm="{% trans 'Are you sure you want to delete ?' %}"
hx-post="{% url 'leave-allocation-request-delete' instance.id %}?{{pd}}"
hx-target="#leave-allocation"
title="{% trans 'Delete' %}">
<ion-icon name="trash-outline"></ion-icon>
</button>
{% if perms.leave.delete_leaveallocationrequest or request.user.employee_get == instance.employee_id or can_manage %}
{% if instance.status == 'requested' %}
<button class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-50" id="delete-link"
hx-confirm="{% trans 'Are you sure you want to delete ?' %}"
hx-post="{% url 'leave-allocation-request-delete' instance.id %}?{{pd}}"
hx-target="#leave-allocation"
title="{% trans 'Delete' %}">
<ion-icon name="trash-outline"></ion-icon>
</button>
{% else %}
<button class="oh-btn oh-btn--light-bkg w-50" disabled>
<ion-icon name="trash-outline"></ion-icon>
</button>
{% endif %}
{% else %}
<button class="oh-btn oh-btn--light-bkg w-50" disabled>
<ion-icon name="trash-outline"></ion-icon>

View File

@@ -87,7 +87,7 @@ class DeductionListView(HorillaListView):
self.view_id = "deduct-container"
if self.request.user.has_perm(
"payroll.change_deduction"
) or self.request.user.has_perm("payroll.change_deduction"):
) or self.request.user.has_perm("payroll.delete_deduction"):
self.action_method = "deduct_actions"
else:
self.action_method = None

View File

@@ -2,27 +2,31 @@
{% if perms.payroll.change_allowance or perms.payroll.delete_allowance %}
<div class="oh-modal__button-container w-100">
<div class="oh-btn-group">
<a href="{% url 'update-allowance' instance.id %}" class="oh-btn oh-btn--info" style="width: 50%;">
<ion-icon
name="create-outline"
role="img"
class="md hydrated"
aria-label="create outline"
></ion-icon>{% trans "Edit" %}
</a>
<a hx-post="{% url 'delete-employee-allowance' instance.id %}?instances_ids={{ request.GET.instance_ids }}" onclick="event.preventDefault();event.stopPropagation();"
class="oh-btn oh-btn--danger" style="width: 50%;"
hx-confirm="{% trans 'Do you want to delete this Allowance?' %}"
hx-target="#genericModalBody"
>
<ion-icon
name="trash-outline"
role="img"
class="md hydrated"
aria-label="create outline"
>
</ion-icon>{% trans "Delete" %}
{% if perms.payroll.change_allowance %}
<a href="{% url 'update-allowance' instance.id %}" class="oh-btn oh-btn--info" style="width: 100%;">
<ion-icon
name="create-outline"
role="img"
class="md hydrated"
aria-label="create outline"
></ion-icon>{% trans "Edit" %}
</a>
{% endif %}
{% if perms.payroll.delete_allowance %}
<a hx-post="{% url 'delete-employee-allowance' instance.id %}?instances_ids={{ request.GET.instance_ids }}" onclick="event.preventDefault();event.stopPropagation();"
class="oh-btn oh-btn--danger" style="width: 100%;"
hx-confirm="{% trans 'Do you want to delete this Allowance?' %}"
hx-target="#genericModalBody"
>
<ion-icon
name="trash-outline"
role="img"
class="md hydrated"
aria-label="create outline"
>
</ion-icon>{% trans "Delete" %}
</a>
{% endif %}
</div>
</div>

View File

@@ -2,21 +2,25 @@
{% if perms.payroll.change_allowance or perms.payroll.delete_allowance %}
<div class="oh-sticky-table__right">
<div class="oh-btn-group">
<a onclick="event.stopPropagation();" class="oh-btn oh-btn--light-bkg w-100"
href="{% url 'update-allowance' instance.id %}" title='{% trans "Update" %}'>
<ion-icon name="create-outline" role="img" class="md hydrated" style="color: blue"
aria-label="create outline"></ion-icon>
</a>
<a class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100"
onclick = "event.preventDefault();event.stopPropagation();"
hx-get="{% url 'generic-delete' %}?model=payroll.Allowance&pk={{instance.id}}"
hx-target="#deleteConfirmationBody" data-toggle="oh-modal-toggle"
data-target="#deleteConfirmation"
itle="{% trans 'Delete' %}">
<ion-icon name="trash-outline" role="img" class="md hydrated"
aria-label="trash outline" >
</ion-icon>
</a>
{% if perms.payroll.change_allowance %}
<a onclick="event.stopPropagation();" class="oh-btn oh-btn--light-bkg w-100"
href="{% url 'update-allowance' instance.id %}" title='{% trans "Update" %}'>
<ion-icon name="create-outline" role="img" class="md hydrated" style="color: blue"
aria-label="create outline"></ion-icon>
</a>
{% endif %}
{% if perms.payroll.delete_allowance %}
<a class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100"
onclick = "event.preventDefault();event.stopPropagation();"
hx-get="{% url 'generic-delete' %}?model=payroll.Allowance&pk={{instance.id}}"
hx-target="#deleteConfirmationBody" data-toggle="oh-modal-toggle"
data-target="#deleteConfirmation"
itle="{% trans 'Delete' %}">
<ion-icon name="trash-outline" role="img" class="md hydrated"
aria-label="trash outline" >
</ion-icon>
</a>
{% endif %}
</div>
</div>
{% endif %}

View File

@@ -1,36 +1,40 @@
{% load i18n %}
{% if perms.payroll.change_deduction or perms.payroll.change_deduction %}
<div class="">
<div class="oh-btn-group">
<a
onclick="event.stopPropagation();"
class="oh-btn oh-btn--light-bkg w-100"
href="{% url 'update-deduction' instance.id %}"
title="{% trans 'Update' %}"
>
<ion-icon
name="create-outline"
role="img"
class="md hydrated"
style="color: blue"
aria-label="create outline"
></ion-icon>
</a>
<a
class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100"
onclick = "event.preventDefault();event.stopPropagation();"
hx-get="{% url 'generic-delete' %}?model=payroll.Deduction&pk={{instance.id}}"
hx-target="#deleteConfirmationBody" data-toggle="oh-modal-toggle"
data-target="#deleteConfirmation"
title="{% trans 'Delete' %}"
>
<ion-icon
name="trash-outline"
role="img"
class="md hydrated"
aria-label="trash outline"
></ion-icon>
</a>
</div>
</div>
{% endif %}
{% if perms.payroll.change_deduction or perms.payroll.delete_deduction %}
<div class="">
<div class="oh-btn-group">
{% if perms.payroll.change_deduction %}
<a
onclick="event.stopPropagation();"
class="oh-btn oh-btn--light-bkg w-100"
href="{% url 'update-deduction' instance.id %}"
title="{% trans 'Update' %}"
>
<ion-icon
name="create-outline"
role="img"
class="md hydrated"
style="color: blue"
aria-label="create outline"
></ion-icon>
</a>
{% endif %}
{% if perms.payroll.delete_deduction %}
<a
class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100"
onclick = "event.preventDefault();event.stopPropagation();"
hx-get="{% url 'generic-delete' %}?model=payroll.Deduction&pk={{instance.id}}"
hx-target="#deleteConfirmationBody" data-toggle="oh-modal-toggle"
data-target="#deleteConfirmation"
title="{% trans 'Delete' %}"
>
<ion-icon
name="trash-outline"
role="img"
class="md hydrated"
aria-label="trash outline"
></ion-icon>
</a>
{% endif %}
</div>
</div>
{% endif %}

View File

@@ -2,16 +2,20 @@
{% if perms.payroll.change_deduction or perms.payroll.delete_deduction %}
<div class="oh-modal__button-container text-center w-100">
<div class="oh-btn-group">
<a href="{% url 'update-deduction' instance.id %}" class="oh-btn oh-btn--info" style="width: 50%;">
{% if perms.payroll.change_deduction %}
<a href="{% url 'update-deduction' instance.id %}" class="oh-btn oh-btn--info" style="width: 100%;">
<ion-icon name="create-outline" role="img" class="md hydrated" aria-label="create outline"></ion-icon>
{% trans "Edit" %}
</a>
{% endif %}
{% if perms.payroll.delete_deduction %}
<a onclick = "event.preventDefault();event.stopPropagation();" hx-confirm="{% trans 'Do you want to delete this deduction?' %}"
hx-post="{% url 'delete-deduction' instance.id %}?instances_ids={{ request.GET.instance_ids }}" hx-target = "#genericModalBody"
class="oh-btn oh-btn--danger" style="width: 50%;">
class="oh-btn oh-btn--danger" style="width: 100%;">
<ion-icon name="trash-outline" role="img" class="md hydrated" aria-label="create outline"></ion-icon>
{% trans "Delete" %}
</a>
{% endif %}
</div>
</div>
{% endif %}