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

v1.3 #1058

Merged
merged 37 commits into from
Oct 13, 2020
Merged

v1.3 #1058

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0e04a75
refactor src/components/Notification/messages.tsx into messages.tsx a…
jxofficial Jun 27, 2020
9d6c2b4
use friendly error messages for failed login
jxofficial Jun 27, 2020
261312f
delete cypress bug test 649
jxofficial Jun 27, 2020
e5543ac
Merge branch 'master' into 649-login-friendly-messages
jxofficial Jul 11, 2020
da4fd91
Bump googleapis from 35.0.0 to 39.1.0 in /functions
dependabot[bot] Sep 8, 2020
4993e6f
Merge branch 'master' into feat/974-extra-infos-profile
alromh87 Oct 1, 2020
c21debf
Fix use of delta for counting user stats
alromh87 Oct 1, 2020
37683ce
Merge remote-tracking branch 'onearmy/master' into feat/974-extra-inf…
alromh87 Oct 1, 2020
0e8a5eb
Improve stats efficiency by using querySnapshot.size instead of counting
alromh87 Oct 2, 2020
9a15c3c
style
alromh87 Oct 2, 2020
d97cbd6
Merge pull request #1053 from ONEARMY/feat/974-extra-infos-profile
chrismclarke Oct 12, 2020
0cff021
Merge pull request #991 from jxofficial/649-login-friendly-messages
chrismclarke Oct 12, 2020
66c3dd8
Merge pull request #1026 from ONEARMY/dependabot/npm_and_yarn/functio…
chrismclarke Oct 12, 2020
6de50e9
add migration script
chrismclarke Oct 12, 2020
6ad5657
code refactoring and tidying
chrismclarke Oct 12, 2020
7928f26
add comments
chrismclarke Oct 12, 2020
a46cfb4
update frontend bindings
chrismclarke Oct 12, 2020
ae27246
refactor userUpdate functions
chrismclarke Oct 12, 2020
b75d002
code tidying
chrismclarke Oct 12, 2020
5fb21e4
deprecate unused functions
chrismclarke Oct 12, 2020
2421b73
refactor db endpoints to allow single endpoint changes
chrismclarke Oct 12, 2020
8545223
Fix flexbox cross-browser issue for step images
tudi2d Oct 12, 2020
3e4f1db
fully remove deprecations
chrismclarke Oct 12, 2020
7632d42
update deps
chrismclarke Oct 12, 2020
90381b9
functions db mapping and emulators
chrismclarke Oct 12, 2020
e15f4dc
refactor to store stat meta
chrismclarke Oct 12, 2020
6019c26
type tidying
chrismclarke Oct 12, 2020
4711358
fix display logic for stats
chrismclarke Oct 12, 2020
8c0a66f
add id to display component attrs for debugging
chrismclarke Oct 12, 2020
d05aa98
fix test integrations for db refactor
chrismclarke Oct 13, 2020
72f6886
Update how-to _modified field to show new flag on how-to lists when u…
alromh87 Oct 13, 2020
ee620aa
Merge pull request #1055 from ONEARMY/feat/user-stats-migration
BenGamma Oct 13, 2020
55b244a
apply change on new file to fix conflict
BenGamma Oct 13, 2020
88d2a90
Merge pull request #1057 from ONEARMY/feat/972CountryFlagAtUSername
BenGamma Oct 13, 2020
f422bc2
Merge pull request #1056 from tudi2d/1054-how-to-images-landscape
BenGamma Oct 13, 2020
5fa2b62
remove user stats migration function
chrismclarke Oct 13, 2020
3ef1896
bump cache number and travis node version
chrismclarke Oct 13, 2020
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
4 changes: 2 additions & 2 deletions .firebaserc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"projects": {
"default": "precious-plastics-v4-dev",
"production": "onearmyworld",
"ci":"onearmy-test-ci"
"ci": "onearmy-test-ci"
}
}
}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- '10'
- '12'
dist: xenial
cache:
# cache both yarn (.cache) and npm (for global installs)
Expand Down
15 changes: 0 additions & 15 deletions cypress/integration/bugs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,6 @@ describe('[Bugs]', () => {
// .should('include', Page.HOME_PAGE)
// })

// it('[649]', () => {
// cy.step('Wrong email and wrong password')
// cy.visit('/sign-in')
// cy.get('[data-cy=email').type('wrong_email@test.com')
// cy.get('[data-cy=password').type('anything')
// cy.get('[data-cy=submit').click()
// cy.get('div[color=red]').contains(`Incorrect email`)

// cy.step('Correct email and wrong password')
// cy.get('[data-cy=email').type('howto_reader@test.com')
// cy.get('[data-cy=password').type('wrong_password')
// cy.get('[data-cy=submit').click()
// cy.get('div[color=red]').contains(`Incorrect password`)
// })

// it('[651]', () => {
// cy.visit('/how-to')
// cy.login('howto_reader@test.com', 'test1234')
Expand Down
29 changes: 29 additions & 0 deletions cypress/support/db/endpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// React apps populate a process variable, however it might not always be accessible outside (e.g. cypress)
const e = process ? process.env : ({} as any)
/**
* A prefix can be used to simplify large-scale schema changes or multisite hosting
* and allow multiple sites to use one DB (used for parallel test seed DBs)
* e.g. oa_
*/
const DB_PREFIX = e.REACT_APP_DB_PREFIX ? e.REACT_APP_DB_PREFIX : ''

/**
* Mapping of generic database endpoints to specific prefixed and revisioned versions for the
* current implementation
* @example
* ```
* const allHowtos = await db.get(DB_ENDPOINTS.howtos)
* ```
* NOTE - these are a bit messy due to various migrations and changes
* In the future all endpoints should try to just retain prefix-base-revision, e.g. oa_users_rev20201012
*/
export const DB_ENDPOINTS = {
howtos: `${DB_PREFIX}v3_howtos`,
users: `${DB_PREFIX}v3_users`,
tags: `${DB_PREFIX}v3_tags`,
events: `${DB_PREFIX}v3_events`,
mappins: `${DB_PREFIX}v3_mappins`,
}
export type DBEndpoint = keyof typeof DB_ENDPOINTS
// legacy - want to use upper case naming convention but keep alternate until all code migrated
export const DBEndpoints = DB_ENDPOINTS
16 changes: 11 additions & 5 deletions cypress/support/db/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'firebase/functions'
import 'firebase/database'
import Query = firebase.firestore.Query
import { SEED_DATA } from '../../fixtures/seed'
import { DB_ENDPOINTS } from './endpoints'
const fbConfig = {
apiKey: 'AIzaSyDAxS_7M780mI3_tlwnAvpbaqRsQPlmp64',
authDomain: 'onearmy-test-ci.firebaseapp.com',
Expand Down Expand Up @@ -46,8 +47,9 @@ class FirestoreDB {
opStr: any,
value: string,
): Promise<any> | Promise<any[]> => {
const mapping = DB_ENDPOINTS[collectionName] || collectionName
return db
.collection(`${prefix}${collectionName}`)
.collection(`${prefix}${mapping}`)
.where(fieldPath, opStr, value)
.get()
.then(snapshot => {
Expand All @@ -63,17 +65,19 @@ class FirestoreDB {
})
}
addDocuments = (collectionName: string, docs: any[]) => {
const mapping = DB_ENDPOINTS[collectionName] || collectionName
const batch = db.batch()
const col = db.collection(`${prefix}${collectionName}`)
const col = db.collection(`${prefix}${mapping}`)
docs.forEach(doc => {
const ref = col.doc(doc._id)
batch.set(ref, doc)
})
return batch.commit()
}
deleteAll = async (collectionName: string) => {
const mapping = DB_ENDPOINTS[collectionName] || collectionName
const batch = db.batch()
const col = db.collection(`${prefix}${collectionName}`)
const col = db.collection(`${prefix}${mapping}`)
const docs = await col.get()
docs.forEach(d => {
batch.delete(col.doc(d.id))
Expand All @@ -87,8 +91,9 @@ class FirestoreDB {
opStr: any,
value: string,
) => {
const mapping = DB_ENDPOINTS[collectionName] || collectionName
const query = db
.collection(`${prefix}${collectionName}`)
.collection(`${prefix}${mapping}`)
.where(fieldPath, opStr, value)
.limit(MAX_BATCH_SIZE)
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -133,8 +138,9 @@ class FirestoreDB {
}

updateDocument = (collectionName: string, docId: string, docData: any) => {
const mapping = DB_ENDPOINTS[collectionName] || collectionName
return db
.collection(`${prefix}${collectionName}`)
.collection(`${prefix}${mapping}`)
.doc(docId)
.set(docData)
}
Expand Down
24 changes: 21 additions & 3 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"hosting": {
"public": "build",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "/api",
Expand All @@ -15,7 +19,6 @@
"source": "/DHSite_migrateAvatar",
"function": "DHSite_migrateAvatar"
},

{
"source": "**",
"destination": "/index.html",
Expand Down Expand Up @@ -57,6 +60,21 @@
"yarn --cwd \"$RESOURCE_DIR\" install",
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
],
"source": "functions"
},
"emulators": {
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"hosting": {
"port": 5000
},
"ui": {
"enabled": true
}
}
}
1 change: 1 addition & 0 deletions firestore.rules.WiP
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// WiP - CC - 2020-02-24
// As part of future security update will make better use of firestore rules, as stubbed out below
// Note - will also need to include any legacy revisions as required

service cloud.firestore {
// rules will apply to all docs in database
Expand Down
3 changes: 2 additions & 1 deletion functions/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ lib/
# Testing config files
.runtimeconfig.json

./firebase-debug.log
./firebase-debug.log
*.log
36 changes: 30 additions & 6 deletions functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ Note, this will require authentication for the firebase project. You can request
and the relevant config will automatically be made available
(viewable with command `firebase functions:config:get`)

This also only works for specific triggers (namely the api endpoints). If you want to
test a functions triggered in other ways you may first want to create an api endpoint
for testing and later test further with the [firebase functions shell](https://firebase.google.com/docs/functions/local-emulator#install_and_configure_the_cloud_functions_shell), via command `$npm run shell`
This also only works for specific triggers (namely the https callable functions, api endpoints). For more information see https://firebase.google.com/docs/functions/local-emulator.

NOTE - if running a function that requires access to the live database (and not just emulated), use `npm run serve:only:functions`, which will exclude db emulator and default to live project db


Additionally, the functions won't be automatically reloaded on change. This should be possible
(easier when working with JS instead of TS), so if anybody wishes to investigate further they would
be most welcome. Alternatively just restart the serve process on changes.

## Handling headers and redirects

Expand Down Expand Up @@ -75,3 +73,29 @@ To view console logs and events from deployed functions request project access f
Both production and live have small app-engine instances that run cron tasks, schedules can be seen in ../functions-cron.

If changing either of these remember to deploy both to production and development servers

# Using functions for data migrations

If making changes across the entire DB it is likely that backend functions will be used to do so.
A couple tips to help implementing:

1. Create backups of all the collection points potentially affected.
(note, you will need admin access to the project, and initialise using gcloud. Confirm access via `gcloud config list` and select project via `gcloud init`)
```
gcloud firestore export gs://[BUCKET_NAME] --collection-ids=[COLLECTION_ID_1],[COLLECTION_ID_2]
```
E.g. for the staging server, updating howtos and events:
```
gcloud firestore export gs://precious-plastics-v4-dev-exports/2020-10-12 --collection-ids=v3_howtos,v3_events
```
Or production
```
gcloud firestore export gs://onearmyworld-exports/2020-10-12_manual_backup --collection-ids=v3_events,v3_howtos,v3_mappings,v3_tags,v3_users
```
(note - whilst the full database can be backed up without specifying collection ids, this makes it harder to re-import a single collection)
For more info see https://firebase.google.com/docs/firestore/manage-data/export-import#export_specific_collections

1. For any data that you want to be reflected immediately, also change the `modified` field so that user caches will update as required

2. If less confident or making large scale changes, consider populating to a new db endpoint, e.g. `v4_howtos`
(this will need to also be updated in the models for both functions and frontend)
43 changes: 22 additions & 21 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,42 @@
"copyDevConfig": "firebase functions:config:get > .runtimeconfig.json",
"copyDevConfigWin": "firebase functions:config:get | ac .runtimeconfig.json",
"db:backup:local": "firestore-export -a service.json -b backup.json -p",
"serve": "concurrently --kill-others \"npm run watch\" \"firebase emulators:start\"",
"serve": "concurrently --kill-others \"npm run watch\" \"firebase emulators:start \"",
"serve:only:functions": "concurrently --kill-others \"npm run watch\" \"firebase emulators:start --only functions\"",
"shell": "npm run build && firebase functions:shell",
"deploy:dev": "firebase use default && firebase deploy --only functions",
"start": "npm run copyDevConfig && npm run serve",
"logs": "firebase functions:log"
},
"main": "./lib/index.js",
"dependencies": {
"axios": "^0.18.1",
"body-parser": "^1.18.3",
"axios": "^0.20.0",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dateformat": "^3.0.3",
"express": "^4.16.4",
"firebase-admin": "^8.3.0",
"firebase-functions": "^3.2.0",
"fs-extra": "^7.0.1",
"google-auth-library": "^2.0.1",
"googleapis": "^35.0.0",
"log-update": "^3.2.0",
"request": "^2.88.0",
"sharp": "^0.23.3"
"express": "^4.17.1",
"firebase-admin": "^9.2.0",
"firebase-functions": "^3.11.0",
"fs-extra": "^9.0.1",
"google-auth-library": "^6.1.1",
"googleapis": "^61.0.0",
"log-update": "^4.0.0",
"request": "^2.88.2",
"sharp": "^0.26.1"
},
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/cors": "^2.8.5",
"@types/dateformat": "^3.0.0",
"@types/fs-extra": "^5.0.5",
"@types/request": "^2.48.3",
"@types/sharp": "^0.22.1",
"concurrently": "^4.1.1",
"tslint": "^5.12.0",
"typescript": "^3.7.4"
"@types/cors": "^2.8.8",
"@types/dateformat": "^3.0.1",
"@types/fs-extra": "^9.0.2",
"@types/request": "^2.48.5",
"@types/sharp": "^0.26.0",
"concurrently": "^5.3.0",
"tslint": "^6.1.3",
"typescript": "^4.0.3"
},
"engines": {
"node": "10"
"node": "12"
},
"private": true
}
67 changes: 0 additions & 67 deletions functions/src/DaveHakkensNL/BPMember.model.ts

This file was deleted.

21 changes: 0 additions & 21 deletions functions/src/DaveHakkensNL/avatarMigrate.ts

This file was deleted.

Loading