-
Notifications
You must be signed in to change notification settings - Fork 18
Publish notification when adding user #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,3 +21,4 @@ | |
|
|
||
| $app = new \OCA\CustomGroups\Application(); | ||
| $app->registerGroupBackend(); | ||
| $app->registerNotifier(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| <?php | ||
| /** | ||
| * @author Vincent Petry <pvince81@owncloud.com> | ||
| * | ||
| * @copyright Copyright (c) 2017, ownCloud GmbH | ||
| * @license AGPL-3.0 | ||
| * | ||
| * This code is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License, version 3, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License, version 3, | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/> | ||
| * | ||
| */ | ||
|
|
||
| namespace OCA\CustomGroups; | ||
|
|
||
| use OCP\L10N\IFactory; | ||
| use OCP\Notification\IManager; | ||
| use OCP\Notification\INotification; | ||
| use OCP\Notification\INotifier; | ||
| use OCA\CustomGroups\CustomGroupsDatabaseHandler; | ||
|
|
||
| class Notifier implements INotifier { | ||
|
|
||
| /** | ||
| * @var IFactory | ||
| */ | ||
| protected $l10NFactory; | ||
|
|
||
| /** | ||
| * @var CustomGroupsDatabaseHandler | ||
| */ | ||
| protected $handler; | ||
|
|
||
| /** | ||
| * Notifier constructor. | ||
| * | ||
| * @param IFactory $l10NFactory | ||
| * @param CustomGroupsDatabaseHandler $handler | ||
| */ | ||
| public function __construct(IFactory $l10NFactory, CustomGroupsDatabaseHandler $handler) { | ||
| $this->l10NFactory = $l10NFactory; | ||
| $this->handler = $handler; | ||
| } | ||
|
|
||
| /** | ||
| * @param INotification $notification | ||
| * @param string $languageCode The code of the language that should be used to prepare the notification | ||
| * @return INotification | ||
| * @throws \InvalidArgumentException When the notification was not prepared by a notifier | ||
| */ | ||
| public function prepare(INotification $notification, $languageCode) { | ||
| if ($notification->getApp() !== 'customgroups') { | ||
| throw new \InvalidArgumentException(); | ||
| } | ||
|
|
||
| $l = $this->l10NFactory->get('customgroups', $languageCode); | ||
| if ($notification->getObjectType() === 'customgroup') { | ||
| if ($notification->getSubject() === 'added_member') { | ||
| $notification->setParsedSubject( | ||
| $l->t('Added to group "%1$s" by "%2$s".', $notification->getSubjectParameters()) | ||
| ); | ||
| } | ||
| if ($notification->getMessage() === 'added_member') { | ||
| $notification->setParsedMessage( | ||
| $l->t('You have been added to the group "%1$s" by "%2$s".', $notification->getMessageParameters()) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| return $notification; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| <?php | ||
| /** | ||
| * @author Vincent Petry <pvince81@owncloud.com> | ||
| * | ||
| * @copyright Copyright (c) 2017, ownCloud GmbH | ||
| * @license AGPL-3.0 | ||
| * | ||
| * This code is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License, version 3, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License, version 3, | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/> | ||
| * | ||
| */ | ||
| namespace OCA\CustomGroups\Tests\unit; | ||
|
|
||
| use OCP\Notification\IManager; | ||
| use OCP\L10N\IFactory; | ||
| use OCA\CustomGroups\Notifier; | ||
| use OCA\CustomGroups\CustomGroupsDatabaseHandler; | ||
| use OCP\Notification\INotification; | ||
|
|
||
| /** | ||
| * Class NotifierTest | ||
| * | ||
| * @package OCA\CustomGroups\Tests\Unit | ||
| */ | ||
| class NotifierTest extends \Test\TestCase { | ||
|
|
||
| /** | ||
| * @var Notifier | ||
| */ | ||
| private $notifier; | ||
|
|
||
| /** | ||
| * @var CustomGroupsDatabaseHandler | ||
| */ | ||
| private $handler; | ||
|
|
||
| public function setUp() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. parent:setup? |
||
| parent::setUp(); | ||
|
|
||
| $this->handler = $this->createMock(CustomGroupsDatabaseHandler::class); | ||
|
|
||
| $this->notifier = new Notifier( | ||
| \OC::$server->getL10NFactory(), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mock?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't want to mock it... too many calls to it and in the end the default one works fine as it will return the same texts untranslated but formatted |
||
| $this->handler | ||
| ); | ||
| } | ||
|
|
||
| public function testPrepare() { | ||
| $notification = $this->createMock(INotification::class); | ||
|
|
||
| $notification->method('getApp')->willReturn('customgroups'); | ||
| $notification->method('getObjectType')->willReturn('customgroup'); | ||
| $notification->method('getSubject')->willReturn('added_member'); | ||
| $notification->method('getMessage')->willReturn('added_member'); | ||
| $notification->method('getSubjectParameters')->willReturn(['group1', 'user1']); | ||
| $notification->method('getMessageParameters')->willReturn(['group1', 'user1']); | ||
|
|
||
| $notification->expects($this->once()) | ||
| ->method('setParsedSubject') | ||
| ->with('Added to group "group1" by "user1".'); | ||
| $notification->expects($this->once()) | ||
| ->method('setParsedMessage') | ||
| ->with('You have been added to the group "group1" by "user1".'); | ||
|
|
||
| $notification = $this->notifier->prepare($notification, 'en_US'); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cries for info.xml enhancement ....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we had a generic service registration we wouldn't need to enhance core for everything out there
<services><service type="\OC\INotifier">\OCA\CustomGroups\Notifier</service></services>then core (or any app) could just find all services of a given type/namespace.
That was what I hoped to achieve with https://central.owncloud.org/t/service-based-app-imlpementation-to-solve-inter-app-dependencies/1615