Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
auloin committed Aug 23, 2021
2 parents 0e50124 + 8ee0051 commit bda6d5f
Show file tree
Hide file tree
Showing 109 changed files with 6,336 additions and 9,921 deletions.
14 changes: 14 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
VITE_USE_API_EMULATOR=false

# https://docs.mapbox.com/help/glossary/access-token/
VITE_MAPBOX_ACCESS_TOKEN=

#https://firebase.google.com/docs/web/setup
VITE_FIREBASE_API_KEY=
VITE_FIREBASE_AUTH_DOMAIN=
VITE_FIREBASE_DATABASE_URL=null
VITE_FIREBASE_PROJECT_ID=null
VITE_FIREBASE_STORAGE_BUCKET=null
VITE_FIREBASE_MESSAGING_SENDER_ID=null
VITE_FIREBASE_APP_ID=null
VITE_FIREBASE_MEASUREMENT_ID=null
4 changes: 0 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,5 @@
"no-unused-expressions": ["error", { "allowTernary": true }],
"no-return-assign": [2, "except-parens"],
"no-param-reassign": ["error", { "props": false }]
},
"globals": {
"NODE_ENV": true,
"WTMG_CONFIG": true
}
}
6 changes: 6 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projects": {
"default": "wtmg-dev",
"prod": "wtmg-production"
}
}
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/firebase-hosting-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Deploy to Firebase Hosting on merge
'on':
push:
branches:
- master
jobs:
build_and_deploy:
runs-on: ubuntu-latest
environment: production
env:
VITE_FIREBASE_API_KEY: ${{secrets.FIREBASE_API_KEY}}
VITE_FIREBASE_AUTH_DOMAIN: ${{secrets.FIREBASE_AUTH_DOMAIN}}
VITE_FIREBASE_DATABASE_URL: ${{secrets.FIREBASE_DATABASE_URL}}
VITE_FIREBASE_PROJECT_ID: ${{secrets.FIREBASE_PROJECT_ID}}
VITE_FIREBASE_STORAGE_BUCKET: ${{secrets.FIREBASE_STORAGE_BUCKET}}
VITE_FIREBASE_MESSAGING_SENDER_ID: ${{secrets.FIREBASE_MESSAGING_SENDER_ID}}
VITE_FIREBASE_APP_ID: ${{secrets.FIREBASE_APP_ID}}
VITE_FIREBASE_MEASUREMENT_ID: ${{secrets.FIREBASE_MEASUREMENT_ID}}
VITE_MAPBOX_ACCESS_TOKEN: ${{secrets.MAPBOX_ACCESS_TOKEN}}
steps:
- uses: actions/checkout@v2
- name: Install Dependencies
run: yarn
- name: Build project
run: yarn run build:prod
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_WTMG_PRODUCTION }}'
channelId: live
projectId: wtmg-production
27 changes: 27 additions & 0 deletions .github/workflows/firebase-hosting-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy to Firebase Hosting on PR
'on': pull_request
jobs:
build_and_preview:
if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}'
runs-on: ubuntu-latest
environment: staging
env:
VITE_FIREBASE_API_KEY: ${{secrets.FIREBASE_API_KEY}}
VITE_FIREBASE_AUTH_DOMAIN: ${{secrets.FIREBASE_AUTH_DOMAIN}}
VITE_FIREBASE_DATABASE_URL: ${{secrets.FIREBASE_DATABASE_URL}}
VITE_FIREBASE_PROJECT_ID: ${{secrets.FIREBASE_PROJECT_ID}}
VITE_FIREBASE_STORAGE_BUCKET: ${{secrets.FIREBASE_STORAGE_BUCKET}}
VITE_FIREBASE_MESSAGING_SENDER_ID: ${{secrets.FIREBASE_MESSAGING_SENDER_ID}}
VITE_FIREBASE_APP_ID: ${{secrets.FIREBASE_APP_ID}}
VITE_MAPBOX_ACCESS_TOKEN: ${{secrets.MAPBOX_ACCESS_TOKEN}}
steps:
- uses: actions/checkout@v2
- name: Install Dependencies
run: yarn
- name: Build project
run: yarn run build:staging
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_WTMG_STAGING }}'
projectId: wtmg-dev
13 changes: 3 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,11 @@ lerna-debug.log*
.DS_Store
node_modules

public/data
public/build
public/bundle
dist
.routify

.env*
.firebase
wtmg.config*.js
!wtmg.config.example.js
wtmg.config*.json
!wtmg.config.example.json

!.env.example

.firebaserc
.firebase
firestore.rules
8 changes: 0 additions & 8 deletions .nolluprc.js

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"i18n-ally.localesPaths": ["src/locales"]
}
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Welcome To My Garden [![Open Collective backers and sponsors](https://img.shields.io/opencollective/all/welcometomygarden?label=Support%20through%20Open%20Collective&logo=open-collective)](https://opencollective.com/welcometomygarden) ![GitHub](https://img.shields.io/github/license/welcometomygarden/welcometomygarden?label=License)
# Welcome To My Garden [![Open Collective backers and sponsors](https://img.shields.io/opencollective/all/welcometomygarden?label=Support%20through%20Open%20Collective&logo=open-collective)](https://opencollective.com/welcometomygarden) ![GitHub](https://img.shields.io/github/license/welcometomygarden/welcometomygarden?label=License) [![Translation status](https://hosted.weblate.org/widgets/wtmg/-/svg-badge.svg)](https://hosted.weblate.org/engage/wtmg/)

This repository houses the entire Welcome To My Garden app.

Problems, feedback or questions are welcome in [issues](https://github.com/WelcometoMyGarden/welcometomygarden/issues) or on our [Slack](https://join.slack.com/t/welcometomygarden/shared_invite/zt-f31i37dj-_zFgnfe40B6EexJuB2f_~w)
Problems, feedback or questions are welcome in [issues](https://github.com/WelcometoMyGarden/welcometomygarden/issues) or on our [Slack](https://join.slack.com/t/welcometomygarden/shared_invite/zt-f31i37dj-_zFgnfe40B6EexJuB2f_~w).

## Prerequisites

- [Node](https://nodejs.org/en/download/) version >=10 installed
- This project uses the [Yarn](https://yarnpkg.com/getting-started/install) package manager

Create `wtmg.config.json` file and make sure it has the values specified in [`wtmg.config.example.json`](https://github.com/WelcometoMyGarden/welcometomygarden/blob/master/wtmg.config.example.json).
Create a `.env` file and make sure it has the values specified in [`.env.example`](https://github.com/WelcometoMyGarden/welcometomygarden/blob/master/.env.example).

You will need a Mapbox and Maptiler access token if you'd like to work on features that concern the map.
You will need a Mapbox access token if you'd like to work on features that concern the map.


## Usage
From a terminal located at project root, install project dependencies:
From a terminal located at the project root, install project dependencies:

```bash
yarn
Expand All @@ -27,5 +27,13 @@ Start the project in development mode
yarn run dev
```

## Translations

The website is translated through [Hosted Weblate](https://hosted.weblate.org/projects/wtmg/).
You can easily make an account and start translating in their web-environment - no installation required.

[![Translation status](https://hosted.weblate.org/widgets/wtmg/-/multi-auto.svg)](https://hosted.weblate.org/engage/wtmg/)


## License
![GitHub](https://img.shields.io/github/license/welcometomygarden/welcometomygarden?label=License)
1 change: 1 addition & 0 deletions api/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"env": {
"node": true
},
"root": true,
"rules": {
"prettier/prettier": ["error"],
"comma-dangle": ["error", "never"],
Expand Down
12 changes: 7 additions & 5 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
"node": "10"
},
"dependencies": {
"@google-cloud/firestore": "^4.12.3",
"@sendgrid/mail": "^7.1.1",
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.7.0"
"firebase-admin": "^9.11.0",
"firebase-functions": "^3.7.0",
"json2csv": "^5.0.6"
},
"devDependencies": {
"@babel/core": "^7.10.2",
"@babel/preset-env": "^7.9.6",
"babel-eslint": "^10.1.0",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.1.0",
"eslint": "^7.30.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.1.2",
"firebase-functions-test": "^0.2.0",
"prettier": "^2.0.2"
Expand Down
88 changes: 84 additions & 4 deletions api/src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const functions = require('firebase-functions');
const countries = require('./countries');
const { sendAccountVerificationEmail, sendPasswordResetEmail } = require('./mail');

exports.createUser = async (data, context) => {
const fail = (code) => {
throw new functions.https.HttpsError(code);
};
const fail = (code) => {
throw new functions.https.HttpsError(code);
};

exports.createUser = async (data, context) => {
if (!context.auth) {
fail('unauthenticated');
}
Expand Down Expand Up @@ -83,6 +83,11 @@ exports.createUser = async (data, context) => {
}
});

await db
.collection('stats')
.doc('users')
.update({ count: admin.firestore.FieldValue.increment(1) });

const link = await admin.auth().generateEmailVerificationLink(email, {
url: `${functions.config().frontend.url}/account`
});
Expand Down Expand Up @@ -141,3 +146,78 @@ exports.resendAccountVerification = async (data, context) => {
});
await sendAccountVerificationEmail(user.email, user.displayName, link);
};

exports.cleanupUserOnDelete = async (user) => {
const userId = user.uid;
const db = admin.firestore();

const batch = db.batch();

batch.delete(db.doc(`campsites/${userId}`));
batch.delete(db.doc(`users-private/${userId}`));

try {
await batch.commit();
await db
.collection('stats')
.doc('users')
.update({ count: admin.firestore.FieldValue.increment(-1) });
} catch (ex) {
console.error(ex);
}
};

exports.setAdminRole = async (data, context) => {
if (!context.auth) {
return fail('unauthenticated');
}

const { uid } = context.auth;
const adminUser = await admin.auth().getUser(uid);
if (!adminUser.customClaims || !adminUser.customClaims.admin) {
return fail('permission-denied');
}

const { newStatus } = data;
const user = await admin.auth().getUserByEmail(data.email);
admin.auth().setCustomUserClaims(user.uid, { admin: newStatus });

return { message: `${data.email} admin status set successfully.` };
};

exports.verifyEmail = async ({ email }, context) => {
if (!context.auth) {
return fail('unauthenticated');
}

const { uid } = context.auth;
const adminUser = await admin.auth().getUser(uid);
if (!adminUser.customClaims || !adminUser.customClaims.admin) {
return fail('permission-denied');
}

const userToUpdate = await admin.auth().getUserByEmail(email);
await admin.auth().updateUser(userToUpdate.uid, {
emailVerified: true
});
return { message: `${email} was verified` };
};

exports.updateEmail = async ({ oldEmail, newEmail }, context) => {
if (!context.auth) {
return fail('unauthenticated');
}

const { uid } = context.auth;
const adminUser = await admin.auth().getUser(uid);
if (!adminUser.customClaims || !adminUser.customClaims.admin) {
return fail('permission-denied');
}

const userToUpdate = await admin.auth().getUserByEmail(oldEmail);
await admin.auth().updateUser(userToUpdate.uid, {
email: newEmail,
emailVerified: true
});
return { message: `${oldEmail} was changed to ${newEmail}` };
};
17 changes: 17 additions & 0 deletions api/src/campsites.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const admin = require('firebase-admin');

exports.onCampsiteCreate = async () => {
const db = admin.firestore();
await db
.collection('stats')
.doc('campsites')
.update({ count: admin.firestore.FieldValue.increment(1) });
};

exports.onCampsiteDelete = async () => {
const db = admin.firestore();
await db
.collection('stats')
.doc('campsites')
.update({ count: admin.firestore.FieldValue.increment(-1) });
};
15 changes: 14 additions & 1 deletion api/src/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { sendMessageReceivedEmail } = require('./mail');
const normalizeMessage = (str) => str.replace(/\n\s*\n\s*\n/g, '\n\n');
const normalizeName = (str) => removeDiacritics(str).toLowerCase();

exports.onChatCreate = async (snap, context) => {
exports.onMessageCreate = async (snap, context) => {
const message = snap.data();
const senderId = message.from;
const { chatId } = context.params;
Expand All @@ -23,6 +23,11 @@ exports.onChatCreate = async (snap, context) => {
.doc(chatId)
.get();

await db
.collection('stats')
.doc('messages')
.update({ count: admin.firestore.FieldValue.increment(1) });

const recipientDoc = await db.collection('users-private').doc(recipientId).get();
const recipientEmailPreferences = recipientDoc.data().emailPreferences;

Expand Down Expand Up @@ -64,3 +69,11 @@ exports.onChatCreate = async (snap, context) => {
console.log(ex);
}
};

exports.onChatCreate = async () => {
const db = admin.firestore();
await db
.collection('stats')
.doc('chats')
.update({ count: admin.firestore.FieldValue.increment(1) });
};
Loading

0 comments on commit bda6d5f

Please sign in to comment.