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

Add pending notifications incident history messages #127

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions library/Notifications/Model/IncidentHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* @property ?string $new_recipient_role
* @property ?string $old_recipient_role
* @property ?string $message
* @property string $notification_state
* @property DateTime $sent_at
*
* @property Query | Incident $incident
* @property Query | Event $event
Expand Down Expand Up @@ -67,7 +69,9 @@ public function getColumns()
'old_severity',
'new_recipient_role',
'old_recipient_role',
'message'
'message',
'notification_state',
'sent_at'
yhabteab marked this conversation as resolved.
Show resolved Hide resolved
];
}

Expand All @@ -93,7 +97,7 @@ public function getColumnDefinitions()

public function createBehaviors(Behaviors $behaviors)
{
$behaviors->add(new MillisecondTimestamp(['time']));
$behaviors->add(new MillisecondTimestamp(['time', 'sent_at']));
}

public function getDefaultSort()
Expand All @@ -113,4 +117,25 @@ public function createRelations(Relations $relations)
$relations->belongsTo('rule_escalation', RuleEscalation::class)->setJoinType('LEFT');
$relations->belongsTo('channel', Channel::class)->setJoinType('LEFT');
}

/**
* Transform the given notification state into a translatable message.
*
* @param string $state
*
* @return string
*/
public static function translateNotificationState(string $state): string
nilmerg marked this conversation as resolved.
Show resolved Hide resolved
{
switch ($state) {
case 'sent':
return t('sent', 'notifications.transmission.state');
case 'failed':
return t('failed', 'notifications.transmission.state');
case 'pending':
return t('pending', 'notifications.transmission.state');
default:
return t('unknown', 'notifications.transmission.state');
}
}
}
49 changes: 38 additions & 11 deletions library/Notifications/Widget/ItemList/IncidentHistoryListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,51 @@ protected function buildMessage(): string
break;
case "notified":
if ($this->item->contactgroup_id) {
$message = sprintf(
t('Contact %s notified via %s as member of contact group %s'),
$this->item->contact->full_name,
$this->item->channel->type,
$this->item->contactgroup->name
);
if ($this->item->notification_state === 'sent') {
$message = sprintf(
t('Contact %s notified via %s as member of contact group %s'),
$this->item->contact->full_name,
$this->item->channel->type,
$this->item->contactgroup->name
);
} else {
$message = sprintf(
t('Contact %s notified via %s as member of contact group %s (%s)'),
$this->item->contact->full_name,
$this->item->channel->type,
$this->item->contactgroup->name,
IncidentHistory::translateNotificationState($this->item->notification_state)
);
}
} elseif ($this->item->schedule_id) {
if ($this->item->notfication_state === 'sent') {
$message = sprintf(
t('Contact %s notified via %s as member of schedule %s'),
$this->item->contact->full_name,
$this->item->channel->type,
$this->item->schedule->name
);
} else {
$message = sprintf(
t('Contact %s notified via %s as member of schedule %s (%s)'),
$this->item->contact->full_name,
$this->item->schedule->name,
$this->item->channel->type,
IncidentHistory::translateNotificationState($this->item->notification_state)
);
}
} elseif ($this->item->notification_state === 'sent') {
$message = sprintf(
t('Contact %s notified via %s as member of schedule %s'),
t('Contact %s notified via %s'),
$this->item->contact->full_name,
$this->item->channel->type,
$this->item->schedule->name
$this->item->channel->type
);
} else {
$message = sprintf(
t('Contact %s notified via %s'),
t('Contact %s notified via %s (%s)'),
$this->item->contact->full_name,
$this->item->channel->type
$this->item->channel->type,
IncidentHistory::translateNotificationState($this->item->notification_state)
);
}

Expand Down
Loading