Skip to content

Commit

Permalink
Tracking pull request to merge release-1.58.0 to master (#2118)
Browse files Browse the repository at this point in the history
* use object storage for docs (#2120)

* feat: zeva-2058 - object storage changes (#2119)

* Replace Minio with Object Storge

* fix: 2113 - load icon (#2126)

* fix: adds loading to handle submit

* chore: removes extra line

* Feat: Timezones Default PST #2125 (#2128)

* Setting default timezone at the top of the application to use PST

* Updating test to use the on_commit function so that testing happens after all database actions have completed (#2130)

* Updating test to use on_commit to only test after all database actions have completed (#2131)

* Updated back button routing to return user to the vehicle suppliers credit transactions list or all supplier transactions list based on href state (#2132)

* Updating settings.py to change default field back to older version (#2134)

* feat: zeva-2112 - refined emails (#2135)

* fix: zeva-2129 - rounding error (#2133)

* add FRONTEND_URL_BASE for backend

* fix: 2129 v2 - fix rounding errors (#2138)

* fix: 2146 - compliance ration reduction calculation (#2148)

---------

Co-authored-by: tim738745 <[email protected]>
Co-authored-by: Emily <[email protected]>
Co-authored-by: JulianForeman <[email protected]>
  • Loading branch information
4 people authored Apr 4, 2024
1 parent b370c4e commit c708259
Show file tree
Hide file tree
Showing 29 changed files with 536 additions and 117 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/dev-build.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## For each release, please update the value of workflow name, branches and PR_NUMBER
## Also update frontend/package.json version

name: Dev Build 1.57.0
name: Dev Build 1.58.0

on:
push:
branches: [ release-1.57.0 ]
branches: [ release-1.58.0 ]
paths:
- frontend/**
- backend/**
Expand All @@ -14,8 +14,8 @@ on:

env:
## The pull request number of the Tracking pull request to merge the release branch to main
PR_NUMBER: 2104
VERSION: 1.57.0
PR_NUMBER: 2118
VERSION: 1.58.0
GIT_URL: https://github.com/bcgov/zeva.git
TOOLS_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-tools
DEV_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-dev
Expand All @@ -32,7 +32,7 @@ jobs:
call-unit-test:
uses: ./.github/workflows/unit-test-template.yaml
with:
pr-number: 2104
pr-number: 2118

build:

Expand All @@ -47,7 +47,7 @@ jobs:
uses: actions/checkout@v3

- name: Log in to Openshift
uses: redhat-actions/oc-login@v1.2
uses: redhat-actions/oc-login@v1.3
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
ref: refs/pull/${{ env.PR_NUMBER }}/head

- name: Log in to Openshift
uses: redhat-actions/oc-login@v1.2
uses: redhat-actions/oc-login@v1.3
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/emergency-release-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
# uses: actions/checkout@v3

# - name: Log in to Openshift
# uses: redhat-actions/oc-login@v1.2
# uses: redhat-actions/oc-login@v1.3
# with:
# openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
# openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
uses: actions/checkout@v3

- name: Log in to Openshift
uses: redhat-actions/oc-login@v1.2
uses: redhat-actions/oc-login@v1.3
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
Expand Down Expand Up @@ -134,7 +134,7 @@ jobs:
uses: actions/checkout@v3

- name: Log in to Openshift
uses: redhat-actions/oc-login@v1.2
uses: redhat-actions/oc-login@v1.3
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pr-build-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
ref: refs/pull/${{ inputs.pr-number }}/head

- name: Log in to Openshift
uses: redhat-actions/oc-login@v1.2
uses: redhat-actions/oc-login@v1.3
with:
openshift_server_url: ${{ secrets.openshift-server }}
openshift_token: ${{ secrets.openshift-token }}
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
ref: refs/pull/${{ inputs.pr-number }}/head

- name: Log in to Openshift
uses: redhat-actions/oc-login@v1.2
uses: redhat-actions/oc-login@v1.3
with:
openshift_server_url: ${{ secrets.openshift-server }}
openshift_token: ${{ secrets.openshift-token }}
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:
ref: refs/pull/${{ inputs.pr-number }}/head

- name: Log in to Openshift
uses: redhat-actions/oc-login@v1.2
uses: redhat-actions/oc-login@v1.3
with:
openshift_server_url: ${{ secrets.openshift-server }}
openshift_token: ${{ secrets.openshift-token }}
Expand Down Expand Up @@ -152,7 +152,7 @@ jobs:
ref: refs/pull/${{ inputs.pr-number }}/head

- name: Log in to Openshift
uses: redhat-actions/oc-login@v1.2
uses: redhat-actions/oc-login@v1.3
with:
openshift_server_url: ${{ secrets.openshift-server }}
openshift_token: ${{ secrets.openshift-token }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-teardown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:

- name: Log in to Openshift
uses: redhat-actions/oc-login@v1.2
uses: redhat-actions/oc-login@v1.3
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/release-build.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
## For each release, please update the value of workflow name, branches and PR_NUMBER
## Also update frontend/package.json version

name: Release Build 1.57.0
name: Release Build 1.58.0

on:
workflow_dispatch:
workflow_call:

env:
## The pull request number of the Tracking pull request to merge the release branch to main
PR_NUMBER: 2104
VERSION: 1.57.0
PR_NUMBER: 2118
VERSION: 1.58.0
GIT_URL: https://github.com/bcgov/zeva.git
TOOLS_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-tools
DEV_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-dev
Expand All @@ -27,7 +27,7 @@ jobs:
call-unit-test:
uses: ./.github/workflows/unit-test-template.yaml
with:
pr-number: 2104
pr-number: 2118

build:

Expand All @@ -42,7 +42,7 @@ jobs:
uses: actions/checkout@v3

- name: Log in to Openshift
uses: redhat-actions/oc-login@v1.2
uses: redhat-actions/oc-login@v1.3
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
uses: actions/checkout@v3

- name: Log in to Openshift
uses: redhat-actions/oc-login@v1.2
uses: redhat-actions/oc-login@v1.3
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
Expand Down Expand Up @@ -135,7 +135,7 @@ jobs:
uses: actions/checkout@v3

- name: Log in to Openshift
uses: redhat-actions/oc-login@v1.2
uses: redhat-actions/oc-login@v1.3
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
Expand Down
13 changes: 10 additions & 3 deletions backend/api/services/minio.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,25 @@
)


def get_refined_object_name(object_name):
prefix = MINIO['PREFIX']
if prefix:
return prefix + '/' + object_name
return object_name


def minio_get_object(object_name):
return minio.presigned_get_object(
bucket_name=MINIO['BUCKET_NAME'],
object_name=object_name,
object_name=get_refined_object_name(object_name),
expires=timedelta(seconds=3600)
)


def minio_put_object(object_name):
return minio.presigned_put_object(
bucket_name=MINIO['BUCKET_NAME'],
object_name=object_name,
object_name=get_refined_object_name(object_name),
expires=MINIO['EXPIRY']
)

Expand All @@ -37,5 +44,5 @@ def minio_remove_objects(objects_iter):
def minio_remove_object(object_name):
return minio.remove_object(
bucket_name=MINIO['BUCKET_NAME'],
object_name=object_name
object_name=get_refined_object_name(object_name)
)
45 changes: 36 additions & 9 deletions backend/api/services/send_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
from api.models.credit_agreement_statuses import CreditAgreementStatuses
from api.models.notification_subscription import NotificationSubscription
from api.models.organization import Organization
from api.models.credit_transfer import CreditTransfer
from api.models.sales_submission import SalesSubmission
from api.models.vehicle import Vehicle
from api.models.model_year_report import ModelYearReport
from api.models.credit_agreement import CreditAgreement

import requests
from django.db.models import Q
from typing import List
Expand Down Expand Up @@ -75,7 +81,7 @@ def get_email_service_token() -> dict:
return {"error": str(e)}


def generate_email_body(email_type: str, test_info: dict) -> str:
def generate_email_body(email_type: str, link: str, test_info: dict) -> str:
"""
Generates an email body based on the provided email_type and test_info parameters.
Expand All @@ -92,7 +98,7 @@ def generate_email_body(email_type: str, test_info: dict) -> str:
<html>
<body>
This email was generated by the Government of B.C. Zero-Emission Vehicle Reporting System.
<p>A {email_type} has occurred within the Zero-Emission Vehicle Reporting System that may require your action or be of interest to you, please logon to the system at: <a href="https://zeroemissionvehicles.gov.bc.ca/">https://zeroemissionvehicles.gov.bc.ca/</a></p>
<p>A {email_type} has occurred within the Zero-Emission Vehicle Reporting System. For more details, please go to: <a href={link}>{link}</a></p>
<p>You received this email because you subscribed at the site above, to stop receiving these email logon to your account here <a href="https://zeroemissionvehicles.gov.bc.ca/notifications">https://zeroemissionvehicles.gov.bc.ca/notifications</a></p>
"""

Expand Down Expand Up @@ -121,7 +127,7 @@ def generate_email_body(email_type: str, test_info: dict) -> str:
return body


def send_email(recipient_emails: List[str], email_type: str, test_info: dict):
def send_email(recipient_emails: List[str], email_type: str, direct_link: str, test_info: dict):
"""
Sends an email to the specified recipients with the given email type and test information.
Expand Down Expand Up @@ -159,7 +165,7 @@ def send_email(recipient_emails: List[str], email_type: str, test_info: dict):
LOGGER.error("No email type provided")
return

body = generate_email_body(email_type, test_info)
body = generate_email_body(email_type, direct_link, test_info)

subject = "BC ZEVA Notification"
bodyType = "html"
Expand Down Expand Up @@ -488,6 +494,22 @@ def notifications_zev_model(vehicle: object, validation_status: str):
send_zev_model_emails(notifications, vehicle)


def get_direct_link(object):
result = settings.FRONTEND_URL_BASE
object_id = str(object.id)
if isinstance(object, CreditTransfer):
result = result + '/credit-transfers/' + object_id
elif isinstance(object, SalesSubmission):
result = result + '/credit-requests/' + object_id
elif isinstance(object, Vehicle):
result = result + '/vehicles/' + object_id
elif isinstance(object, ModelYearReport):
result = result + '/compliance/reports/' + object_id + '/supplier-information'
elif isinstance(object, CreditAgreement):
result = result + '/credit-agreements/' + object_id
return result


def send_credit_transfer_emails(notifications, transfer):
"""
Sends emails to subscribed users with credit transfer updates.
Expand All @@ -502,10 +524,11 @@ def send_credit_transfer_emails(notifications, transfer):
user_emails = get_subscribed_user_emails(notifications, transfer, request_type)
notification_objects = get_notification_objects(notifications)
test_info = prepare_test_info(transfer, notification_objects)
direct_link = get_direct_link(transfer)

if user_emails:
email_type = '<b>credit transfer update</b>'
send_email(list(user_emails), email_type, test_info)
send_email(list(user_emails), email_type, direct_link, test_info)


def send_credit_application_emails(notifications, submission):
Expand All @@ -522,10 +545,11 @@ def send_credit_application_emails(notifications, submission):
user_emails = get_subscribed_user_emails(notifications, submission, request_type)
notification_objects = get_notification_objects(notifications)
test_info = prepare_test_info(submission, notification_objects)
direct_link = get_direct_link(submission)

if user_emails:
email_type = '<b>credit application update</b>'
send_email(list(user_emails), email_type, test_info)
send_email(list(user_emails), email_type, direct_link, test_info)


def send_zev_model_emails(notifications, vehicle):
Expand All @@ -542,10 +566,11 @@ def send_zev_model_emails(notifications, vehicle):
user_emails = get_subscribed_user_emails(notifications, vehicle, request_type)
notification_objects = get_notification_objects(notifications)
test_info = prepare_test_info(vehicle, notification_objects)
direct_link = get_direct_link(vehicle)

if user_emails:
email_type = '<b>ZEV model update</b>'
send_email(list(user_emails), email_type, test_info)
send_email(list(user_emails), email_type, direct_link, test_info)


def send_model_year_report_emails(notifications, model_year_report):
Expand All @@ -562,10 +587,11 @@ def send_model_year_report_emails(notifications, model_year_report):
user_emails = get_subscribed_user_emails(notifications, model_year_report, request_type)
notification_objects = get_notification_objects(notifications)
test_info = prepare_test_info(model_year_report, notification_objects)
direct_link = get_direct_link(model_year_report)

if user_emails:
email_type = '<b>model year report update</b>'
send_email(list(user_emails), email_type, test_info)
send_email(list(user_emails), email_type, direct_link, test_info)


def send_credit_agreement_emails(notifications, agreement):
Expand All @@ -582,7 +608,8 @@ def send_credit_agreement_emails(notifications, agreement):
user_emails = get_subscribed_user_emails(notifications, agreement, request_type)
notification_objects = get_notification_objects(notifications)
test_info = prepare_test_info(agreement, notification_objects)
direct_link = get_direct_link(agreement)

if user_emails:
email_type = '<b>credit agreement update</b>'
send_email(list(user_emails), email_type, test_info)
send_email(list(user_emails), email_type, direct_link, test_info)
Loading

0 comments on commit c708259

Please sign in to comment.