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

Release - 2024-July #957

Merged
merged 22 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
dab4717
feature(manager-dashboard): add optional manualUrl field to new proje…
ofr1tz Jun 20, 2024
509d30b
Update README.md
nashmsf Jun 24, 2024
4d4e338
Add validation for unique project while creating
puranban May 7, 2024
deb41d9
Add cloud function to update project data
puranban Jul 3, 2024
716d82e
Merge pull request #931 from mapswipe/feature/unique-project-title
frozenhelium Jul 5, 2024
fb3a13f
Merge pull request #941 from mapswipe/feature/add-manual-url-field
ofr1tz Jul 10, 2024
311c417
Merge pull request #942 from nashmsf/patch-1
tnagorra Jul 11, 2024
4e6fd4a
Update README.md
ofr1tz Jul 15, 2024
3f1c8d5
Add cloud function to save username in lowercase
puranban Jul 25, 2024
231ec08
[Quick Fix] Use static version for setuptools
thenav56 Jul 26, 2024
8318b07
Improve cloud function
puranban Jul 26, 2024
7be7d6d
Merge pull request #955 from mapswipe/feature/username-lowercase-func…
samshara Jul 26, 2024
0e8a8f2
Fix project draft topic save
puranban Jul 29, 2024
90d6913
Add projectTopicKey in firebase rule for query optimization
puranban Jul 29, 2024
4f25192
Add projectTopicKey to projectDraft -> project
thenav56 Jul 29, 2024
51f8345
Add projectTopicKey to projectDraft -> project
thenav56 Jul 29, 2024
30a6b57
Feat: add utility function to format project and other improvements
puranban Jul 30, 2024
0c3fcde
Merge pull request #958 from mapswipe/fix/project-draft-topic
tnagorra Jul 31, 2024
9fcd215
black/isort update
thenav56 Jul 31, 2024
2f3ce51
Fix project delete issue
thenav56 Jul 31, 2024
8c8d3c9
GH: Replace docker-compose with docker compose
thenav56 Aug 1, 2024
8592b90
Merge pull request #960 from mapswipe/fix/project-delete
thenav56 Aug 1, 2024
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
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
Loading