Skip to content

Commit 037a19f

Browse files
authored
Merge pull request #957 from mapswipe/dev
Release - 2024-July
2 parents f9c3438 + 8592b90 commit 037a19f

File tree

28 files changed

+1775
-1074
lines changed

28 files changed

+1775
-1074
lines changed

.github/workflows/actions.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
working-directory: ./mapswipe_workers
2323
run: |
2424
python -m pip install --upgrade pip
25-
pip install flake8 black==22.3.0 isort
25+
pip install flake8 black==24.4.2 isort
2626
2727
- name: Code style
2828
working-directory: ./mapswipe_workers
@@ -47,15 +47,15 @@ jobs:
4747
run: |
4848
# Create a mock file for wal-g setup
4949
touch postgres/serviceAccountKey.json
50-
docker-compose up --build --detach postgres
51-
for i in {1..5}; do docker-compose exec -T postgres pg_isready && s=0 && break || s=$? && sleep 5; done; (docker-compose logs postgres && exit $s)
50+
docker compose up --build --detach postgres
51+
for i in {1..5}; do docker compose exec -T postgres pg_isready && s=0 && break || s=$? && sleep 5; done; (docker compose logs postgres && exit $s)
5252
5353
- name: Deploy Firebase Rules and Functions
5454
env:
5555
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
5656
FIREBASE_DB: ${{ secrets.FIREBASE_DB }}
5757
run: |
58-
docker-compose run --rm firebase_deploy sh -c "firebase use $FIREBASE_DB && firebase deploy --token $FIREBASE_TOKEN --only database"
58+
docker compose run --rm firebase_deploy sh -c "firebase use $FIREBASE_DB && firebase deploy --token $FIREBASE_TOKEN --only database"
5959
6060
- name: Decrypt Service Account Key File
6161
working-directory: ./
@@ -78,16 +78,16 @@ jobs:
7878
OSMCHA_API_KEY: ${{ secrets.OSMCHA_API_KEY }}
7979
DJANGO_SECRET_KEY: test-django-secret-key
8080
run: |
81-
docker-compose run --rm mapswipe_workers_creation python -m unittest discover --verbose --start-directory tests/unittests/
82-
docker-compose run --rm mapswipe_workers_creation bash -c 'pip install pytest && pytest -ra -v --durations=10 tests/integration/'
83-
docker-compose run --rm django pytest -ra -v --durations=10
81+
docker compose run --rm mapswipe_workers_creation python -m unittest discover --verbose --start-directory tests/unittests/
82+
docker compose run --rm mapswipe_workers_creation bash -c 'pip install pytest && pytest -ra -v --durations=10 tests/integration/'
83+
docker compose run --rm django pytest -ra -v --durations=10
8484
8585
- name: Django Graphql Schema Check
8686
env:
8787
SOURCE_SCHEMA: './django/schema.graphql'
8888
LATEST_SCHEMA: './django-data/schema-latest.graphql'
8989
run: |
90-
docker-compose run --rm django bash -c 'wait-for-it postgres:5432 && ./manage.py graphql_schema --out /django-data/schema-latest.graphql' &&
90+
docker compose run --rm django bash -c 'wait-for-it postgres:5432 && ./manage.py graphql_schema --out /django-data/schema-latest.graphql' &&
9191
cmp --silent $SOURCE_SCHEMA $LATEST_SCHEMA || {
9292
echo 'The schema.graphql is not up to date with the latest changes. Please update and push latest';
9393
diff $SOURCE_SCHEMA $LATEST_SCHEMA;
@@ -101,7 +101,7 @@ jobs:
101101
POSTGRES_DB: postgres
102102
DJANGO_SECRET_KEY: test-django-secret-key
103103
run: |
104-
docker-compose run --rm django bash -c 'wait-for-it postgres:5432 && ./manage.py makemigrations --check --dry-run' || {
104+
docker compose run --rm django bash -c 'wait-for-it postgres:5432 && ./manage.py makemigrations --check --dry-run' || {
105105
echo 'There are some changes to be reflected in the migration. Make sure to run makemigrations';
106106
exit 1;
107107
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Please refer to the documentation for more information: https://mapswipe-workers
1717

1818
- MapSwipe Back-End: https://github.com/mapswipe/python-mapswipe-workers
1919
- MapSwipe App https://github.com/mapswipe/mapswipe
20+
- MapSwipe Web App https://github.com/mapswipe/mapswipe-web
2021
- MapSwipe Website: https://mapswipe.org
2122
- MapSwipe OSM-Wiki: https://wiki.openstreetmap.org/wiki/MapSwipe
2223

firebase/database.rules.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
"
3737
},
3838
".indexOn": [
39-
"status", "isFeatured", "teamId"
39+
"status",
40+
"isFeatured",
41+
"teamId",
42+
"projectTopicKey"
4043
]
4144
},
4245
"projectDrafts": {
@@ -138,7 +141,8 @@
138141
},
139142
".indexOn": [
140143
"created",
141-
"teamId"
144+
"teamId",
145+
"usernameKey"
142146
]
143147
},
144148
"OSMAccessToken": {

firebase/functions/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"axios": "^0.25.0",
1818
"cookie-parser": "^1.4.4",
1919
"firebase-admin": "^10.0.2",
20-
"firebase-functions": "^3.18.0",
20+
"firebase-functions": "^3.24.1",
2121
"request": "^2.88.2",
2222
"request-promise-native": "^1.0.8",
2323
"simple-oauth2": "3.3.0"
@@ -35,7 +35,7 @@
3535
"typescript": "^4.5.4"
3636
},
3737
"engines": {
38-
"node": "16"
38+
"node": "18"
3939
},
4040
"private": true
4141
}

firebase/functions/src/index.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ admin.initializeApp();
99
// seem possible to split them using the split system for multiple sites from
1010
// https://firebase.google.com/docs/hosting/multisites
1111
import {redirect, token} from './osm_auth';
12+
import { formatProjectTopic, formatUserName } from './utils';
1213

1314
exports.osmAuth = {};
1415

@@ -343,3 +344,63 @@ exports.incProjectProgress = functions.database.ref('/v2/projects/{projectId}/re
343344
exports.decProjectProgress = functions.database.ref('/v2/projects/{projectId}/requiredResults/').onUpdate(() => {
344345
return null;
345346
});
347+
348+
exports.addProjectTopicKey = functions.https.onRequest(async (_, res) => {
349+
try {
350+
const projectRef = await admin.database().ref('v2/projects').once('value');
351+
const data = projectRef.val();
352+
353+
const isEmptyProject = Object.keys(data).length === 0;
354+
if (isEmptyProject) {
355+
res.status(404).send('No projects found');
356+
}
357+
358+
if (!isEmptyProject && data) {
359+
const newProjectData: {[key: string]: string} = {};
360+
361+
Object.keys(data).forEach((id) => {
362+
if (data[id]?.projectTopic) {
363+
const newProjectTopicKey = formatProjectTopic(data[id].projectTopic);
364+
newProjectData[`v2/projects/${id}/projectTopicKey`] = newProjectTopicKey;
365+
}
366+
});
367+
368+
await admin.database().ref().update(newProjectData);
369+
const updatedProjectsCount = Object.keys(newProjectData).length;
370+
res.status(200).send(`Updated ${updatedProjectsCount} projects.`);
371+
}
372+
} catch (error) {
373+
console.log(error);
374+
res.status(500).send('Some error occurred');
375+
}
376+
});
377+
378+
exports.addUserNameLowercase = functions.https.onRequest(async (_, res) => {
379+
try {
380+
const userRef = await admin.database().ref('v2/users').once('value');
381+
const data = userRef.val();
382+
383+
const isEmptyUser = Object.keys(data).length === 0;
384+
if (isEmptyUser) {
385+
res.status(404).send('No user found');
386+
}
387+
388+
if (!isEmptyUser && data) {
389+
const newUserData: {[key: string]: string} = {};
390+
391+
Object.keys(data).forEach((id) => {
392+
if (data[id]?.username) {
393+
const newUsernameKey = formatUserName(data[id].username);
394+
newUserData[`v2/users/${id}/usernameKey`] = newUsernameKey;
395+
}
396+
});
397+
398+
await admin.database().ref().update(newUserData);
399+
const updatedUserCount = Object.keys(newUserData).length;
400+
res.status(200).send(`Updated ${updatedUserCount} users.`);
401+
}
402+
} catch (error) {
403+
console.log(error);
404+
res.status(500).send('Some error occurred');
405+
}
406+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// NOTE: We have a similar function in manager-dashbaord
2+
// manager-dashbaord/app/utills/common.tsx
3+
4+
export const formatProjectTopic = (projectTopic: string) => {
5+
// Note: this will remove start and end space
6+
const projectWithoutStartAndEndSpace = projectTopic.trim();
7+
8+
// Note: this will change multi space to single space
9+
const removeMultiSpaceToSingle = projectWithoutStartAndEndSpace.replace(/\s+/g, ' ');
10+
const newProjectTopic = removeMultiSpaceToSingle.toLowerCase();
11+
12+
return newProjectTopic;
13+
};
14+
15+
// NOTE: this validation mirrors feature from the app on signup
16+
export const formatUserName = (name: string) => {
17+
// Note: remove all space
18+
const removeUserNameSpace = name.replace(/\s+/g, '');
19+
const userNameLowercase = removeUserNameSpace.toLowerCase();
20+
21+
return userNameLowercase;
22+
};

0 commit comments

Comments
 (0)