Skip to content

Commit

Permalink
Merge pull request #1314 from bcgov/feat/hamed-notifications-settings…
Browse files Browse the repository at this point in the history
…-118

Feat: Notifications Settings Page - 118
  • Loading branch information
hamed-valiollahi authored Dec 6, 2024
2 parents a1aa138 + 09f594e commit abd3c15
Show file tree
Hide file tree
Showing 51 changed files with 1,899 additions and 379 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Add notifications email to user_profile
Revision ID: b69a33bbd135
Revises: 8491890dd688
Create Date: 2024-12-05 20:48:24.724112
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "b69a33bbd135"
down_revision = "8491890dd688"
branch_labels = None
depends_on = None


def upgrade() -> None:
# Add notifications_email column to user_profile table
op.add_column(
"user_profile",
sa.Column(
"notifications_email",
sa.String(length=255),
nullable=True,
comment="Email address used for notifications",
),
)


def downgrade() -> None:
# Remove notifications_email column from user_profile table
op.drop_column("user_profile", "notifications_email")
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""Update Notification Types and remove data
Revision ID: d4104af84f2b
Revises: b69a33bbd135
Create Date: 2024-12-05 02:20:33.898150
"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects.postgresql import ENUM

# Revision identifiers, used by Alembic.
revision = "d4104af84f2b"
down_revision = "b69a33bbd135"
branch_labels = None
depends_on = None


def upgrade():
# Remove the notification types added in the previous migration
op.execute("DELETE FROM notification_type;")

# Alter the `name` column in `notification_type` to be a VARCHAR
with op.batch_alter_table("notification_type") as batch_op:
batch_op.alter_column(
"name",
existing_type=ENUM(
"TRANSFER_PARTNER_UPDATE",
"TRANSFER_DIRECTOR_REVIEW",
"INITIATIVE_APPROVED",
"INITIATIVE_DA_REQUEST",
"SUPPLEMENTAL_REQUESTED",
"DIRECTOR_ASSESSMENT",
name="notification_type_enum_v2",
),
type_=sa.String(length=255),
existing_nullable=False,
)

# Drop the old enum types
op.execute("DROP TYPE IF EXISTS notification_type_enum_v2;")


def downgrade():
# Re-create the old enum type
notification_type_enum_v2 = ENUM(
"TRANSFER_PARTNER_UPDATE",
"TRANSFER_DIRECTOR_REVIEW",
"INITIATIVE_APPROVED",
"INITIATIVE_DA_REQUEST",
"SUPPLEMENTAL_REQUESTED",
"DIRECTOR_ASSESSMENT",
name="notification_type_enum_v2",
)
notification_type_enum_v2.create(op.get_bind(), checkfirst=False)

# Alter the `name` column back to the old enum
with op.batch_alter_table("notification_type") as batch_op:
batch_op.alter_column(
"name",
type_=notification_type_enum_v2,
existing_type=sa.String(length=255),
postgresql_using="name::text::notification_type_enum_v2",
existing_nullable=False,
)

# Re-insert the previous notification types
op.execute(
"""
INSERT INTO notification_type (notification_type_id, name, description, email_content, create_user, update_user)
VALUES
(1, 'TRANSFER_PARTNER_UPDATE', 'Transfer partner update notification', 'Email content for transfer partner update', 'system', 'system'),
(2, 'TRANSFER_DIRECTOR_REVIEW', 'Director review notification', 'Email content for director review', 'system', 'system'),
(3, 'INITIATIVE_APPROVED', 'Initiative approved notification', 'Email content for initiative approval', 'system', 'system'),
(4, 'INITIATIVE_DA_REQUEST', 'DA request notification', 'Email content for DA request', 'system', 'system'),
(5, 'SUPPLEMENTAL_REQUESTED', 'Supplemental requested notification', 'Email content for supplemental request', 'system', 'system'),
(6, 'DIRECTOR_ASSESSMENT', 'Director assessment notification', 'Email content for director assessment', 'system', 'system');
"""
)

# Reset the sequence for the id column
op.execute(
"""
SELECT setval('notification_type_id_seq', (SELECT MAX(notification_type_id) FROM notification_type));
"""
)
4 changes: 2 additions & 2 deletions backend/lcfs/db/models/notification/NotificationChannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


class ChannelEnum(enum.Enum):
EMAIL = "Email"
IN_APP = "In-Application"
EMAIL = "EMAIL"
IN_APP = "IN_APP"


class NotificationChannel(BaseModel, Auditable):
Expand Down
21 changes: 5 additions & 16 deletions backend/lcfs/db/models/notification/NotificationType.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
import enum
from lcfs.db.base import BaseModel, Auditable
from sqlalchemy import Column, Integer, Enum, Text
from sqlalchemy import Column, Integer, Text, String
from sqlalchemy.orm import relationship


class NotificationTypeEnum(enum.Enum):
TRANSFER_PARTNER_UPDATE = "Transfer partner proposed, declined, rescinded, or signed"
TRANSFER_DIRECTOR_REVIEW = "Director recorded/refused"
INITIATIVE_APPROVED = "Director approved"
INITIATIVE_DA_REQUEST = "DA request"
SUPPLEMENTAL_REQUESTED = "Supplemental requested"
DIRECTOR_ASSESSMENT = "Director assessment"


class NotificationType(BaseModel, Auditable):
__tablename__ = "notification_type"
__table_args__ = {"comment": "Represents a Notification type"}

notification_type_id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(
Enum(NotificationTypeEnum, name="notification_type_enum", create_type=True),
nullable=False,
)
name = Column(String(255), nullable=False)
description = Column(Text, nullable=True)
email_content = Column(Text, nullable=True)

subscriptions = relationship("NotificationChannelSubscription", back_populates="notification_type")
subscriptions = relationship(
"NotificationChannelSubscription", back_populates="notification_type"
)
2 changes: 2 additions & 0 deletions backend/lcfs/db/models/notification/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from .NotificationChannel import NotificationChannel
from .NotificationChannel import ChannelEnum
from .NotificationChannelSubscription import NotificationChannelSubscription
from .NotificationMessage import NotificationMessage
from .NotificationType import NotificationType

__all__ = [
"NotificationChannel",
"ChannelEnum",
"NotificationChannelSubscription",
"NotificationMessage",
"NotificationType",
Expand Down
3 changes: 3 additions & 0 deletions backend/lcfs/db/models/user/UserProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class UserProfile(BaseModel, Auditable):
String(150), unique=True, nullable=False, comment="keycloak Username"
)
email = Column(String(255), nullable=True, comment="Primary email address")
notifications_email = Column(
String(255), nullable=True, comment="Email address used for notifications"
)
title = Column(String(100), nullable=True, comment="Professional Title")
phone = Column(String(50), nullable=True, comment="Primary phone number")
mobile_phone = Column(String(50), nullable=True, comment="Mobile phone number")
Expand Down
113 changes: 95 additions & 18 deletions backend/lcfs/db/seeders/common/notifications_seeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,44 +58,121 @@ async def seed_notification_types(session):
"""
types_to_seed = [
{
"name": "TRANSFER_PARTNER_UPDATE",
"description": "Transfer partner update notification",
"email_content": "Email content for transfer partner update",
"name": "BCEID__COMPLIANCE_REPORT__DIRECTOR_ASSESSMENT",
"description": "Director assessed a compliance report or supplemental report.",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
{
"name": "TRANSFER_DIRECTOR_REVIEW",
"description": "Director review notification",
"email_content": "Email content for director review",
"name": "BCEID__INITIATIVE_AGREEMENT__DIRECTOR_APPROVAL",
"description": "Director approved the initiative agreement or transaction",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
{
"name": "INITIATIVE_APPROVED",
"description": "Initiative approved notification",
"email_content": "Email content for initiative approval",
"name": "BCEID__TRANSFER__DIRECTOR_DECISION",
"description": "Director recorded or refused a transfer request",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
{
"name": "INITIATIVE_DA_REQUEST",
"description": "DA request notification",
"email_content": "Email content for DA request",
"name": "BCEID__TRANSFER__PARTNER_ACTIONS",
"description": "A transfer partner took action (proposed, declined, rescinded, or signed & submitted) on a transfer request",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
{
"name": "SUPPLEMENTAL_REQUESTED",
"description": "Supplemental requested notification",
"email_content": "Email content for supplemental request",
"name": "IDIR_ANALYST__COMPLIANCE_REPORT__DIRECTOR_DECISION",
"description": "Director assessed compliance report",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
{
"name": "DIRECTOR_ASSESSMENT",
"description": "Director assessment notification",
"email_content": "Email content for director assessment",
"name": "IDIR_ANALYST__COMPLIANCE_REPORT__MANAGER_RECOMMENDATION",
"description": "Compliance manager recommended action on the compliance report.",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
{
"name": "IDIR_ANALYST__COMPLIANCE_REPORT__SUBMITTED_FOR_REVIEW",
"description": "Compliance report submitted for government analyst review or returned by compliance manager",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
{
"name": "IDIR_ANALYST__INITIATIVE_AGREEMENT__RETURNED_TO_ANALYST",
"description": "Director approved/returned the initiative agreement to the analyst",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
{
"name": "IDIR_ANALYST__TRANSFER__DIRECTOR_RECORDED",
"description": "Director recorded or refused a transfer request",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
{
"name": "IDIR_ANALYST__TRANSFER__RESCINDED_ACTION",
"description": "A transfer request was rescinded by a transfer partner",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
{
"name": "IDIR_ANALYST__TRANSFER__SUBMITTED_FOR_REVIEW",
"description": "Transfer request submitted for government analyst review",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
{
"name": "IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__ANALYST_RECOMMENDATION",
"description": "Analyst recommendation on the compliance report or returned by the director",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
{
"name": "IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__DIRECTOR_ASSESSMENT",
"description": "Director assessed a compliance report",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
{
"name": "IDIR_COMPLIANCE_MANAGER__COMPLIANCE_REPORT__SUBMITTED_FOR_REVIEW",
"description": "Compliance report submitted for government analyst review",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
{
"name": "IDIR_DIRECTOR__COMPLIANCE_REPORT__MANAGER_RECOMMENDATION",
"description": "Compliance manager recommended action on the compliance report",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
{
"name": "IDIR_DIRECTOR__INITIATIVE_AGREEMENT__ANALYST_RECOMMENDATION",
"description": "Analyst recommendation provided for the initiative agreement",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
{
"name": "IDIR_DIRECTOR__TRANSFER__ANALYST_RECOMMENDATION",
"description": "Analyst recommendation provided for the transfer request",
"email_content": "Email content",
"create_user": "system",
"update_user": "system",
},
Expand Down
Loading

0 comments on commit abd3c15

Please sign in to comment.