Internal: Fix URL handling in notification links for CLI script - refs BT#22050

pull/5896/head
christianbeeznst 11 months ago
parent 677d739504
commit c489f3bc5c
  1. 6
      public/main/inc/lib/message.lib.php
  2. 31
      public/main/inc/lib/notification.lib.php
  3. 34
      tests/scripts/disable_user_conditions.php

@ -132,7 +132,8 @@ class MessageManager
$forwardId = 0, $forwardId = 0,
$checkCurrentAudioId = false, $checkCurrentAudioId = false,
$forceTitleWhenSendingEmail = false, $forceTitleWhenSendingEmail = false,
$msgType = null $msgType = null,
$baseUrl = null
) { ) {
$group_id = (int) $group_id; $group_id = (int) $group_id;
$receiverUserId = (int) $receiverUserId; $receiverUserId = (int) $receiverUserId;
@ -374,7 +375,8 @@ class MessageManager
$content, $content,
$sender_info, $sender_info,
$attachmentAddedByMail, $attachmentAddedByMail,
$forceTitleWhenSendingEmail $forceTitleWhenSendingEmail,
$baseUrl
); );
} else { } else {
$usergroup = new UserGroupModel(); $usergroup = new UserGroupModel();

@ -228,7 +228,8 @@ class Notification extends Model
$content, $content,
$senderInfo = [], $senderInfo = [],
$attachments = [], $attachments = [],
$forceTitleWhenSendingEmail = false $forceTitleWhenSendingEmail = false,
$baseUrl = null
) { ) {
$this->type = (int) $type; $this->type = (int) $type;
$messageId = (int) $messageId; $messageId = (int) $messageId;
@ -267,7 +268,7 @@ class Notification extends Model
$userInfo = api_get_user_info($user_id); $userInfo = api_get_user_info($user_id);
$recipientLanguage = !empty($userInfo['locale']) ? $userInfo['locale'] : null; $recipientLanguage = !empty($userInfo['locale']) ? $userInfo['locale'] : null;
$content = $this->formatContent($messageId, $content, $senderInfo, $recipientLanguage); $content = $this->formatContent($messageId, $content, $senderInfo, $recipientLanguage, $baseUrl);
$titleToNotification = $this->formatTitle($title, $senderInfo, $forceTitleWhenSendingEmail, $recipientLanguage); $titleToNotification = $this->formatTitle($title, $senderInfo, $forceTitleWhenSendingEmail, $recipientLanguage);
// Extra field was deleted or removed? Use the default status. // Extra field was deleted or removed? Use the default status.
@ -353,11 +354,13 @@ class Notification extends Model
* *
* @return string * @return string
* */ * */
public function formatContent($messageId, $content, $senderInfo, $recipientLanguage = null) public function formatContent($messageId, $content, $senderInfo, $recipientLanguage = null, $baseUrl = null)
{ {
$newMessageText = $linkToNewMessage = ''; $newMessageText = $linkToNewMessage = '';
$showEmail = ('true' === api_get_setting('mail.show_user_email_in_notification')); $showEmail = ('true' === api_get_setting('mail.show_user_email_in_notification'));
$senderInfoName = ''; $senderInfoName = '';
$baseUrl = $baseUrl ?: rtrim(api_get_path(WEB_PATH), '/');
if (!empty($senderInfo) && isset($senderInfo['complete_name'])) { if (!empty($senderInfo) && isset($senderInfo['complete_name'])) {
$senderInfoName = $senderInfo['complete_name']; $senderInfoName = $senderInfo['complete_name'];
if ($showEmail && isset($senderInfo['complete_name_with_email_forced'])) { if ($showEmail && isset($senderInfo['complete_name_with_email_forced'])) {
@ -370,7 +373,7 @@ class Notification extends Model
$newMessageText = ''; $newMessageText = '';
$linkToNewMessage = Display::url( $linkToNewMessage = Display::url(
get_lang('See message', $recipientLanguage), get_lang('See message', $recipientLanguage),
api_get_path(WEB_PATH).'resources/messages/show?id=/api/messages/'.$messageId $baseUrl . '/resources/messages/show?id=/api/messages/' . $messageId
); );
break; break;
case self::NOTIFICATION_TYPE_MESSAGE: case self::NOTIFICATION_TYPE_MESSAGE:
@ -386,7 +389,7 @@ class Notification extends Model
} }
$linkToNewMessage = Display::url( $linkToNewMessage = Display::url(
get_lang('See message', $recipientLanguage), get_lang('See message', $recipientLanguage),
api_get_path(WEB_PATH).'resources/messages/show?id=/api/messages/'.$messageId $baseUrl . '/resources/messages/show?id=/api/messages/' . $messageId
); );
break; break;
case self::NOTIFICATION_TYPE_INVITATION: case self::NOTIFICATION_TYPE_INVITATION:
@ -398,7 +401,7 @@ class Notification extends Model
} }
$linkToNewMessage = Display::url( $linkToNewMessage = Display::url(
get_lang('See invitation', $recipientLanguage), get_lang('See invitation', $recipientLanguage),
api_get_path(WEB_CODE_PATH).'social/invitations.php' $baseUrl . '/main/social/invitations.php'
); );
break; break;
case self::NOTIFICATION_TYPE_GROUP: case self::NOTIFICATION_TYPE_GROUP:
@ -408,15 +411,15 @@ class Notification extends Model
$newMessageText = sprintf(get_lang('You have received a new message in group %s', $recipientLanguage), $senderName); $newMessageText = sprintf(get_lang('You have received a new message in group %s', $recipientLanguage), $senderName);
$senderName = Display::url( $senderName = Display::url(
$senderInfoName, $senderInfoName,
api_get_path(WEB_CODE_PATH).'social/profile.php?'.$senderInfo['user_info']['user_id'] $baseUrl . '/main/social/profile.php?' . $senderInfo['user_info']['user_id']
); );
$newMessageText .= '<br />'.get_lang('User', $recipientLanguage).': '.$senderName; $newMessageText .= '<br />' . get_lang('User', $recipientLanguage) . ': ' . $senderName;
} }
$groupUrl = api_get_path(WEB_PATH).'resources/usergroups/show/'.$senderInfo['group_info']['id']; $groupUrl = $baseUrl . '/resources/usergroups/show/' . $senderInfo['group_info']['id'];
$linkToNewMessage = Display::url(get_lang('See message', $recipientLanguage), $groupUrl); $linkToNewMessage = Display::url(get_lang('See message', $recipientLanguage), $groupUrl);
break; break;
} }
$preferenceUrl = api_get_path(WEB_CODE_PATH).'auth/profile.php'; $preferenceUrl = $baseUrl . '/main/auth/profile.php';
// You have received a new message text // You have received a new message text
if (!empty($newMessageText)) { if (!empty($newMessageText)) {
@ -435,14 +438,6 @@ class Notification extends Model
Display::url($preferenceUrl, $preferenceUrl) Display::url($preferenceUrl, $preferenceUrl)
).'</i>'; ).'</i>';
/*if (!empty($hook)) {
$hook->setEventData(['content' => $content]);
$data = $hook->notifyNotificationContent(HOOK_EVENT_TYPE_POST);
if (isset($data['content'])) {
$content = $data['content'];
}
}*/
return $content; return $content;
} }

@ -18,6 +18,8 @@
die('Remove the "die()" statement on line '.__LINE__.' to execute this script'.PHP_EOL); die('Remove the "die()" statement on line '.__LINE__.' to execute this script'.PHP_EOL);
require_once __DIR__.'/../../public/main/inc/global.inc.php'; require_once __DIR__.'/../../public/main/inc/global.inc.php';
$options = getopt('', ['url:']);
$baseUrl = isset($options['url']) ? rtrim($options['url'], '/') : null;
$senderId = api_get_setting('platform.disable_user_conditions_sender_id'); $senderId = api_get_setting('platform.disable_user_conditions_sender_id');
if (empty($senderId)) { if (empty($senderId)) {
@ -98,7 +100,13 @@ foreach ($students as $student) {
0, 0,
0, 0,
0, 0,
$senderId $senderId,
false,
0,
false,
false,
null,
$baseUrl
); );
UserManager::disable($studentId); UserManager::disable($studentId);
} }
@ -157,7 +165,13 @@ foreach ($students as $student) {
0, 0,
0, 0,
0, 0,
$senderId $senderId,
false,
0,
false,
false,
null,
$baseUrl
); );
UserManager::disable($studentId); UserManager::disable($studentId);
} }
@ -223,7 +237,13 @@ foreach ($students as $student) {
0, 0,
0, 0,
0, 0,
$senderId $senderId,
false,
0,
false,
false,
null,
$baseUrl
); );
UserManager::disable($studentId); UserManager::disable($studentId);
if (!empty($bossInfo) && !empty($subjectBoss)) { if (!empty($bossInfo) && !empty($subjectBoss)) {
@ -237,7 +257,13 @@ foreach ($students as $student) {
0, 0,
0, 0,
0, 0,
$senderId $senderId,
false,
0,
false,
false,
null,
$baseUrl
); );
} }
UserManager::removeAllBossFromStudent($studentId); UserManager::removeAllBossFromStudent($studentId);

Loading…
Cancel
Save