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

New notification when user marks "Attend" and attach ICS files #484

Merged
merged 1 commit into from
Jun 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
38 changes: 21 additions & 17 deletions controllers/EntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +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\MarkAttend;
use humhub\modules\calendar\notifications\ParticipantAdded;
use humhub\modules\calendar\widgets\ParticipantItem;
use humhub\modules\content\components\ContentContainerController;
Expand Down Expand Up @@ -39,7 +40,6 @@
*/
class EntryController extends ContentContainerController
{

/**
* @inheritdoc
*/
Expand All @@ -57,8 +57,8 @@ public function actionView($id, $cal = null)
{
$entry = $this->getCalendarEntry($id);

if (!$entry) {
throw new HttpException('404');
if (!$entry->content->canView()) {
throw new ForbiddenHttpException('You have no permission to view the event!');
}

$this->view->meta->setDescription(RichTextToPlainTextConverter::process($entry->getTitle() . ' - ' . $entry->getDescription()));
Expand Down Expand Up @@ -149,7 +149,7 @@ protected function renderModalParticipation(CalendarEntry $entry, ?string $activ
'update-url' => $this->contentContainer->createUrl('/calendar/entry/update-participant-status'),
'remove-url' => $this->contentContainer->createUrl('/calendar/entry/remove-participant'),
'filter-url' => $this->contentContainer->createUrl('/calendar/entry/participants-list'),
]
],
],
]);
}
Expand All @@ -166,21 +166,25 @@ public function actionRespond($id, $type)
{
$calendarEntry = $this->getCalendarEntry($id);

if (!$calendarEntry) {
throw new HttpException('404');
}

if (!$calendarEntry->canRespond(Yii::$app->user->identity)) {
throw new HttpException(403);
throw new ForbiddenHttpException('You cannot be a participant of the event!');
}

if ($calendarEntry->isPast()) {
throw new HttpException(403, 'Event is over!');
throw new ForbiddenHttpException('Event is over!');
}

return $this->asJson([
'success' => $calendarEntry->setParticipationStatus(Yii::$app->user->identity, (int)$type)
]);
if (!$calendarEntry->setParticipationStatus(Yii::$app->user->identity, (int)$type)) {
throw new ForbiddenHttpException('You cannot be a participant of the event!');
}

if ($type == CalendarEntryParticipation::PARTICIPATION_STATUS_ACCEPTED) {
MarkAttend::instance()->from(Yii::$app->user->identity)
->about($calendarEntry)
->sendBulk([Yii::$app->user->identity]);
}

return $this->asJson(['success' => true]);
}

/**
Expand Down Expand Up @@ -257,7 +261,7 @@ public function actionEdit($id = null, $start = null, $end = null, $cal = null,
return $this->renderAjax('edit', [
'calendarEntryForm' => $calendarEntryForm,
'contentContainer' => $this->contentContainer,
'editUrl' => Url::toEditEntry($calendarEntryForm->entry, $cal, $this->contentContainer, $calendarEntryForm->wall)
'editUrl' => Url::toEditEntry($calendarEntryForm->entry, $cal, $this->contentContainer, $calendarEntryForm->wall),
]);
}

Expand All @@ -282,7 +286,7 @@ public function actionEditParticipation($id = null)
/**
* Action to render modal window with participation settings and active tab "Participants of the event"
*
* @param integer|null $id
* @param int|null $id
* @return string
*/
public function actionModalParticipants($id = null)
Expand All @@ -294,7 +298,7 @@ public function actionModalParticipants($id = null)
* Action to render only participants list
* Used for filtering and pagination
*
* @param integer|null $id
* @param int|null $id
* @return string
*/
public function actionParticipantsList($id = null)
Expand Down Expand Up @@ -565,7 +569,7 @@ protected function getCalendarEntry($id): CalendarEntry
$entry = CalendarEntry::find()->contentContainer($this->contentContainer)->readable()->where(['calendar_entry.id' => $id])->one();

if (!$entry) {
throw new HttpException(404);
throw new NotFoundHttpException();
}

return $entry;
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changelog
- Enh #473: Add footer to global calendar
- Fix #474: Fix checking for past event when it is created from different time zone
- Fix #478: Revert missed controls on space calendar
- Enh #484: New notification when user marks "Attend" and attach ICS files

1.5.10 (March 19, 2024)
-----------------------
Expand Down
51 changes: 51 additions & 0 deletions notifications/BaseEventNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

namespace humhub\modules\calendar\notifications;

use humhub\modules\calendar\models\CalendarEntry;
use humhub\modules\notification\components\BaseNotification;
use yii\mail\MessageInterface;

/* @property CalendarEntry $source */
abstract class BaseEventNotification extends BaseNotification
{
/**
* @inheritdoc
*/
public $moduleId = 'calendar';

/**
* @inheritdoc
*/
public $viewName = 'participationInfoNotification';

/**
* @inheritdoc
*/
public function category()
{
return new CalendarNotificationCategory();
}

/**
* @inheritdoc
*/
public function beforeMailSend(MessageInterface $message)
{
$ics = $this->source->generateIcs();

if (!empty($ics)) {
$message->attachContent($ics, [
'fileName' => $this->source->getUid() . '.ics',
'contentType' => 'text/calendar',
]);
}

return true;
}
}
48 changes: 14 additions & 34 deletions notifications/EventUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
namespace humhub\modules\calendar\notifications;

use humhub\libs\Html;
use humhub\modules\content\notifications\ContentCreatedNotificationCategory;
use humhub\modules\notification\components\BaseNotification;
use humhub\modules\space\models\Space;
use Yii;

Expand All @@ -20,43 +18,25 @@
* Date: 21.07.2017
* Time: 23:12
*/
class EventUpdated extends BaseNotification
class EventUpdated extends BaseEventNotification
{
/**
* @inheritdoc
*/
public $moduleId = 'calendar';

/**
* @inheritdoc
*/
public $viewName = 'participationInfoNotification';

/**
* @inheritdoc
*/
public function category()
{
return new CalendarNotificationCategory();
}

/**
* @inheritdoc
*/
public function html()
{
if($this->source->content->container instanceof Space) {
return Yii::t('CalendarModule.notifications_views_CanceledEvent', '{displayName} just updated event "{contentTitle}" in space {spaceName}.', [
'displayName' => Html::tag('strong', Html::encode($this->originator->displayName)),
'contentTitle' => $this->getContentInfo($this->source, false),
'spaceName' => Html::encode($this->source->content->container->displayName)
]);
} else {
return Yii::t('ContentModule.notifications_views_ContentCreated', '{displayName} just updated event "{contentTitle}".', [
'displayName' => Html::tag('strong', Html::encode($this->originator->displayName)),
'contentTitle' => $this->getContentInfo($this->source, false)
]);
$params = [
'displayName' => Html::tag('strong', Html::encode($this->originator->displayName)),
'contentTitle' => $this->getContentInfo($this->source, false),
];

if ($this->source->content->container instanceof Space) {
return Yii::t('CalendarModule.notifications_views_CanceledEvent', '{displayName} just updated event "{contentTitle}" in space {spaceName}.', array_merge([
'spaceName' => Html::encode($this->source->content->container->displayName),
]));
}

return Yii::t('ContentModule.notifications_views_ContentCreated', '{displayName} just updated event "{contentTitle}".', $params);
}

/**
Expand All @@ -66,7 +46,7 @@ public function getMailSubject()
{
return Yii::t('CalendarModule.notifications_views_CanceledEvent', '{displayName} just updated event {contentTitle}.', [
'displayName' => Html::encode($this->originator->displayName),
'contentTitle' => $this->getContentInfo($this->source, false)
'contentTitle' => $this->getContentInfo($this->source, false),
]);
}
}
}
51 changes: 51 additions & 0 deletions notifications/MarkAttend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* @link https://www.humhub.org/
* @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\space\models\Space;
use Yii;

class MarkAttend extends BaseEventNotification
{
public ?int $participationStatus = null;

/**
* @inheritdoc
*/
public $suppressSendToOriginator = false;

/**
* @inheritdoc
*/
public function html()
{
$params = [
'contentTitle' => $this->getContentInfo($this->source, false),
'time' => $this->source->getFormattedTime(),
];

if ($this->source->content->container instanceof Space) {
return Yii::t('CalendarModule.base', 'You have been registered for the event "{contentTitle}" in {spaceName}, starting at {time}', array_merge($params, [
'spaceName' => Html::encode($this->source->content->container->displayName),
]));
}

return Yii::t('CalendarModule.base', 'You have been registered for the event "{contentTitle}", starting at {time}.', $params);
}

/**
* @inheritdoc
*/
public function getMailSubject()
{
return Yii::t('CalendarModule.base', 'You have been registered for the event "{contentTitle}".', [
'contentTitle' => $this->getContentInfo($this->source, false),
]);
}
}
50 changes: 3 additions & 47 deletions notifications/ParticipantAdded.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,12 @@

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;

class ParticipantAdded extends BaseNotification
class ParticipantAdded extends BaseEventNotification
{

/**
* @var CalendarEntry
*/
public $source;

/**
* @inheritdoc
*/
public $moduleId = 'calendar';

/**
* @inheritdoc
*/
public $viewName = 'participationInfoNotification';

public ?int $participationStatus = null;

/**
* @inheritdoc
*/
public function category()
{
return new CalendarNotificationCategory();
}

/**
* @inheritdoc
*/
Expand All @@ -51,7 +24,7 @@ public function html()
'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()
'time' => $this->source->getFormattedTime(),
];

return $this->isInvited()
Expand All @@ -66,31 +39,14 @@ public function getMailSubject()
{
$params = [
'displayName' => Html::encode($this->originator->displayName),
'contentTitle' => $this->getContentInfo($this->source, false)
'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);
}

/**
* @inheritdoc
*/
public function beforeMailSend(MessageInterface $message)
{
$ics = $this->source->generateIcs();

if (!empty($ics)) {
$message->attachContent($ics, [
'fileName' => $this->source->getUid() . '.ics',
'contentType' => 'text/calendar'
]);
}

return true;
}

private function isInvited(): bool
{
if ($this->participationStatus === null) {
Expand Down
Loading
Loading