Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mhieta committed Dec 14, 2023
2 parents f528b7b + b5cf76b commit 4d6e3a3
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 22 deletions.
3 changes: 2 additions & 1 deletion parking_permits/admin_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ def resolve_customers(obj, info, page_input, order_by=None, search_params=None):
)
def resolve_vehicle(obj, info, reg_number, national_id_number):
customer = Customer.objects.get_or_create(national_id_number=national_id_number)[0]
customer.fetch_driving_licence_detail()
if settings.TRAFICOM_CHECK:
customer.fetch_driving_licence_detail()
vehicle = customer.fetch_vehicle_detail(reg_number)
if not settings.TRAFICOM_CHECK:
return vehicle
Expand Down
26 changes: 14 additions & 12 deletions parking_permits/customer_permit.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,24 @@ def create(self, address_id, registration):
primary_vehicle = not primary_permit.primary_vehicle
end_time = primary_permit.end_time

self.customer.fetch_driving_licence_detail()
if settings.TRAFICOM_CHECK:
self.customer.fetch_driving_licence_detail()

vehicle = self.customer.fetch_vehicle_detail(registration)
is_user_of_vehicle = self.customer.is_user_of_vehicle(vehicle)
if not is_user_of_vehicle:
raise TraficomFetchVehicleError(
_("Owner/holder data of a vehicle could not be verified")
)
if settings.TRAFICOM_CHECK:
is_user_of_vehicle = self.customer.is_user_of_vehicle(vehicle)
if not is_user_of_vehicle:
raise TraficomFetchVehicleError(
_("Owner/holder data of a vehicle could not be verified")
)

has_valid_licence = self.customer.has_valid_driving_licence_for_vehicle(
vehicle
)
if not has_valid_licence:
raise TraficomFetchVehicleError(
_("Customer does not have a valid driving licence")
has_valid_licence = self.customer.has_valid_driving_licence_for_vehicle(
vehicle
)
if not has_valid_licence:
raise TraficomFetchVehicleError(
_("Customer does not have a valid driving licence")
)

start_time = tz.now()
if not end_time:
Expand Down
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 4d6e3a3

Please sign in to comment.