Add a URL to the notifications
This commit is contained in:
parent
12ec0dfe3c
commit
a1e872aad6
|
@ -30,6 +30,7 @@ use OCP\Http\Client\IClientService;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\IGroup;
|
use OCP\IGroup;
|
||||||
use OCP\IGroupManager;
|
use OCP\IGroupManager;
|
||||||
|
use OCP\IURLGenerator;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\Notification\IManager;
|
use OCP\Notification\IManager;
|
||||||
|
|
||||||
|
@ -50,6 +51,9 @@ class BackgroundJob extends TimedJob {
|
||||||
/** @var IClientService */
|
/** @var IClientService */
|
||||||
protected $client;
|
protected $client;
|
||||||
|
|
||||||
|
/** @var IURLGenerator */
|
||||||
|
protected $urlGenerator;
|
||||||
|
|
||||||
/** @var IUser[] */
|
/** @var IUser[] */
|
||||||
protected $users;
|
protected $users;
|
||||||
|
|
||||||
|
@ -61,8 +65,9 @@ class BackgroundJob extends TimedJob {
|
||||||
* @param IGroupManager $groupManager
|
* @param IGroupManager $groupManager
|
||||||
* @param IAppManager $appManager
|
* @param IAppManager $appManager
|
||||||
* @param IClientService $client
|
* @param IClientService $client
|
||||||
|
* @param IURLGenerator $urlGenerator
|
||||||
*/
|
*/
|
||||||
public function __construct(IConfig $config, IManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IClientService $client) {
|
public function __construct(IConfig $config, IManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IClientService $client, IURLGenerator $urlGenerator) {
|
||||||
// Run once a day
|
// Run once a day
|
||||||
$this->setInterval(60 * 60 * 24);
|
$this->setInterval(60 * 60 * 24);
|
||||||
|
|
||||||
|
@ -71,6 +76,7 @@ class BackgroundJob extends TimedJob {
|
||||||
$this->groupManager = $groupManager;
|
$this->groupManager = $groupManager;
|
||||||
$this->appManager = $appManager;
|
$this->appManager = $appManager;
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
|
$this->urlGenerator = $urlGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function run($argument) {
|
protected function run($argument) {
|
||||||
|
@ -91,7 +97,8 @@ class BackgroundJob extends TimedJob {
|
||||||
|
|
||||||
$status = $updater->check();
|
$status = $updater->check();
|
||||||
if (isset($status['version'])) {
|
if (isset($status['version'])) {
|
||||||
$this->createNotifications('core', $status['version']);
|
$url = $this->urlGenerator->linkToRouteAbsolute('settings_admin') . '#updater';
|
||||||
|
$this->createNotifications('core', $status['version'], $url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +110,8 @@ class BackgroundJob extends TimedJob {
|
||||||
foreach ($apps as $app) {
|
foreach ($apps as $app) {
|
||||||
$update = $this->isUpdateAvailable($app);
|
$update = $this->isUpdateAvailable($app);
|
||||||
if ($update !== false) {
|
if ($update !== false) {
|
||||||
$this->createNotifications($app, $update);
|
$url = $this->urlGenerator->linkToRouteAbsolute('settings.AppSettings.viewApps') . '#app-' . $app;
|
||||||
|
$this->createNotifications($app, $update, $url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,8 +121,9 @@ class BackgroundJob extends TimedJob {
|
||||||
*
|
*
|
||||||
* @param string $app
|
* @param string $app
|
||||||
* @param string $version
|
* @param string $version
|
||||||
|
* @param string $url
|
||||||
*/
|
*/
|
||||||
protected function createNotifications($app, $version) {
|
protected function createNotifications($app, $version, $url) {
|
||||||
$lastNotification = $this->config->getAppValue('updatenotification', $app, false);
|
$lastNotification = $this->config->getAppValue('updatenotification', $app, false);
|
||||||
if ($lastNotification === $version) {
|
if ($lastNotification === $version) {
|
||||||
// We already notified about this update
|
// We already notified about this update
|
||||||
|
@ -129,7 +138,8 @@ class BackgroundJob extends TimedJob {
|
||||||
$notification->setApp('updatenotification')
|
$notification->setApp('updatenotification')
|
||||||
->setDateTime(new \DateTime())
|
->setDateTime(new \DateTime())
|
||||||
->setObject($app, $version)
|
->setObject($app, $version)
|
||||||
->setSubject('update_available');
|
->setSubject('update_available')
|
||||||
|
->setLink($url);
|
||||||
|
|
||||||
foreach ($this->getUsersToNotify() as $uid) {
|
foreach ($this->getUsersToNotify() as $uid) {
|
||||||
$notification->setUser($uid);
|
$notification->setUser($uid);
|
||||||
|
|
|
@ -22,14 +22,12 @@
|
||||||
namespace OCA\UpdateNotification\Tests\Notification;
|
namespace OCA\UpdateNotification\Tests\Notification;
|
||||||
|
|
||||||
|
|
||||||
use OC\Installer;
|
|
||||||
use OC\Updater\VersionCheck;
|
|
||||||
use OCA\UpdateNotification\Notification\BackgroundJob;
|
use OCA\UpdateNotification\Notification\BackgroundJob;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
use OCP\Http\Client\IClientService;
|
use OCP\Http\Client\IClientService;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\IGroup;
|
|
||||||
use OCP\IGroupManager;
|
use OCP\IGroupManager;
|
||||||
|
use OCP\IURLGenerator;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\Notification\IManager;
|
use OCP\Notification\IManager;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
@ -46,6 +44,8 @@ class BackgroundJobTest extends TestCase {
|
||||||
protected $appManager;
|
protected $appManager;
|
||||||
/** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */
|
/** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $client;
|
protected $client;
|
||||||
|
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
protected $urlGenerator;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
@ -55,6 +55,7 @@ class BackgroundJobTest extends TestCase {
|
||||||
$this->groupManager = $this->getMock('OCP\IGroupManager');
|
$this->groupManager = $this->getMock('OCP\IGroupManager');
|
||||||
$this->appManager = $this->getMock('OCP\App\IAppManager');
|
$this->appManager = $this->getMock('OCP\App\IAppManager');
|
||||||
$this->client = $this->getMock('OCP\Http\Client\IClientService');
|
$this->client = $this->getMock('OCP\Http\Client\IClientService');
|
||||||
|
$this->urlGenerator = $this->getMock('OCP\IURLGenerator');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +69,8 @@ class BackgroundJobTest extends TestCase {
|
||||||
$this->notificationManager,
|
$this->notificationManager,
|
||||||
$this->groupManager,
|
$this->groupManager,
|
||||||
$this->appManager,
|
$this->appManager,
|
||||||
$this->client
|
$this->client,
|
||||||
|
$this->urlGenerator
|
||||||
);
|
);
|
||||||
} {
|
} {
|
||||||
return $this->getMockBuilder('OCA\UpdateNotification\Notification\BackgroundJob')
|
return $this->getMockBuilder('OCA\UpdateNotification\Notification\BackgroundJob')
|
||||||
|
@ -78,6 +80,7 @@ class BackgroundJobTest extends TestCase {
|
||||||
$this->groupManager,
|
$this->groupManager,
|
||||||
$this->appManager,
|
$this->appManager,
|
||||||
$this->client,
|
$this->client,
|
||||||
|
$this->urlGenerator,
|
||||||
])
|
])
|
||||||
->setMethods($methods)
|
->setMethods($methods)
|
||||||
->getMock();
|
->getMock();
|
||||||
|
@ -152,12 +155,20 @@ class BackgroundJobTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($notification === null) {
|
if ($notification === null) {
|
||||||
|
$this->urlGenerator->expects($this->never())
|
||||||
|
->method('linkToRouteAbsolute');
|
||||||
|
|
||||||
$job->expects($this->never())
|
$job->expects($this->never())
|
||||||
->method('createNotifications');
|
->method('createNotifications');
|
||||||
} else {
|
} else {
|
||||||
|
$this->urlGenerator->expects($this->once())
|
||||||
|
->method('linkToRouteAbsolute')
|
||||||
|
->with('settings_admin')
|
||||||
|
->willReturn('admin-url');
|
||||||
|
|
||||||
$job->expects($this->once())
|
$job->expects($this->once())
|
||||||
->method('createNotifications')
|
->method('createNotifications')
|
||||||
->willReturn('core', $notification);
|
->willReturn('core', $notification, 'admin-url#updater');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->invokePrivate($job, 'checkCoreUpdate');
|
$this->invokePrivate($job, 'checkCoreUpdate');
|
||||||
|
@ -172,7 +183,7 @@ class BackgroundJobTest extends TestCase {
|
||||||
['app2', '1.9.2'],
|
['app2', '1.9.2'],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
['app2', '1.9.2'],
|
['app2', '1.9.2', 'apps-url#app-app2'],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
@ -199,6 +210,11 @@ class BackgroundJobTest extends TestCase {
|
||||||
->method('isUpdateAvailable')
|
->method('isUpdateAvailable')
|
||||||
->willReturnMap($isUpdateAvailable);
|
->willReturnMap($isUpdateAvailable);
|
||||||
|
|
||||||
|
$this->urlGenerator->expects($this->exactly(sizeof($notifications)))
|
||||||
|
->method('linkToRouteAbsolute')
|
||||||
|
->with('settings.AppSettings.viewApps')
|
||||||
|
->willReturn('apps-url');
|
||||||
|
|
||||||
$mockedMethod = $job->expects($this->exactly(sizeof($notifications)))
|
$mockedMethod = $job->expects($this->exactly(sizeof($notifications)))
|
||||||
->method('createNotifications');
|
->method('createNotifications');
|
||||||
call_user_func_array([$mockedMethod, 'withConsecutive'], $notifications);
|
call_user_func_array([$mockedMethod, 'withConsecutive'], $notifications);
|
||||||
|
@ -208,9 +224,9 @@ class BackgroundJobTest extends TestCase {
|
||||||
|
|
||||||
public function dataCreateNotifications() {
|
public function dataCreateNotifications() {
|
||||||
return [
|
return [
|
||||||
['app1', '1.0.0', '1.0.0', false, false, null, null],
|
['app1', '1.0.0', 'link1', '1.0.0', false, false, null, null],
|
||||||
['app2', '1.0.1', '1.0.0', '1.0.0', true, ['user1'], [['user1']]],
|
['app2', '1.0.1', 'link2', '1.0.0', '1.0.0', true, ['user1'], [['user1']]],
|
||||||
['app3', '1.0.1', false, false, true, ['user2', 'user3'], [['user2'], ['user3']]],
|
['app3', '1.0.1', 'link3', false, false, true, ['user2', 'user3'], [['user2'], ['user3']]],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,13 +235,14 @@ class BackgroundJobTest extends TestCase {
|
||||||
*
|
*
|
||||||
* @param string $app
|
* @param string $app
|
||||||
* @param string $version
|
* @param string $version
|
||||||
|
* @param string $url
|
||||||
* @param string|false $lastNotification
|
* @param string|false $lastNotification
|
||||||
* @param string|false $callDelete
|
* @param string|false $callDelete
|
||||||
* @param bool $createNotification
|
* @param bool $createNotification
|
||||||
* @param string[]|null $users
|
* @param string[]|null $users
|
||||||
* @param array|null $userNotifications
|
* @param array|null $userNotifications
|
||||||
*/
|
*/
|
||||||
public function testCreateNotifications($app, $version, $lastNotification, $callDelete, $createNotification, $users, $userNotifications) {
|
public function testCreateNotifications($app, $version, $url, $lastNotification, $callDelete, $createNotification, $users, $userNotifications) {
|
||||||
$job = $this->getJob([
|
$job = $this->getJob([
|
||||||
'deleteOutdatedNotifications',
|
'deleteOutdatedNotifications',
|
||||||
'getUsersToNotify',
|
'getUsersToNotify',
|
||||||
|
@ -277,6 +294,10 @@ class BackgroundJobTest extends TestCase {
|
||||||
->method('setSubject')
|
->method('setSubject')
|
||||||
->with('update_available')
|
->with('update_available')
|
||||||
->willReturnSelf();
|
->willReturnSelf();
|
||||||
|
$notification->expects($this->once())
|
||||||
|
->method('setLink')
|
||||||
|
->with($url)
|
||||||
|
->willReturnSelf();
|
||||||
|
|
||||||
if ($userNotifications !== null) {
|
if ($userNotifications !== null) {
|
||||||
$mockedMethod = $notification->expects($this->exactly(sizeof($userNotifications)))
|
$mockedMethod = $notification->expects($this->exactly(sizeof($userNotifications)))
|
||||||
|
@ -297,7 +318,7 @@ class BackgroundJobTest extends TestCase {
|
||||||
->method('createNotification');
|
->method('createNotification');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->invokePrivate($job, 'createNotifications', [$app, $version]);
|
$this->invokePrivate($job, 'createNotifications', [$app, $version, $url]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataGetUsersToNotify() {
|
public function dataGetUsersToNotify() {
|
||||||
|
|
Loading…
Reference in New Issue