Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/admin_notifications.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2018-02-16 15:39:30 +0300
committerJoas Schilling <coding@schilljs.com>2018-02-16 15:39:30 +0300
commit0f1e454b3bfb568927190376b4ec258ea12732db (patch)
treed2e8afa1e405fb5606a546381a331addce630148 /lib
parent3359ee584fc17937f7aacdebbed770d217d941e6 (diff)
This app is obsoleted with Notifications app for Nextcloud 14
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/AppInfo/Application.php41
-rw-r--r--lib/Controller/APIController.php109
-rw-r--r--lib/Notification/Notifier.php79
3 files changed, 29 insertions, 200 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 3c08909..4f0f64b 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -34,19 +34,36 @@ class Application extends App {
}
public function register() {
- $this->registerNotifier();
- }
+ $config = $this->getContainer()->getServer()->getConfig();
+
+ if ($config->getAppValue(self::APP_ID, 'published-deprecation-notification', 'no') === 'yes') {
+ return;
+ }
+
+ $notificationManager = $this->getContainer()->getServer()->getNotificationManager();
+ $groupManager = $this->getContainer()->getServer()->getGroupManager();
+
+ $notification = $notificationManager->createNotification();
+ $time = time();
+ $datetime = new \DateTime();
+ $datetime->setTimestamp($time);
+
+ try {
+ $notification->setApp(Application::APP_ID)
+ ->setDateTime($datetime)
+ ->setObject(Application::APP_ID, dechex($time))
+ ->setSubject('cli', ['App "admin_notifications" is obsolete'])
+ ->setMessage('cli', ['The functionality of the "admin_notifications" app has been merged into the default notifications app for Nextcloud 14. You can safely uninstall and delete the "admin_notifications" app, because it does not do anything anymore.']);
+ $admins = $groupManager->get('admin');
+ foreach ($admins->getUsers() as $admin) {
+ $notification->setUser($admin->getUID());
+ $notificationManager->notify($notification);
+ }
+ } catch (\InvalidArgumentException $e) {
+ return;
+ }
- protected function registerNotifier() {
- $this->getContainer()->getServer()->getNotificationManager()->registerNotifier(function() {
- return $this->getContainer()->query(Notifier::class);
- }, function() {
- $l = $this->getContainer()->getServer()->getL10NFactory()->get(self::APP_ID);
- return [
- 'id' => self::APP_ID,
- 'name' => $l->t('Admin notifications'),
- ];
- });
+ $config->setAppValue(self::APP_ID, 'published-deprecation-notification', 'yes');
}
}
diff --git a/lib/Controller/APIController.php b/lib/Controller/APIController.php
deleted file mode 100644
index 31387c7..0000000
--- a/lib/Controller/APIController.php
+++ /dev/null
@@ -1,109 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
- *
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * 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
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\AdminNotifications\Controller;
-
-use OCA\AdminNotifications\AppInfo\Application;
-use OCP\AppFramework\Http;
-use OCP\AppFramework\Http\DataResponse;
-use OCP\AppFramework\OCSController;
-use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\IRequest;
-use OCP\IUser;
-use OCP\IUserManager;
-use OCP\Notification\IManager;
-
-class APIController extends OCSController {
-
- /** @var ITimeFactory */
- protected $timeFactory;
-
- /** @var IUserManager */
- protected $userManager;
-
- /** @var IManager */
- protected $notificationManager;
-
- /**
- * @param string $appName
- * @param IRequest $request
- * @param ITimeFactory $timeFactory
- * @param IUserManager $userManager
- * @param IManager $notificationManager
- */
- public function __construct($appName, IRequest $request, ITimeFactory $timeFactory, IUserManager $userManager, IManager $notificationManager) {
- parent::__construct($appName, $request);
-
- $this->timeFactory = $timeFactory;
- $this->userManager = $userManager;
- $this->notificationManager = $notificationManager;
- }
-
- /**
- * @param string $userId
- * @param string $shortMessage
- * @param string $longMessage
- * @return DataResponse
- */
- public function generateNotification($userId, $shortMessage, $longMessage) {
- $shortMessage = (string) $shortMessage;
- $longMessage = (string) $longMessage;
-
- $user = $this->userManager->get($userId);
-
- if (!$user instanceof IUser) {
- return new DataResponse(null, Http::STATUS_NOT_FOUND);
- }
-
- if ($shortMessage === '' || strlen($shortMessage) > 255) {
- return new DataResponse(null, Http::STATUS_BAD_REQUEST);
- }
-
- if ($longMessage !== '' && strlen($longMessage) > 4000) {
- return new DataResponse(null, Http::STATUS_BAD_REQUEST);
- }
-
- $notification = $this->notificationManager->createNotification();
- $time = $this->timeFactory->getTime();
- $datetime = new \DateTime();
- $datetime->setTimestamp($time);
-
- try {
- $notification->setApp(Application::APP_ID)
- ->setUser($user->getUID())
- ->setDateTime($datetime)
- ->setObject(Application::APP_ID, dechex($time))
- ->setSubject('ocs', [$shortMessage]);
-
- if ($longMessage !== '') {
- $notification->setMessage('ocs', [$longMessage]);
- }
-
- $this->notificationManager->notify($notification);
- } catch (\InvalidArgumentException $e) {
- return new DataResponse(null, Http::STATUS_INTERNAL_SERVER_ERROR);
- }
-
- return new DataResponse();
- }
-}
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php
deleted file mode 100644
index 3c7c3f2..0000000
--- a/lib/Notification/Notifier.php
+++ /dev/null
@@ -1,79 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
- *
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * 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
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\AdminNotifications\Notification;
-
-
-use OCA\AdminNotifications\AppInfo\Application;
-use OCP\IURLGenerator;
-use OCP\L10N\IFactory;
-use OCP\Notification\INotification;
-use OCP\Notification\INotifier;
-
-class Notifier implements INotifier {
-
- /** @var IFactory */
- protected $l10nFactory;
-
- /** @var IURLGenerator */
- protected $urlGenerator;
-
- /**
- * @param IFactory $l10nFactory
- * @param IURLGenerator $urlGenerator
- */
- public function __construct(IFactory $l10nFactory, IURLGenerator $urlGenerator) {
- $this->l10nFactory = $l10nFactory;
- $this->urlGenerator = $urlGenerator;
- }
-
- /**
- * @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() !== Application::APP_ID) {
- throw new \InvalidArgumentException('Unknown app');
- }
-
- switch ($notification->getSubject()) {
- // Deal with known subjects
- case 'cli':
- case 'ocs':
- $subjectParams = $notification->getSubjectParameters();
- $notification->setParsedSubject($subjectParams[0]);
- $messageParams = $notification->getMessageParameters();
- if (isset($messageParams[0]) && $messageParams[0] !== '') {
- $notification->setParsedMessage($messageParams[0]);
- }
-
- $notification->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath(Application::APP_ID, 'app-dark.svg')));
- return $notification;
-
- default:
- throw new \InvalidArgumentException('Unknown subject');
- }
- }
-}