From 41f60e10112fef49f2807dd10d2ff56c86867191 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tumanov Date: Wed, 22 Mar 2023 20:30:20 +0500 Subject: [PATCH] TSK-745: Do not allow changing previous months events (Requests and public holidays) (#2796) Signed-off-by: Vyacheslav Tumanov --- .../src/components/schedule/MonthView.svelte | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/hr-resources/src/components/schedule/MonthView.svelte b/plugins/hr-resources/src/components/schedule/MonthView.svelte index 01adb62bc1..8255399f2f 100644 --- a/plugins/hr-resources/src/components/schedule/MonthView.svelte +++ b/plugins/hr-resources/src/components/schedule/MonthView.svelte @@ -16,7 +16,7 @@ import { Employee } from '@hcengineering/contact' import { EmployeePresenter } from '@hcengineering/contact-resources' import contact from '@hcengineering/contact-resources/src/plugin' - import { Ref } from '@hcengineering/core' + import { AccountRole, getCurrentAccount, Ref } from '@hcengineering/core' import type { Department, Request, RequestType, Staff } from '@hcengineering/hr' import { areDatesEqual, @@ -75,8 +75,16 @@ ) } + function isFutureDate () { + const today = new Date(Date.now()) + return ( + currentDate >= today || + (currentDate.getMonth() === today.getMonth() && currentDate.getFullYear() === today.getFullYear()) + ) + } + function isEditable (employee: Staff): boolean { - return editableList.includes(employee._id) + return editableList.includes(employee._id) && (isFutureDate() || getCurrentAccount().role === AccountRole.Owner) } const noWeekendHolidayType: Ref[] = [hr.ids.PTO, hr.ids.PTO2, hr.ids.Vacation] @@ -158,7 +166,7 @@ on:mouseleave={() => { hoveredIndex = -1 }} - on:click={() => setPublicHoliday(day)} + on:click={() => isFutureDate() && setPublicHoliday(day)} > {getWeekDayName(day, 'short')} {day.getDate()}