From a8af657cf1dd7c7ba795069e752986db3cb4d74b Mon Sep 17 00:00:00 2001 From: SanttuA Date: Tue, 20 Feb 2024 15:00:49 +0200 Subject: [PATCH] Changed resource time slot isAdmin check (#304) Before only user's general staff perm was used in `isAdmin` check. Now `isAdmin` is checked against unit permissions (admin, manager, viewer) --- .../ReservationCalendarContainer.js | 6 ++++-- .../ReservationCalendarContainer.spec.js | 11 ++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/pages/resource/reservation-calendar/ReservationCalendarContainer.js b/app/pages/resource/reservation-calendar/ReservationCalendarContainer.js index 9b3225dc3..870258f35 100644 --- a/app/pages/resource/reservation-calendar/ReservationCalendarContainer.js +++ b/app/pages/resource/reservation-calendar/ReservationCalendarContainer.js @@ -28,7 +28,7 @@ import ReservationConfirmation from 'shared/reservation-confirmation'; import recurringReservations from 'state/recurringReservations'; import { injectT } from 'i18n'; import { getEditReservationUrl } from 'utils/reservationUtils'; -import { hasMaxReservations, reservingIsRestricted } from 'utils/resourceUtils'; +import { hasMaxReservations, reservingIsRestricted, isStaffForResource } from 'utils/resourceUtils'; import reservationCalendarSelector from './reservationCalendarSelector'; import ReservingRestrictedText from './ReservingRestrictedText'; import TimeSlots from './time-slots'; @@ -155,6 +155,8 @@ export class UnconnectedReservationCalendarContainer extends Component { const isOpen = Boolean(timeSlots.length); const showTimeSlots = isOpen && !reservingIsRestricted(resource, date); const selectedDateSlots = this.getSelectedDateSlots(timeSlots, selected); + const isResourceStaff = (isAdmin && resource) ? isStaffForResource(resource) : false; + return (

{t('ReservationCalendar.header')}

@@ -162,7 +164,7 @@ export class UnconnectedReservationCalendarContainer extends Component { { const actions = { @@ -91,7 +92,15 @@ describe('pages/resource/reservation-calendar/ReservationCalendarContainer', () }); test(`${renderTimeSlots ? 'renders' : 'does not render'} TimeSlots`, () => { - expect(wrapper.find(TimeSlots).length === 1).toBe(renderTimeSlots); + const timeslots = wrapper.find(TimeSlots); + expect(timeslots.length === 1).toBe(renderTimeSlots); + if (renderTimeSlots) { + const isResourceStaff = (defaultProps.isAdmin && defaultProps.resource) + ? isStaffForResource(resource) : false; + expect(timeslots.prop('isAdmin')).toBe(isResourceStaff); + expect(timeslots.prop('isEditing')).toBe(defaultProps.isEditing); + expect(timeslots.prop('resource')).toBe(defaultProps.resource); + } }); test(`${renderClosedText ? 'renders' : 'does not render'} closed text`, () => {