From 161312ea0cd336e68a16cea2fbe4b9d49d2f1583 Mon Sep 17 00:00:00 2001 From: buddh4 Date: Sun, 22 Jan 2017 00:08:20 +0100 Subject: [PATCH] Notification Mails/Rendering --- img/mail_ico_check.png | Bin 0 -> 3559 bytes img/mail_ico_not.png | Bin 0 -> 3039 bytes .../humhub/components/SocialActivity.php | 54 +++++++- .../components/queue/driver/Instant.php | 45 +++++++ .../rendering/DefaultViewPathRenderer.php | 66 ++++++++++ .../components/rendering/LayoutRenderer.php | 19 ++- .../rendering/MailLayoutRenderer.php | 19 ++- .../components/rendering/MailRenderer.php | 50 ++++++++ .../humhub/components/rendering/Renderer.php | 5 + .../components/rendering/ViewPathRenderer.php | 70 ++++++++-- .../humhub/docs/guide/dev-notifications.md | 53 ++------ ...lRenderer.php => ActivityMailRenderer.php} | 6 +- ...ebRenderer.php => ActivityWebRenderer.php} | 30 +++-- .../activity/components/MailSummary.php | 2 +- .../modules/activity/models/Activity.php | 6 +- .../_support/_generated/UnitTesterActions.php | 2 +- .../modules/activity/views/activityEntry.php | 5 + .../mail_plaintext.php} | 0 .../modules/activity/views/layouts/web.php | 8 +- .../activity/views/mails/activityLayout.php | 121 ------------------ .../activity/views/mails/mailSummary.php | 4 +- .../views/mails/plaintext/mailSummary.php | 6 +- .../modules/comment/activities/NewComment.php | 7 + .../comment/controllers/CommentController.php | 6 +- .../humhub/modules/comment/models/Comment.php | 34 ++++- .../comment/notifications/NewComment.php | 104 +++++++++++++-- .../notifications/views/mails/newComment.php | 68 ++++++++++ .../_support/_generated/UnitTesterActions.php | 2 +- .../tests/codeception/unit/CommentTest.php | 1 - .../components/ContentActiveRecord.php | 9 +- .../components/ContentContainerController.php | 2 +- .../content/notifications/ContentCreated.php | 77 ++++++++--- .../views/mails/contentCreated.php | 24 ++++ .../_support/_generated/UnitTesterActions.php | 2 +- .../codeception/unit/ContentCreatedTest.php | 15 --- .../codeception/unit/models/TestContent.php | 50 -------- .../content/views/mails/plaintext/Update.php | 12 -- .../components/BaseNotification.php | 76 ++++------- .../components/MailNotificationTarget.php | 50 ++++---- .../components/MailTargetRenderer.php | 104 ++------------- .../components/NotificationTarget.php | 7 - .../components/WebTargetRenderer.php | 83 +----------- .../jobs/SendBulkNotification.php | 42 ++++++ .../notification/jobs/SendNotification.php | 40 ++++++ .../_support/_generated/UnitTesterActions.php | 2 +- .../unit/rendering/MailTargetRenderTest.php | 17 +-- .../unit/rendering/WebTargetRenderTest.php | 11 -- .../notifications/views/mail/special.php | 2 - .../notifications/views/mails/special.php | 4 + .../rendering/notifications/views/special.php | 2 + .../modules/notification/views/default.php | 3 + .../notification/views/layouts/mail.php | 60 +-------- .../views/layouts/mail_plaintext.php | 6 +- .../views/mails/Update.php | 19 +-- .../notification/views/mails/default.php | 3 + .../views/mails/plaintext/Update.php | 4 + .../views/mails/plaintext/default.php | 3 + .../views/notification/default.php | 1 - .../views/notification/mail/default.php | 1 - .../notification/mail/plaintext/default.php | 1 - .../widgets/MailContentContainerImage.php | 44 +++++++ .../widgets/MailContentContainerInfoBox.php | 44 +++++++ .../notification/widgets/MailContentEntry.php | 82 ++++++++++++ .../modules/notification/widgets/Overview.php | 9 +- .../widgets/views/contentContainerInfoBox.php | 36 ++++++ .../views/mailContentContainerImage.php | 20 +++ .../widgets/views/mailContentEntry.php | 75 +++++++++++ .../modules/space/notifications/Invite.php | 28 +++- .../space/notifications/InviteAccepted.php | 20 ++- .../space/notifications/InviteDeclined.php | 29 ++++- .../notifications/views/mails/invite.php | 41 ++++++ .../views/mails/inviteAccepted.php | 51 ++++++++ .../views/mails/inviteDeclined.php | 51 ++++++++ .../_support/_generated/UnitTesterActions.php | 2 +- .../{ApprovalTest.php => MembershipTest.php} | 22 +++- .../codeception/unit/SpaceFollowTest.php | 47 +++++++ .../space/widgets/HeaderControlsMenu.php | 4 +- protected/humhub/modules/user/models/User.php | 12 ++ .../modules/user/notifications/Followed.php | 19 ++- .../modules/user/notifications/Mentioned.php | 29 +++++ .../notifications/views/mails/followed.php | 32 +++++ .../notifications/views/mails/mentioned.php | 24 ++++ .../views/mails/mentionedComment.php | 57 +++++++++ .../_support/_generated/UnitTesterActions.php | 2 +- .../tests/codeception/unit/FollowTest.php | 2 +- .../tests/codeception/unit/MentionTest.php | 22 +++- .../_support/_generated/UnitTesterActions.php | 2 +- .../rendering/DefaultViewPathRendererTest.php | 53 ++++++++ .../rendering/LayoutRendererTest.php | 28 ++++ .../rendering/MailLayoutRendererTest.php | 41 ++++++ .../components/rendering/MailRendererTest.php | 42 ++++++ .../rendering/ViewPathRendererTest.php | 62 +++++++++ .../components/rendering/lib/TestViewable.php | 39 ++++++ .../rendering/lib/views/specialView.php | 4 + .../rendering/lib/views/testView.php | 4 + .../components/rendering/lib/views2/view2.php | 4 + .../rendering/views/layouts/testLayout.php | 3 + .../components/rendering/views/mails/mail.php | 4 + .../views/mails/plaintext/testView.php | 4 + .../components/rendering/views/parent.php | 4 + .../components/rendering/views/parent2.php | 4 + protected/humhub/tests/config/common.php | 30 +++-- .../css/{theme.less => theme.deprecated.less} | 0 103 files changed, 1935 insertions(+), 722 deletions(-) create mode 100644 img/mail_ico_check.png create mode 100644 img/mail_ico_not.png create mode 100644 protected/humhub/components/queue/driver/Instant.php create mode 100644 protected/humhub/components/rendering/DefaultViewPathRenderer.php create mode 100644 protected/humhub/components/rendering/MailRenderer.php rename protected/humhub/modules/activity/components/{MailRenderer.php => ActivityMailRenderer.php} (67%) rename protected/humhub/modules/activity/components/{WebRenderer.php => ActivityWebRenderer.php} (69%) create mode 100644 protected/humhub/modules/activity/views/activityEntry.php rename protected/humhub/modules/activity/views/{mails/plaintext/activityLayout.php => layouts/mail_plaintext.php} (100%) delete mode 100644 protected/humhub/modules/activity/views/mails/activityLayout.php create mode 100644 protected/humhub/modules/comment/notifications/views/mails/newComment.php create mode 100644 protected/humhub/modules/content/notifications/views/mails/contentCreated.php delete mode 100644 protected/humhub/modules/content/tests/codeception/unit/models/TestContent.php delete mode 100644 protected/humhub/modules/content/views/mails/plaintext/Update.php create mode 100644 protected/humhub/modules/notification/jobs/SendBulkNotification.php create mode 100644 protected/humhub/modules/notification/jobs/SendNotification.php delete mode 100644 protected/humhub/modules/notification/tests/codeception/unit/rendering/notifications/views/mail/special.php create mode 100644 protected/humhub/modules/notification/tests/codeception/unit/rendering/notifications/views/mails/special.php create mode 100644 protected/humhub/modules/notification/views/default.php rename protected/humhub/modules/{content => notification}/views/mails/Update.php (93%) create mode 100644 protected/humhub/modules/notification/views/mails/default.php create mode 100644 protected/humhub/modules/notification/views/mails/plaintext/Update.php create mode 100644 protected/humhub/modules/notification/views/mails/plaintext/default.php delete mode 100644 protected/humhub/modules/notification/views/notification/default.php delete mode 100644 protected/humhub/modules/notification/views/notification/mail/default.php delete mode 100644 protected/humhub/modules/notification/views/notification/mail/plaintext/default.php create mode 100644 protected/humhub/modules/notification/widgets/MailContentContainerImage.php create mode 100644 protected/humhub/modules/notification/widgets/MailContentContainerInfoBox.php create mode 100644 protected/humhub/modules/notification/widgets/MailContentEntry.php create mode 100644 protected/humhub/modules/notification/widgets/views/contentContainerInfoBox.php create mode 100644 protected/humhub/modules/notification/widgets/views/mailContentContainerImage.php create mode 100644 protected/humhub/modules/notification/widgets/views/mailContentEntry.php create mode 100644 protected/humhub/modules/space/notifications/views/mails/invite.php create mode 100644 protected/humhub/modules/space/notifications/views/mails/inviteAccepted.php create mode 100644 protected/humhub/modules/space/notifications/views/mails/inviteDeclined.php rename protected/humhub/modules/space/tests/codeception/unit/{ApprovalTest.php => MembershipTest.php} (74%) create mode 100644 protected/humhub/modules/space/tests/codeception/unit/SpaceFollowTest.php create mode 100644 protected/humhub/modules/user/notifications/views/mails/followed.php create mode 100644 protected/humhub/modules/user/notifications/views/mails/mentioned.php create mode 100644 protected/humhub/modules/user/notifications/views/mails/mentionedComment.php create mode 100644 protected/humhub/tests/codeception/unit/components/rendering/DefaultViewPathRendererTest.php create mode 100644 protected/humhub/tests/codeception/unit/components/rendering/LayoutRendererTest.php create mode 100644 protected/humhub/tests/codeception/unit/components/rendering/MailLayoutRendererTest.php create mode 100644 protected/humhub/tests/codeception/unit/components/rendering/MailRendererTest.php create mode 100644 protected/humhub/tests/codeception/unit/components/rendering/ViewPathRendererTest.php create mode 100644 protected/humhub/tests/codeception/unit/components/rendering/lib/TestViewable.php create mode 100644 protected/humhub/tests/codeception/unit/components/rendering/lib/views/specialView.php create mode 100644 protected/humhub/tests/codeception/unit/components/rendering/lib/views/testView.php create mode 100644 protected/humhub/tests/codeception/unit/components/rendering/lib/views2/view2.php create mode 100644 protected/humhub/tests/codeception/unit/components/rendering/views/layouts/testLayout.php create mode 100644 protected/humhub/tests/codeception/unit/components/rendering/views/mails/mail.php create mode 100644 protected/humhub/tests/codeception/unit/components/rendering/views/mails/plaintext/testView.php create mode 100644 protected/humhub/tests/codeception/unit/components/rendering/views/parent.php create mode 100644 protected/humhub/tests/codeception/unit/components/rendering/views/parent2.php rename themes/HumHub/css/{theme.less => theme.deprecated.less} (100%) mode change 100755 => 100644 diff --git a/img/mail_ico_check.png b/img/mail_ico_check.png new file mode 100644 index 0000000000000000000000000000000000000000..9aa9dae51071f7723d6bab2ab3d94ca2ef9f8e39 GIT binary patch literal 3559 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 literal 0 HcmV?d00001 diff --git a/img/mail_ico_not.png b/img/mail_ico_not.png new file mode 100644 index 0000000000000000000000000000000000000000..9cd9c37ae9460271018ce803d33095fecfdaf526 GIT binary patch literal 3039 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 $this->className(), @@ -288,15 +290,61 @@ abstract class SocialActivity extends \yii\base\Object implements rendering\View * * This is a combination a the type of the content with a short preview * of it. + * + * If no $content is provided the contentInfo of $source is returned. * * @param Content $content * @return string */ - public function getContentInfo(ContentOwner $content) - { + public function getContentInfo(ContentOwner $content = null) + { + if(!$this->hasContent() && !$content) { + return; + }else if(!$content) { + $content = $this->source; + } + return Html::encode($content->getContentName()) . ' "' . RichText::widget(['text' => $content->getContentDescription(), 'minimal' => true, 'maxLength' => 60]) . '"'; } + + /** + * Returns the content name of $content or if not $content is provided of the + * notification source. + * + * @param ContentOwner $content + * @return type + */ + public function getContentName(ContentOwner $content = null) + { + if(!$this->hasContent() && !$content) { + return; + }else if(!$content) { + $content = $this->source; + } + + return $content->getContentName(); + } + + /** + * Returns a short preview text of the content. The max length can be defined by setting + * $maxLength (25 by default). + * + * If no $content is provided the contentPreview of $source is returned. + * + * @param Content $content + * @return string + */ + public function getContentPreview(ContentOwner $content = null, $maxLength = 25) + { + if(!$this->hasContent() && !$content) { + return; + } else if(!$content) { + $content = $this->source; + } + + return RichText::widget(['text' => $content->getContentDescription(), 'minimal' => true, 'maxLength' => $maxLength]); + } } diff --git a/protected/humhub/components/queue/driver/Instant.php b/protected/humhub/components/queue/driver/Instant.php new file mode 100644 index 0000000000..137fbf28c3 --- /dev/null +++ b/protected/humhub/components/queue/driver/Instant.php @@ -0,0 +1,45 @@ +_messages[] = $this->serialize($job); + + while (($message = array_shift($this->_messages)) !== null) { + $job = $this->unserialize($message); + $this->getQueue()->run($job); + } + } + +} diff --git a/protected/humhub/components/rendering/DefaultViewPathRenderer.php b/protected/humhub/components/rendering/DefaultViewPathRenderer.php new file mode 100644 index 0000000000..650d79cad9 --- /dev/null +++ b/protected/humhub/components/rendering/DefaultViewPathRenderer.php @@ -0,0 +1,66 @@ +defaultViewPath) { + $viewFile = Yii::getAlias($this->defaultViewPath) . '/' . $this->suffix($viewable->getViewName()); + } + + if (!file_exists($viewFile) && $this->defaultView) { + $viewFile = Yii::getAlias($this->defaultView); + } + + return $viewFile; + } +} diff --git a/protected/humhub/components/rendering/LayoutRenderer.php b/protected/humhub/components/rendering/LayoutRenderer.php index 2a9ed80387..b0c15f485a 100644 --- a/protected/humhub/components/rendering/LayoutRenderer.php +++ b/protected/humhub/components/rendering/LayoutRenderer.php @@ -20,6 +20,7 @@ use Yii; * '@myModule/views/layouts/myLayout.php' * * @author buddha + * @since 1.2 */ class LayoutRenderer extends ViewPathRenderer { @@ -30,20 +31,25 @@ class LayoutRenderer extends ViewPathRenderer public $layout; /** - * @inheritdoc + * If a $layout is given the result will embed the rendered viewFile into the + * given $layout. + * + * @param \humhub\components\rendering\Viewable $viewable + * @param type $params + * @return string */ public function render(Viewable $viewable, $params = []) { - // Render the view itself $viewParams = $viewable->getViewParams($params); + // Render the viewFile if(!isset($viewParams['content'])) { $viewParams['content'] = parent::renderView($viewable, $viewParams); } + // Embed content in layout if valid layout is given. $layout = $this->getLayout($viewable); - // Embed view into layout if provided if ($layout) { return Yii::$app->getView()->renderFile($layout, $viewParams, $viewable); } else { @@ -51,6 +57,13 @@ class LayoutRenderer extends ViewPathRenderer } } + /** + * Returns the layout file path. + * Subclasses may use the $viewable to determine the layout path. + * + * @param \humhub\components\rendering\Viewable $viewable + * @return string + */ protected function getLayout(Viewable $viewable) { return $this->layout; diff --git a/protected/humhub/components/rendering/MailLayoutRenderer.php b/protected/humhub/components/rendering/MailLayoutRenderer.php index 099e109428..9be402bed4 100644 --- a/protected/humhub/components/rendering/MailLayoutRenderer.php +++ b/protected/humhub/components/rendering/MailLayoutRenderer.php @@ -2,19 +2,19 @@ namespace humhub\components\rendering; -use Yii; - /** - * Description of MailLayoutRenderer + * MailLayoutRenderer extends the LayoutRenderer with a renderText function. * * @author buddha + * @since 1.2 */ class MailLayoutRenderer extends LayoutRenderer { + + public $subPath = 'mails'; /** - * Layout for text rendering. - * @var type + * @var string Layout file path */ public $textLayout; @@ -28,14 +28,23 @@ class MailLayoutRenderer extends LayoutRenderer public function renderText(Viewable $viewable, $params = []) { $textRenderer = new LayoutRenderer([ + 'subPath' => 'mails/plaintext', + 'parent' => $this->parent, 'layout' => $this->getTextLayout($viewable) ]); + // exclude the view only embed the viewable text to the textlayout. $params['content'] = $viewable->text(); return strip_tags($textRenderer->render($viewable, $params)); } + /** + * Returns the $textLayout for the given $viewable. + * + * @param \humhub\components\rendering\Viewable $viewable + * @return type + */ public function getTextLayout(Viewable $viewable) { return $this->textLayout; diff --git a/protected/humhub/components/rendering/MailRenderer.php b/protected/humhub/components/rendering/MailRenderer.php new file mode 100644 index 0000000000..5f7d86e470 --- /dev/null +++ b/protected/humhub/components/rendering/MailRenderer.php @@ -0,0 +1,50 @@ + 'mails/plaintext', + 'parent' => $this->parent, + 'defaultView' => $this->defaultTextView, + 'defaultViewPath' => $this->defaultTextViewPath, + ]); + + return strip_tags($textRenderer->render($viewable, $params)); + } +} diff --git a/protected/humhub/components/rendering/Renderer.php b/protected/humhub/components/rendering/Renderer.php index e6c02649ab..6ff9cb4eb3 100644 --- a/protected/humhub/components/rendering/Renderer.php +++ b/protected/humhub/components/rendering/Renderer.php @@ -8,6 +8,7 @@ namespace humhub\components\rendering; * by converting it's data into a specific format. * * @author buddha + * @since 1.2 */ interface Renderer { @@ -18,6 +19,10 @@ interface Renderer * forward the given $params to $viewable->getViewParams($params). By doing so, the * $params can be used to overwrite the default view parameter of $viewable. * + * It is upon the renderer implementation to handle non existing views. + * They could throw a yii\base\ViewNotFoundException, or provide a + * default view. + * * @param \humhub\components\rendering\Viewable $viewable * @param type $params */ diff --git a/protected/humhub/components/rendering/ViewPathRenderer.php b/protected/humhub/components/rendering/ViewPathRenderer.php index 285c79c01d..c6e36fad80 100644 --- a/protected/humhub/components/rendering/ViewPathRenderer.php +++ b/protected/humhub/components/rendering/ViewPathRenderer.php @@ -5,17 +5,44 @@ namespace humhub\components\rendering; use Yii; /** - * A ViewPathRenderer is a simple Renderer implementation for rendering Viewable - * instances by searching for the Viewable viewName within the given $viewPath. + * A ViewPathRenderer is a simple Renderer implementation for rendering Viewables by searching for a matching viewFile relative + * to the Viewables class path or relative to a given $viewPath. * - * If no $viewPath is given, we'll determine the view path of the viewable as following: + * If a $viewPath is given the renderer will search for the view within this path directly. * - * ViewableClassPath/../views + * If no $viewPath is given, the ViewPathRenderer will determine the view path relative to the Viewable as following: + * + * - In case $parent = false the renderer will search directly in the class path subdirectory views: + * + * `viewableClassPath/views` + * + * - in case $parent = true the renderer will search in the parents views folder (e.g. in the modules main view folder): + * + * `viewableClassPath/../views` + * + * - in case $subPath is given the subPath will be appended to the view path e.g: + * + * For a subPath 'mail' and $parent = false the search path will be: `viewableClassPath/views/mail` * * @author buddha + * @since 1.2 */ class ViewPathRenderer extends \yii\base\Object implements Renderer { + + /** + * Can be used to search the parent's view folder (e.g. the modules base view folder) for the view file. + * Otherwise this renderer searches for a direct views subdirectory. + * + * This field is ignored if $viewPath is given. + * @var boolean if set to true the renderer will search in the parents view directory for the view. + */ + public $parent = false; + + /** + * @var string a subpath within the view folder used for searching the view e.g mails. This will only be used if $viewPath is not given. + */ + public $subPath; /** * @var string view path @@ -28,7 +55,8 @@ class ViewPathRenderer extends \yii\base\Object implements Renderer * If no viewPath is given this function uses '../views/viewName' as view file path. * * @param \humhub\components\rendering\Viewable $viewable - * @return type + * @return string + * @throws ViewNotFoundException if the view file does not exist */ public function render(Viewable $viewable, $params = []) { @@ -56,8 +84,26 @@ class ViewPathRenderer extends \yii\base\Object implements Renderer */ public function getViewFile(Viewable $viewable) { - return $this->getViewPath($viewable) . '/' . $viewable->getViewName(); + return $this->getViewPath($viewable) . '/' . $this->suffix($viewable->getViewName()); } + + /** + * Checks if the given $viewName has a file suffix or not. + * If the viewName does not have a suffix we assume a php file and append '.php'. + * + * @param string $viewName + * @return string vieName with suffix. + */ + protected function suffix($viewName) + { + // If no suffix is given, we assume a php file. + if (!strpos($viewName, '.')) { + return $viewName . '.php'; + } else { + return $viewName; + } + } + /** * Returns the directory containing the view files for this event. @@ -66,12 +112,20 @@ class ViewPathRenderer extends \yii\base\Object implements Renderer */ public function getViewPath(Viewable $viewable) { - if ($this->viewPath !== null) { + if ($this->viewPath) { return Yii::getAlias($this->viewPath); } $class = new \ReflectionClass($viewable); - return dirname($class->getFileName()) . DIRECTORY_SEPARATOR . 'views'; + + $dir = ($this->parent) ? dirname(dirname($class->getFileName())) . '/' . 'views' + : dirname($class->getFileName()) . '/' . 'views'; + + if(!empty($this->subPath)) { + $dir .= '/' . $this->subPath; + } + + return $dir; } } diff --git a/protected/humhub/docs/guide/dev-notifications.md b/protected/humhub/docs/guide/dev-notifications.md index ef61bfc2f6..96296f45ab 100644 --- a/protected/humhub/docs/guide/dev-notifications.md +++ b/protected/humhub/docs/guide/dev-notifications.md @@ -1,18 +1,15 @@ Notifications ============= -Notifications are used to inform one or a given set of users about a specific event, as the liking of a post or mentioning of a user, over multiple channels (e.g. web and mail). +Notifications are used to inform one or a given set of users about a specific event in your network as the liking of a post or mentioning of a user over multiple channels (e.g. web and mail). -Custom notification types are derived from [[humhub\modules\notification\components\BaseNotification]] and can be assigned with an optional `$originator` user instance, which links -the notification to the user who triggered the event. Furthermore the [[humhub\modules\notification\components\BaseNotification|BaseNotification]] can be assigned with a `$source` attribute of type [[yii\db\ActiveRecord]], -which links the notification to a source instance like a Content or ContentAddon (e.g. a Post or Like). +Custom notification classes are derived from [[humhub\modules\notification\components\BaseNotification]]. +A [[humhub\modules\notification\components\BaseNotification|BaseNotification]] usually is assigned with an +`$originator` user instance and a `$source` instance, which connects the Notification with a Content or any other kind of [[yii\db\ActiveRecord]]. -The BaseNotification is responsible for: +A Notification can be sent to a user by calling the `send()` or `sendBulk()` function. This will persist an [[humhub\modules\notification\models\Notification]] instance for each user send out a notification to all allowed NotificationTargets. - - **instantiating** and **persisting** [[humhub\modules\notification\models\Notification]] model instances. - - **rendering** the notification output for the differen output channels. - -![Notification Class Diagram](images/notificationClassDiag.jpg) +> Note: Unlike Activities which are targeted for multiple users e.g. all Users of a Space, a Notification Model instance is always related to a single user. Examples for core notifications are: @@ -26,7 +23,8 @@ Examples for core notifications are: #### Notification Class Custom Notifications are derived from [[humhub\modules\notification\components\BaseNotification|BaseNotification]] and should reside in the `notifications` subfolder of your module's root directory. -The notification class at least has to overwrite the `$moduleId` variable with the id of your module and the `$viewName` with the name of the view which is used to render the notification. + +The notification class at least has to overwrite the `$moduleId` variable with the id of your module and the. ```php ``` #### Notification View By default, the view of a notification should be located inside the subfolder `notifications/views`. -The view of our example is therefore located in `/modules/examples/notifications/views/somethingHappened.php`. +The view of the example above should therefore be located in `/modules/examples/notifications/views/somethingHappened.php`. ```php '' . Html::encode($originator->displayName) . '' ]); -?> ``` > Info: If you require a different notification view for mails, you have to add an extra view file to a subfolder `notifications/views/mail`. @@ -75,36 +71,15 @@ After an event was triggered, you'll have to instantiate your custom [[humhub\mo A notification can optionally be assigned with a `$source` model instance (e.g. a post or comment related to the notification) which has to be derived from [[yii\db\ActiveRecord]]. ```php -$notification = new \johndoe\example\notifications\SomethingHappend(); +// Sending to a single user +\johndoe\example\notifications\SomethingHappend::instance()->from($user)->about($source)->send($targetUser); -// Link to the object which fired the notification e.g. a SomethingHappened content-addon (optional) -$notification->source = $this; - -// The user which triggered the notification (optional) -$notification->originator = $this->user; - -// Send it to a set of users -$notification->sendBulk(User::find()->where([...])); - -// or: a single user -$notification->send($user); +// Sending to multiple users +\johndoe\example\notifications\SomethingHappend::instance()->from($user)->about($source)->sendBulk($users); ``` -> Info: If the notification was created in the context of a space (e.g. `$source` is a Content, ContentAddon or ContentContainer) the `$space` variable is set with the corresponding space instance automatically. > Info: The `send` and `sendBulk` will create and persist a [[humhub\modules\notification\models\Notification]] instance for each user. > Tip: Notifications are often created and sent within the `afterSave` hook of the related `source` instance. This should be prefered over the instantiation within a controller. -> Note: Notifications are only sent by mail depending on the user's account settings. - -## Delete Notifications - -By default notifications will automatically be deleted after a given period of time or if the originator(user) object is removed. - -Example for manual notification deletion: - -```php -$notification = new johndoe\example\notifications\SomethingHappend(); -$notification->source = $this; -$notification->delete(User::findOne(['id' => $userId])); -``` \ No newline at end of file +> Note: Notifications are only sent to a specific NotificationTarget depending on the user's account settings. \ No newline at end of file diff --git a/protected/humhub/modules/activity/components/MailRenderer.php b/protected/humhub/modules/activity/components/ActivityMailRenderer.php similarity index 67% rename from protected/humhub/modules/activity/components/MailRenderer.php rename to protected/humhub/modules/activity/components/ActivityMailRenderer.php index b91fcaad7c..933b48c6f0 100644 --- a/protected/humhub/modules/activity/components/MailRenderer.php +++ b/protected/humhub/modules/activity/components/ActivityMailRenderer.php @@ -16,17 +16,17 @@ use humhub\components\rendering\MailLayoutRenderer; * @since 1.2 * @author buddha */ -class MailRenderer extends MailLayoutRenderer +class ActivityMailRenderer extends MailLayoutRenderer { /** * @inheritdoc */ - public $layout = '@activity/views/mails/activityLayout.php'; + public $layout = '@activity/views/layouts/mail.php'; /** * @inheritdoc */ - public $textLayout = "@activity/views/mails/plaintext/activityLayout.php"; + public $textLayout = '@activity/views/layouts/mail_plaintext.php'; } diff --git a/protected/humhub/modules/activity/components/WebRenderer.php b/protected/humhub/modules/activity/components/ActivityWebRenderer.php similarity index 69% rename from protected/humhub/modules/activity/components/WebRenderer.php rename to protected/humhub/modules/activity/components/ActivityWebRenderer.php index 203b8046e0..dff674e1ac 100644 --- a/protected/humhub/modules/activity/components/WebRenderer.php +++ b/protected/humhub/modules/activity/components/ActivityWebRenderer.php @@ -12,20 +12,21 @@ use Yii; use humhub\components\rendering\Viewable; /** - * The WebTargetRenderer is used to render Notifications for the WebNotificationTarget. + * The ActivityWebRenderer is used to render BaseActivity instances for the Activity Stream. * - * A BaseNotification can overwrite the default view and layout by setting a specific $viewName and + * A BaseActivity can overwrite the default view and layout by setting a specific $viewName and * defining the following files: * - * Overwrite default view for this notification: - * @module/views/notification/viewname.php + * Overwrite default view for this Activity: + * @module/activities/views/[viewname].php * - * Overwrite default layout for this notification: - * @module/views/layouts/notification/viewname.php + * Overwrite default layout for this Activity: + * @module/activities/views/layout/[viewname].php * * @author buddha + * @since 1.2 */ -class WebRenderer extends \humhub\components\rendering\LayoutRenderer +class ActivityWebRenderer extends \humhub\components\rendering\LayoutRenderer { /** @@ -36,7 +37,7 @@ class WebRenderer extends \humhub\components\rendering\LayoutRenderer /** * @var string default layout */ - public $defaultLayout = '@humhub/modules/activity/views/layouts/web.php'; + public $defaultLayout = '@activity/views/layouts/web.php'; /** * @inheritdoc @@ -65,10 +66,10 @@ class WebRenderer extends \humhub\components\rendering\LayoutRenderer */ public function getViewFile(Viewable $viewable) { - $viewFile = $this->getViewPath($viewable) . DIRECTORY_SEPARATOR . $viewable->getViewName(); + $viewFile = parent::getViewFile($viewable); if (!file_exists($viewFile)) { - $viewFile = Yii::getAlias($this->defaultViewPath) . DIRECTORY_SEPARATOR . $viewable->getViewName(); + $viewFile = Yii::getAlias($this->defaultViewPath) . '/' . $this->suffix($viewable->getViewName()); } if (!file_exists($viewFile)) { @@ -81,17 +82,17 @@ class WebRenderer extends \humhub\components\rendering\LayoutRenderer /** * Returns the layout for the given Notification Viewable. * - * This function will search for a layout file under module/views/layouts/mail with the view name defined - * by $viwable. + * This function will search for a layout file under `@module/views/layouts/mail` with the view name defined + * by $viewable. * - * If this file does not exists the default notification mail layout will be returned. + * If this file does not exists the default layout will be returned. * * @param \humhub\modules\notification\components\Viewable $viewable * @return type */ public function getLayout(Viewable $viewable) { - $layout = $this->getViewPath($viewable) . '/layouts/' . $viewable->getViewName(); + $layout = $this->getViewPath($viewable) . '/layouts/' . $this->suffix($viewable->getViewName()); if (!file_exists($layout)) { $layout = Yii::getAlias($this->defaultLayout); @@ -101,3 +102,4 @@ class WebRenderer extends \humhub\components\rendering\LayoutRenderer } } + diff --git a/protected/humhub/modules/activity/components/MailSummary.php b/protected/humhub/modules/activity/components/MailSummary.php index 8842132337..474562f181 100644 --- a/protected/humhub/modules/activity/components/MailSummary.php +++ b/protected/humhub/modules/activity/components/MailSummary.php @@ -70,7 +70,7 @@ class MailSummary extends Component $outputHtml = ''; $outputPlaintext = ''; - $mailRenderer = new MailRenderer(); + $mailRenderer = new ActivityMailRenderer(); foreach ($this->getActivities() as $activity) { $outputHtml .= $mailRenderer->render($activity); $outputPlaintext .= $mailRenderer->renderText($activity); diff --git a/protected/humhub/modules/activity/models/Activity.php b/protected/humhub/modules/activity/models/Activity.php index 40a5970fd9..97ec80ac3d 100644 --- a/protected/humhub/modules/activity/models/Activity.php +++ b/protected/humhub/modules/activity/models/Activity.php @@ -11,7 +11,7 @@ namespace humhub\modules\activity\models; use Yii; use yii\base\Exception; use humhub\modules\content\components\ContentActiveRecord; -use humhub\modules\activity\components\WebRenderer; +use humhub\modules\activity\components\ActivityWebRenderer; /** * This is the model class for table "activity". @@ -105,13 +105,12 @@ class Activity extends ContentActiveRecord if ($output === false) { $activity = $this->getActivityBaseClass(); if ($activity !== null) { - $renderer = new WebRenderer(); + $renderer = new ActivityWebRenderer(); $output = $renderer->render($activity); Yii::$app->cache->set($cacheKey, $output); return $output; } } - return $output; } @@ -125,5 +124,4 @@ class Activity extends ContentActiveRecord { return $this->getPolymorphicRelation(); } - } diff --git a/protected/humhub/modules/activity/tests/codeception/_support/_generated/UnitTesterActions.php b/protected/humhub/modules/activity/tests/codeception/_support/_generated/UnitTesterActions.php index 740c2cd488..d118550b7e 100644 --- a/protected/humhub/modules/activity/tests/codeception/_support/_generated/UnitTesterActions.php +++ b/protected/humhub/modules/activity/tests/codeception/_support/_generated/UnitTesterActions.php @@ -1,4 +1,4 @@ -beginContent('@activity/views/layouts/web.php', $_params_); ?> + +endContent(); ?> + + diff --git a/protected/humhub/modules/activity/views/mails/plaintext/activityLayout.php b/protected/humhub/modules/activity/views/layouts/mail_plaintext.php similarity index 100% rename from protected/humhub/modules/activity/views/mails/plaintext/activityLayout.php rename to protected/humhub/modules/activity/views/layouts/mail_plaintext.php diff --git a/protected/humhub/modules/activity/views/layouts/web.php b/protected/humhub/modules/activity/views/layouts/web.php index d58aa4c595..fb621adbe2 100644 --- a/protected/humhub/modules/activity/views/layouts/web.php +++ b/protected/humhub/modules/activity/views/layouts/web.php @@ -5,7 +5,7 @@ 32x32 + src="getProfileImage()->getUrl(); ?>"> @@ -27,11 +27,11 @@
-
+
- $record->content->created_at]); ?> + $record->content->created_at]); ?>
- \ No newline at end of file + \ No newline at end of file diff --git a/protected/humhub/modules/activity/views/mails/activityLayout.php b/protected/humhub/modules/activity/views/mails/activityLayout.php deleted file mode 100644 index 060c45d3a0..0000000000 --- a/protected/humhub/modules/activity/views/mails/activityLayout.php +++ /dev/null @@ -1,121 +0,0 @@ - - - - - - - - - - -
- - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - -
- - - " - width="50" - alt="" - style="max-width:50px; display:block !important; border-radius: 4px;" - border="0" hspace="0" vspace="0"/> - - - - - - - - - - -
- - - - - - content->space !== null): ?> - ( - - content->space->name); ?>) - - - - - - - - - - - - -
- -
-
- - - -
- -
- - - - \ No newline at end of file diff --git a/protected/humhub/modules/activity/views/mails/mailSummary.php b/protected/humhub/modules/activity/views/mails/mailSummary.php index 4be4393c3c..0c6dd592ab 100644 --- a/protected/humhub/modules/activity/views/mails/mailSummary.php +++ b/protected/humhub/modules/activity/views/mails/mailSummary.php @@ -1,3 +1,4 @@ +beginContent('@activity/views/layouts/mail.php', $_params_); ?> @@ -55,4 +56,5 @@ - \ No newline at end of file + +endContent(); ?> \ No newline at end of file diff --git a/protected/humhub/modules/activity/views/mails/plaintext/mailSummary.php b/protected/humhub/modules/activity/views/mails/plaintext/mailSummary.php index 847a708944..28507125fd 100644 --- a/protected/humhub/modules/activity/views/mails/plaintext/mailSummary.php +++ b/protected/humhub/modules/activity/views/mails/plaintext/mailSummary.php @@ -1,3 +1,5 @@ -Latest updates')); ?> +beginContent('@activity/views/layouts/mail.php', $_params_); ?> + Latest updates')); ?> - \ No newline at end of file + +endContent(); ?> \ No newline at end of file diff --git a/protected/humhub/modules/comment/activities/NewComment.php b/protected/humhub/modules/comment/activities/NewComment.php index 340365333d..d60fedbdaa 100644 --- a/protected/humhub/modules/comment/activities/NewComment.php +++ b/protected/humhub/modules/comment/activities/NewComment.php @@ -20,7 +20,14 @@ use humhub\modules\activity\interfaces\ConfigurableActivityInterface; class NewComment extends BaseActivity implements ConfigurableActivityInterface { + /** + * @inheritdoc + */ public $moduleId = 'comment'; + + /** + * @inheritdoc + */ public $viewName = "newComment"; /** diff --git a/protected/humhub/modules/comment/controllers/CommentController.php b/protected/humhub/modules/comment/controllers/CommentController.php index eec3c5ecc0..3639cdb728 100644 --- a/protected/humhub/modules/comment/controllers/CommentController.php +++ b/protected/humhub/modules/comment/controllers/CommentController.php @@ -90,10 +90,8 @@ class CommentController extends \humhub\modules\content\components\ContentAddonC return ''; } - $comment = new Comment; - $comment->message = $message; - $comment->object_model = $this->parentContent->className(); - $comment->object_id = $this->parentContent->getPrimaryKey(); + $comment = new Comment(['message' => $message]); + $comment->setPolyMorphicRelation($this->parentContent); $comment->save(); $comment->fileManager->attach($files); diff --git a/protected/humhub/modules/comment/models/Comment.php b/protected/humhub/modules/comment/models/Comment.php index 9cfe33fa00..a3bde1c072 100644 --- a/protected/humhub/modules/comment/models/Comment.php +++ b/protected/humhub/modules/comment/models/Comment.php @@ -9,6 +9,7 @@ namespace humhub\modules\comment\models; use humhub\modules\post\models\Post; +use \humhub\modules\content\interfaces\ContentOwner; use humhub\modules\comment\activities\NewComment; use humhub\modules\content\components\ContentAddonActiveRecord; use Yii; @@ -33,7 +34,7 @@ use Yii; * @package humhub.modules_core.comment.models * @since 0.5 */ -class Comment extends ContentAddonActiveRecord +class Comment extends ContentAddonActiveRecord implements ContentOwner { /** @@ -53,6 +54,21 @@ class Comment extends ContentAddonActiveRecord [['message'], 'safe'], ]; } + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + [ + 'class' => \humhub\components\behaviors\PolymorphicRelation::className(), + 'mustBeInstanceOf' => [ + \yii\db\ActiveRecord::className(), + ] + ] + ]; + } /** * @inheritdoc @@ -105,7 +121,7 @@ class Comment extends ContentAddonActiveRecord \humhub\modules\comment\notifications\NewComment::instance() ->from($this->user) ->about($this) - ->sendBulk($this->content->getPolymorphicRelation()->getFollowers(null, true, true)); + ->sendBulk($this->getCommentedRecord()->getFollowers(null, true, true)); } $this->updateContentSearch(); @@ -119,10 +135,20 @@ class Comment extends ContentAddonActiveRecord */ protected function updateContentSearch() { - if ($this->content->getPolymorphicRelation() instanceof \humhub\modules\search\interfaces\Searchable) { - Yii::$app->search->update($this->content->getPolymorphicRelation()); + if ($this->getCommentedRecord() instanceof \humhub\modules\search\interfaces\Searchable) { + Yii::$app->search->update($this->getCommentedRecord()); } } + + /** + * Returns the commented record e.g. a Post + * + * @return \humhub\modules\content\components\ContentActiveRecord + */ + public function getCommentedRecord() + { + return $this->content->getPolymorphicRelation(); + } /** * Returns a limited amount of comments diff --git a/protected/humhub/modules/comment/notifications/NewComment.php b/protected/humhub/modules/comment/notifications/NewComment.php index 7c5c491b4b..5782484806 100644 --- a/protected/humhub/modules/comment/notifications/NewComment.php +++ b/protected/humhub/modules/comment/notifications/NewComment.php @@ -11,6 +11,7 @@ namespace humhub\modules\comment\notifications; use Yii; use yii\bootstrap\Html; use humhub\modules\user\models\User; +use humhub\libs\Helpers; /** * Notification for new comments @@ -24,11 +25,17 @@ class NewComment extends \humhub\modules\notification\components\BaseNotificatio * @inheritdoc */ public $moduleId = 'comment'; - + /** * @inheritdoc */ - public function category() { + public $viewName = 'newComment'; + + /** + * @inheritdoc + */ + public function category() + { return new CommentNotificationCategory(); } @@ -38,7 +45,11 @@ class NewComment extends \humhub\modules\notification\components\BaseNotificatio public function send(User $user) { // Check if there is also a mention notification, so skip this notification - if (\humhub\modules\notification\models\Notification::find()->where(['class' => \humhub\modules\user\notifications\Mentioned::className(), 'user_id' => $user->id, 'source_class' => $this->source->className(), 'source_pk' => $this->source->getPrimaryKey()])->count() > 0) { + if (\humhub\modules\notification\models\Notification::find()->where([ + 'class' => \humhub\modules\user\notifications\Mentioned::className(), + 'user_id' => $user->id, + 'source_class' => $this->source->className(), + 'source_pk' => $this->source->getPrimaryKey()])->count() > 0) { return; } @@ -54,6 +65,75 @@ class NewComment extends \humhub\modules\notification\components\BaseNotificatio return $model->className() . '-' . $model->getPrimaryKey(); } + /** + * @inheritdoc + */ + public function getTitle(User $user) + { + if ($this->groupCount > 1) { + return $this->getGroupTitle($user); + } + + $contentRecord = $this->getCommentedRecord(); + $space = $this->getSpace(); + + if ($user->is($contentRecord->owner)) { + if ($space) { + return Yii::t('CommentModule.notification', "{displayName} just commented your content \"{preview}\" in space {space}", [ + 'displayName' => Html::encode($this->originator->displayName), + 'preview' => Helpers::truncateText($contentRecord->getContentDescription(), 25), + 'space' => Html::encode($space->displayName) + ]); + } + return Yii::t('CommentModule.notification', "{displayName} just commented your content \"{preview}\"", [ + 'displayName' => Html::encode($this->originator->displayName), + 'preview' => Helpers::truncateText($contentRecord->getContentDescription(), 25), + ]); + } else if ($space) { + return Yii::t('CommentModule.notification', "{displayName} commented \"{preview}\" in space {space}", [ + 'displayName' => Html::encode($this->originator->displayName), + 'preview' => Helpers::truncateText($contentRecord->getContentDescription(), 25), + 'space' => Html::encode($space->displayName) + ]); + } else { + return Yii::t('CommentModule.notification', "{displayName} commented \"{preview}\"", [ + 'displayName' => Html::encode($this->originator->displayName), + 'preview' => Helpers::truncateText($contentRecord->getContentDescription(), 25), + ]); + } + } + + private function getGroupTitle(User $user) + { + $contentRecord = $this->getCommentedRecord(); + $space = $this->getSpace(); + + if ($user->is($contentRecord->owner)) { + if ($space) { + return Yii::t('CommentModule.notification', "{displayNames} just commented your content \"{preview}\" in space {space}", [ + 'displayNames' => $this->getGroupUserDisplayNames(), + 'preview' => Helpers::truncateText($contentRecord->getContentDescription(), 25), + 'space' => Html::encode($space->displayName) + ]); + } + return Yii::t('CommentModule.notification', "{displayNames} just commented your content \"{preview}\"", [ + 'displayNames' => $this->getGroupUserDisplayNames(), + 'preview' => Helpers::truncateText($contentRecord->getContentDescription(), 25), + ]); + } else if ($space) { + return Yii::t('CommentModule.notification', "{displayNames} commented \"{preview}\" in space {space}", [ + 'displayNames' => $this->getGroupUserDisplayNames(), + 'preview' => Helpers::truncateText($contentRecord->getContentDescription(), 25), + 'space' => Html::encode($space->displayName) + ]); + } else { + return Yii::t('CommentModule.notification', "{displayNames} commented \"{preview}\"", [ + 'displayNames' => $this->getGroupUserDisplayNames(), + 'preview' => Helpers::truncateText($contentRecord->getContentDescription(), 25), + ]); + } + } + /** * @inheritdoc */ @@ -62,28 +142,26 @@ class NewComment extends \humhub\modules\notification\components\BaseNotificatio $contentInfo = $this->getContentInfo($this->getCommentedRecord()); if ($this->groupCount > 1) { - return Yii::t('CommentModule.notification', "{displayNames} commented {contentTitle}.", array( + return Yii::t('CommentModule.notification', "{displayNames} commented {contentTitle}.", [ 'displayNames' => $this->getGroupUserDisplayNames(), 'contentTitle' => $contentInfo - )); + ]); } - return Yii::t('CommentModule.notification', "{displayName} commented {contentTitle}.", array( + return Yii::t('CommentModule.notification', "{displayName} commented {contentTitle}.", [ 'displayName' => Html::tag('strong', Html::encode($this->originator->displayName)), 'contentTitle' => $contentInfo - )); + ]); } /** - * The commented record + * The commented record e.g. a Post * - * @return \humhub\components\ActiveRecord + * @return \humhub\modules\content\components\ContentActiveRecord */ - protected function getCommentedRecord() + public function getCommentedRecord() { - return $this->source->content->getPolymorphicRelation(); - ; + return $this->source->getCommentedRecord(); } - } ?> diff --git a/protected/humhub/modules/comment/notifications/views/mails/newComment.php b/protected/humhub/modules/comment/notifications/views/mails/newComment.php new file mode 100644 index 0000000000..5f34423882 --- /dev/null +++ b/protected/humhub/modules/comment/notifications/views/mails/newComment.php @@ -0,0 +1,68 @@ + +beginContent('@notification/views/layouts/mail.php', $_params_); ?> + +source; ?> +getCommentedRecord() ?> + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ $originator, + 'content' => $comment, + 'date' => $date, + 'space' => $space, + 'isComment' => true + ]); + ?> +
+
+ $contentRecord->owner, + 'content' => $contentRecord, + 'date' => $date, + 'space' => $space + ]); + ?> +
+endContent(); diff --git a/protected/humhub/modules/comment/tests/codeception/_support/_generated/UnitTesterActions.php b/protected/humhub/modules/comment/tests/codeception/_support/_generated/UnitTesterActions.php index dfcc62efb6..c60b1f788f 100644 --- a/protected/humhub/modules/comment/tests/codeception/_support/_generated/UnitTesterActions.php +++ b/protected/humhub/modules/comment/tests/codeception/_support/_generated/UnitTesterActions.php @@ -1,4 +1,4 @@ -content->createdBy; + } /** * Related Content model @@ -224,7 +232,6 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner { return Yii::createObject(ActiveQueryContent::className(), [get_called_class()]); } - } ?> diff --git a/protected/humhub/modules/content/components/ContentContainerController.php b/protected/humhub/modules/content/components/ContentContainerController.php index 1b3029e806..dfdcfbc633 100644 --- a/protected/humhub/modules/content/components/ContentContainerController.php +++ b/protected/humhub/modules/content/components/ContentContainerController.php @@ -122,7 +122,7 @@ class ContentContainerController extends Controller if ($this->contentContainer instanceof Space && (Yii::$app->request->isPjax || !Yii::$app->request->isAjax)) { $options = [ 'guid' => $this->contentContainer->guid, - 'name' => $this->contentContainer->name, + 'name' => \yii\helpers\Html::encode($this->contentContainer->name), 'archived' => $this->contentContainer->isArchived(), 'image' => \humhub\modules\space\widgets\Image::widget([ 'space' => $this->contentContainer, diff --git a/protected/humhub/modules/content/notifications/ContentCreated.php b/protected/humhub/modules/content/notifications/ContentCreated.php index e0436a7b48..5e312b6bf4 100644 --- a/protected/humhub/modules/content/notifications/ContentCreated.php +++ b/protected/humhub/modules/content/notifications/ContentCreated.php @@ -10,6 +10,8 @@ namespace humhub\modules\content\notifications; use Yii; use yii\bootstrap\Html; +use humhub\modules\user\models\User; +use humhub\libs\Helpers; /** * ContentCreatedNotification is fired to all users which are manually selected @@ -21,12 +23,18 @@ class ContentCreated extends \humhub\modules\notification\components\BaseNotific /** * @inheritdoc */ - public $moduleId = 'content'; - + public $viewName = 'contentCreated'; + /** * @inheritdoc */ - public function category() { + public $moduleId = 'content'; + + /** + * @inheritdoc + */ + public function category() + { return new \humhub\modules\content\notifications\ContentCreatedNotificationCategory(); } @@ -35,28 +43,55 @@ class ContentCreated extends \humhub\modules\notification\components\BaseNotific */ public function html() { - return Yii::t('ContentModule.notifications_views_ContentCreated', '{displayName} created {contentTitle}.', array( + return Yii::t('ContentModule.notifications_views_ContentCreated', '{displayName} created {contentTitle}.', [ 'displayName' => Html::tag('strong', Html::encode($this->originator->displayName)), 'contentTitle' => $this->getContentInfo($this->source) - )); - } - - /** - * @inheritdoc - */ - public function getTitle() - { - return Yii::t('ContentModule.notifications_ContentCreated', 'There is new content your are following available at '.Html::encode(Yii::$app->name)); - } - - /** - * @inheritdoc - */ - public function getHeadline() - { - return Yii::t('ContentModule.notifications_ContentCreated', 'New content available'); + ]); } + /** + * @inheritdoc + */ + public function getTitle(User $user) + { + $space = $this->getSpace(); + if ($space) { + if ($this->isExplicitNotifyUser($user)) { + return Yii::t('ContentModule.notifications_ContentCreated', '{originator} notifies you about {contentType} "{preview}" in {space}', + ['originator' => Html::encode($this->originator->displayName), + 'space' => Html::encode($space->displayName), + 'contentType' => $this->source->getContentName(), + 'preview' => Helpers::truncateText($this->source->getContentDescription(), 25)]); + } + return Yii::t('ContentModule.notifications_ContentCreated', '{originator} just wrote {contentType} "{preview}" in space {space}', + ['originator' => Html::encode($this->originator->displayName), + 'space' => Html::encode($space->displayName), + 'contentType' => $this->source->getContentName(), + 'preview' => Helpers::truncateText($this->source->getContentDescription(), 25)]); + } else { + if ($this->isExplicitNotifyUser($user)) { + return Yii::t('ContentModule.notifications_ContentCreated', '{originator} notifies you about {contentType} "{preview}"', + ['originator' => Html::encode($this->originator->displayName), + 'contentType' => $this->source->getContentName(), + 'preview' => Helpers::truncateText($this->source->getContentDescription(), 25)]); + } + return Yii::t('ContentModule.notifications_ContentCreated', '{originator} just wrote {contentType} "{preview}"', + ['originator' => Html::encode($this->originator->displayName), + 'contentType' => $this->source->getContentName(), + 'preview' => Helpers::truncateText($this->source->getContentDescription(), 25)]); + } + } + + protected function isExplicitNotifyUser(User $user) + { + $content = $this->getContent(); + foreach ($content->notifyUsersOfNewContent as $notifyUser) { + if ($notifyUser->id === $user->id) { + return true; + } + } + return false; + } } ?> diff --git a/protected/humhub/modules/content/notifications/views/mails/contentCreated.php b/protected/humhub/modules/content/notifications/views/mails/contentCreated.php new file mode 100644 index 0000000000..42633b692d --- /dev/null +++ b/protected/humhub/modules/content/notifications/views/mails/contentCreated.php @@ -0,0 +1,24 @@ + +beginContent('@notification/views/layouts/mail.php', $_params_); ?> + $originator, + 'content' => $viewable->source, + 'date' => $date, + 'space' => $space +]) +?> +endContent(); diff --git a/protected/humhub/modules/content/tests/codeception/_support/_generated/UnitTesterActions.php b/protected/humhub/modules/content/tests/codeception/_support/_generated/UnitTesterActions.php index 7623058d10..c4a0f7b50e 100644 --- a/protected/humhub/modules/content/tests/codeception/_support/_generated/UnitTesterActions.php +++ b/protected/humhub/modules/content/tests/codeception/_support/_generated/UnitTesterActions.php @@ -1,4 +1,4 @@ -becomeUser('User2'); - - $testContent = new TestContent(['message' => 'MyTestContent']); - $testContent->content->setContainer(Space::findOne(['id' => 2])); - $testContent->save(); - - $this->assertEquals('
Wallentry:MyTestContent
', trim($testContent->getWallOut())); - } - /** * Test CreateContent notification for a space follower with send_notification setting (see user_follow fixture) */ diff --git a/protected/humhub/modules/content/tests/codeception/unit/models/TestContent.php b/protected/humhub/modules/content/tests/codeception/unit/models/TestContent.php deleted file mode 100644 index 212489e630..0000000000 --- a/protected/humhub/modules/content/tests/codeception/unit/models/TestContent.php +++ /dev/null @@ -1,50 +0,0 @@ -afterSave(true, []); - } - - public function getPrimaryKey($asArray = false) - { - return 1; - } - - /** - * @inheritdoc - */ - public function __get($name) - { - /** - * Ensure there is always a corresponding Content - */ - if ($name == 'content') { - if (!$this->_content) { - $this->_content = new \humhub\modules\content\models\Content(); - $this->_content->setPolymorphicRelation($this); - } - return $this->_content; - } - return parent::__get($name); - } - -} diff --git a/protected/humhub/modules/content/views/mails/plaintext/Update.php b/protected/humhub/modules/content/views/mails/plaintext/Update.php deleted file mode 100644 index 1df3f8854f..0000000000 --- a/protected/humhub/modules/content/views/mails/plaintext/Update.php +++ /dev/null @@ -1,12 +0,0 @@ -Latest updates')); ?> - - - diff --git a/protected/humhub/modules/notification/components/BaseNotification.php b/protected/humhub/modules/notification/components/BaseNotification.php index fe2333c7ae..57460ff5d1 100644 --- a/protected/humhub/modules/notification/components/BaseNotification.php +++ b/protected/humhub/modules/notification/components/BaseNotification.php @@ -12,6 +12,8 @@ use Yii; use yii\helpers\Url; use yii\bootstrap\Html; use humhub\modules\notification\models\Notification; +use humhub\modules\notification\jobs\SendNotification; +use humhub\modules\notification\jobs\SendBulkNotification; use humhub\modules\user\models\User; /** @@ -29,12 +31,6 @@ use humhub\modules\user\models\User; abstract class BaseNotification extends \humhub\components\SocialActivity { - /** - * Can be used to delay the NotificationJob execution. - * @var type - */ - public $delay = 0; - /** * @var boolean automatically mark notification as seen after click on it */ @@ -93,9 +89,10 @@ abstract class BaseNotification extends \humhub\components\SocialActivity } /** + * @param User $user the recipient * @return string title text for this notification */ - public function getTitle() + public function getTitle(User $user) { $category = $this->getCategory(); if ($category) { @@ -106,11 +103,12 @@ abstract class BaseNotification extends \humhub\components\SocialActivity } /** - * @return string the headline for this notification used for example in mails. + * @param User $user the recipient + * @return string the headline for this notification, can be used for example in mails. */ - public function getHeadline() + public function getHeadline(User $user) { - return Yii::t('base', 'Latest updates'); + return null; } /** @@ -118,8 +116,18 @@ abstract class BaseNotification extends \humhub\components\SocialActivity */ public function getViewParams($params = []) { + if($this->hasContent() && $this->getContent()->updated_at instanceof \yii\db\Expression) { + $this->getContent()->refresh(); + $date = $this->getContent()->updated_at; + } else if($this->hasContent()) { + $date = $this->getContent()->updated_at; + } else { + $date = null; + } + $result = [ 'url' => Url::to(['/notification/entry', 'id' => $this->record->id], true), + 'date' => $date, 'isNew' => !$this->record->seen, ]; @@ -145,25 +153,23 @@ abstract class BaseNotification extends \humhub\components\SocialActivity } // Filter out duplicates and the originator and save records - $filteredUsers = $this->saveAndFilterRecords($users); + $filteredUsers = $this->filterRecepients($users); - Yii::$app->notification->sendBulk($this, $filteredUsers); + Yii::$app->queue->push(new SendBulkNotification(['notification' => $this, 'recepients' => $filteredUsers])); } /** - * Saves an Notification record for users and filters out duplicates and the originator of the notification. - * This function will return the array with unique user instances. + * Filters out duplicates and the originator of the notification itself. * * @param User[] $users + * @return User[] array of unique user instances */ - protected function saveAndFilterRecords($users) + protected function filterRecepients($users) { $userIds = []; $filteredUsers = []; foreach ($users as $user) { - // Filter our duplicates and the originator of this notification. if (!in_array($user->id, $userIds) && !$this->isOriginator($user)) { - $this->saveRecord($user); $filteredUsers[] = $user; $userIds[] = $user->id; } @@ -186,11 +192,8 @@ abstract class BaseNotification extends \humhub\components\SocialActivity if ($this->isOriginator($user)) { return; } - - //$this->queueJob($user); - $this->saveRecord($user); - Yii::$app->notification->send($this, $user); + Yii::$app->queue->push(new SendNotification(['notification' => $this, 'recepient' => $user])); } /** @@ -204,29 +207,6 @@ abstract class BaseNotification extends \humhub\components\SocialActivity return $this->originator && $this->originator->id == $user->id; } - /** - * Queues the notification job. The Job is responsible for creating and sending - * the Notifications out to its NotificationTargets. - * - * @param User $user - */ - protected function queueJob(User $user) - { - Yii::$app->notificationQueue->push(new NotificationJob([ - 'notification' => $this, - 'user_id' => $user->id - ])); - } - - public function save(User $user) - { - // We reuse our record instance to save multiple records. - $this->record->id = null; - $this->record->isNewRecord = true; - $this->record->user_id = $user->id; - return $this->record->save(); - } - /** * Creates the an Notification instance of the current BaseNotification type for the * given $user. @@ -417,11 +397,11 @@ abstract class BaseNotification extends \humhub\components\SocialActivity /** * @inheritdoc */ - public function asArray() + public function asArray(User $user) { - $result = parent::asArray(); - $result['title'] = $this->getTitle(); - $result['headline'] = $this->getHeadline(); + $result = parent::asArray($user); + $result['title'] = $this->getTitle($user); + $result['headline'] = $this->getHeadline($user); return $result; } diff --git a/protected/humhub/modules/notification/components/MailNotificationTarget.php b/protected/humhub/modules/notification/components/MailNotificationTarget.php index dde0da972b..b45275ab10 100644 --- a/protected/humhub/modules/notification/components/MailNotificationTarget.php +++ b/protected/humhub/modules/notification/components/MailNotificationTarget.php @@ -4,6 +4,7 @@ namespace humhub\modules\notification\components; use Yii; use humhub\modules\user\models\User; +use yii\helpers\Html; /** * @@ -23,9 +24,12 @@ class MailNotificationTarget extends NotificationTarget */ public $defaultSetting = true; + /** + * @var array Notification mail layout. + */ public $view = [ - 'html' => '@humhub/modules/content/views/mails/Update', - 'text' => '@humhub/modules/content/views/mails/plaintext/Update' + 'html' => '@notification/views/mails/Update', + 'text' => '@notification/views/mails/plaintext/Update' ]; /** @@ -39,32 +43,28 @@ class MailNotificationTarget extends NotificationTarget /** * @inheritdoc */ - public function handle(BaseNotification $notification, User $user) + public function handle(BaseNotification $notification, User $recipient) { - // TODO: find cleaner solution... Yii::$app->view->params['showUnsubscribe'] = true; - - $viewParams = [ - 'headline' => $notification->getHeadline(), - 'notifications' => $notification->render($this), - 'notifications_plaintext' => $this->getText($notification) - ]; + + // Note: the renderer is configured in common.php by default its an instance of MailNotificatoinTarget + $renderer = $this->getRenderer(); + + $viewParams = \yii\helpers\ArrayHelper::merge([ + 'headline' => $notification->getHeadline($recipient), + 'notification' => $notification, + 'space' => $notification->getSpace(), + 'content' => $renderer->render($notification), + 'content_plaintext' => $renderer->renderText($notification) + ], $notification->getViewParams()); + + $from = $notification->originator + ? Html::encode($notification->originator->displayName).' ('.Html::encode(Yii::$app->name).')' + : Yii::$app->settings->get('mailer.systemEmailName'); return Yii::$app->mailer->compose($this->view, $viewParams) - ->setFrom([Yii::$app->settings->get('mailer.systemEmailAddress') => Yii::$app->settings->get('mailer.systemEmailName')]) - ->setTo($user->email) - ->setSubject($notification->getTitle())->send(); + ->setFrom([Yii::$app->settings->get('mailer.systemEmailAddress') => $from]) + ->setTo($recipient->email) + ->setSubject($notification->getTitle($recipient))->send(); } - - public function getText(BaseNotification $notification) - { - $textRenderer = $this->getRenderer(); - - if (!method_exists($textRenderer, 'renderText')) { - $textRenderer = Yii::createObject(MailTargetRenderer::class); - } - - return $textRenderer->renderText($notification); - } - } diff --git a/protected/humhub/modules/notification/components/MailTargetRenderer.php b/protected/humhub/modules/notification/components/MailTargetRenderer.php index b250b760f1..fc91778d54 100644 --- a/protected/humhub/modules/notification/components/MailTargetRenderer.php +++ b/protected/humhub/modules/notification/components/MailTargetRenderer.php @@ -2,9 +2,6 @@ namespace humhub\modules\notification\components; -use Yii; -use humhub\components\rendering\Viewable; - /** * The MailTargetRenderer is used to render Notifications for the MailNotificationTarget. * @@ -22,104 +19,25 @@ use humhub\components\rendering\Viewable; * * @author buddha */ -class MailTargetRenderer extends \humhub\components\rendering\MailLayoutRenderer +class MailTargetRenderer extends \humhub\components\rendering\MailRenderer { + /** + * @inheritdoc + */ + public $defaultView = '@notification/views/mails/default.php'; /** - * @var string default notification mail view path + * @inheritdoc */ - public $defaultViewPath = '@notification/views/notification/mail'; + public $defaultViewPath = '@notification/views/mails'; /** - * @var string default notification mail view + * @inheritdoc */ - public $defaultView = '@notification/views/notification/mail/default.php'; + public $defaultTextView = '@notification/views/mails/plaintext/default.php'; /** - * @var string layout file path + * @inheritdoc */ - public $defaultLayout = '@notification/views/layouts/mail.php'; - - /** - * @var string default notification mail text view path - */ - public $defaultTextViewPath = '@notification/views/notification/mail/plaintext'; - - /** - * @var string text layout file - */ - public $defaultTextLayout = "@notification/views/layouts/mail_plaintext.php"; - - /** - * Returns the view file for the given Viewable Notification. - * - * This function will search for the view file defined in the Viewable within the module/views/notification/mail directory of - * the viewable module. - * - * If the module view does not exist we search for the viewName within the default notification viewPath. - * - * If this view also does not exist we return the base notification view file. - * - * @param \humhub\modules\notification\components\Viewable $viewable - * @return string view file of this notification - */ - public function getViewFile(Viewable $viewable) - { - $viewFile = $this->getViewPath($viewable) . '/mail/' . $viewable->getViewName(); - - if (!file_exists($viewFile)) { - $viewFile = Yii::getAlias($this->defaultViewPath) . DIRECTORY_SEPARATOR . $viewable->getViewName(); - } - - if (!file_exists($viewFile)) { - $viewFile = Yii::getAlias($this->defaultView); - } - - return $viewFile; - } - - /** - * Returns the layout for the given Notification Viewable. - * - * This function will search for a layout file under module/views/layouts/mail with the view name defined - * by $viwable. - * - * If this file does not exists the default notification mail layout will be returned. - * - * @param \humhub\modules\notification\components\Viewable $viewable - * @return type - */ - public function getLayout(Viewable $viewable) - { - $layout = $this->getViewPath($viewable) . '/layouts/mail/' . $viewable->getViewName(); - - if (!file_exists($layout)) { - $layout = Yii::getAlias($this->defaultLayout); - } - - return $layout; - } - - /** - * Returns the text layout for the given Notification Viewable. - * - * This function will search for a view file under module/views/layouts/mail/plaintext with the view name defined - * by $viwable. - * - * If this file does not exists the default notification text mail layout is returned. - * - * @param \humhub\modules\notification\components\Viewable $viewable - * @return type - */ - public function getTextLayout(Viewable $viewable) - { - $layout = $this->getViewPath($viewable) . '/layouts/mail/plaintext/' . $viewable->getViewName(); - - if (!file_exists($layout)) { - $layout = Yii::getAlias($this->defaultTextLayout); - } - - return $layout; - } - + public $defaultTextViewPath = '@notification/views/mails/plaintext'; } diff --git a/protected/humhub/modules/notification/components/NotificationTarget.php b/protected/humhub/modules/notification/components/NotificationTarget.php index fd02996034..cc92aa8aba 100644 --- a/protected/humhub/modules/notification/components/NotificationTarget.php +++ b/protected/humhub/modules/notification/components/NotificationTarget.php @@ -146,9 +146,6 @@ abstract class NotificationTarget extends \yii\base\Object } catch (\Exception $e) { Yii::error($e); $this->acknowledge($notification, false); - if(!YII_ENV_PROD) { - throw $e; - } } } @@ -160,10 +157,6 @@ abstract class NotificationTarget extends \yii\base\Object */ public function sendBulk(BaseNotification $notification, $users) { - if ($users instanceof \yii\db\ActiveQuery) { - $users = $users->all(); - } - foreach ($users as $user) { $this->send($notification, $user); } diff --git a/protected/humhub/modules/notification/components/WebTargetRenderer.php b/protected/humhub/modules/notification/components/WebTargetRenderer.php index f1b40072cf..f37dcc0b15 100644 --- a/protected/humhub/modules/notification/components/WebTargetRenderer.php +++ b/protected/humhub/modules/notification/components/WebTargetRenderer.php @@ -2,89 +2,20 @@ namespace humhub\modules\notification\components; -use Yii; -use humhub\components\rendering\Viewable; - /** * The WebTargetRenderer is used to render Notifications for the WebNotificationTarget. - * - * A BaseNotification can overwrite the default view and layout by setting a specific $viewName and - * defining the following files: - * - * Overwrite default view for this notification: - * @module/views/notification/viewname.php - * - * Overwrite default layout for this notification: - * @module/views/layouts/notification/viewname.php * * @author buddha */ -class WebTargetRenderer extends \humhub\components\rendering\LayoutRenderer +class WebTargetRenderer extends \humhub\components\rendering\DefaultViewPathRenderer { + /** + * @inheritdoc + */ + public $defaultView = '@notification/views/default.php'; /** - * @var string default view path + * @inheritdoc */ - public $defaultViewPath = '@notification/views/notification'; - - /* - * @var string default view - */ - public $defaultView = '@notification/views/notification/default.php'; - - /** - * @var string default layout - */ - public $defaultLayout = '@notification/views/layouts/web.php'; - - /** - * Returns the view file for the given Viewable Notification. - * - * This function will search for the view file defined in the Viewable within the module/views/mail directory of - * the viewable module. - * - * If the module view does not exist we search for the viewName within the default notification viewPath. - * - * If this view also does not exist we return the base notification view file. - * - * @param \humhub\modules\notification\components\Viewable $viewable - * @return string view file of this notification - */ - public function getViewFile(Viewable $viewable) - { - $viewFile = $this->getViewPath($viewable) . '/' . $viewable->getViewName(); - - if (!file_exists($viewFile)) { - $viewFile = Yii::getAlias($this->defaultViewPath) . DIRECTORY_SEPARATOR . $viewable->getViewName(); - } - - if (!file_exists($viewFile)) { - $viewFile = Yii::getAlias($this->defaultView); - } - - return $viewFile; - } - - /** - * Returns the layout for the given Notification Viewable. - * - * This function will search for a layout file under module/views/layouts/mail with the view name defined - * by $viwable. - * - * If this file does not exists the default notification mail layout will be returned. - * - * @param \humhub\modules\notification\components\Viewable $viewable - * @return type - */ - public function getLayout(Viewable $viewable) - { - $layout = $this->getViewPath($viewable) . '/layouts/' . $viewable->getViewName(); - - if (!file_exists($layout)) { - $layout = Yii::getAlias($this->defaultLayout); - } - - return $layout; - } - + public $defaultViewPath = '@notification/views'; } diff --git a/protected/humhub/modules/notification/jobs/SendBulkNotification.php b/protected/humhub/modules/notification/jobs/SendBulkNotification.php new file mode 100644 index 0000000000..f9c8d8f491 --- /dev/null +++ b/protected/humhub/modules/notification/jobs/SendBulkNotification.php @@ -0,0 +1,42 @@ +recepients as $recepient) { + $this->notification->saveRecord($recepient); + } + + Yii::$app->notification->sendBulk($this->notification, $this->recepients); + } +} diff --git a/protected/humhub/modules/notification/jobs/SendNotification.php b/protected/humhub/modules/notification/jobs/SendNotification.php new file mode 100644 index 0000000000..bf9dadbf9c --- /dev/null +++ b/protected/humhub/modules/notification/jobs/SendNotification.php @@ -0,0 +1,40 @@ +notification->saveRecord($this->recepient); + Yii::$app->notification->send($this->notification, $this->recepient); + } +} diff --git a/protected/humhub/modules/notification/tests/codeception/_support/_generated/UnitTesterActions.php b/protected/humhub/modules/notification/tests/codeception/_support/_generated/UnitTesterActions.php index 2a7e44f10f..01ba04d69b 100644 --- a/protected/humhub/modules/notification/tests/codeception/_support/_generated/UnitTesterActions.php +++ b/protected/humhub/modules/notification/tests/codeception/_support/_generated/UnitTesterActions.php @@ -1,4 +1,4 @@ -viewName = 'special'; $target = Yii::$app->notification->getTarget(MailNotificationTarget::class); $renderer = $target->getRenderer(); - $this->assertContains('
Special:

TestedMailViewNotificationHTML

', $renderer->render($notification)); + $result = $renderer->render($notification); + $this->assertContains('
Special:

TestedMailViewNotificationHTML

', $result); + $this->assertContains('
MyLayout:', $result); $this->assertContains('TestedMailViewNotificationText', $renderer->renderText($notification)); } - - public function testOverwriteLayoutFile() - { - $notification = notifications\TestedMailViewNotification::instance(); - $notification->viewName = 'specialLayout'; - $target = Yii::$app->notification->getTarget(MailNotificationTarget::class); - $renderer = $target->getRenderer(); - $this->assertEquals('
MyLayout:

TestedMailViewNotificationHTML

', trim($renderer->render($notification))); - $this->assertEquals('MyLayout:TestedMailViewNotificationText', trim($renderer->renderText($notification))); - } } diff --git a/protected/humhub/modules/notification/tests/codeception/unit/rendering/WebTargetRenderTest.php b/protected/humhub/modules/notification/tests/codeception/unit/rendering/WebTargetRenderTest.php index 5d5de98f66..df5d9a8887 100644 --- a/protected/humhub/modules/notification/tests/codeception/unit/rendering/WebTargetRenderTest.php +++ b/protected/humhub/modules/notification/tests/codeception/unit/rendering/WebTargetRenderTest.php @@ -32,15 +32,4 @@ class WebTargetRenderTest extends HumHubDbTestCase $this->assertContains('New', $result); $this->assertContains('
Special:

TestedMailViewNotificationHTML

', $result); } - - public function testOverwriteLayoutFile() - { - $notification = notifications\TestedMailViewNotification::instance(); - $notification->viewName = 'specialLayout'; - $target = Yii::$app->notification->getTarget(WebNotificationTarget::class); - $renderer = $target->getRenderer(); - $result = $renderer->render($notification); - $this->assertNotContains('New', $result); - $this->assertEquals('
MyLayout:

TestedMailViewNotificationHTML

', trim($result)); - } } diff --git a/protected/humhub/modules/notification/tests/codeception/unit/rendering/notifications/views/mail/special.php b/protected/humhub/modules/notification/tests/codeception/unit/rendering/notifications/views/mail/special.php deleted file mode 100644 index 645cf5c65c..0000000000 --- a/protected/humhub/modules/notification/tests/codeception/unit/rendering/notifications/views/mail/special.php +++ /dev/null @@ -1,2 +0,0 @@ -
Special:
- diff --git a/protected/humhub/modules/notification/tests/codeception/unit/rendering/notifications/views/mails/special.php b/protected/humhub/modules/notification/tests/codeception/unit/rendering/notifications/views/mails/special.php new file mode 100644 index 0000000000..0729977d04 --- /dev/null +++ b/protected/humhub/modules/notification/tests/codeception/unit/rendering/notifications/views/mails/special.php @@ -0,0 +1,4 @@ +beginContent('@notification/tests/codeception/unit/rendering/notifications/views/layouts/specialLayout.php', $_params_); ?> +
Special:
+endContent(); ?> + diff --git a/protected/humhub/modules/notification/tests/codeception/unit/rendering/notifications/views/special.php b/protected/humhub/modules/notification/tests/codeception/unit/rendering/notifications/views/special.php index 645cf5c65c..492d9bc577 100644 --- a/protected/humhub/modules/notification/tests/codeception/unit/rendering/notifications/views/special.php +++ b/protected/humhub/modules/notification/tests/codeception/unit/rendering/notifications/views/special.php @@ -1,2 +1,4 @@ +beginContent('@notification/views/layouts/web.php', $_params_); ?>
Special:
+endContent(); ?> diff --git a/protected/humhub/modules/notification/views/default.php b/protected/humhub/modules/notification/views/default.php new file mode 100644 index 0000000000..b16b0aa55d --- /dev/null +++ b/protected/humhub/modules/notification/views/default.php @@ -0,0 +1,3 @@ +beginContent('@notification/views/layouts/web.php', $_params_); ?> + +endContent(); ?> \ No newline at end of file diff --git a/protected/humhub/modules/notification/views/layouts/mail.php b/protected/humhub/modules/notification/views/layouts/mail.php index fff0933c47..a5fde7037a 100644 --- a/protected/humhub/modules/notification/views/layouts/mail.php +++ b/protected/humhub/modules/notification/views/layouts/mail.php @@ -1,7 +1,3 @@ - @@ -23,74 +19,24 @@ use yii\helpers\Html; - - - - - + - + @@ -54,13 +53,7 @@ - - - - + + + + \ No newline at end of file diff --git a/protected/humhub/modules/notification/views/mails/default.php b/protected/humhub/modules/notification/views/mails/default.php new file mode 100644 index 0000000000..5a57997948 --- /dev/null +++ b/protected/humhub/modules/notification/views/mails/default.php @@ -0,0 +1,3 @@ +beginContent('@notification/views/layouts/mail.php', $_params_); ?> + +endContent(); ?> \ No newline at end of file diff --git a/protected/humhub/modules/notification/views/mails/plaintext/Update.php b/protected/humhub/modules/notification/views/mails/plaintext/Update.php new file mode 100644 index 0000000000..eab36f2a54 --- /dev/null +++ b/protected/humhub/modules/notification/views/mails/plaintext/Update.php @@ -0,0 +1,4 @@ +Latest updates')); ?> + + + diff --git a/protected/humhub/modules/notification/views/mails/plaintext/default.php b/protected/humhub/modules/notification/views/mails/plaintext/default.php new file mode 100644 index 0000000000..3a594f06b7 --- /dev/null +++ b/protected/humhub/modules/notification/views/mails/plaintext/default.php @@ -0,0 +1,3 @@ +beginContent('@notification/views/layouts/mail_plaintext.php', $_params_); ?> + +endContent(); ?> \ No newline at end of file diff --git a/protected/humhub/modules/notification/views/notification/default.php b/protected/humhub/modules/notification/views/notification/default.php deleted file mode 100644 index 1c69925a76..0000000000 --- a/protected/humhub/modules/notification/views/notification/default.php +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/protected/humhub/modules/notification/views/notification/mail/default.php b/protected/humhub/modules/notification/views/notification/mail/default.php deleted file mode 100644 index 1c69925a76..0000000000 --- a/protected/humhub/modules/notification/views/notification/mail/default.php +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/protected/humhub/modules/notification/views/notification/mail/plaintext/default.php b/protected/humhub/modules/notification/views/notification/mail/plaintext/default.php deleted file mode 100644 index 039a97d3d5..0000000000 --- a/protected/humhub/modules/notification/views/notification/mail/plaintext/default.php +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/protected/humhub/modules/notification/widgets/MailContentContainerImage.php b/protected/humhub/modules/notification/widgets/MailContentContainerImage.php new file mode 100644 index 0000000000..7649575bd4 --- /dev/null +++ b/protected/humhub/modules/notification/widgets/MailContentContainerImage.php @@ -0,0 +1,44 @@ +container instanceof Space) + ? $this->container->createUrl('/space/space', [], true) + : $this->container->createUrl('/user/profile', [], true); + + return $this->render('mailContentContainerImage', [ + 'container' => $this->container, + 'url' => $url, + ]); + } + +} + +?> \ No newline at end of file diff --git a/protected/humhub/modules/notification/widgets/MailContentContainerInfoBox.php b/protected/humhub/modules/notification/widgets/MailContentContainerInfoBox.php new file mode 100644 index 0000000000..e79cf34a80 --- /dev/null +++ b/protected/humhub/modules/notification/widgets/MailContentContainerInfoBox.php @@ -0,0 +1,44 @@ +container instanceof \humhub\modules\space\models\Space) { + return $this->render('contentContainerInfoBox', [ + 'container' => $this->container, + 'url' => $this->container->createUrl('/space/space', [], true), + 'description' => Helpers::trimText($this->container->description, 60) + + ]); + } else if ($this->container instanceof \humhub\modules\user\models\User) { + return $this->render('contentContainerInfoBox', [ + 'container' => $this->container, + 'url' => $this->container->createUrl('/user/profile', [], true), + 'description' => Helpers::trimText($this->container->profile->title, 60) + + ]); + } + } +} diff --git a/protected/humhub/modules/notification/widgets/MailContentEntry.php b/protected/humhub/modules/notification/widgets/MailContentEntry.php new file mode 100644 index 0000000000..c405bdabf9 --- /dev/null +++ b/protected/humhub/modules/notification/widgets/MailContentEntry.php @@ -0,0 +1,82 @@ +content)) { + $content = $this->content; + } else if ($this->content instanceof Viewable) { + try { + $renderer = new ViewPathRenderer(['parent' => true, 'subPath' => 'mail']); + $content = $renderer->render($this->content); + } catch (\yii\base\ViewNotFoundException $e) { + Yii::error($e); + } + } else if ($this->content instanceof \humhub\modules\content\interfaces\ContentOwner) { + $content = RichText::widget(['text' => $this->content->getContentDescription(), 'minimal' => true]); + } + + + return $this->render('mailContentEntry', [ + 'originator' => $this->originator, + 'content' => $content, + 'space' => $this->space, + 'date' => $this->date, + 'isComment' => $this->isComment, + ]); + } + +} + +?> \ No newline at end of file diff --git a/protected/humhub/modules/notification/widgets/Overview.php b/protected/humhub/modules/notification/widgets/Overview.php index 7a644b87e2..0db4990d68 100644 --- a/protected/humhub/modules/notification/widgets/Overview.php +++ b/protected/humhub/modules/notification/widgets/Overview.php @@ -11,10 +11,10 @@ namespace humhub\modules\notification\widgets; use Yii; /** - * NotificationListWidget shows an stream of notifications for an user at the top menu. + * Notificaiton overview widget. * - * @author andystrobel - * @since 0.5 + * @author buddha + * @since 1.1 */ class Overview extends \yii\base\Widget { @@ -24,8 +24,9 @@ class Overview extends \yii\base\Widget */ public function run() { - if (Yii::$app->user->isGuest) + if (Yii::$app->user->isGuest) { return; + } return $this->render('overview', array( 'update' => \humhub\modules\notification\controllers\ListController::getUpdates(), diff --git a/protected/humhub/modules/notification/widgets/views/contentContainerInfoBox.php b/protected/humhub/modules/notification/widgets/views/contentContainerInfoBox.php new file mode 100644 index 0000000000..6611593299 --- /dev/null +++ b/protected/humhub/modules/notification/widgets/views/contentContainerInfoBox.php @@ -0,0 +1,36 @@ + +
- - - - - - - - - - -
- - - - - " - width="50" - alt="" - style="max-width:50px; display:block !important; border-radius: 4px;" - border="0" hspace="0" vspace="0"/> - - - - - - - - - - -
- - - - - - ( - - name); ?> - ) - - -
- -
+
+
- diff --git a/protected/humhub/modules/notification/views/layouts/mail_plaintext.php b/protected/humhub/modules/notification/views/layouts/mail_plaintext.php index fe41819041..6f79b4e87e 100644 --- a/protected/humhub/modules/notification/views/layouts/mail_plaintext.php +++ b/protected/humhub/modules/notification/views/layouts/mail_plaintext.php @@ -4,10 +4,10 @@ use yii\helpers\Html; ?> - + -( name); ?>) +( name); ?>) -: +: diff --git a/protected/humhub/modules/content/views/mails/Update.php b/protected/humhub/modules/notification/views/mails/Update.php similarity index 93% rename from protected/humhub/modules/content/views/mails/Update.php rename to protected/humhub/modules/notification/views/mails/Update.php index 51ce25b597..4c0e2fd678 100644 --- a/protected/humhub/modules/content/views/mails/Update.php +++ b/protected/humhub/modules/notification/views/mails/Update.php @@ -1,6 +1,6 @@ +
- @@ -37,11 +37,10 @@
- -
+ + + + + + + + + +
+ $container]); ?> + + + + + + + + +
+ + displayName) ?> + +
+ +
+
\ No newline at end of file diff --git a/protected/humhub/modules/notification/widgets/views/mailContentContainerImage.php b/protected/humhub/modules/notification/widgets/views/mailContentContainerImage.php new file mode 100644 index 0000000000..2a98981345 --- /dev/null +++ b/protected/humhub/modules/notification/widgets/views/mailContentContainerImage.php @@ -0,0 +1,20 @@ + + + + " + width="50" + height="50" + alt="" + style="border-radius: 4px;" + border="0" hspace="0" vspace="0"/> + \ No newline at end of file diff --git a/protected/humhub/modules/notification/widgets/views/mailContentEntry.php b/protected/humhub/modules/notification/widgets/views/mailContentEntry.php new file mode 100644 index 0000000000..485e2ab068 --- /dev/null +++ b/protected/humhub/modules/notification/widgets/views/mailContentEntry.php @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + +
+ + + $originator]); ?> + + + + + + + + + + + + + + + +
+ + displayName ?> + + + + ► displayName) ?> + + + + + $date]) ?> + + +
+ + + profile->title); ?> +
+ +
+ + + +
\ No newline at end of file diff --git a/protected/humhub/modules/space/notifications/Invite.php b/protected/humhub/modules/space/notifications/Invite.php index f12c365d70..8143e1fa1c 100644 --- a/protected/humhub/modules/space/notifications/Invite.php +++ b/protected/humhub/modules/space/notifications/Invite.php @@ -25,11 +25,16 @@ class Invite extends BaseNotification */ public $moduleId = "space"; + /** + * @inheritdoc + */ + public $viewName = "invite"; + /** * @inheritdoc */ public $markAsSeenOnClick = false; - + /** * @inheritdoc */ @@ -37,6 +42,25 @@ class Invite extends BaseNotification { return new SpaceMemberNotificationCategory; } + + /** + * @inheritdoc + */ + public function getSpace() + { + return $this->source; + } + + /** + * @inheritdoc + */ + public function getTitle(\humhub\modules\user\models\User $user) + { + return Yii::t('SpaceModule.notification', '{displayName} just invited you to the space {spaceName}', array( + '{displayName}' => Html::encode($this->originator->displayName), + '{spaceName}' => Html::encode($this->getSpace()->name) + )); + } /** * @inheritdoc @@ -45,7 +69,7 @@ class Invite extends BaseNotification { return Yii::t('SpaceModule.notification', '{displayName} invited you to the space {spaceName}', array( '{displayName}' => Html::tag('strong', Html::encode($this->originator->displayName)), - '{spaceName}' => Html::tag('strong', Html::encode($this->source->name)) + '{spaceName}' => Html::tag('strong', Html::encode($this->getSpace()->name)) )); } diff --git a/protected/humhub/modules/space/notifications/InviteAccepted.php b/protected/humhub/modules/space/notifications/InviteAccepted.php index 3ab68cace7..1394a00b1d 100644 --- a/protected/humhub/modules/space/notifications/InviteAccepted.php +++ b/protected/humhub/modules/space/notifications/InviteAccepted.php @@ -27,6 +27,11 @@ class InviteAccepted extends BaseNotification */ public $moduleId = "space"; + /** + * @inheritdoc + */ + public $viewName = "inviteDeclined"; + /** * @inheritdoc */ @@ -34,16 +39,27 @@ class InviteAccepted extends BaseNotification { return new SpaceMemberNotificationCategory; } + + /** + * @inheritdoc + */ + public function getTitle(\humhub\modules\user\models\User $user) + { + return Yii::t('SpaceModule.notification', '{displayName} accepted your invite for the space {spaceName}', [ + '{displayName}' => Html::encode($this->originator->displayName), + '{spaceName}' => Html::encode($this->source->name) + ]); + } /** * @inheritdoc */ public function html() { - return Yii::t('SpaceModule.notification', '{displayName} accepted your invite for the space {spaceName}', array( + return Yii::t('SpaceModule.notification', '{displayName} accepted your invite for the space {spaceName}', [ '{displayName}' => Html::tag('strong', Html::encode($this->originator->displayName)), '{spaceName}' => Html::tag('strong', Html::encode($this->source->name)) - )); + ]); } } diff --git a/protected/humhub/modules/space/notifications/InviteDeclined.php b/protected/humhub/modules/space/notifications/InviteDeclined.php index e193928942..df52993983 100644 --- a/protected/humhub/modules/space/notifications/InviteDeclined.php +++ b/protected/humhub/modules/space/notifications/InviteDeclined.php @@ -26,7 +26,12 @@ class InviteDeclined extends BaseNotification * @inheritdoc */ public $moduleId = "space"; - + + /** + * @inheritdoc + */ + public $viewName = "inviteDeclined"; + /** * @inheritdoc */ @@ -35,15 +40,31 @@ class InviteDeclined extends BaseNotification return new SpaceMemberNotificationCategory; } + /** + * @inheritdoc + */ + public function getSpace() + { + return $this->source; + } + + public function getTitle(\humhub\modules\user\models\User $user) + { + return Yii::t('SpaceModule.notification', '{displayName} declined your invite for the space {spaceName}', [ + '{displayName}' => Html::encode($this->originator->displayName), + '{spaceName}' => Html::encode($this->getSpace()->name) + ]); + } + /** * @inheritdoc */ public function html() { - return Yii::t('SpaceModule.notification', '{displayName} declined your invite for the space {spaceName}', array( + return Yii::t('SpaceModule.notification', '{displayName} declined your invite for the space {spaceName}', [ '{displayName}' => Html::tag('strong', Html::encode($this->originator->displayName)), - '{spaceName}' => Html::tag('strong', Html::encode($this->source->name)) - )); + '{spaceName}' => Html::tag('strong', Html::encode($this->getSpace()->name)) + ]); } } diff --git a/protected/humhub/modules/space/notifications/views/mails/invite.php b/protected/humhub/modules/space/notifications/views/mails/invite.php new file mode 100644 index 0000000000..36e7229a9c --- /dev/null +++ b/protected/humhub/modules/space/notifications/views/mails/invite.php @@ -0,0 +1,41 @@ + + +beginContent('@notification/views/layouts/mail.php', $_params_); ?> + + + + + + + + + + + +
+ html(); ?> +
+ $space])?> +
+endContent(); \ No newline at end of file diff --git a/protected/humhub/modules/space/notifications/views/mails/inviteAccepted.php b/protected/humhub/modules/space/notifications/views/mails/inviteAccepted.php new file mode 100644 index 0000000000..8541d83fd9 --- /dev/null +++ b/protected/humhub/modules/space/notifications/views/mails/inviteAccepted.php @@ -0,0 +1,51 @@ + + +beginContent('@notification/views/layouts/mail.php', $_params_); ?> + + + + + + + + + + +
+ html(); ?> +
+ + + + + + + + + + + +
$originator])?> $space])?>
+
+endContent(); \ No newline at end of file diff --git a/protected/humhub/modules/space/notifications/views/mails/inviteDeclined.php b/protected/humhub/modules/space/notifications/views/mails/inviteDeclined.php new file mode 100644 index 0000000000..93675ea9e1 --- /dev/null +++ b/protected/humhub/modules/space/notifications/views/mails/inviteDeclined.php @@ -0,0 +1,51 @@ + + +beginContent('@notification/views/layouts/mail.php', $_params_); ?> + + + + + + + + + + +
+ html(); ?> +
+ + + + + + + + + + + +
$originator])?> $space])?>
+
+endContent(); \ No newline at end of file diff --git a/protected/humhub/modules/space/tests/codeception/_support/_generated/UnitTesterActions.php b/protected/humhub/modules/space/tests/codeception/_support/_generated/UnitTesterActions.php index 50813335a5..768814bdb3 100644 --- a/protected/humhub/modules/space/tests/codeception/_support/_generated/UnitTesterActions.php +++ b/protected/humhub/modules/space/tests/codeception/_support/_generated/UnitTesterActions.php @@ -1,4 +1,4 @@ -becomeUser('User1'); - // Space 1 is approval space + $user1 = Yii::$app->user->getIdentity(); + + // Request Membership for Space 1 (approval join policity) $space = Space::findOne(['id' => 1]); $space->requestMembership(Yii::$app->user->id, 'Let me in!'); + // Check approval mails are send and notification $this->assertMailSent(1, 'Approval notification admin mail'); $this->assertHasNotification(\humhub\modules\space\notifications\ApprovalRequest::class, $space, Yii::$app->user->id, 'Approval Request Notification'); - $membership = \humhub\modules\space\models\Membership::findOne(['space_id' => 1, 'user_id' => Yii::$app->user->id]); + $membership = Membership::findOne(['space_id' => 1, 'user_id' => Yii::$app->user->id]); $this->assertNotNull($membership); $this->assertEquals($membership->status, \humhub\modules\space\models\Membership::STATUS_APPLICANT); @@ -32,6 +36,18 @@ class ApprovalTest extends HumHubDbTestCase $space->addMember(2); $this->assertMailSent(2, 'Approval notification admin mail'); $this->assertHasNotification(\humhub\modules\space\notifications\ApprovalRequestAccepted::class, $space, 1, 'Approval Accepted Notification'); + + $memberships = Membership::findByUser($user1)->all(); + $this->assertNotEmpty($memberships, 'get all memberships of user query.'); + $match = null; + + foreach($memberships as $membership) { + if($membership->user_id == $user1->id) { + $match = $membership; + } + } + + $this->assertNotNull($match); } public function testJoinPolicityApprovalDecline() diff --git a/protected/humhub/modules/space/tests/codeception/unit/SpaceFollowTest.php b/protected/humhub/modules/space/tests/codeception/unit/SpaceFollowTest.php new file mode 100644 index 0000000000..1e851cf955 --- /dev/null +++ b/protected/humhub/modules/space/tests/codeception/unit/SpaceFollowTest.php @@ -0,0 +1,47 @@ +becomeUser('User1'); + + // Follow Space 2 + $space = Space::findOne(['id' => 2]); + $space->follow(null, false); + + // Check if follow record was saved + $follow = Follow::findOne(['object_model' => Space::class, 'object_id' => 2, 'user_id' => 2]); + $this->assertNotNull($follow); + $this->assertFalse(boolval($follow->send_notifications)); + + // Get all spaces this user follows and check if the new space is included + $spaces = Follow::getFollowedSpacesQuery(Yii::$app->user->getIdentity())->all(); + $this->assertEquals(count($spaces), 1); + $this->assertEquals($spaces[0]->id, 2); + + // Get all followers of Space 2 and check if the user is included + $followers = Follow::getFollowersQuery($space)->all(); + $this->assertEquals(count($followers), 2); + + if($followers[0]->id == 2) { + $this->assertTrue(true); + } else if($followers[1]->id == 2) { + $this->assertTrue(true); + } else { + $this->assertTrue(false, 'User not in follower list.'); + } + } + +} diff --git a/protected/humhub/modules/space/widgets/HeaderControlsMenu.php b/protected/humhub/modules/space/widgets/HeaderControlsMenu.php index 2af29bf359..21c0283b9f 100644 --- a/protected/humhub/modules/space/widgets/HeaderControlsMenu.php +++ b/protected/humhub/modules/space/widgets/HeaderControlsMenu.php @@ -78,7 +78,7 @@ class HeaderControlsMenu extends \humhub\widgets\BaseMenu if (!$membership->send_notifications) { $this->addItem(array( - 'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'Receive notifications'), + 'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'Receive Notifications for new content'), 'group' => 'admin', 'url' => $this->space->createUrl('/space/membership/receive-notifications'), 'icon' => '', @@ -88,7 +88,7 @@ class HeaderControlsMenu extends \humhub\widgets\BaseMenu )); } else { $this->addItem(array( - 'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'Don\'t receive notifications' ), + 'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'Don\'t receive notifications for new content'), 'group' => 'admin', 'url' => $this->space->createUrl('/space/membership/revoke-notifications'), 'icon' => '', diff --git a/protected/humhub/modules/user/models/User.php b/protected/humhub/modules/user/models/User.php index 402d6982af..d95f72ca13 100644 --- a/protected/humhub/modules/user/models/User.php +++ b/protected/humhub/modules/user/models/User.php @@ -469,6 +469,18 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte return false; } + + /** + * Checks if the given $user instance shares the same identity with this + * user instance. + * + * @param \humhub\modules\user\models\User $user + * @return boolean + */ + public function is(User $user) + { + return $user->id === $this->id; + } /** * @inheritdoc diff --git a/protected/humhub/modules/user/notifications/Followed.php b/protected/humhub/modules/user/notifications/Followed.php index 79dd9ef620..a66a6aaccb 100644 --- a/protected/humhub/modules/user/notifications/Followed.php +++ b/protected/humhub/modules/user/notifications/Followed.php @@ -24,6 +24,11 @@ class Followed extends BaseNotification */ public $moduleId = 'user'; + /** + * @inheritdoc + */ + public $viewName = 'followed'; + /** * @inheritdoc */ @@ -40,14 +45,24 @@ class Followed extends BaseNotification return $this->originator->getUrl(); } + /** + * @inheritdoc + */ + public function getTitle(\humhub\modules\user\models\User $user) + { + return Yii::t('UserModule.notification', '{displayName} is now following you', [ + 'displayName' => Html::encode($this->originator->displayName), + ]); + } + /** * @inheritdoc */ public function html() { - return Yii::t('UserModule.notification', '{displayName} is now following you.', array( + return Yii::t('UserModule.notification', '{displayName} is now following you.', [ 'displayName' => Html::tag('strong', Html::encode($this->originator->displayName)), - )); + ]); } } diff --git a/protected/humhub/modules/user/notifications/Mentioned.php b/protected/humhub/modules/user/notifications/Mentioned.php index a403f3c266..10028c4501 100644 --- a/protected/humhub/modules/user/notifications/Mentioned.php +++ b/protected/humhub/modules/user/notifications/Mentioned.php @@ -19,6 +19,11 @@ use humhub\modules\notification\components\BaseNotification; class Mentioned extends BaseNotification { + /** + * @inheritdoc + */ + public $viewName = 'mentioned'; + /** * @inheritdoc */ @@ -31,6 +36,18 @@ class Mentioned extends BaseNotification { return new MentionedNotificationCategory; } + + /** + * @inheritdoc + */ + public function getViewName() + { + if($this->source instanceof \humhub\modules\comment\models\Comment) { + return 'mentionedComment'; + } + + return 'mentioned'; + } /** * inheritdoc @@ -45,6 +62,18 @@ class Mentioned extends BaseNotification return parent::send($user); } + /** + * inheritdoc + */ + public function getTitle(\humhub\modules\user\models\User $user) + { + return Yii::t('UserModule.notification', "{displayName} just mentioned you in {contentTitle} \"{preview}\"", [ + 'displayName' => Html::encode($this->originator->displayName), + 'contentTitle' => $this->getContentName(), + 'preview' => $this->getContentPreview() + ]); + } + /** * @inheritdoc */ diff --git a/protected/humhub/modules/user/notifications/views/mails/followed.php b/protected/humhub/modules/user/notifications/views/mails/followed.php new file mode 100644 index 0000000000..38471e04f4 --- /dev/null +++ b/protected/humhub/modules/user/notifications/views/mails/followed.php @@ -0,0 +1,32 @@ + + +beginContent('@notification/views/layouts/mail.php', $_params_); ?> + $originator, + 'content' => $viewable->html(), + 'date' => $date, + 'space' => $space +]) +?> +endContent(); \ No newline at end of file diff --git a/protected/humhub/modules/user/notifications/views/mails/mentioned.php b/protected/humhub/modules/user/notifications/views/mails/mentioned.php new file mode 100644 index 0000000000..b2e755b675 --- /dev/null +++ b/protected/humhub/modules/user/notifications/views/mails/mentioned.php @@ -0,0 +1,24 @@ + +beginContent('@notification/views/layouts/mail.php', $_params_); ?> + $originator, + 'content' => $viewable->source, + 'date' => $date, + 'space' => $space +]) +?> +endContent(); \ No newline at end of file diff --git a/protected/humhub/modules/user/notifications/views/mails/mentionedComment.php b/protected/humhub/modules/user/notifications/views/mails/mentionedComment.php new file mode 100644 index 0000000000..bb1f2c8979 --- /dev/null +++ b/protected/humhub/modules/user/notifications/views/mails/mentionedComment.php @@ -0,0 +1,57 @@ + +beginContent('@notification/views/layouts/mail.php', $_params_); ?> + +source; ?> +getCommentedRecord() ?> + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ $originator, + 'content' => $comment, + 'date' => $date, + 'space' => $space, + 'isComment' => true + ]); + ?> +
+
+ $contentRecord->owner, + 'content' => $contentRecord, + 'date' => $date, + 'space' => $space + ]); + ?> +
+endContent(); diff --git a/protected/humhub/modules/user/tests/codeception/_support/_generated/UnitTesterActions.php b/protected/humhub/modules/user/tests/codeception/_support/_generated/UnitTesterActions.php index c915275b21..1b2692beaa 100644 --- a/protected/humhub/modules/user/tests/codeception/_support/_generated/UnitTesterActions.php +++ b/protected/humhub/modules/user/tests/codeception/_support/_generated/UnitTesterActions.php @@ -1,4 +1,4 @@ -becomeUser('User2'); $space = Space::findOne(['id' => 1]); - $post = new \humhub\modules\post\models\Post(['message' => '@-u01e50e0d-82cd-41fc-8b0c-552392f5839c']); + $post = new Post(['message' => '@-u01e50e0d-82cd-41fc-8b0c-552392f5839c']); $post->content->container = $space; $post->save(); @@ -27,5 +29,21 @@ class MentionTest extends HumHubDbTestCase $this->assertHasNotification(Mentioned::class, $post); $this->assertMailSent(1, 'Mentioned Notification'); } + + public function testCreateComment() + { + $this->becomeUser('User2'); + + $comment = new Comment([ + 'message' => 'Hi @-u01e50e0d-82cd-41fc-8b0c-552392f5839c', + 'object_model' => Post::className(), + 'object_id' => 7 + ]); + $comment->save(); + + $this->assertHasNotification(Mentioned::class, $comment); + // Commented and Mentioned mail + $this->assertMailSent(2, 'Comment Notification Mail sent'); + } } diff --git a/protected/humhub/tests/codeception/_support/_generated/UnitTesterActions.php b/protected/humhub/tests/codeception/_support/_generated/UnitTesterActions.php index 2b7b5fa796..e044d14ffe 100644 --- a/protected/humhub/tests/codeception/_support/_generated/UnitTesterActions.php +++ b/protected/humhub/tests/codeception/_support/_generated/UnitTesterActions.php @@ -1,4 +1,4 @@ - 'nonExistent']); + $renderer = new DefaultViewPathRenderer(['defaultView' => '@tests/codeception/unit/components/rendering/views/parent.php']); + $this->assertEquals('

ParentView:TestTitle

', $renderer->render($viewable)); + } + + public function testDefaultPathView() + { + $viewable = new TestViewable(['viewName' => 'parent2']); + $renderer = new DefaultViewPathRenderer([ + 'defaultViewPath' => '@tests/codeception/unit/components/rendering/views', + 'defaultView' => '@tests/codeception/unit/components/rendering/views/parent.php' + ]); + $this->assertEquals('

ParentView2:TestTitle

', $renderer->render($viewable)); + } + + public function testViewFoundView() + { + $viewable = new TestViewable(['viewName' => 'testView']); + $renderer = new DefaultViewPathRenderer([ + 'defaultViewPath' => '@tests/codeception/unit/components/rendering/views', + 'defaultView' => '@tests/codeception/unit/components/rendering/views/parent.php' + ]); + $this->assertEquals('
TestTitle
', $renderer->render($viewable)); + } + + public function testViewFoundSettingsView() + { + $viewable = new TestViewable(['viewName' => 'mail']); + $renderer = new DefaultViewPathRenderer([ + 'parent' => true, + 'subPath' => 'mails', + 'defaultViewPath' => '@tests/codeception/unit/components/rendering/views', + 'defaultView' => '@tests/codeception/unit/components/rendering/views/parent.php' + ]); + $this->assertEquals('

MailView:TestTitle

', $renderer->render($viewable)); + } +} diff --git a/protected/humhub/tests/codeception/unit/components/rendering/LayoutRendererTest.php b/protected/humhub/tests/codeception/unit/components/rendering/LayoutRendererTest.php new file mode 100644 index 0000000000..20e9925ad5 --- /dev/null +++ b/protected/humhub/tests/codeception/unit/components/rendering/LayoutRendererTest.php @@ -0,0 +1,28 @@ + 'parent']); + $renderer = new LayoutRenderer(['parent' => true, 'layout' => '@tests/codeception/unit/components/rendering/views/layouts/testLayout.php']); + $this->assertEquals('
TestLayout:

ParentView:TestTitle

', $renderer->render($viewable)); + } + + public function testNoLayout() + { + $viewable = new TestViewable(['viewName' => 'parent']); + $renderer = new LayoutRenderer(['parent' => true]); + $this->assertEquals('

ParentView:TestTitle

', $renderer->render($viewable)); + } +} diff --git a/protected/humhub/tests/codeception/unit/components/rendering/MailLayoutRendererTest.php b/protected/humhub/tests/codeception/unit/components/rendering/MailLayoutRendererTest.php new file mode 100644 index 0000000000..bae9d0bd81 --- /dev/null +++ b/protected/humhub/tests/codeception/unit/components/rendering/MailLayoutRendererTest.php @@ -0,0 +1,41 @@ + 'parent']); + $renderer = new MailLayoutRenderer(['parent' => true, + 'textLayout' => '@tests/codeception/unit/components/rendering/views/layouts/testLayout.php']); + $this->assertEquals('TestLayout:TestViewText', $renderer->renderText($viewable)); + } + + public function testNoLayoutRenderText() + { + $viewable = new TestViewable(['viewName' => 'parent']); + $renderer = new MailLayoutRenderer(['parent' => true]); + $this->assertEquals('TestViewText', $renderer->renderText($viewable)); + } + + public function testNonExistingTextLayout() + { + try { + $viewable = new TestViewable(['viewName' => 'nonExisting']); + $renderer = new MailLayoutRenderer(['textLayout' => '@tests/codeception/unit/components/rendering/views/layouts/nonExsting.php']); + $renderer->renderText($viewable); + $this->assertTrue(false); + } catch (\yii\base\ViewNotFoundException $ex) { + $this->assertTrue(true); + } + } +} diff --git a/protected/humhub/tests/codeception/unit/components/rendering/MailRendererTest.php b/protected/humhub/tests/codeception/unit/components/rendering/MailRendererTest.php new file mode 100644 index 0000000000..c26393eeeb --- /dev/null +++ b/protected/humhub/tests/codeception/unit/components/rendering/MailRendererTest.php @@ -0,0 +1,42 @@ + 'testView']); + $renderer = new MailRenderer(['parent' => true, + 'defaultTextView' => '@tests/codeception/unit/components/rendering/lib/views', + 'defaultTextViewPath' => '@tests/codeception/unit/components/rendering/lib/views/specialView.php']); + $this->assertEquals('TextView:TestTitle', $renderer->renderText($viewable)); + } + + public function testNonExistingTextView() + { + $viewable = new TestViewable(['viewName' => 'nonExisting']); + $renderer = new MailRenderer(['parent' => true, + 'defaultTextView' => '@tests/codeception/unit/components/rendering/lib/views/testView.php', + 'defaultTextViewPath' => '@tests/codeception/unit/components/rendering/lib/views']); + $this->assertEquals('TestTitle', $renderer->renderText($viewable)); + } + + public function testExistingViewPathTextView() + { + $viewable = new TestViewable(['viewName' => 'specialView']); + $renderer = new MailRenderer(['parent' => true, + 'defaultTextView' => '@tests/codeception/unit/components/rendering/lib/views/testView.php', + 'defaultTextViewPath' => '@tests/codeception/unit/components/rendering/lib/views']); + $this->assertEquals('SpecialView', $renderer->renderText($viewable)); + } + +} diff --git a/protected/humhub/tests/codeception/unit/components/rendering/ViewPathRendererTest.php b/protected/humhub/tests/codeception/unit/components/rendering/ViewPathRendererTest.php new file mode 100644 index 0000000000..7d40444db3 --- /dev/null +++ b/protected/humhub/tests/codeception/unit/components/rendering/ViewPathRendererTest.php @@ -0,0 +1,62 @@ + 'testView']); + $renderer = new ViewPathRenderer(); + $this->assertEquals('
TestTitle
', $renderer->render($viewable)); + } + + public function testViewPathRendererSuffix() + { + $viewable = new TestViewable(['viewName' => 'testView.php']); + $renderer = new ViewPathRenderer(); + $this->assertEquals('
TestTitle
', $renderer->render($viewable)); + } + + public function testSetViewPath() + { + $viewable = new TestViewable(['viewName' => 'view2']); + $renderer = new ViewPathRenderer(['viewPath' => '@tests/codeception/unit/components/rendering/lib/views2']); + $this->assertEquals('

TestTitle

', $renderer->render($viewable)); + } + + public function testParentSettingViewPath() + { + $viewable = new TestViewable(['viewName' => 'parent']); + $renderer = new ViewPathRenderer(['parent' => true]); + $this->assertEquals('

ParentView:TestTitle

', $renderer->render($viewable)); + } + + public function testSubPathSettingViewPath() + { + $viewable = new TestViewable(['viewName' => 'mail']); + $renderer = new ViewPathRenderer(['parent' => true, 'subPath' => 'mails']); + $this->assertEquals('

MailView:TestTitle

', $renderer->render($viewable)); + } + + public function testNonExistingViewPath() + { + $viewable = new TestViewable(['viewName' => 'nonExisting']); + $renderer = new ViewPathRenderer(['parent' => true, 'subPath' => 'mails']); + + try { + $renderer->render($viewable); + $this->assertTrue(false); + } catch (\yii\base\ViewNotFoundException $ex) { + $this->assertTrue(true); + } + } +} diff --git a/protected/humhub/tests/codeception/unit/components/rendering/lib/TestViewable.php b/protected/humhub/tests/codeception/unit/components/rendering/lib/TestViewable.php new file mode 100644 index 0000000000..6b08a46797 --- /dev/null +++ b/protected/humhub/tests/codeception/unit/components/rendering/lib/TestViewable.php @@ -0,0 +1,39 @@ +viewName; + } + + public function getViewParams($params = []) + { + return \yii\helpers\ArrayHelper::merge(['title' => 'TestTitle'], $params); + } + + public function html() + { + return '

TestView

'; + } + + public function json() + { + return null; + } + + public function text() + { + return 'TestViewText'; + } + +} diff --git a/protected/humhub/tests/codeception/unit/components/rendering/lib/views/specialView.php b/protected/humhub/tests/codeception/unit/components/rendering/lib/views/specialView.php new file mode 100644 index 0000000000..3e4fdd3115 --- /dev/null +++ b/protected/humhub/tests/codeception/unit/components/rendering/lib/views/specialView.php @@ -0,0 +1,4 @@ +'.$title.'
'; + diff --git a/protected/humhub/tests/codeception/unit/components/rendering/lib/views2/view2.php b/protected/humhub/tests/codeception/unit/components/rendering/lib/views2/view2.php new file mode 100644 index 0000000000..b088d60003 --- /dev/null +++ b/protected/humhub/tests/codeception/unit/components/rendering/lib/views2/view2.php @@ -0,0 +1,4 @@ +'.$title.''; + diff --git a/protected/humhub/tests/codeception/unit/components/rendering/views/layouts/testLayout.php b/protected/humhub/tests/codeception/unit/components/rendering/views/layouts/testLayout.php new file mode 100644 index 0000000000..e147969bf3 --- /dev/null +++ b/protected/humhub/tests/codeception/unit/components/rendering/views/layouts/testLayout.php @@ -0,0 +1,3 @@ +TestLayout:'.$content.''; + diff --git a/protected/humhub/tests/codeception/unit/components/rendering/views/mails/mail.php b/protected/humhub/tests/codeception/unit/components/rendering/views/mails/mail.php new file mode 100644 index 0000000000..0b0c1fd921 --- /dev/null +++ b/protected/humhub/tests/codeception/unit/components/rendering/views/mails/mail.php @@ -0,0 +1,4 @@ +MailView:'.$title.''; + diff --git a/protected/humhub/tests/codeception/unit/components/rendering/views/mails/plaintext/testView.php b/protected/humhub/tests/codeception/unit/components/rendering/views/mails/plaintext/testView.php new file mode 100644 index 0000000000..1742506f37 --- /dev/null +++ b/protected/humhub/tests/codeception/unit/components/rendering/views/mails/plaintext/testView.php @@ -0,0 +1,4 @@ +ParentView:'.$title.''; + diff --git a/protected/humhub/tests/codeception/unit/components/rendering/views/parent2.php b/protected/humhub/tests/codeception/unit/components/rendering/views/parent2.php new file mode 100644 index 0000000000..9eca9ad39e --- /dev/null +++ b/protected/humhub/tests/codeception/unit/components/rendering/views/parent2.php @@ -0,0 +1,4 @@ +ParentView2:'.$title.''; + diff --git a/protected/humhub/tests/config/common.php b/protected/humhub/tests/config/common.php index e73e31f482..e24da9ba11 100644 --- a/protected/humhub/tests/config/common.php +++ b/protected/humhub/tests/config/common.php @@ -4,23 +4,29 @@ return [ 'components' => [ 'db' => [ 'dsn' => 'mysql:host=localhost;dbname=humhub_test', - 'username' => 'root', - 'password' => 'kingbuddha', + 'username' => 'travis', + 'password' => '', 'charset' => 'utf8', - 'attributes'=>[ + 'attributes' => [ PDO::ATTR_PERSISTENT => true ] - ], - 'view' => - array ( - 'theme' => - array ( - 'name' => 'HumHub', - 'basePath' => '@webroot/themes/HumHub', - ), - ), ], + 'view' => [ + 'theme' => + [ + 'name' => 'HumHub', + 'basePath' => '@webroot/themes/HumHub', + ], + ], + 'queue' => [ + 'class' => humhub\components\queue\Queue::class, + 'driver' => [ + 'class' => 'humhub\components\queue\driver\Instant', + ], + ], + ], 'params' => [ 'installed' => true, + 'moduleAutoloadPaths' => ['/home/travis/build/humhub'], ] ]; diff --git a/themes/HumHub/css/theme.less b/themes/HumHub/css/theme.deprecated.less old mode 100755 new mode 100644 similarity index 100% rename from themes/HumHub/css/theme.less rename to themes/HumHub/css/theme.deprecated.less