Skip to content

Commit 7e461ae

Browse files
committed
update nginx + allow admin access to SCEvents
1 parent 1f1cb80 commit 7e461ae

10 files changed

Lines changed: 42 additions & 67 deletions

File tree

nginx.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ http {
150150
}
151151

152152
#Load balancer
153+
location /api/scevents/ {
154+
resolver 127.0.0.11 valid=15s;
155+
proxy_set_header Host $host;
156+
proxy_set_header X-Real-IP $remote_addr;
157+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
158+
proxy_set_header X-Forwarded-Proto $scheme;
159+
160+
set $upstream http://scevents-server:8002;
161+
rewrite ^/api/scevents/?(.*)$ /$1 break;
162+
proxy_pass $upstream;
163+
}
153164
location /api {
154165
proxy_pass http://mainendpoints;
155166
}

src/APIFunctions/SCEvents.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ApiResponse } from './ApiResponses';
2+
import config from '../config/config.json';
23

3-
const SCEVENTS_API_URL = 'http://localhost:8002';
4+
const SCEVENTS_API_URL = config.SCEvents?.BASE_URL || '/api/scevents';
45
export async function getAllSCEvents() {
56
const status = new ApiResponse();
67
try {

src/Components/Navbar/AdminNavbar.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import { useSCE } from '../context/SceContext';
3-
import config from '../../config/config.json';
43
import { membershipState } from '../../Enums';
54

65
export default function UserNavBar(props) {
@@ -44,27 +43,25 @@ export default function UserNavBar(props) {
4443
];
4544

4645
const sceventsAdminNavLinks = [];
47-
if (config.SCEvents?.ENABLED) {
46+
sceventsAdminNavLinks.push({
47+
title: 'Events',
48+
route: '/events',
49+
icon: (
50+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
51+
<path strokeLinecap="round" strokeLinejoin="round" d="M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 0 1 2.25-2.25h13.5A2.25 2.25 0 0 1 21 7.5v11.25m-18 0A2.25 2.25 0 0 0 5.25 21h13.5a2.25 2.25 0 0 0 2.25-2.25m-18 0v-7.5A2.25 2.25 0 0 1 5.25 9h13.5a2.25 2.25 0 0 1 2.25 2.25v7.5" />
52+
</svg>
53+
),
54+
});
55+
if (user?.accessLevel >= membershipState.OFFICER) {
4856
sceventsAdminNavLinks.push({
49-
title: 'Events',
50-
route: '/events',
57+
title: 'Create event',
58+
route: '/events/create',
5159
icon: (
5260
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
53-
<path strokeLinecap="round" strokeLinejoin="round" d="M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 0 1 2.25-2.25h13.5A2.25 2.25 0 0 1 21 7.5v11.25m-18 0A2.25 2.25 0 0 0 5.25 21h13.5a2.25 2.25 0 0 0 2.25-2.25m-18 0v-7.5A2.25 2.25 0 0 1 5.25 9h13.5a2.25 2.25 0 0 1 2.25 2.25v7.5" />
61+
<path strokeLinecap="round" strokeLinejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
5462
</svg>
5563
),
5664
});
57-
if (user?.accessLevel >= membershipState.OFFICER) {
58-
sceventsAdminNavLinks.push({
59-
title: 'Create event',
60-
route: '/events/create',
61-
icon: (
62-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
63-
<path strokeLinecap="round" strokeLinejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
64-
</svg>
65-
),
66-
});
67-
}
6865
}
6966

7067
const adminLinks = [

src/Components/Navbar/UserNavbar.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { useState, useEffect, useRef } from 'react';
22
import { membershipState } from '../../Enums';
33
import { useSCE } from '../context/SceContext';
4-
import config from '../../config/config.json';
54

65
export default function UserNavbar(props) {
76
const { user, authenticated } = useSCE();
@@ -15,14 +14,12 @@ export default function UserNavbar(props) {
1514
{ title: 'About', route: '/about' },
1615
{ title: 'Projects', route: '/projects' },
1716
{ title: 'Summer Internship', route: '/s/internship', newTab: true },
18-
...(config.SCEvents?.ENABLED ? [{ title: 'Events', route: '/events' }] : []),
1917
];
2018

2119
const authedRoutes = [
2220
{ title: 'Printing', route: '/2DPrinting' },
2321
{ title: 'Chat', route: '/messaging' },
2422
{ title: 'LED Sign', route: '/led-sign' },
25-
...(config.SCEvents?.ENABLED ? [{ title: 'Events', route: '/events' }] : []),
2623
];
2724

2825
const authentication = [

src/Pages/Events/CreateEventPage.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/* eslint-disable camelcase -- mirrors SCEvents JSON field names in state and payloads */
22
import React, { useMemo, useState } from 'react';
3-
import { Link, useHistory, Redirect } from 'react-router-dom';
3+
import { Link, useHistory } from 'react-router-dom';
44
import { useSCE } from '../../Components/context/SceContext.js';
55
import { createSCEvent } from '../../APIFunctions/SCEvents.js';
66
import CreateEventFormQuestionBlock from './CreateEventFormQuestionBlock.js';
77
import { membershipState } from '../../Enums';
8-
import config from '../../config/config.json';
98

109
/** Matches SCEvents `max_attendees` when there is no cap. */
1110
const UNLIMITED_ATTENDEES = -1;
@@ -71,7 +70,6 @@ function toApiRegistrationForm(questions) {
7170
export default function CreateEventPage() {
7271
const { user } = useSCE();
7372
const history = useHistory();
74-
const isSCEventsEnabled = config.SCEvents?.ENABLED;
7573

7674
const [eventId] = useState(() => crypto.randomUUID());
7775
const [eventName, setEventName] = useState('');
@@ -234,10 +232,6 @@ export default function CreateEventPage() {
234232
history.push('/events');
235233
}
236234

237-
if (!isSCEventsEnabled) {
238-
return <Redirect to="/notfound" />;
239-
}
240-
241235
if (!isOfficerOrAdmin) {
242236
return (
243237
<div className="m-10">

src/Pages/Events/EditEventPage.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/* eslint-disable camelcase -- mirrors SCEvents JSON field names in state and payloads */
22
import React, { useMemo, useState, useEffect } from 'react';
3-
import { Link, useHistory, useParams, Redirect } from 'react-router-dom';
3+
import { Link, useHistory, useParams } from 'react-router-dom';
44
import { useSCE } from '../../Components/context/SceContext.js';
55
import { getEventByID, updateSCEvent } from '../../APIFunctions/SCEvents.js';
66
import CreateEventFormQuestionBlock from './CreateEventFormQuestionBlock.js';
77
import { membershipState } from '../../Enums';
8-
import config from '../../config/config.json';
98

109
/** Matches SCEvents `max_attendees` when there is no cap. */
1110
const UNLIMITED_ATTENDEES = -1;
@@ -46,7 +45,6 @@ export default function EditEventPage() {
4645
const { id } = useParams();
4746
const { user } = useSCE();
4847
const history = useHistory();
49-
const isSCEventsEnabled = config.SCEvents?.ENABLED;
5048

5149
const [isLoading, setIsLoading] = useState(true);
5250
const [fetchError, setFetchError] = useState('');
@@ -96,12 +94,8 @@ export default function EditEventPage() {
9694
setEventAdmins(evt.admins || []);
9795
}
9896

99-
if (!isSCEventsEnabled) {
100-
return;
101-
}
102-
10397
loadEvent();
104-
}, [id, isSCEventsEnabled]);
98+
}, [id]);
10599

106100
function addQuestion() {
107101
setQuestions((prev) => [...prev, newQuestionTemplate()]);
@@ -229,10 +223,6 @@ export default function EditEventPage() {
229223
history.push('/events');
230224
}
231225

232-
if (!isSCEventsEnabled) {
233-
return <Redirect to="/notfound" />;
234-
}
235-
236226
if (!isOfficerOrAdmin) {
237227
return (
238228
<div className="m-10">

src/Pages/Events/Events.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useEffect, useState } from 'react';
2-
import config from '../../config/config.json';
3-
import { Link, Redirect } from 'react-router-dom';
2+
import { Link } from 'react-router-dom';
43
import { getAllSCEvents } from '../../APIFunctions/SCEvents';
54
import { useSCE } from '../../Components/context/SceContext';
65
import { membershipState } from '../../Enums';
@@ -50,14 +49,11 @@ export default function EventsPage() {
5049
const [isLoading, setIsLoading] = useState(true);
5150
const [hasError, setHasError] = useState(false);
5251

53-
const isSCEventsEnabled = config.SCEvents?.ENABLED;
5452
const canCreateEvent = user?.accessLevel >= membershipState.OFFICER;
5553
const visibleEvents = events.filter((event) => canUserSeeEvent(event, user));
5654
const isAdminView = canCreateEvent;
5755

5856
useEffect(() => {
59-
if (!isSCEventsEnabled) return;
60-
6157
async function fetchEvents() {
6258
setIsLoading(true);
6359
setHasError(false);
@@ -74,11 +70,7 @@ export default function EventsPage() {
7470
}
7571

7672
fetchEvents();
77-
}, [isSCEventsEnabled]);
78-
79-
if (!isSCEventsEnabled) {
80-
return <Redirect to="/notfound" />;
81-
}
73+
}, []);
8274

8375
return (
8476
<div className="relative min-h-screen overflow-hidden bg-gradient-to-r from-gray-800 to-gray-600 text-white">

src/Pages/Events/EventsRegistation.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable camelcase -- mirrors SCEvents JSON field names in state and payloads */
22
import React, { useState, useEffect } from 'react';
3-
import { useParams, useHistory, Redirect } from 'react-router-dom';
4-
import config from '../../config/config.json';
3+
import { useParams, useHistory } from 'react-router-dom';
54
import { useSCE } from '../../Components/context/SceContext';
65
import { getEventByID, registerForSCEvent } from '../../APIFunctions/SCEvents';
76

@@ -24,7 +23,6 @@ export default function EventRegistration() {
2423
const { user } = useSCE();
2524
const { id } = useParams();
2625
const history = useHistory();
27-
const isSCEventsEnabled = Boolean(config.SCEvents?.ENABLED);
2826
const [event, setEvent] = useState(null);
2927
const [formData, setFormData] = useState({});
3028
const [isLoading, setIsLoading] = useState(true);
@@ -33,10 +31,6 @@ export default function EventRegistration() {
3331
const [submitting, setSubmitting] = useState(false);
3432

3533
useEffect(() => {
36-
if (!isSCEventsEnabled) {
37-
return;
38-
}
39-
4034
async function fetchEvent() {
4135
setIsLoading(true);
4236
setHasError(false);
@@ -55,11 +49,7 @@ export default function EventRegistration() {
5549
setIsLoading(false);
5650
}
5751
fetchEvent();
58-
}, [id, isSCEventsEnabled]);
59-
60-
if (!isSCEventsEnabled) {
61-
return <Redirect to="/notfound" />;
62-
}
52+
}, [id]);
6353

6454
const handleInputChange = (fieldId, value, type) => {
6555
if (type === 'checkbox') {

src/Routes.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ export const officerOrAdminRoutes = [
186186
redirect: '/',
187187
inAdminNavbar: false
188188
},
189+
{
190+
Component: EventsPage,
191+
path: '/events',
192+
pageName: 'Events',
193+
allowedIf: allowedIf.OFFICER_OR_ADMIN,
194+
redirect: '/',
195+
inAdminNavbar: true
196+
},
189197
...memberRoutes,
190198
];
191199

@@ -217,11 +225,6 @@ export const signedOutRoutes = [
217225
path: '/projects',
218226
pageName: 'Projects'
219227
},
220-
{
221-
Component: EventsPage,
222-
path: '/events',
223-
pageName: 'Events'
224-
},
225228
{
226229
Component: EventRegistration,
227230
path: '/events/:id/register',

src/config/config.example.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"TINYMCE_API_KEY": "XXXXXXXXXXXXXXXXXXXXX",
44
"GOOGLE_API_CLIENT_ID": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com",
55
"SCEvents": {
6-
"ENABLED": false
6+
"BASE_URL": "/api/scevents"
77
}
88
}

0 commit comments

Comments
 (0)