Skip to content

Commit

Permalink
Banning a user should prohibit them from booking
Browse files Browse the repository at this point in the history
  • Loading branch information
rlho committed Jan 11, 2024
1 parent d94a571 commit d65ad9f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useState, useEffect } from 'react';
import { serverFunctions } from '../../utils/serverFunctions';
import { formatDate } from '../../utils/date';
import { Loading } from '../../utils/Loading';
const BAN_SHEET_NAME = 'banned_users';
export const BAN_SHEET_NAME = 'banned_users';

type Ban = {
email: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

export const Header = ({ isSafetyTrained, userEmail }) => {
export const Header = ({ isBanned, isSafetyTrained, userEmail }) => {
if (!isSafetyTrained) {
//alert('You have to take safty training before booking!');
}
Expand All @@ -16,6 +16,9 @@ export const Header = ({ isSafetyTrained, userEmail }) => {
You have to take safty training before booking!
</span>
)}
{isBanned && (
<span className="text-red-500 text-bold ">You're Banned.</span>
)}
</p>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MultipleCalendars } from './MultipleCalendars';
import { Modal } from 'react-bootstrap';
import { InitialModal } from './InitialModal';
import { Loading } from '../../utils/Loading';
import { BAN_SHEET_NAME } from '../../admin-page/components/Ban';
export type RoomSetting = {
roomId: string;
name: string;
Expand Down Expand Up @@ -41,6 +42,7 @@ const SheetEditor = () => {
const [userEmail, setUserEmail] = useState();
const [bookInfo, setBookInfo] = useState<DateSelectArg>();
const [isSafetyTrained, setIsSafetyTrained] = useState(false);
const [isBanned, setIsBanned] = useState(false);

const [selectedRoom, setSelectedRoom] = useState([]);
const [roomSettings, setRoomSettings] = useState([]);
Expand Down Expand Up @@ -80,6 +82,7 @@ const SheetEditor = () => {
}, []);
useEffect(() => {
getSafetyTrainingStudents();
getBannedStudents();
}, [userEmail]);

// google api key for calendar
Expand Down Expand Up @@ -150,6 +153,19 @@ const SheetEditor = () => {
});
};

const getBannedStudents = () => {
const students = serverFunctions
.getSheetRows(BAN_SHEET_NAME)
.then((rows) => {
const emails = rows.reduce(
(accumulator, value) => accumulator.concat(value),
[]
);
const banned = emails.includes(userEmail);
setIsBanned(banned);
});
};

const registerEvent = (data) => {
const email = userEmail || data.missingEmail;
selectedRoom.map(async (room) => {
Expand All @@ -160,7 +176,7 @@ const SheetEditor = () => {
)?.calendarId;
const calendarEventId = await serverFunctions.addEventToCalendar(
roomCalendarId,
`[REQUESTED] ${room.roomId} ${data.department} ${userEmail}`,
`[REQUESTED] ${room.roomId} ${data.firstName} ${data.lastName} (${data.netId})`,
'Your reservation is not yet confirmed. The coordinator will review and finalize your reservation within a few days.',
bookInfo.startStr,
bookInfo.endStr,
Expand Down Expand Up @@ -235,6 +251,10 @@ const SheetEditor = () => {
alert('You have to take safty training before booking!');
return;
}
if (userEmail && isBanned) {
alert('You are banned');
return;
}
setSection('form');
};

Expand Down Expand Up @@ -291,7 +311,11 @@ const SheetEditor = () => {
{!showModal && (
<>
<div className="flex flex-col justify-items-end items-end">
<Header isSafetyTrained={isSafetyTrained} userEmail={userEmail} />
<Header
isBanned={isBanned}
isSafetyTrained={isSafetyTrained}
userEmail={userEmail}
/>
</div>
{UserSection()}
</>
Expand Down
7 changes: 6 additions & 1 deletion media_commons_booking_app/src/server/sheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,17 @@ export const addEventToCalendar = (
) => {
const calendar = CalendarApp.getCalendarById(id);
console.log('guestEmail', guestEmail);
const htmlTemplate = HtmlService.createTemplateFromFile(templateName);
for (const key in contents) {
htmlTemplate[key] = contents[key] || '';
}
const htmlBody = htmlTemplate.evaluate().getContent();
const event = calendar.createEvent(
title,
new Date(startTime),
new Date(endTime),
{
description,
htmlBody,
}
);
event.setColor(CalendarApp.EventColor.GRAY);
Expand Down

0 comments on commit d65ad9f

Please sign in to comment.