[UPDT] EMPLOYEE: User can acces and manipulate data on employee individual view if it's their own individual view

This commit is contained in:
Horilla
2024-04-09 10:04:57 +05:30
parent c94ac361a7
commit 405cffffd7
4 changed files with 129 additions and 128 deletions

View File

@@ -400,7 +400,7 @@
>
</li>
{% endif %}
{% if perms.horilla_documents.view_document %}
{% if perms.horilla_documents.view_document or request.user == employee.employee_user_id %}
<li data-cell-index="20" data-cell-title="{% trans 'Documents' %}" class="oh-general__tab">
<a
hx-get="{% url 'document-tab' employee.id %}?employee_view=true"
@@ -426,7 +426,7 @@
>
</li>
{% endif %}
{% if perms.employee.view_employeenote or request.user|check_manager:employee %}
{% if perms.employee.view_employeenote or request.user|check_manager:employee or request.user == employee.employee_user_id %}
<li data-cell-index="21" data-cell-title="{% trans 'Bonus' %}" class="oh-general__tab">
<a
hx-get={% url 'bonus-points-tab' employee.id %}
@@ -541,7 +541,7 @@
class="oh-general__tab-target oh-profile__info-tab mb-4 d-none"
id="payroll"
>
{% if perms.view_payslip %}
{% if perms.view_payslip or request.user == employee.employee_user_id %}
{% include "tabs/payroll-tab.html" %}
{% endif %}
</div>

View File

@@ -44,76 +44,73 @@
<div class="oh-layout--grid-3">
{% if data %}
{% for emp in data %}
<div class="oh-kanban-card" style="color: inherit;text-decoration: none;{% if emp.employee_work_info.reporting_manager_id == request.user.employee_get %} background-color: hsl(38.08deg 100% 50% / 8%);{% endif %}">
<a href="{% url 'employee-view-individual' emp.id %}" style="color: inherit;text-decoration: none; display: flex;">
<div class="oh-kanban-card__avatar">
<div class="oh-kanban-card__profile-container {% if emp.employee_profile %} profile-picture {% endif %}">
<img
src="{{emp.get_avatar}}"
class="oh-kanban-card__profile-image"
alt=""
/>
<div class="oh-kanban-card" style="color: inherit;text-decoration: none;{% if emp.employee_work_info.reporting_manager_id == request.user.employee_get %} background-color: hsl(38.08deg 100% 50% / 8%);{% endif %}"
onclick="window.location.href = `{% url 'employee-view-individual' emp.id %}`"
>
<div class="oh-kanban-card__avatar">
<div class="oh-kanban-card__profile-container {% if emp.employee_profile %} profile-picture {% endif %}">
<img
src="{{emp.get_avatar}}"
class="oh-kanban-card__profile-image"
alt=""
/>
</div>
</div>
</div>
<div class="oh-kanban-card__details">
<span class="oh-kanban-card__title">{{emp}}</span>
<span class="oh-kanban-card__subtitle">{{emp.email}}</span><br>
<span class="oh-kanban-card__subtitle">{{emp.employee_work_info.job_position_id}}</span>
<div class="oh-kanban-card__subtitle">
{% if emp.check_online %}
<span class="oh-dot oh-dot--small me-1" style="background-color:yellowgreen"></span> {% trans "Online" %}
{% else %}
<span class="oh-dot oh-dot--small me-1" style="background-color:rgba(128, 128, 128, 0.482)"></span> {% trans "Offline" %}
<div class="oh-kanban-card__details">
<span class="oh-kanban-card__title">{{emp}}</span>
<span class="oh-kanban-card__subtitle">{{emp.email}}</span><br>
<span class="oh-kanban-card__subtitle">{{emp.employee_work_info.job_position_id}}</span>
<div class="oh-kanban-card__subtitle">
{% if emp.check_online %}
<span class="oh-dot oh-dot--small me-1" style="background-color:yellowgreen"></span> {% trans "Online" %}
{% else %}
<span class="oh-dot oh-dot--small me-1" style="background-color:rgba(128, 128, 128, 0.482)"></span> {% trans "Offline" %}
{% endif %}
</div>
</div>
{% if perms.employee.change_employee or perms.employee.delete_employee or request.user|check_manager:emp %}
<div class="oh-kanban-card__dots" onclick="event.stopPropagation()">
<div class="oh-dropdown" x-data="{show: false}">
<button class="oh-btn oh-btn--transparent text-muted p-3" @click="show = !show" title='{% trans "Actions" %}'>
<ion-icon name="ellipsis-vertical-sharp" role="img" class="md hydrated" aria-label="ellipsis vertical sharp"></ion-icon>
</button>
<div class="oh-dropdown__menu oh-dropdown__menu--dark-border oh-dropdown__menu--right" x-show="show" @click.outside="show = false" style="display: none;">
<ul class="oh-dropdown__items">
{% if perms.employee.change_employee or request.user|check_manager:emp %}
<li class="oh-dropdown__item">
<a href="{% url 'employee-view-update' emp.id %}" class="oh-dropdown__link">{% trans "Edit" %}</a>
</li>
{% endif %}
{% if perms.employee.delete_employee %}
<li class="oh-dropdown__item">
{% if emp.is_active %}
<a hx-confirm="{% trans 'Do you want to archive this employee?' %}" hx-post="{% url 'employee-archive' emp.id %}?{{pd}}" hx-target="#relatedModel" class="oh-dropdown__link">
{% trans "Archive" %}
</a>
{% else %}
<a hx-confirm="{% trans 'Do you want to un archive this employee?' %}" hx-post="{% url 'employee-archive' emp.id %}" hx-target="#relatedModel" class="oh-dropdown__link">
{% trans "Un-Archive" %}
</a>
{% endif %}
</li>
{% endif %}
{% if perms.employee.delete_employee %}
<li class="oh-dropdown__item">
<form action="{% url 'employee-delete' emp.id %}?view=card" method="post" onsubmit="return confirm('{% trans "Do you want to delete this employee?" %}')">
{% csrf_token %}
<button type="submit" class="oh-dropdown__link oh-dropdown__link--danger">{% trans "Delete" %}</button>
</form>
</li>
{% endif %}
</ul>
</div>
</div>
</div>
{% endif %}
</div>
</div>
</a>
{% if perms.employee.change_employee or perms.employee.delete_employee or request.user|check_manager:emp %}
<div class="oh-kanban-card__dots">
<div class="oh-dropdown" x-data="{show: false}">
<button class="oh-btn oh-btn--transparent text-muted p-3" @click="show = !show" title='{% trans "Actions" %}'>
<ion-icon name="ellipsis-vertical-sharp" role="img" class="md hydrated" aria-label="ellipsis vertical sharp"></ion-icon>
</button>
<div class="oh-dropdown__menu oh-dropdown__menu--dark-border oh-dropdown__menu--right" x-show="show" @click.outside="show = false" style="display: none;">
<ul class="oh-dropdown__items">
{% if perms.employee.change_employee or request.user|check_manager:emp %}
<li class="oh-dropdown__item">
<a href="{% url 'employee-view-update' emp.id %}" class="oh-dropdown__link">{% trans "Edit" %}</a>
</li>
{% endif %}
{% if perms.employee.delete_employee %}
<li class="oh-dropdown__item">
{% if emp.is_active %}
<a hx-confirm="{% trans 'Do you want to archive this employee?' %}" hx-post="{% url 'employee-archive' emp.id %}?{{pd}}" hx-target="#relatedModel" class="oh-dropdown__link">
{% trans "Archive" %}
</a>
{% else %}
<a hx-confirm="{% trans 'Do you want to un archive this employee?' %}" hx-post="{% url 'employee-archive' emp.id %}" hx-target="#relatedModel" class="oh-dropdown__link">
{% trans "Un-Archive" %}
</a>
{% endif %}
</li>
{% endif %}
{% if perms.employee.delete_employee %}
<li class="oh-dropdown__item">
<form action="{% url 'employee-delete' emp.id %}?view=card" method="post" onsubmit="return confirm('{% trans "Do you want to delete this employee?" %}')">
{% csrf_token %}
<button type="submit" class="oh-dropdown__link oh-dropdown__link--danger">{% trans "Delete" %}</button>
</form>
</li>
{% endif %}
</ul>
</div>
</div>
</div>
{% endif %}
</div>
{% endfor %}
</div>
<div class="oh-pagination">
@@ -159,17 +156,17 @@
</nav>
</div>
{% else %}
<!-- start of empty page -->
<div class="oh-404">
<img
style="width: 150px; height: 150px"
src="{% static 'images/ui/no-results.png' %}"
class="oh-404__image mb-4"
/>
<h5 class="oh-404__subtitle">
{% trans "No search result found!" %}
</h5>
</div>
<!-- end of empty page -->
<!-- start of empty page -->
<div class="oh-404">
<img
style="width: 150px; height: 150px"
src="{% static 'images/ui/no-results.png' %}"
class="oh-404__image mb-4"
/>
<h5 class="oh-404__subtitle">
{% trans "No search result found!" %}
</h5>
</div>
<!-- end of empty page -->
{% endif %}

View File

@@ -1,5 +1,4 @@
{% load i18n %}
<style>
a:hover {
text-decoration: none;
@@ -41,48 +40,47 @@
</div>
<div class="oh-sticky-table__tbody">
{% for payslip in employee.payslip_set.all %}
<a href="{% url 'view-created-payslip' payslip.id %}" class="oh-sticky-table__tr" >
<div class="oh-sticky-table__sd {% if payslip.status == "review_ongoing" %}row-status--orange {% elif payslip.status == "confirmed" %} row-status--blue {% elif payslip.status == "paid" %} row-status--yellow {% elif payslip.status == "draft" %} row-status--gray{% endif %}">
<div class="d-flex">
<div class="oh-profile oh-profile--md">
<div class="oh-profile__avatar mr-1">
<img
src="https://ui-avatars.com/api/?name={{payslip.employee_id.employee_first_name}}+{{payslip.employee_id.employee_last_name}}&background=random"
class="oh-profile__image"
alt=""
/>
<a href="{% url 'view-created-payslip' payslip.id %}" class="oh-sticky-table__tr" >
<div class="oh-sticky-table__sd {% if payslip.status == "review_ongoing" %}row-status--orange {% elif payslip.status == "confirmed" %} row-status--blue {% elif payslip.status == "paid" %} row-status--yellow {% elif payslip.status == "draft" %} row-status--gray{% endif %}">
<div class="d-flex">
<div class="oh-profile oh-profile--md">
<div class="oh-profile__avatar mr-1">
<img
src="https://ui-avatars.com/api/?name={{payslip.employee_id.employee_first_name}}+{{payslip.employee_id.employee_last_name}}&background=random"
class="oh-profile__image"
alt=""
/>
</div>
<span class="oh-profile__name oh-text--dark">{{payslip.employee_id}}</span>
</div>
<span class="oh-profile__name oh-text--dark">{{payslip.employee_id}}</span>
</div>
</div>
</div>
<div class="oh-sticky-table__td dateformat_changer">
{{payslip.start_date}}
</div>
<div class="oh-sticky-table__td dateformat_changer">
{{payslip.end_date}}
</div>
<div class="oh-sticky-table__td">
{{payslip.get_status_display}}
</div>
<div class="oh-sticky-table__td">
{{currency}} {{payslip.gross_pay|floatformat:2}}
</div>
<div class="oh-sticky-table__td">
{{currency}} {{payslip.deduction|floatformat:2}}
</div>
<div class="oh-sticky-table__td">
{{currency}} {{payslip.net_pay|floatformat:2}}
</div>
<div class="oh-sticky-table__td">
<div class="oh-btn-group">
<div type="button" id="download" data-id={{payslip.id}} title="{% trans 'Download' %}" class="oh-btn oh-btn--light-bkg w-100"> <ion-icon name="download"></ion-icon></div>
</div>
</div>
</a>
</div>
<div class="oh-sticky-table__td dateformat_changer">
{{payslip.start_date}}
</div>
<div class="oh-sticky-table__td dateformat_changer">
{{payslip.end_date}}
</div>
<div class="oh-sticky-table__td">
{{payslip.get_status_display}}
</div>
<div class="oh-sticky-table__td">
{{currency}} {{payslip.gross_pay|floatformat:2}}
</div>
<div class="oh-sticky-table__td">
{{currency}} {{payslip.deduction|floatformat:2}}
</div>
<div class="oh-sticky-table__td">
{{currency}} {{payslip.net_pay|floatformat:2}}
</div>
<div class="oh-sticky-table__td">
<div class="oh-btn-group">
<div type="button" id="download" data-id={{payslip.id}} title="{% trans 'Download' %}" class="oh-btn oh-btn--light-bkg w-100"> <ion-icon name="download"></ion-icon></div>
</div>
</div>
</a>
{% endfor %}
</div>
</div>

View File

@@ -237,7 +237,7 @@ def employee_view_individual(request, obj_id, **kwargs):
"""
This method is used to view profile of an employee.
"""
employee = Employee.objects.get(id=obj_id)
employee = Employee.objects.get(id=obj_id)
instances = LeaveRequest.objects.filter(employee_id=employee)
leave_request_ids = json.dumps([instance.id for instance in instances])
employee_leaves = employee.available_leave.all()
@@ -245,16 +245,22 @@ def employee_view_individual(request, obj_id, **kwargs):
AccountBlockUnblock.objects.exists()
and AccountBlockUnblock.objects.first().is_enabled
)
return render(
request,
"employee/view/individual.html",
{
context={
"employee": employee,
"employee_leaves": employee_leaves,
"current_date": date.today(),
"leave_request_ids": leave_request_ids,
"enabled_block_unblock": enabled_block_unblock,
},
}
# if the requesting user opens own data
if request.user.employee_get == employee:
context['user_leaves']=employee_leaves
else:
context['employee_leaves']=employee_leaves
return render(
request,
"employee/view/individual.html",
context,
)