Skip to content

Commit

Permalink
Auto approval for platform applications
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-daxiom committed Oct 26, 2024
1 parent 45e2deb commit 836b4d0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 33 deletions.
62 changes: 32 additions & 30 deletions jobs/auto-approval/src/auto_approval/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,39 @@ def process_applications(app, applications):
token = AuthService.get_service_client_token()
for application in applications:
app.logger.info(f"Auto processing application {str(application.id)}")
application_status, registration_id = ApprovalService.process_auto_approval(
token=token, application=application
ApprovalService.process_auto_approval(application=application)
# _generate_certificate(app, token, application_status, registration_id)


def _generate_certificate(app, token, application_status, registration_id):
if (
application_status
and application_status == Application.Status.AUTO_APPROVED
and registration_id
):
url = (
f"{app.config.get('STRR_API_URL')}"
f"/registrations/{registration_id}"
f"/certificate"
)
if (
application_status
and application_status == Application.Status.AUTO_APPROVED
and registration_id
):
url = (
f"{app.config.get('STRR_API_URL')}"
f"/registrations/{registration_id}"
f"/certificate"
)
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json",
}
try:
response = requests.post(url, headers=headers, timeout=10)
response.raise_for_status() # Raises HTTPError for 4xx/5xx responses
if response.status_code != HTTPStatus.CREATED:
app.logger.error(
f"Unexpected response error: Status Code: {response.status_code}, "
f"URL: {url}"
)
except (Timeout, RequestsConnectionError, HTTPError) as e:
app.logger.error(f"Request failed due to network error: {e}")
except RequestException as e: # Catch all other requests exceptions
app.logger.error(f"Request error: {e}")
except Exception as e: # pylint: disable=broad-except
app.logger.error(f"Unexpected error occurred: {e}", exc_info=True)
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json",
}
try:
response = requests.post(url, headers=headers, timeout=10)
response.raise_for_status() # Raises HTTPError for 4xx/5xx responses
if response.status_code != HTTPStatus.CREATED:
app.logger.error(
f"Unexpected response error: Status Code: {response.status_code}, "
f"URL: {url}"
)
except (Timeout, RequestsConnectionError, HTTPError) as e:
app.logger.error(f"Request failed due to network error: {e}")
except RequestException as e: # Catch all other requests exceptions
app.logger.error(f"Request error: {e}")
except Exception as e: # pylint: disable=broad-except
app.logger.error(f"Unexpected error occurred: {e}", exc_info=True)


def run():
Expand Down
2 changes: 1 addition & 1 deletion strr-api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "strr-api"
version = "0.0.16"
version = "0.0.17"
description = ""
authors = ["thorwolpert <thor@wolpert.ca>"]
license = "BSD 3-Clause"
Expand Down
22 changes: 20 additions & 2 deletions strr-api/src/strr_api/services/approval_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
# pylint: disable=C0103

"""For a successfully paid registration, this service determines its auto-approval state."""
from datetime import datetime
from typing import Any, Tuple

import requests
Expand All @@ -51,6 +52,7 @@
from strr_api.responses.LTSAResponse import LtsaResponse
from strr_api.services import EventsService, LtsaService
from strr_api.services.geocoder_service import GeoCoderService
from strr_api.services.registration_service import RegistrationService
from strr_api.services.rest_service import RestService


Expand Down Expand Up @@ -90,7 +92,7 @@ def check_full_name_exists_in_ownership_groups(cls, ltsa_response: LtsaResponse,
return False

@classmethod
def process_auto_approval(cls, token, application: Application) -> Tuple[Any, Any]:
def process_auto_approval(cls, application: Application) -> Tuple[Any, Any]:
"""Process approval logic and produce output JSON to store in the DB."""
try:
application_json = application.application_json
Expand Down Expand Up @@ -135,8 +137,24 @@ def process_auto_approval(cls, token, application: Application) -> Tuple[Any, An
auto_approval.titleCheck = cls.check_full_name_exists_in_ownership_groups(ltsa_response, owner_name)

cls.save_approval_record_by_application(application.id, auto_approval)
cls._update_application_status_to_full_review(application)

cls._update_application_status_to_full_review(application)
elif registration_type == RegistrationType.PLATFORM.value:
application.status = Application.Status.AUTO_APPROVED
registration = RegistrationService.create_registration(
application.submitter_id, application.payment_account, application.application_json
)
registration_id = registration.id
application.registration_id = registration.id
application.decision_date = datetime.utcnow()
application.save()

EventsService.save_event(
event_type=Events.EventType.APPLICATION,
event_name=Events.EventName.AUTO_APPROVAL_APPROVED,
application_id=application.id,
visible_to_applicant=False,
)
return application.status, registration_id

except Exception as default_exception: # noqa: B902; log error
Expand Down

0 comments on commit 836b4d0

Please sign in to comment.