Skip to content

Commit 8fa3cc9

Browse files
authored
Merge pull request #200 from mapswipe/fix/validate-image-uniqueness
2 parents 0ed92c2 + f42c8ce commit 8fa3cc9

File tree

30 files changed

+291
-155
lines changed

30 files changed

+291
-155
lines changed

apps/common/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def clear_expired_django_sessions():
1717
if not acquired:
1818
logger.warning("Clear expired django sessions")
1919
return
20-
management.call_command("clearsessions", verbosity=0)
20+
management.call_command("clearsessions", verbosity=0)
2121

2222

2323
@shared_task

apps/community_dashboard/graphql/queries.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import strawberry
66
from asgiref.sync import sync_to_async
77
from django.db import models
8-
from django.shortcuts import aget_object_or_404
98
from django.utils import timezone
109

1110
from apps.community_dashboard.models import AggregatedUserGroupStatData, AggregatedUserStatData
12-
from apps.contributor.models import ContributorUser
11+
from apps.contributor.models import ContributorUser, ContributorUserGroup
12+
from utils.graphql.inputs import FirebaseOrInternalIdInputType
1313

1414
from .types import (
1515
AggregateHelper,
@@ -117,17 +117,19 @@ async def community_filtered_stats(
117117
) -> CommunityFilteredStats:
118118
return CommunityFilteredStats(date_range=date_range)
119119

120+
# By Internal ID
120121
@strawberry.field
121122
async def community_user_stats(
122123
self,
123-
firebase_id: strawberry.ID,
124+
user_id: FirebaseOrInternalIdInputType,
124125
) -> ContributorUserStats:
125-
user = await aget_object_or_404(ContributorUser, firebase_id=firebase_id)
126+
user = await FirebaseOrInternalIdInputType.aget_object_or_404(ContributorUser, object_id=user_id)
126127
return ContributorUserStats(user=user)
127128

128129
@strawberry.field
129130
async def community_user_group_stats(
130131
self,
131-
user_group_id: strawberry.ID,
132+
user_group_id: FirebaseOrInternalIdInputType,
132133
) -> ContributorUserGroupStats:
133-
return ContributorUserGroupStats(user_group_id=int(user_group_id))
134+
user_group = await FirebaseOrInternalIdInputType.aget_object_or_404(ContributorUserGroup, object_id=user_group_id)
135+
return ContributorUserGroupStats(user_group=user_group)

apps/community_dashboard/graphql/types.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from django_cte import With # type: ignore[reportMissingTypeStubs]
1212

1313
from apps.community_dashboard.models import AggregatedUserGroupStatData, AggregatedUserStatData
14-
from apps.contributor.models import ContributorUser
14+
from apps.contributor.models import ContributorUser, ContributorUserGroup
1515
from apps.project.models import Project, ProjectTypeEnum
1616
from utils.graphql.inputs import DateRangeInput
1717
from utils.graphql.types import AreaSqKm, GenericJSON
@@ -349,6 +349,10 @@ def __post_init__(self, user: ContributorUser):
349349
async def id(self) -> strawberry.ID:
350350
return typing.cast("strawberry.ID", self._user.pk)
351351

352+
@strawberry.field
353+
async def firebase_id(self) -> strawberry.ID:
354+
return typing.cast("strawberry.ID", self._user.firebase_id)
355+
352356
@strawberry.field
353357
async def stats(self) -> ContributorUserStatType:
354358
# TODO: Cache this
@@ -423,15 +427,15 @@ def __post_init__(self, date_range: DateRangeInput | None, user_group_id: int):
423427

424428
@strawberry.type
425429
class ContributorUserGroupStats:
426-
user_group_id: InitVar[int]
430+
user_group: InitVar[ContributorUserGroup]
427431

428432
_user_group_id: strawberry.Private[int] = dataclass_field(init=False)
429433
_ug_qs: strawberry.Private[models.QuerySet[AggregatedUserGroupStatData]] = dataclass_field(init=False)
430434

431-
def __post_init__(self, user_group_id: int):
432-
self._user_group_id = user_group_id
435+
def __post_init__(self, user_group: ContributorUserGroup):
436+
self._user_group_id = user_group.pk
433437
self._ug_qs = AggregatedUserGroupStatData.objects.filter(
434-
user_group_id=user_group_id,
438+
user_group_id=user_group.pk,
435439
)
436440

437441
@strawberry.field

apps/community_dashboard/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ def update_aggregated_data():
1919
logger.warning("Community Dashboard update aggregate already running")
2020
return
2121

22-
UpdateAggregateCommand().handle()
22+
UpdateAggregateCommand().handle()

apps/community_dashboard/tests/query_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def test_filtered_community_stats(self):
256256
def test_user_group_aggregated_calc(self):
257257
query = """
258258
query MyQuery($userGroupId: ID!) {
259-
communityUserGroupStats(userGroupId: $userGroupId) {
259+
communityUserGroupStats(userGroupId: {id: $userGroupId}) {
260260
stats {
261261
totalAreaSwiped
262262
totalContributors
@@ -306,7 +306,7 @@ def test_user_group_aggregated_calc(self):
306306
def test_user_group_query(self):
307307
query = """
308308
query MyQuery($userGroupId: ID!, $pagination: OffsetPaginationInput!) {
309-
contributorUserGroup(id: $userGroupId) {
309+
contributorUserGroup(userGroupId: {id: $userGroupId}) {
310310
id
311311
name
312312
createdAt
@@ -502,13 +502,13 @@ def test_user_query(self):
502502
$toDate: Date!,
503503
) {
504504
505-
contributorUserByFirebaseId(firebaseId: $firebaseId) {
505+
contributorUser(userId: {firebaseId: $firebaseId}) {
506506
id
507507
firebaseId
508508
username
509509
}
510510
511-
communityUserStats(firebaseId: $firebaseId) {
511+
communityUserStats(userId: {firebaseId: $firebaseId}) {
512512
id
513513
stats {
514514
totalSwipes
@@ -644,7 +644,7 @@ def test_user_query(self):
644644
)
645645

646646
assert {
647-
"contributorUserByFirebaseId": {
647+
"contributorUser": {
648648
"id": self.gID(contributor_user.pk),
649649
"firebaseId": contributor_user.firebase_id,
650650
"username": contributor_user.username,

apps/contributor/firebase/pull.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pyfirebase_mapswipe import extended_models as firebase_ext_models
66
from pyfirebase_mapswipe import models as firebase_models
77

8+
from apps.common.models import FirebasePushStatusEnum
89
from apps.contributor.models import (
910
ContributorUser,
1011
ContributorUserGroupMembershipLogActionEnum,
@@ -41,6 +42,9 @@ def pull_users_from_firebase():
4142
username=valid_user.username,
4243
created_at=valid_user.created,
4344
modified_at=valid_user.created,
45+
# NOTE: Setting firebase_last_pushed so that we can send updates to firebase.
46+
firebase_last_pushed=datetime.datetime.now(),
47+
firebase_push_status=FirebasePushStatusEnum.SUCCESS,
4448
)
4549
users_to_pull.append(user)
4650

apps/contributor/graphql/queries.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import strawberry
44
import strawberry_django
55
from django.db.models import QuerySet
6-
from django.shortcuts import aget_object_or_404
76
from strawberry_django.pagination import OffsetPaginated
87
from strawberry_django.permissions import IsAuthenticated
98

109
from apps.contributor.models import ContributorTeam, ContributorUser, ContributorUserGroup, ContributorUserGroupMembership
10+
from utils.graphql.inputs import FirebaseOrInternalIdInputType
1111

1212
from .filters import (
1313
ContributorTeamFilter,
@@ -31,18 +31,25 @@ class Query:
3131
filters=ContributorUserFilter,
3232
)
3333

34-
contributor_user: ContributorUserType = strawberry_django.field()
35-
36-
contributor_user_group: ContributorUserGroupType = strawberry_django.field()
37-
3834
# Team
3935
contributor_team: ContributorTeamType = strawberry_django.field()
4036

4137
@strawberry.field
42-
async def contributor_user_by_firebase_id(self, firebase_id: strawberry.ID) -> ContributorUserType:
43-
obj = await aget_object_or_404(ContributorUser, firebase_id=firebase_id)
38+
async def contributor_user(
39+
self,
40+
user_id: FirebaseOrInternalIdInputType,
41+
) -> ContributorUserType:
42+
obj = await FirebaseOrInternalIdInputType.aget_object_or_404(ContributorUser, object_id=user_id)
4443
return typing.cast("ContributorUserType", obj)
4544

45+
@strawberry.field
46+
async def contributor_user_group(
47+
self,
48+
user_group_id: FirebaseOrInternalIdInputType,
49+
) -> ContributorUserGroupType:
50+
obj = await FirebaseOrInternalIdInputType.aget_object_or_404(ContributorUserGroup, object_id=user_group_id)
51+
return typing.cast("ContributorUserGroupType", obj)
52+
4653
# --- Paginated
4754
# --- ContributorUserGroup
4855
@strawberry_django.offset_paginated(

apps/contributor/tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def pull_users_from_firebase_task():
1515
logger.warning("Pull users from firebase is already running")
1616
return
1717

18-
pull_users_from_firebase()
18+
pull_users_from_firebase()
1919

2020

2121
@shared_task
@@ -25,4 +25,4 @@ def pull_user_group_memberships_from_firebase_task():
2525
logger.warning("Pull user group memberships from firebase is already running")
2626
return
2727

28-
pull_user_group_memberships_from_firebase()
28+
pull_user_group_memberships_from_firebase()

apps/existing_database/management/commands/loaddata_from_existing_database.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,11 @@ def parse_project_name(
532532
def parse_project_status(existing_project: existing_db_models.Project) -> ProjectStatusEnum:
533533
assert existing_project.status is not None
534534
return {
535-
"inactive": ProjectStatusEnum.PAUSED,
535+
"inactive": ProjectStatusEnum.DISCARDED,
536536
"active": ProjectStatusEnum.PUBLISHED,
537537
"private_active": ProjectStatusEnum.PUBLISHED,
538538
"private_finished": ProjectStatusEnum.FINISHED,
539+
"private_inactive": ProjectStatusEnum.DISCARDED,
539540
"finished": ProjectStatusEnum.FINISHED,
540541
"archived": ProjectStatusEnum.WITHDRAWN,
541542
}[existing_project.status]
@@ -573,6 +574,8 @@ def create_project(
573574
requesting_organization=get_organization_by_name(requesting_organization, bot_user),
574575
created_by_id=get_user_by_contributor_user_firebase_id(existing_project.created_by, fallback=bot_user),
575576
modified_by_id=get_user_by_contributor_user_firebase_id(existing_project.created_by, fallback=bot_user),
577+
project_type_specifics=existing_project.project_type_specifics,
578+
description=existing_project.project_details.strip() if existing_project.project_details else "",
576579
)
577580

578581
# Progress metadata
@@ -986,7 +989,7 @@ def handle_project(self):
986989
output_field=GeometryField(geography=True),
987990
),
988991
)
989-
/ 100_000,
992+
/ 1_000_000,
990993
)
991994

992995
self.stdout.write("\n")

apps/mapping/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212

1313
class MappingSessionClientTypeEnum(models.IntegerChoices):
14-
"""Enum representing client type used during a mapping session."""
14+
"""Enum representing client type used during a mapping session.
15+
https://github.com/react-native-device-info/react-native-device-info#getsystemname.
16+
"""
1517

1618
UNKNOWN = 0, "Unknown"
1719
MOBILE_ANDROID = 1, "Mobile (Android)"
@@ -23,6 +25,8 @@ def get_client_type(cls, value: str) -> "MappingSessionClientTypeEnum":
2325
return {
2426
"mobile-android": cls.MOBILE_ANDROID,
2527
"mobile-ios": cls.MOBILE_IOS,
28+
"mobile-iphone os": cls.MOBILE_IOS,
29+
"mobile-ipados": cls.MOBILE_IOS,
2630
"web": cls.WEB,
2731
}.get(value, cls.UNKNOWN)
2832

0 commit comments

Comments
 (0)