Skip to content
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
7 changes: 5 additions & 2 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\Notifications\Controller;

use OCA\Notifications\AppInfo\Application;
use OCA\Notifications\Model\Settings;
use OCA\Notifications\Model\SettingsMapper;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
Expand All @@ -34,7 +35,8 @@ public function __construct(
/**
* Update personal notification settings
*
* @param int $batchSetting How often E-mails about missed notifications should be sent (hourly: 1; every three hours: 2; daily: 3; weekly: 4)
* @param int<0, 4> $batchSetting How often E-mails about missed notifications should be sent (off: 0; hourly: 1; every three hours: 2; daily: 3; weekly: 4)
* @psalm-param Settings::EMAIL_SEND_* $batchSetting
* @param string $soundNotification Enable sound for notifications ('yes' or 'no')
* @param string $soundTalk Enable sound for Talk notifications ('yes' or 'no')
* @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
Expand All @@ -56,7 +58,8 @@ public function personal(int $batchSetting, string $soundNotification, string $s
/**
* Update default notification settings for new users
*
* @param int $batchSetting How often E-mails about missed notifications should be sent (hourly: 1; every three hours: 2; daily: 3; weekly: 4)
* @param int<0, 4> $batchSetting How often E-mails about missed notifications should be sent (off: 0; hourly: 1; every three hours: 2; daily: 3; weekly: 4)
* @psalm-param Settings::EMAIL_SEND_* $batchSetting
* @param string $soundNotification Enable sound for notifications ('yes' or 'no')
* @param string $soundTalk Enable sound for Talk notifications ('yes' or 'no')
* @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
Expand Down
19 changes: 16 additions & 3 deletions lib/MailNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,11 @@ protected function getHTMLContents(INotification $notification): string {
$HTMLSubject = $this->getHTMLSubject($notification);
$link = $notification->getLink();
if ($link !== '') {
$HTMLSubject = '<a href="' . $link . '">' . $HTMLSubject . '</a>';
// Only render absolute links
$scheme = strtolower((string)parse_url($link, PHP_URL_SCHEME));
if ($scheme === 'http' || $scheme === 'https') {
$HTMLSubject = '<a href="' . htmlspecialchars($link) . '">' . $HTMLSubject . '</a>';
}
}

return $HTMLSubject . '<br>' . $this->getHTMLMessage($notification);
Expand Down Expand Up @@ -338,8 +342,17 @@ protected function replaceRichParameters(array $parameters, string $contentStrin
$replacement = $parameter['name'];
}

if (isset($parameter['link'])) {
$replacements[] = '<a href="' . $parameter['link'] . '">' . htmlspecialchars($replacement) . '</a>';
// Only render absolute links
$href = '';
if (isset($parameter['link']) && is_string($parameter['link'])) {
$scheme = strtolower((string)parse_url($parameter['link'], PHP_URL_SCHEME));
if ($scheme === 'http' || $scheme === 'https') {
$href = htmlspecialchars($parameter['link']);
}
}

if ($href !== '') {
$replacements[] = '<a href="' . $href . '">' . htmlspecialchars($replacement) . '</a>';
} else {
$replacements[] = '<strong>' . htmlspecialchars($replacement) . '</strong>';
}
Expand Down
4 changes: 3 additions & 1 deletion openapi-administration.json
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,9 @@
"batchSetting": {
"type": "integer",
"format": "int64",
"description": "How often E-mails about missed notifications should be sent (hourly: 1; every three hours: 2; daily: 3; weekly: 4)"
"description": "How often E-mails about missed notifications should be sent (off: 0; hourly: 1; every three hours: 2; daily: 3; weekly: 4)",
"minimum": 0,
"maximum": 4
},
"soundNotification": {
"type": "string",
Expand Down
8 changes: 6 additions & 2 deletions openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,9 @@
"batchSetting": {
"type": "integer",
"format": "int64",
"description": "How often E-mails about missed notifications should be sent (hourly: 1; every three hours: 2; daily: 3; weekly: 4)"
"description": "How often E-mails about missed notifications should be sent (off: 0; hourly: 1; every three hours: 2; daily: 3; weekly: 4)",
"minimum": 0,
"maximum": 4
},
"soundNotification": {
"type": "string",
Expand Down Expand Up @@ -2251,7 +2253,9 @@
"batchSetting": {
"type": "integer",
"format": "int64",
"description": "How often E-mails about missed notifications should be sent (hourly: 1; every three hours: 2; daily: 3; weekly: 4)"
"description": "How often E-mails about missed notifications should be sent (off: 0; hourly: 1; every three hours: 2; daily: 3; weekly: 4)",
"minimum": 0,
"maximum": 4
},
"soundNotification": {
"type": "string",
Expand Down
4 changes: 3 additions & 1 deletion openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,9 @@
"batchSetting": {
"type": "integer",
"format": "int64",
"description": "How often E-mails about missed notifications should be sent (hourly: 1; every three hours: 2; daily: 3; weekly: 4)"
"description": "How often E-mails about missed notifications should be sent (off: 0; hourly: 1; every three hours: 2; daily: 3; weekly: 4)",
"minimum": 0,
"maximum": 4
},
"soundNotification": {
"type": "string",
Expand Down
18 changes: 9 additions & 9 deletions tests/Unit/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ public function testFull(): void {
'getSubjectParameters' => [],
'getMessage' => 'message',
'getMessageParameters' => [],
'getLink' => 'https://link',
'getIcon' => 'https://icon',
'getLink' => 'https://example.tld/notification',
'getIcon' => 'https://example.tld/icon',
'getActions' => [
[
'getLabel' => 'action_label',
'getLink' => 'https://action_link',
'getLink' => 'https://example.tld/action',
'getRequestType' => 'GET',
'isPrimary' => false,
]
Expand Down Expand Up @@ -120,12 +120,12 @@ public function testFullEmptyMessageForOracle(): void {
'getSubjectParameters' => [],
'getMessage' => '',
'getMessageParameters' => [],
'getLink' => 'https://link',
'getIcon' => 'https://icon',
'getLink' => 'https://example.tld/notification',
'getIcon' => 'https://example.tld/icon',
'getActions' => [
[
'getLabel' => 'action_label',
'getLink' => 'https://action_link',
'getLink' => 'https://example.tld/action',
'getRequestType' => 'GET',
'isPrimary' => false,
]
Expand Down Expand Up @@ -176,12 +176,12 @@ public function testDeleteById(): void {
'getSubjectParameters' => [],
'getMessage' => 'message',
'getMessageParameters' => [],
'getLink' => 'https://link',
'getIcon' => 'https://icon',
'getLink' => 'https://example.tld/notification',
'getIcon' => 'https://example.tld/icon',
'getActions' => [
[
'getLabel' => 'action_label',
'getLink' => 'https://action_link',
'getLink' => 'https://example.tld/action',
'getRequestType' => 'GET',
'isPrimary' => true,
]
Expand Down
Loading