TSK-745: Do not allow changing previous months events (Requests and public holidays) (#2796)

Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
Vyacheslav Tumanov 2023-03-22 20:30:20 +05:00 committed by GitHub
parent cfda41bb66
commit 41f60e1011
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,7 +16,7 @@
import { Employee } from '@hcengineering/contact' import { Employee } from '@hcengineering/contact'
import { EmployeePresenter } from '@hcengineering/contact-resources' import { EmployeePresenter } from '@hcengineering/contact-resources'
import contact from '@hcengineering/contact-resources/src/plugin' 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 type { Department, Request, RequestType, Staff } from '@hcengineering/hr'
import { import {
areDatesEqual, 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 { function isEditable (employee: Staff): boolean {
return editableList.includes(employee._id) return editableList.includes(employee._id) && (isFutureDate() || getCurrentAccount().role === AccountRole.Owner)
} }
const noWeekendHolidayType: Ref<RequestType>[] = [hr.ids.PTO, hr.ids.PTO2, hr.ids.Vacation] const noWeekendHolidayType: Ref<RequestType>[] = [hr.ids.PTO, hr.ids.PTO2, hr.ids.Vacation]
@ -158,7 +166,7 @@
on:mouseleave={() => { on:mouseleave={() => {
hoveredIndex = -1 hoveredIndex = -1
}} }}
on:click={() => setPublicHoliday(day)} on:click={() => isFutureDate() && setPublicHoliday(day)}
> >
{getWeekDayName(day, 'short')} {getWeekDayName(day, 'short')}
<span>{day.getDate()}</span> <span>{day.getDate()}</span>