[FIX] RECRUITMENT: Mail template permission fix

This commit is contained in:
Horilla
2024-01-06 12:48:01 +05:30
parent 759b5d62fa
commit 7e8f9ecb2a
3 changed files with 25 additions and 16 deletions

View File

@@ -1,4 +1,6 @@
{% extends 'index.html' %}
{% load static %}
{% load i18n %}
{% block content %}
<style>
.truncated-text {
@@ -23,22 +25,28 @@
<section class="oh-wrapper oh-main__topbar">
<div class="oh-main__titlebar oh-main__titlebar--left oh-d-flex-column--resp oh-mb-3--small">
<h1 class="oh-main__titlebar-title fw-bold">Mail Templates</h1>
</div>
<div class="oh-main__titlebar oh-main__titlebar--right oh-d-flex-column--resp oh-mb-3--small">
<a href="#" data-toggle="oh-modal-toggle" data-target="#addTemplateModal" class="oh-btn oh-btn--secondary ml-2"><ion-icon name="add" class="mr-1 md hydrated" role="img" aria-label="add"></ion-icon>Add</a>
<h1 class="oh-main__titlebar-title fw-bold">{% trans "Mail Templates" %}</h1>
</div>
{% if perms.recruitment.add_recruitmentmailtemplate %}
<div class="oh-main__titlebar oh-main__titlebar--right oh-d-flex-column--resp oh-mb-3--small">
<a href="#" data-toggle="oh-modal-toggle" data-target="#addTemplateModal" class="oh-btn oh-btn--secondary ml-2"><ion-icon name="add" class="mr-1 md hydrated" role="img" aria-label="add"></ion-icon>{% trans "Add" %}</a>
</div>
{% endif %}
</section>
<div class="oh-wrapper oh-faq-cards">
{% for template in templates %}
<div class="oh-faq-card">
<h3 class="oh-faq-card__title d-flex justify-content-between"><span>{{ template.title }}</span> <a href="{% url "delete-mail-template" %}?ids={{template.id}}" class="text-danger" style="cursor: pointer;" onclick="return confirm('Do you want to delete this template?')"><ion-icon name="trash-outline"></ion-icon></a></h3>
<p class="oh-faq-card__desc oh-card__footer--border-top">
{% if perms.recruitment.delete_recruitmentmailtemplate %}
<h3 class="oh-faq-card__title d-flex justify-content-between"><span>{{ template.title }}</span> <a href="{% url "delete-mail-template" %}?ids={{template.id}}" class="text-danger" style="cursor: pointer;" onclick="return confirm('Do you want to delete this template?')"><ion-icon name="trash-outline"></ion-icon></a></h3>
{% endif %}
<p class="oh-faq-card__desc oh-card__footer--border-top">
<div style="max-height: 350px;overflow: hidden;" class="truncated-text">{{ template.body|safe }}</div>
</p>
<a hx-get="{% url 'view-mail-template' template.id %}" hx-target="#viewTemplateModalBody" data-toggle="oh-modal-toggle" data-target="#viewTemplateModal" class="oh-btn oh-btn--secondary oh-btn--block">View Template</a>
</div>
{% if perms.recruitment.change_recruitmentmailtemplate %}
<a hx-get="{% url 'view-mail-template' template.id %}" hx-target="#viewTemplateModalBody" data-toggle="oh-modal-toggle" data-target="#viewTemplateModal" class="oh-btn oh-btn--secondary oh-btn--block">{% trans "View Template" %}</a>
{% endif %}
</div>
{% endfor %}
</div>
<div class="oh-modal" id="viewTemplateModal" role="dialog" aria-labelledby="viewTemplateModal" aria-hidden="true">
@@ -49,21 +57,21 @@
</div>
<div class="oh-modal__dialog-body" id="viewTemplateModalBody"></div>
<div class="oh-modal__dialog-footer">
<button type="submit" onclick="$('#submitFormButton')[0].click()" class="oh-btn oh-btn--secondary oh-btn--shadow">Save Preferences</button>
<button type="submit" onclick="$('#submitFormButton')[0].click()" class="oh-btn oh-btn--secondary oh-btn--shadow">{% trans "Save Preferences" %}</button>
</div>
</div>
</div>
<div class="oh-modal" id="addTemplateModal" role="dialog" aria-labelledby="addTemplateModal" aria-hidden="true">
<div class="oh-modal__dialog">
<div class="oh-modal__dialog-header">
<span class="oh-modal__dialog-title" id="addTemplateModalLabel">Add Template</span>
<span class="oh-modal__dialog-title" id="addTemplateModalLabel">{% trans "Add Template" %}</span>
<button class="oh-modal__close" aria-label="Close"><ion-icon name="close-outline"></ion-icon></button>
</div>
<div class="oh-modal__dialog-body" id="addTemplateModalBody">
{% include 'offerletter/htmx/form.html' %}
</div>
<div class="oh-modal__dialog-footer">
<button type="submit" onclick="$('#submitFormButton')[0].click()" class="oh-btn oh-btn--secondary oh-btn--shadow">Save Preferences</button>
<button type="submit" onclick="$('#submitFormButton')[0].click()" class="oh-btn oh-btn--secondary oh-btn--shadow">{% trans "Save Preferences" %}</button>
</div>
</div>
</div>

View File

@@ -13,7 +13,7 @@ from recruitment.forms import OfferLetterForm
@login_required
@permission_required("recruitment.view_offerletterdelete")
@permission_required("recruitment.view_recruitmentmailtemplate")
def view_mail_templates(request):
"""
This method will render template to disply the offerletter templates
@@ -28,7 +28,7 @@ def view_mail_templates(request):
@login_required
@permission_required("recruitment.change_offerletterdelete")
@permission_required("recruitment.change_recruitmentmailtemplate")
def view_letter(request, obj_id):
"""
This method is used to display the template/form to edit
@@ -47,7 +47,7 @@ def view_letter(request, obj_id):
@login_required
@require_http_methods(["POST"])
@permission_required("recruitment.add_offerletterdelete")
@permission_required("recruitment.add_recruitmentmailtemplate")
def create_letter(request):
"""
This method is used to create offerletter template
@@ -63,10 +63,11 @@ def create_letter(request):
@login_required
@permission_required("recruitment.delete_offerlettertemplate")
@permission_required("recruitment.delete_recruitmentmailtemplate")
def delete_mail_templates(request):
ids = request.GET.getlist("ids")
result = RecruitmentMailTemplate.objects.filter(id__in=ids).delete()
messages.success(request, "Template deleted")
return redirect(view_mail_templates)

View File

@@ -138,7 +138,7 @@
>
</li>
{% endif %}
{% if perms.recruitment.view_offerlettertemplate %}
{% if perms.recruitment.view_recruitmentmailtemplate %}
<li class="oh-sidebar__submenu-item">
<a
class="oh-sidebar__submenu-link"