Skip to content

Commit

Permalink
Merge pull request #957 from mapswipe/dev
Browse files Browse the repository at this point in the history
Release - 2024-July
  • Loading branch information
thenav56 authored Aug 2, 2024
2 parents f9c3438 + 8592b90 commit 037a19f
Show file tree
Hide file tree
Showing 28 changed files with 1,775 additions and 1,074 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
working-directory: ./mapswipe_workers
run: |
python -m pip install --upgrade pip
pip install flake8 black==22.3.0 isort
pip install flake8 black==24.4.2 isort
- name: Code style
working-directory: ./mapswipe_workers
Expand All @@ -47,15 +47,15 @@ jobs:
run: |
# Create a mock file for wal-g setup
touch postgres/serviceAccountKey.json
docker-compose up --build --detach postgres
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)
docker compose up --build --detach postgres
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)
- name: Deploy Firebase Rules and Functions
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
FIREBASE_DB: ${{ secrets.FIREBASE_DB }}
run: |
docker-compose run --rm firebase_deploy sh -c "firebase use $FIREBASE_DB && firebase deploy --token $FIREBASE_TOKEN --only database"
docker compose run --rm firebase_deploy sh -c "firebase use $FIREBASE_DB && firebase deploy --token $FIREBASE_TOKEN --only database"
- name: Decrypt Service Account Key File
working-directory: ./
Expand All @@ -78,16 +78,16 @@ jobs:
OSMCHA_API_KEY: ${{ secrets.OSMCHA_API_KEY }}
DJANGO_SECRET_KEY: test-django-secret-key
run: |
docker-compose run --rm mapswipe_workers_creation python -m unittest discover --verbose --start-directory tests/unittests/
docker-compose run --rm mapswipe_workers_creation bash -c 'pip install pytest && pytest -ra -v --durations=10 tests/integration/'
docker-compose run --rm django pytest -ra -v --durations=10
docker compose run --rm mapswipe_workers_creation python -m unittest discover --verbose --start-directory tests/unittests/
docker compose run --rm mapswipe_workers_creation bash -c 'pip install pytest && pytest -ra -v --durations=10 tests/integration/'
docker compose run --rm django pytest -ra -v --durations=10
- name: Django Graphql Schema Check
env:
SOURCE_SCHEMA: './django/schema.graphql'
LATEST_SCHEMA: './django-data/schema-latest.graphql'
run: |
docker-compose run --rm django bash -c 'wait-for-it postgres:5432 && ./manage.py graphql_schema --out /django-data/schema-latest.graphql' &&
docker compose run --rm django bash -c 'wait-for-it postgres:5432 && ./manage.py graphql_schema --out /django-data/schema-latest.graphql' &&
cmp --silent $SOURCE_SCHEMA $LATEST_SCHEMA || {
echo 'The schema.graphql is not up to date with the latest changes. Please update and push latest';
diff $SOURCE_SCHEMA $LATEST_SCHEMA;
Expand All @@ -101,7 +101,7 @@ jobs:
POSTGRES_DB: postgres
DJANGO_SECRET_KEY: test-django-secret-key
run: |
docker-compose run --rm django bash -c 'wait-for-it postgres:5432 && ./manage.py makemigrations --check --dry-run' || {
docker compose run --rm django bash -c 'wait-for-it postgres:5432 && ./manage.py makemigrations --check --dry-run' || {
echo 'There are some changes to be reflected in the migration. Make sure to run makemigrations';
exit 1;
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Please refer to the documentation for more information: https://mapswipe-workers

- MapSwipe Back-End: https://github.com/mapswipe/python-mapswipe-workers
- MapSwipe App https://github.com/mapswipe/mapswipe
- MapSwipe Web App https://github.com/mapswipe/mapswipe-web
- MapSwipe Website: https://mapswipe.org
- MapSwipe OSM-Wiki: https://wiki.openstreetmap.org/wiki/MapSwipe

Expand Down
8 changes: 6 additions & 2 deletions firebase/database.rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
"
},
".indexOn": [
"status", "isFeatured", "teamId"
"status",
"isFeatured",
"teamId",
"projectTopicKey"
]
},
"projectDrafts": {
Expand Down Expand Up @@ -138,7 +141,8 @@
},
".indexOn": [
"created",
"teamId"
"teamId",
"usernameKey"
]
},
"OSMAccessToken": {
Expand Down
4 changes: 2 additions & 2 deletions firebase/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"axios": "^0.25.0",
"cookie-parser": "^1.4.4",
"firebase-admin": "^10.0.2",
"firebase-functions": "^3.18.0",
"firebase-functions": "^3.24.1",
"request": "^2.88.2",
"request-promise-native": "^1.0.8",
"simple-oauth2": "3.3.0"
Expand All @@ -35,7 +35,7 @@
"typescript": "^4.5.4"
},
"engines": {
"node": "16"
"node": "18"
},
"private": true
}
61 changes: 61 additions & 0 deletions firebase/functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ admin.initializeApp();
// seem possible to split them using the split system for multiple sites from
// https://firebase.google.com/docs/hosting/multisites
import {redirect, token} from './osm_auth';
import { formatProjectTopic, formatUserName } from './utils';

exports.osmAuth = {};

Expand Down Expand Up @@ -343,3 +344,63 @@ exports.incProjectProgress = functions.database.ref('/v2/projects/{projectId}/re
exports.decProjectProgress = functions.database.ref('/v2/projects/{projectId}/requiredResults/').onUpdate(() => {
return null;
});

exports.addProjectTopicKey = functions.https.onRequest(async (_, res) => {
try {
const projectRef = await admin.database().ref('v2/projects').once('value');
const data = projectRef.val();

const isEmptyProject = Object.keys(data).length === 0;
if (isEmptyProject) {
res.status(404).send('No projects found');
}

if (!isEmptyProject && data) {
const newProjectData: {[key: string]: string} = {};

Object.keys(data).forEach((id) => {
if (data[id]?.projectTopic) {
const newProjectTopicKey = formatProjectTopic(data[id].projectTopic);
newProjectData[`v2/projects/${id}/projectTopicKey`] = newProjectTopicKey;
}
});

await admin.database().ref().update(newProjectData);
const updatedProjectsCount = Object.keys(newProjectData).length;
res.status(200).send(`Updated ${updatedProjectsCount} projects.`);
}
} catch (error) {
console.log(error);
res.status(500).send('Some error occurred');
}
});

exports.addUserNameLowercase = functions.https.onRequest(async (_, res) => {
try {
const userRef = await admin.database().ref('v2/users').once('value');
const data = userRef.val();

const isEmptyUser = Object.keys(data).length === 0;
if (isEmptyUser) {
res.status(404).send('No user found');
}

if (!isEmptyUser && data) {
const newUserData: {[key: string]: string} = {};

Object.keys(data).forEach((id) => {
if (data[id]?.username) {
const newUsernameKey = formatUserName(data[id].username);
newUserData[`v2/users/${id}/usernameKey`] = newUsernameKey;
}
});

await admin.database().ref().update(newUserData);
const updatedUserCount = Object.keys(newUserData).length;
res.status(200).send(`Updated ${updatedUserCount} users.`);
}
} catch (error) {
console.log(error);
res.status(500).send('Some error occurred');
}
});
22 changes: 22 additions & 0 deletions firebase/functions/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// NOTE: We have a similar function in manager-dashbaord
// manager-dashbaord/app/utills/common.tsx

export const formatProjectTopic = (projectTopic: string) => {
// Note: this will remove start and end space
const projectWithoutStartAndEndSpace = projectTopic.trim();

// Note: this will change multi space to single space
const removeMultiSpaceToSingle = projectWithoutStartAndEndSpace.replace(/\s+/g, ' ');
const newProjectTopic = removeMultiSpaceToSingle.toLowerCase();

return newProjectTopic;
};

// NOTE: this validation mirrors feature from the app on signup
export const formatUserName = (name: string) => {
// Note: remove all space
const removeUserNameSpace = name.replace(/\s+/g, '');
const userNameLowercase = removeUserNameSpace.toLowerCase();

return userNameLowercase;
};
Loading

0 comments on commit 037a19f

Please sign in to comment.