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

pull/5896/head
christianbeeznst 3 weeks 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,
$checkCurrentAudioId = false,
$forceTitleWhenSendingEmail = false,
$msgType = null
$msgType = null,
$baseUrl = null
) {
$group_id = (int) $group_id;
$receiverUserId = (int) $receiverUserId;
@ -374,7 +375,8 @@ class MessageManager
$content,
$sender_info,
$attachmentAddedByMail,
$forceTitleWhenSendingEmail
$forceTitleWhenSendingEmail,
$baseUrl
);
} else {
$usergroup = new UserGroupModel();

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

@ -18,6 +18,8 @@
die('Remove the "die()" statement on line '.__LINE__.' to execute this script'.PHP_EOL);
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');
if (empty($senderId)) {
@ -98,7 +100,13 @@ foreach ($students as $student) {
0,
0,
0,
$senderId
$senderId,
false,
0,
false,
false,
null,
$baseUrl
);
UserManager::disable($studentId);
}
@ -157,7 +165,13 @@ foreach ($students as $student) {
0,
0,
0,
$senderId
$senderId,
false,
0,
false,
false,
null,
$baseUrl
);
UserManager::disable($studentId);
}
@ -223,7 +237,13 @@ foreach ($students as $student) {
0,
0,
0,
$senderId
$senderId,
false,
0,
false,
false,
null,
$baseUrl
);
UserManager::disable($studentId);
if (!empty($bossInfo) && !empty($subjectBoss)) {
@ -237,7 +257,13 @@ foreach ($students as $student) {
0,
0,
0,
$senderId
$senderId,
false,
0,
false,
false,
null,
$baseUrl
);
}
UserManager::removeAllBossFromStudent($studentId);

Loading…
Cancel
Save