Skip to content

Commit

Permalink
Make Helsinki address checks optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mhieta committed Dec 14, 2023
1 parent c54ee85 commit b5cf76b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
6 changes: 2 additions & 4 deletions parking_permits/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
)
from .services.traficom import Traficom
from .talpa.order import TalpaOrderManager
from .utils import ModelDiffer, get_user_from_resolver_args
from .utils import ModelDiffer, get_user_from_resolver_args, is_valid_city

logger = logging.getLogger("db")
audit_logger = audit.getAuditLoggerAdapter(
Expand Down Expand Up @@ -81,9 +81,7 @@


def is_valid_address(address):
if not address:
return False
return address.get("city").upper() == "HELSINKI"
return address and is_valid_city(address)


@query.field("getPermits")
Expand Down
8 changes: 3 additions & 5 deletions parking_permits/services/dvv.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from parking_permits.exceptions import ObjectNotFound
from parking_permits.models import Customer, ParkingZone
from parking_permits.services.kami import get_address_details, parse_street_data
from parking_permits.utils import is_valid_city

logger = logging.getLogger("db")

Expand Down Expand Up @@ -120,11 +121,8 @@ def format_address(address_data) -> DvvAddressInfo:


def is_valid_address(address):
return (
address["LahiosoiteS"] != ""
and address["PostitoimipaikkaS"]
and address["PostitoimipaikkaS"].upper() == "HELSINKI"
)
address_valid = address and address["LahiosoiteS"] and address["PostitoimipaikkaS"]
return address_valid and is_valid_city(address["PostitoimipaikkaS"])


def get_person_info(national_id_number) -> Optional[DvvPersonInfo]:
Expand Down
7 changes: 7 additions & 0 deletions parking_permits/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from ariadne import convert_camel_case_to_snake
from dateutil.relativedelta import relativedelta
from django.conf import settings
from django.db import models
from django.utils import timezone as tz
from graphql import GraphQLResolveInfo
Expand Down Expand Up @@ -342,3 +343,9 @@ def round_up(v):
if v
else "0.00"
)


def is_valid_city(city):
if settings.HELSINKI_ADDRESS_CHECK:
return city and city.casefold() == "helsinki"
return True
2 changes: 2 additions & 0 deletions project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
TRAFICOM_PALVELU_TUNNUS=(str, ""),
TRAFICOM_VERIFY_SSL=(bool, True),
TRAFICOM_CHECK=(bool, True),
HELSINKI_ADDRESS_CHECK=(bool, True),
DVV_PERSONAL_INFO_URL=(str, ""),
DVV_USERNAME=(str, ""),
DVV_PASSWORD=(str, ""),
Expand Down Expand Up @@ -213,6 +214,7 @@
TRAFICOM_PALVELU_TUNNUS = env("TRAFICOM_PALVELU_TUNNUS")
TRAFICOM_VERIFY_SSL = env("TRAFICOM_VERIFY_SSL")
TRAFICOM_CHECK = env("TRAFICOM_CHECK")
HELSINKI_ADDRESS_CHECK = env("HELSINKI_ADDRESS_CHECK")

# CORS
CORS_ALLOWED_ORIGINS = env("CORS_ALLOWED_ORIGINS")
Expand Down
1 change: 1 addition & 0 deletions project/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

# Debug options. Override these in tests if needed.
DEBUG_SKIP_PARKKIHUBI_SYNC = True
HELSINKI_ADDRESS_CHECK = True
TALPA_WEBHOOK_WAIT_BUFFER_SECONDS = 0

0 comments on commit b5cf76b

Please sign in to comment.