Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue #3539] Add notifications to notifications backend #3794

Conversation

mikehgrantsgov
Copy link
Collaborator

Summary

Fixes #3539

Time to review: 15 mins

Changes proposed

Integrate AWS Pinpoint client to generate_notifications.py task
Set pinpoint app ID as an environment variable

Context for reviewers

Open question: how do we handle pinpoint app id? Is it going to set as an env var?

Additional information

See attached unit tests

Comment on lines 176 to 180
# Get user email from LinkExternalUser using select pattern
stmt = select(LinkExternalUser).where(LinkExternalUser.user_id == user_id)
user = self.db_session.execute(stmt).scalar_one_or_none()

if not user or not user.email:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because we'll likely need the email for other things in the future, and it might get pulled from a few places, what if we add a property to the user table, something like:

@property
def email(self) -> str | None:
     if self.login_gov_user is not None: # TODO - would need to add a relationship that fetches this
          return self.login_gov_user.email

     return None

Comment on lines 190 to 196
send_pinpoint_email_raw(
to_address=user.email,
subject=subject,
message=message,
pinpoint_client=self.pinpoint_client,
app_id=self.config.app_id,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want a try/except around this - if it fails, we should update the UserNotificationLog notification_sent field.

@mikehgrantsgov mikehgrantsgov marked this pull request as ready for review February 6, 2025 21:47
Comment on lines 33 to 44
linked_external_user: Mapped["LinkExternalUser | None"] = relationship(
"LinkExternalUser",
primaryjoin=lambda: LinkExternalUser.user_id == User.user_id,
uselist=False,
viewonly=True,
)

@property
def email(self) -> str | None:
if self.linked_external_user is not None:
return self.linked_external_user.email
return None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While at the moment we only support a single linked user type (login.gov), that will change in the future. Could we do something like:

    login_gov_external_user: Mapped["LinkExternalUser | None"] = relationship(
        "LinkExternalUser",
        primaryjoin=lambda: and_(LinkExternalUser.user_id == User.user_id, LinkExternalUser.external_user_type == ExternalUserType.LOGIN_GOV),
        uselist=False,
        viewonly=True,
    )

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, added this.

Comment on lines 62 to 64
user: Mapped["User"] = relationship(
"User", primaryjoin=lambda: LinkExternalUser.user_id == User.user_id
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this need to change? It should be able to reference the user from the foreign key uneventfully

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change wasn't needed, but a part of the fiddling I was doing to get the sqlalchemy pieces to work. Updated this too

@@ -30,6 +30,22 @@ class User(ApiSchemaTable, TimestampMixin):
"UserSavedSearch", back_populates="user", uselist=True, cascade="all, delete-orphan"
)

linked_external_user: Mapped["LinkExternalUser | None"] = relationship(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one last thing, could we call this linked_login_gov_external_user or something with login_gov in it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, just updated

Base automatically changed from mikehgrantsgov/3538-generate-notifications-saved-searches to main February 7, 2025 21:15
@mikehgrantsgov mikehgrantsgov merged commit fe754bb into main Feb 10, 2025
2 checks passed
@mikehgrantsgov mikehgrantsgov deleted the mikehgrantsgov/3539-add-notifications-to-notifications-backend branch February 10, 2025 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add notifications to the notification backend task
2 participants