Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed resource time slot isAdmin check #304

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading