diff --git a/controllers/EntryController.php b/controllers/EntryController.php index fdd8e244..5ffd61db 100644 --- a/controllers/EntryController.php +++ b/controllers/EntryController.php @@ -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; @@ -39,7 +40,6 @@ */ class EntryController extends ContentContainerController { - /** * @inheritdoc */ @@ -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())); @@ -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'), - ] + ], ], ]); } @@ -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]); } /** @@ -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), ]); } @@ -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) @@ -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) @@ -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; diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 9742a008..b8a2e1f8 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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) ----------------------- diff --git a/notifications/BaseEventNotification.php b/notifications/BaseEventNotification.php new file mode 100644 index 00000000..393cc1e9 --- /dev/null +++ b/notifications/BaseEventNotification.php @@ -0,0 +1,51 @@ +source->generateIcs(); + + if (!empty($ics)) { + $message->attachContent($ics, [ + 'fileName' => $this->source->getUid() . '.ics', + 'contentType' => 'text/calendar', + ]); + } + + return true; + } +} diff --git a/notifications/EventUpdated.php b/notifications/EventUpdated.php index fa40df4f..fea126d7 100644 --- a/notifications/EventUpdated.php +++ b/notifications/EventUpdated.php @@ -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; @@ -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); } /** @@ -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), ]); } -} \ No newline at end of file +} diff --git a/notifications/MarkAttend.php b/notifications/MarkAttend.php new file mode 100644 index 00000000..576eedc5 --- /dev/null +++ b/notifications/MarkAttend.php @@ -0,0 +1,51 @@ + $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), + ]); + } +} diff --git a/notifications/ParticipantAdded.php b/notifications/ParticipantAdded.php index 1aa03c26..d06b56e3 100644 --- a/notifications/ParticipantAdded.php +++ b/notifications/ParticipantAdded.php @@ -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 */ @@ -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() @@ -66,7 +39,7 @@ 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() @@ -74,23 +47,6 @@ public function getMailSubject() : 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) { diff --git a/notifications/ReopenedEvent.php b/notifications/ReopenedEvent.php index 3bc40a6e..95db1b06 100644 --- a/notifications/ReopenedEvent.php +++ b/notifications/ReopenedEvent.php @@ -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; @@ -20,43 +18,30 @@ * Date: 21.07.2017 * Time: 23:12 */ -class ReopenedEvent extends BaseNotification +class ReopenedEvent extends BaseEventNotification { - /** - * @inheritdoc - */ - public $moduleId = 'calendar'; - /** * @inheritdoc */ public $viewName = 'calendarNotification'; - /** - * @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} reopened 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} reopened 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} reopened event "{contentTitle}" in space {spaceName}.', array_merge([ + 'spaceName' => Html::encode($this->source->content->container->displayName), + ])); } + + return Yii::t('ContentModule.notifications_views_ContentCreated', '{displayName} reopened event "{contentTitle}".', $params); } /** @@ -66,7 +51,7 @@ public function getMailSubject() { return Yii::t('CalendarModule.notifications_views_CanceledEvent', '{displayName} reopened event "{contentTitle}".', [ 'displayName' => Html::encode($this->originator->displayName), - 'contentTitle' => $this->getContentInfo($this->source, false) + 'contentTitle' => $this->getContentInfo($this->source, false), ]); } -} \ No newline at end of file +}