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

HackCamp Whitelist Work Around #516

Merged
merged 7 commits into from
Nov 8, 2023
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
48 changes: 28 additions & 20 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
import React, { useEffect, useState } from 'react'
import { Redirect, Route, Switch } from 'wouter'
import GlobalStyle from './theme/GlobalStyle'
import ThemeProvider from './theme/ThemeProvider'
import Navbar from './components/Navbar'
import Form from './components/ApplicationForm'
import Navbar from './components/Navbar'
import Page from './components/Page'
import {
NotFound,
Login,
Application,
ApplicationConfirmation,
ApplicationForm,
ApplicationReview,
Charcuterie,
Home,
DiscordBot,
Faq,
Sponsors,
Gallery,
GettingStarted,
Schedule,
Home,
Judging,
JudgingAdmin,
JudgingView,
DiscordBot,
Submission,
Login,
NotFound,
ProjectView,
ApplicationForm,
ApplicationReview,
ApplicationConfirmation,
Application,
Gallery,
Schedule,
Sponsors,
Submission,
} from './pages'
import Page from './components/Page'
import { db, getLivesiteDoc } from './utility/firebase'
import { APPLICATION_STATUS, DB_COLLECTION, DB_HACKATHON, IS_DEVICE_IOS } from './utility/Constants'
import notifications from './utility/notifications'
import Area51 from './pages/Area51'
import GlobalStyle from './theme/GlobalStyle'
import ThemeProvider from './theme/ThemeProvider'
import { AuthProvider, getRedirectUrl, useAuth } from './utility/Auth'
import { APPLICATION_STATUS, DB_COLLECTION, DB_HACKATHON, IS_DEVICE_IOS } from './utility/Constants'
import { HackerApplicationProvider, useHackerApplication } from './utility/HackerApplicationContext'
import { db, getLivesiteDoc } from './utility/firebase'
import notifications from './utility/notifications'

// only notify user if announcement was created within last 5 secs
const notifyUser = announcement => {
Expand Down Expand Up @@ -67,7 +68,11 @@ const AuthPageRoute = ({ path, children }) => {
}
return (
<Route path={path}>
{user?.status === APPLICATION_STATUS.accepted ? <Page>{children}</Page> : <Redirect to="/" />}
{user?.status === APPLICATION_STATUS.accepted ? (
<Page>{children}</Page>
) : (
<Redirect to="/application/closed" />
)}
</Route>
)
}
Expand Down Expand Up @@ -255,6 +260,9 @@ function App() {
<AdminAuthPageRoute path="/judging/admin">
<JudgingAdmin />
</AdminAuthPageRoute>
<AdminAuthPageRoute path="/area51">
<Area51 />
</AdminAuthPageRoute>
<Route path="/judging/view/:id" component={JudgingViewContainer} />
<Route path="/projects" component={GalleryContainer} />
<Route path="/projects/:id" component={ProjectViewContainer} />
Expand Down
19 changes: 19 additions & 0 deletions src/pages/Area51.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import { Button } from '../components/Input'
import { setWhitelist } from '../utility/firebase'

export default () => {
return (
<div>
<Button
color="secondary"
width="flex"
onClick={() => {
setWhitelist()
}}
>
Add current whitelist
</Button>
</div>
)
}
6 changes: 3 additions & 3 deletions src/utility/Constants.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export const DB_COLLECTION = 'Hackathons'

// CHANGE: firebase collection name for this hackathon
export const DB_HACKATHON = 'nwHacks2024'
export const DB_HACKATHON = 'HackCamp2023'
export const DAYOF_COLLECTION = 'DayOf'
export const FAQ_COLLECTION = 'FAQ'
export const NOTIFICATION_SETTINGS_CACHE_KEY = 'livesiteNotificationSettings'
export const IS_DEVICE_IOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream
export const copyText = Object.freeze({
// CHANGE: name of hackathon to be displayed on login splash
hackathonName: 'nwHacks 2024',
hackathonNameShort: 'nwHacks',
hackathonName: 'HackCamp 2023',
hackathonNameShort: 'HackCamp',
})

export const PROJECTS_TO_JUDGE_COUNT = 4
Expand Down
70 changes: 65 additions & 5 deletions src/utility/firebase.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'firebase/analytics'
import firebase from 'firebase/app'
import 'firebase/firestore'
import 'firebase/analytics'
import 'firebase/storage'
import {
HACKER_APPLICATION_TEMPLATE,
REDIRECT_STATUS,
DB_COLLECTION,
ANALYTICS_EVENTS,
APPLICATION_STATUS,
DB_COLLECTION,
DB_HACKATHON,
ANALYTICS_EVENTS,
HACKER_APPLICATION_TEMPLATE,
REDIRECT_STATUS,
} from '../utility/Constants'

if (!firebase.apps.length) {
Expand Down Expand Up @@ -42,6 +42,49 @@ export const getLivesiteDoc = callback => {
})
}

// -----------------------------------------------------
// TODO: Delete temporary code that whitelists users that have RSVP'd (all the commented bars)
export const setWhitelist = async () => {
let batch = db.batch()

let whitelistedArr = [
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
]
Comment on lines +50 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These emails will have to be the actual hacker emails when pushing to prod


for (let i = 0; i < whitelistedArr.length; i++) {
batch.set(
db.collection(DB_COLLECTION).doc(DB_HACKATHON).collection('Whitelist').doc(whitelistedArr[i]),
{}
)
}

batch.commit().then(() => {
alert('uploaded successfully')
})
}
// -----------------------------------------------------

// -----------------------------------------------------
export const getWhitelisted = async () => {
// db.collection('Hackathons').doc('HackCamp2023').collection('Whitelist')
const whitelisted = []
await db
.collection(DB_COLLECTION)
.doc(DB_HACKATHON)
.collection('Whitelist')
.get()
.then(querySnapshot => {
querySnapshot.forEach(doc => {
whitelisted.push(doc.id)
})
})
return whitelisted
}
// -----------------------------------------------------

const createNewApplication = async user => {
analytics.logEvent(ANALYTICS_EVENTS.signup, { userId: user.uid })
const userId = {
Expand Down Expand Up @@ -82,6 +125,23 @@ const createNewApplication = async user => {
...judging,
}

// -----------------------------------------------------
// If not whitelisted, no
const whitelisted = await getWhitelisted()
if (whitelisted.includes(user.email)) {
// good to go
newApplication = {
...newApplication,
status: {
applicationStatus: 'acceptedAndAttending',
responded: true,
attending: true,
},
}
// else, the default application template will block them from submissions -> redirect to "Applications for this hackathon are closed"
}
// -----------------------------------------------------

await applicantsRef.doc(user.uid).set(newApplication)
}

Expand Down
Loading