Skip to content

Commit

Permalink
Changed when reservation type is shown and selectable (#309)
Browse files Browse the repository at this point in the history
Previously any staff could see reservation type and its selector. Changed permissions so that only unit's staff members can see and select reservation type.
  • Loading branch information
SanttuA authored Mar 6, 2024
1 parent f720851 commit 62a53fb
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ReservationInformation extends Component {
currentCustomerGroup: PropTypes.string.isRequired,
currentPaymentMethod: PropTypes.string.isRequired,
isAdmin: PropTypes.bool.isRequired,
isStaff: PropTypes.bool.isRequired,
isEditing: PropTypes.bool.isRequired,
isMakingReservations: PropTypes.bool.isRequired,
onBack: PropTypes.func.isRequired,
Expand All @@ -47,6 +48,7 @@ class ReservationInformation extends Component {
getFormFields = (termsAndConditions) => {
const {
isAdmin,
isStaff,
resource,
order,
reservation,
Expand All @@ -69,7 +71,6 @@ class ReservationInformation extends Component {

if (isAdmin) {
formFields.push('comments');
formFields.push('type');

/* waiting for backend implementation */
// formFields.push('reserverName');
Expand All @@ -82,6 +83,9 @@ class ReservationInformation extends Component {
formFields.push('staffEvent');
}
*/
if (isStaff) {
formFields.push('type');
}

if (termsAndConditions) {
formFields.push('termsAndConditions');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ describe('pages/reservation/reservation-information/ReservationInformation', ()
const wrapper = getWrapper({ isAdmin: true, resource });
const instance = wrapper.instance();
const actual = instance.getFormFields();
// const adminFields = ['comments',
// 'reserverName', 'reserverEmailAddress', 'reserverPhoneNumber'];
const adminFields = ['comments', 'type'];
const adminFields = ['comments'];

expect(actual).toEqual([...supportedFields, ...adminFields]);
}
Expand All @@ -185,6 +183,13 @@ describe('pages/reservation/reservation-information/ReservationInformation', ()
);
*/

test('returns type when user is staff', () => {
const wrapper = getWrapper({ isStaff: true, resource });
const instance = wrapper.instance();
const actual = instance.getFormFields();
expect(actual).toEqual([...supportedFields, 'type']);
});

test('returns supportedReservationExtraFields and termsAndConditions', () => {
const termsAndConditions = 'some terms and conditions';
const wrapper = getWrapper({ resource });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ConfirmReservationModal extends Component {
isMakingReservations: PropTypes.bool.isRequired,
isPreliminaryReservation: PropTypes.bool.isRequired,
isStaff: PropTypes.bool.isRequired,
isStaffForResource: PropTypes.bool.isRequired,
onCancel: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
onConfirm: PropTypes.func.isRequired,
Expand All @@ -47,6 +48,7 @@ class ConfirmReservationModal extends Component {
getFormFields = (termsAndConditions) => {
const {
isStaff,
isStaffForResource,
resource,
showTimeControls,
} = this.props;
Expand All @@ -56,11 +58,15 @@ class ConfirmReservationModal extends Component {
formFields.push('begin', 'end');
}

// general 'is_staff' perm, not tied to unit perms
if (isStaff) {
formFields.push('comments');
formFields.push('reserverName');
formFields.push('reserverEmailAddress');
formFields.push('reserverPhoneNumber');
}
// unit staff check
if (isStaffForResource) {
formFields.push('type');
}
if (resource.universalField && resource.universalField.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('shared/reservation-confirmation/ConfirmReservationModal', () => {
isMakingReservations: false,
isPreliminaryReservation: false,
isStaff: false,
isStaffForResource: false,
onCancel: simple.stub(),
onClose: simple.stub(),
onConfirm: simple.stub(),
Expand Down Expand Up @@ -182,12 +183,12 @@ describe('shared/reservation-confirmation/ConfirmReservationModal', () => {
});

describe('type', () => {
test('is included if user is staff', () => {
expect(getFormFields({ isStaff: true })).toEqual(expect.arrayContaining(['type']));
test('is included if user is staff for resource', () => {
expect(getFormFields({ isStaffForResource: true })).toEqual(expect.arrayContaining(['type']));
});

test('is not included if user is not staff', () => {
expect(getFormFields({ isStaff: false })).toEqual(expect.not.arrayContaining(['type']));
test('is not included if user is not staff for resource', () => {
expect(getFormFields({ isStaffForResource: false })).toEqual(expect.not.arrayContaining(['type']));
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class UnconnectedReservationConfirmationContainer extends Component {
currentLanguage: PropTypes.string.isRequired,
isMakingReservations: PropTypes.bool.isRequired,
isStaff: PropTypes.bool.isRequired,
isStaffForResource: PropTypes.bool.isRequired,
params: PropTypes.shape({ // eslint-disable-line react/no-unused-prop-types
id: PropTypes.string.isRequired,
}).isRequired,
Expand Down Expand Up @@ -98,6 +99,7 @@ export class UnconnectedReservationConfirmationContainer extends Component {
confirmReservationModalIsOpen,
isMakingReservations,
isStaff,
isStaffForResource,
recurringReservations,
reservationsToEdit,
resource,
Expand All @@ -116,6 +118,7 @@ export class UnconnectedReservationConfirmationContainer extends Component {
isMakingReservations={isMakingReservations}
isPreliminaryReservation={resource.needManualConfirmation}
isStaff={isStaff}
isStaffForResource={isStaffForResource}
onCancel={actions.cancelReservationEdit}
onClose={actions.closeConfirmReservationModal}
onConfirm={isEditing ? this.handleEdit : this.handleReservation}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('pages/resource/reservation-calendar/ReservationConfirmationContainer',
currentLanguage: 'fi',
isMakingReservations: false,
isStaff: false,
isStaffForResource: false,
params: { id: resource.id },
recurringReservations: [Reservation.build()],
reservationsToEdit: [],
Expand Down Expand Up @@ -60,6 +61,7 @@ describe('pages/resource/reservation-calendar/ReservationConfirmationContainer',
expect(actualProps.isPreliminaryReservation)
.toBe(defaultProps.resource.needManualConfirmation);
expect(actualProps.isStaff).toBeDefined();
expect(actualProps.isStaffForResource).toBeDefined();
expect(actualProps.onCancel).toBe(defaultProps.actions.cancelReservationEdit);
expect(actualProps.onClose).toBe(defaultProps.actions.closeConfirmReservationModal);
expect(actualProps.onConfirm).toBe(wrapper.instance().handleReservation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ActionTypes from 'constants/ActionTypes';
import FormTypes from 'constants/FormTypes';
import ModalTypes from 'constants/ModalTypes';
import recurringReservations from 'state/recurringReservations';
import { isAdminSelector } from 'state/selectors/authSelectors';
import { isAdminSelector, createIsStaffSelector } from 'state/selectors/authSelectors';
import { createResourceSelector } from 'state/selectors/dataSelectors';
import selectedReservationsFromStateSelector from 'state/selectors/selectedReservationsSelector';
import modalIsOpenSelectorFactory from 'state/selectors/factories/modalIsOpenSelectorFactory';
Expand All @@ -33,6 +33,7 @@ const reservationConfirmationSelector = createStructuredSelector({
currentLanguage: currentLanguageSelector,
isMakingReservations: requestIsActiveSelectorFactory(ActionTypes.API.RESERVATION_POST_REQUEST),
isStaff: isAdminSelector,
isStaffForResource: createIsStaffSelector(resourceSelector),
recurringReservations: recurringReservations.selectReservations,
reservationsToEdit: toEditSelector,
resource: resourceSelector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ describe('shared/reservation-confirmation/reservationConfirmationSelector', () =
expect(getSelected().isStaff).toBeDefined();
});

test('returns isStaffForResource', () => {
expect(getSelected().isStaffForResource).toBeDefined();
});

test('returns recurringReservations from the state', () => {
expect(getSelected().recurringReservations).toEqual(recurringReservations);
});
Expand Down

0 comments on commit 62a53fb

Please sign in to comment.