mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Include the notification sender name when serializing notifications
The `serialize` method of the Notification model now includes the `created_by_name`. If a notification was sent as a one-off message this value will now be the name of the person who sent the notification. If a notification was sent through the API or by a CSV upload we don't record the id of the sender, so `created_by_name` will be `None`. This change affects the data that gets returned from these endpoints: * /v2/notifications/<notification_id> * /v2/notifications
This commit is contained in:
@@ -1299,6 +1299,12 @@ class Notification(db.Model):
|
||||
# Currently can only be technical-failure
|
||||
return self.status
|
||||
|
||||
def get_created_by_name(self):
|
||||
if self.created_by:
|
||||
return self.created_by.name
|
||||
else:
|
||||
return None
|
||||
|
||||
def serialize_for_csv(self):
|
||||
created_at_in_bst = convert_utc_to_bst(self.created_at)
|
||||
serialized = {
|
||||
@@ -1338,6 +1344,7 @@ class Notification(db.Model):
|
||||
"body": self.content,
|
||||
"subject": self.subject,
|
||||
"created_at": self.created_at.strftime(DATETIME_FORMAT),
|
||||
"created_by_name": self.get_created_by_name(),
|
||||
"sent_at": self.sent_at.strftime(DATETIME_FORMAT) if self.sent_at else None,
|
||||
"completed_at": self.completed_at(),
|
||||
"scheduled_for": (
|
||||
|
||||
Reference in New Issue
Block a user