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

Fix email subject on invite/add users #446

Merged
merged 1 commit into from
Jan 19, 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
4 changes: 2 additions & 2 deletions controllers/EntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use humhub\modules\calendar\models\forms\CalendarEntryForm;
use humhub\modules\calendar\models\forms\CalendarEntryParticipationForm;
use humhub\modules\calendar\models\participation\CalendarEntryParticipation;
use humhub\modules\calendar\notifications\Invited;
use humhub\modules\calendar\notifications\ParticipantAdded;
use humhub\modules\calendar\widgets\ParticipantItem;
use humhub\modules\content\components\ContentContainerController;
use humhub\modules\content\widgets\richtext\converter\RichTextToPlainTextConverter;
Expand Down Expand Up @@ -418,7 +418,7 @@ private function addParticipants(CalendarEntry $entry, $status): Response
}

if ($isInvitation && count($users)) {
Invited::instance()->from(Yii::$app->user->getIdentity())->about($entry)->sendBulk($users);
ParticipantAdded::instance()->from(Yii::$app->user->getIdentity())->about($entry)->sendBulk($users);
}

$successMessageParams = ['users' => implode(', ', $addedUserNames)];
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

1.5.9 (Unreleased)
------------------------
- Fix #443: Fix email subject on invite/add users

1.5.8 (January 19, 2024)
------------------------
- Fix #437: Hide the profile calendar if the module is not available for users
Expand Down
4 changes: 2 additions & 2 deletions jobs/ForceParticipation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use humhub\modules\calendar\models\CalendarEntry;
use humhub\modules\calendar\models\CalendarEntryParticipant;
use humhub\modules\calendar\models\participation\CalendarEntryParticipation;
use humhub\modules\calendar\notifications\ForceAdd;
use humhub\modules\calendar\notifications\ParticipantAdded;
use humhub\modules\queue\ActiveJob;
use humhub\modules\space\models\Membership;
use humhub\modules\space\models\Space;
Expand Down Expand Up @@ -62,7 +62,7 @@ public function run()
}

if (count($users)) {
ForceAdd::instance()->from($originator)->about($entry)->sendBulk($users);
ParticipantAdded::instance()->from($originator)->about($entry)->sendBulk($users);
}
}
}
4 changes: 2 additions & 2 deletions models/forms/CalendarEntryParticipationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use humhub\modules\calendar\models\CalendarEntryParticipant;
use humhub\modules\calendar\models\participation\CalendarEntryParticipation;
use humhub\modules\calendar\notifications\Invited;
use humhub\modules\calendar\notifications\ParticipantAdded;
use humhub\modules\calendar\widgets\ParticipantItem;
use humhub\modules\user\models\User;
use humhub\modules\content\widgets\richtext\RichText;
Expand Down Expand Up @@ -172,7 +172,7 @@ private function addParticipants(): void
}

if ($this->newParticipantStatus == CalendarEntryParticipant::PARTICIPATION_STATE_INVITED && count($users)) {
Invited::instance()->from(Yii::$app->user->getIdentity())->about($this->entry)->sendBulk($users);
ParticipantAdded::instance()->from(Yii::$app->user->getIdentity())->about($this->entry)->sendBulk($users);
}
}
}
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Calendar",
"description": "Calendar for spaces or user profiles.",
"keywords": ["calendar"],
"version": "1.5.8",
"version": "1.5.9",
"humhub": {
"minVersion": "1.14"
},
Expand Down
85 changes: 0 additions & 85 deletions notifications/Invited.php

This file was deleted.

36 changes: 26 additions & 10 deletions notifications/ForceAdd.php → notifications/ParticipantAdded.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/

namespace humhub\modules\calendar\notifications;

use humhub\libs\Html;
use humhub\modules\calendar\interfaces\participation\CalendarEventParticipationIF;
use humhub\modules\calendar\models\CalendarEntry;
use humhub\modules\notification\components\BaseNotification;
use Yii;
use yii\mail\MessageInterface;

/**
* @var $source CalendarEntry
*/
class ForceAdd extends BaseNotification
class ParticipantAdded extends BaseNotification
{

/**
Expand All @@ -35,6 +32,8 @@ class ForceAdd extends BaseNotification
*/
public $viewName = 'participationInfoNotification';

public ?int $participationStatus = null;

/**
* @inheritdoc
*/
Expand All @@ -48,23 +47,31 @@ public function category()
*/
public function html()
{
return Yii::t('CalendarModule.base', '{displayName} just added you to event "{contentTitle}" in space {spaceName} starting at {time}.', [
$params = [
'displayName' => Html::tag('strong', Html::encode($this->originator->displayName)),
'contentTitle' => $this->getContentInfo($this->source, false),
'spaceName' => Html::encode($this->source->content->container->displayName),
'time' => $this->source->getFormattedTime()
]);
];

return $this->isInvited()
? Yii::t('CalendarModule.base', '{displayName} just invited you to event "{contentTitle}" in space {spaceName} starting at {time}.', $params)
: Yii::t('CalendarModule.base', '{displayName} just added you to event "{contentTitle}" in space {spaceName} starting at {time}.', $params);
}

/**
* @inheritdoc
*/
public function getMailSubject()
{
return Yii::t('CalendarModule.notifications_views_CanceledEvent', '{displayName} just added you to event "{contentTitle}".', [
$params = [
'displayName' => Html::encode($this->originator->displayName),
'contentTitle' => $this->getContentInfo($this->source, false)
]);
];

return $this->isInvited()
? Yii::t('CalendarModule.base', '{displayName} just invited you to event "{contentTitle}".', $params)
: Yii::t('CalendarModule.base', '{displayName} just added you to event "{contentTitle}".', $params);
}

/**
Expand All @@ -83,4 +90,13 @@ public function beforeMailSend(MessageInterface $message)

return true;
}

private function isInvited(): bool
{
if ($this->participationStatus === null) {
$this->participationStatus = (int) $this->source->participation->getParticipationStatus($this->record->user);
}

return $this->participationStatus === CalendarEventParticipationIF::PARTICIPATION_STATUS_INVITED;
}
}