Skip to content

Commit

Permalink
fix seed data (#194)
Browse files Browse the repository at this point in the history
Co-authored-by: Anson He <ansonjwhe@gmail.com>
  • Loading branch information
victorzheng02 and ansonjwhe authored Apr 13, 2024
1 parent bcae6f7 commit 2ebcaaf
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 115 deletions.
55 changes: 28 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,20 @@ create a `.env` file in the "backend" folder
Please contact Victor or Anson if you do not know how to set it up

```
ATLAS_URI=<YOUR_MONGO_ATLAS_URI_HERE>
MAILJET_API_KEY=<YOUR_MAILJET_API_KEY>
MAILJET_SECRET_KEY=<YOUR_MAILJET_SECRET_KEY>
FINANCE_EMAIL=<EMAIL_WHERE_YOU_WANT_TO_SEND_FROM>
EMAIL_RECIPIENTS=<EMAILS_TO_RECEIVE_SEPERATED_BY_COMMA_(NO_SPACE)>
CLIENT_URL=http://localhost:3000
```

In order to run the cron that updates the db from the WATO members spreadsheet, please contact Victor or Anson for the following variables you will add in your `.env`

```
GOOGLE_SHEET_ID=<WATO_MEMBERS_SPREADSHEET_ID>
SHEET_TAB_ID=<WATO_MEMBERS_SPREADSHEET_TAB_ID>
SERVICE_ACCOUNT_EMAIL=<DISCORD_AUTOMATION_SERVICE_ACCOUNT>
SERVICE_ACCOUNT_PRIVATE_KEY=<DISCORD_AUTOMATION_SERVICE_ACCOUNT_PRIVATE_KEY>
WATO_FINANCE_ATLAS_URI=<YOUR_MONGO_ATLAS_URI_HERE>
WATO_FINANCE_MAILJET_API_KEY=<YOUR_MAILJET_API_KEY>
WATO_FINANCE_MAILJET_SECRET_KEY=<YOUR_MAILJET_SECRET_KEY>
WATO_FINANCE_FINANCE_EMAIL=<EMAIL_WHERE_YOU_WANT_TO_SEND_FROM>
WATO_FINANCE_EMAIL_RECIPIENTS=<EMAILS_TO_RECEIVE_SEPERATED_BY_COMMA_(NO_SPACE)>
WATO_FINANCE_CLIENT_URL=http://localhost:3000
```

In order to upload attachments, AWS credentials are needed. To access a role that is already set up with policies on WATonomous' AWS account, please contact Victor.

```
AWS_SECRET_ACCESS_KEY=<YOUR_SECRET_ACCESS_KEY>
AWS_ACCESS_KEY_ID=<YOUR_ACCESS_KEY>
AWS_FINANCE_BUCKET_NAME=<S3_BUCKET_NAME>
WATO_FINANCE_AWS_SECRET_ACCESS_KEY=<YOUR_SECRET_ACCESS_KEY>
WATO_FINANCE_AWS_ACCESS_KEY_ID=<YOUR_ACCESS_KEY>
WATO_FINANCE_AWS_FINANCE_BUCKET_NAME=<S3_BUCKET_NAME>
```

To start the server, run
Expand Down Expand Up @@ -71,13 +62,23 @@ In the production environment this file is mounted automatically based on https:

### Generating seeding data

To generate seed data, in the terminal in the backend directory, run:
To generate seed data, in the terminal in the backend directory, you must first add an additional environment variable to `backend/.env`. Note that this is the same firebase api key as the web app, instructions can be found later in this README.

`WATO_FINANCE_FIREBASE_API_KEY=<YOUR_FIREBASE_API_KEY>`

run:

```
npm run seeddata
```

Note that this step is not optional due to the fact we need to inject wato cash's id as it is a special case for a funding item.
or

```
npm run seeddata-prod
```

Note that this step is not optional due to the fact we need to inject wato cash's id as it is a special case for a funding item. The -prod version will only create the wato cash fund, and no dummy data will be created.

---

Expand All @@ -99,13 +100,13 @@ Note that this step is not optional due to the fact we need to inject wato cash'
3. Look for the `firebaseConfig` constant and fill in the following info in the `.env` file you create in the "frontend" folder

```
REACT_APP_API_KEY=<YOUR_FIREBASE_API_KEY>
REACT_APP_AUTH_DOMAIN=<YOUR_FIREBASE_AUTH_DOMAIN>
REACT_APP_PROJECT_ID=<YOUR_FIREBASE_PROJECT_ID>
REACT_APP_STORAGE_BUCKET=<YOUR_FIREBASE_STORAGE_BUCKET>
REACT_APP_MESSAGING_SENDER_ID=<YOUR_FIREBASE_MESSAGING_SENDER_ID>
REACT_APP_APP_ID=<YOUR_FIREBASE_API_ID>
REACT_APP_BACKEND_URL=http://localhost:5000
REACT_APP_WATO_FINANCE_API_KEY=<YOUR_FIREBASE_API_KEY>
REACT_APP_WATO_FINANCE_AUTH_DOMAIN=<YOUR_FIREBASE_AUTH_DOMAIN>
REACT_APP_WATO_FINANCE_PROJECT_ID=<YOUR_FIREBASE_PROJECT_ID>
REACT_APP_WATO_FINANCE_STORAGE_BUCKET=<YOUR_FIREBASE_STORAGE_BUCKET>
REACT_APP_WATO_FINANCE_MESSAGING_SENDER_ID=<YOUR_FIREBASE_MESSAGING_SENDER_ID>
REACT_APP_WATO_FINANCE_APP_ID=<YOUR_FIREBASE_API_ID>
REACT_APP_WATO_FINANCE_BACKEND_URL=http://localhost:5000
```

### Connect Backend to Project
Expand Down
10 changes: 8 additions & 2 deletions backend/auth/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const { authAdmin } = require('./auth')
const authenticateUser = async (req, res, next) => {
const bearerToken = req.headers.authorization?.split(' ')
if (!bearerToken || bearerToken.length !== 2) {
return res.status(401).json({ error: `No user token provided` })
res.status(401).send({ error: `No user token provided` })
return
}
const token = bearerToken[1]
try {
Expand Down Expand Up @@ -44,6 +45,11 @@ const authenticateUser = async (req, res, next) => {
}
}

// special case for seed token, we don't have a user id attached to it
if (decodedToken.uid === 'seed-token') {
next()
return
}
const { isDirector, isAdmin, isTeamCaptain, isReporter } =
await getAuthRoles(
decodedToken.uid,
Expand All @@ -56,7 +62,7 @@ const authenticateUser = async (req, res, next) => {
req.user.isReporter = isReporter
next()
} catch (err) {
res.status(401).json({ error: `Invalid user token: ${err}` })
res.status(401).send({ error: `Invalid user token: ${err}` })
return
}
}
Expand Down
6 changes: 0 additions & 6 deletions backend/aws/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ const {
} = require('@aws-sdk/client-s3')
const { getSignedUrl } = require('@aws-sdk/s3-request-presigner')

const { HttpRequest } = require('@aws-sdk/protocol-http')
const { formatUrl } = require('@aws-sdk/util-format-url')

const { S3RequestPresigner } = require('@aws-sdk/s3-request-presigner')
const { Hash } = require('@aws-sdk/hash-node')

const s3Client = new S3Client({
region: 'us-east-2',
})
Expand Down
Loading

0 comments on commit 2ebcaaf

Please sign in to comment.