Skip to content

Commit

Permalink
Changed resource time slot isAdmin check (#304)
Browse files Browse the repository at this point in the history
Before only user's general staff perm was used in `isAdmin` check. Now `isAdmin` is checked against unit permissions (admin, manager, viewer)
  • Loading branch information
SanttuA authored Feb 20, 2024
1 parent 5fe2a7a commit a8af657
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -155,14 +155,16 @@ 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 (
<div className="reservation-calendar">
<h3 className="visually-hidden reservation-calendar__header">{t('ReservationCalendar.header')}</h3>
{showTimeSlots && (
<TimeSlots
addNotification={debounce(actions.addNotification, 100)}
// TODO: Im a h@ck, remove me
isAdmin={isAdmin}
isAdmin={isResourceStaff}
isEditing={isEditing}
isFetching={isFetchingResource}
isLoggedIn={isLoggedIn || resource.authentication === 'unauthenticated'} // count as logged in if no auth needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { shallowWithIntl } from 'utils/testUtils';
import { UnconnectedReservationCalendarContainer as ReservationCalendarContainer } from './ReservationCalendarContainer';
import ReservingRestrictedText from './ReservingRestrictedText';
import TimeSlots from './time-slots';
import { isStaffForResource } from '../../../utils/resourceUtils';

describe('pages/resource/reservation-calendar/ReservationCalendarContainer', () => {
const actions = {
Expand Down Expand Up @@ -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`, () => {
Expand Down

0 comments on commit a8af657

Please sign in to comment.