Skip to content

Commit

Permalink
21535 - Update url in eft refund email (bcgov#1636)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jxio authored Jul 23, 2024
1 parent 1ae8641 commit 9519dd6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def upgrade():
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('first_name', sa.String(25), nullable=True),
sa.Column('last_name', sa.String(25), nullable=True),
sa.Column('email', sa.String(25), nullable=False),
sa.Column('email', sa.String(25), nullable=False)
)
def downgrade():
op.drop_table('eft_refund_email_list')
46 changes: 46 additions & 0 deletions pay-api/migrations/versions/2024_07_22_f9c15c7f29f5_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""add primary key constraint to eft_refund_email_list table
Revision ID: f9c15c7f29f5
Revises: fb59bf68146d
Create Date: 2024-07-22 14:52:01.050844
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from sqlalchemy.schema import Sequence, CreateSequence

# revision identifiers, used by Alembic.
revision = 'f9c15c7f29f5'
down_revision = 'fb59bf68146d'
branch_labels = None
depends_on = None


def upgrade():
op.drop_table('eft_refund_email_list')

op.execute(CreateSequence(Sequence('eft_refund_email_list_id_seq')))

op.create_table('eft_refund_email_list',
sa.Column('id', sa.Integer(),
sa.Sequence('eft_refund_email_list_id_seq'),
server_default=sa.text("nextval('eft_refund_email_list_id_seq'::regclass)"),
nullable=False),
sa.Column('first_name', sa.String(25), nullable=True),
sa.Column('last_name', sa.String(25), nullable=True),
sa.Column('email', sa.String(25), nullable=False),
sa.PrimaryKeyConstraint('id')
)
def downgrade():
op.drop_table('eft_refund_email_list')

op.execute('DROP SEQUENCE eft_refund_email_list_id_seq')

op.create_table('eft_refund_email_list',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('first_name', sa.String(25), nullable=True),
sa.Column('last_name', sa.String(25), nullable=True),
sa.Column('email', sa.String(25), nullable=False),
sa.PrimaryKeyConstraint('id')
)
8 changes: 5 additions & 3 deletions pay-api/src/pay_api/models/eft_refund_email_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"""Model to handle all operations related to Fee related to accounts."""
from __future__ import annotations

from sqlalchemy import Sequence

from .base_model import BaseModel
from .db import db

Expand All @@ -34,7 +36,7 @@ class EFTRefundEmailList(BaseModel):
# Exception, id is always first, _fields first
__mapper_args__ = {
'include_properties': [
'email'
'email',
'first_name',
'id',
'last_name',
Expand All @@ -43,8 +45,8 @@ class EFTRefundEmailList(BaseModel):

email = db.Column(db.String(25), nullable=False)
first_name = db.Column(db.String(25), nullable=True)
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
last_name = db.Column(db.String(25), nullable=False)
id = db.Column(db.Integer, Sequence('eft_refund_email_list_id_seq'), primary_key=True)
last_name = db.Column(db.String(25), nullable=True)

@classmethod
def find_all_emails(cls):
Expand Down
6 changes: 3 additions & 3 deletions pay-api/src/pay_api/services/eft_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def create_shortname_refund(cls, request: Dict[str, str], **kwargs) -> Dict[str,
recipients = EFTRefundEmailList.find_all_emails()

subject = f'Pending Refund Request for Short Name {shortname}'
html_body = cls._render_email_body(shortname, amount, comment)
html_body = cls._render_email_body(shortname, amount, comment, shortname_id)

send_email(recipients, subject, html_body, **kwargs)
refund.save()
Expand All @@ -144,15 +144,15 @@ def _create_refund_model(cls, request: Dict[str, str],
return refund

@classmethod
def _render_email_body(cls, shortname: str, amount: str, comment: str) -> str:
def _render_email_body(cls, shortname: str, amount: str, comment: str, shortname_id: str) -> str:
"""Render the email body using the provided template."""
current_dir = os.path.dirname(os.path.abspath(__file__))
project_root_dir = os.path.dirname(current_dir)
templates_dir = os.path.join(project_root_dir, 'templates')
env = Environment(loader=FileSystemLoader(templates_dir), autoescape=True)
template = env.get_template('eft_refund_notification.html')

url = f"{current_app.config.get('AUTH_WEB_URL')}/account/settings/transactions"
url = f"{current_app.config.get('AUTH_WEB_URL')}/pay/shortname-details/{shortname_id}"
params = {
'shortname': shortname,
'refundAmount': amount,
Expand Down

0 comments on commit 9519dd6

Please sign in to comment.