summaryrefslogtreecommitdiffstats
path: root/apps/updatenotification
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2018-06-26 17:25:37 +0200
committerMorris Jobke <hey@morrisjobke.de>2018-06-29 09:11:04 +0200
commit25d9c3e52921b107383e5d05f3649178bd7cd1cf (patch)
tree837fb580784174aa14a1d412056b1e9bf4f61772 /apps/updatenotification
parent4ed8ee1c1e8ada0e5d26f6e014896accc89d4d6a (diff)
downloadnextcloud-server-25d9c3e52921b107383e5d05f3649178bd7cd1cf.tar.gz
nextcloud-server-25d9c3e52921b107383e5d05f3649178bd7cd1cf.zip
adjust backend and gui to update and changelog server
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/updatenotification')
-rw-r--r--apps/updatenotification/lib/Settings/Admin.php73
-rw-r--r--apps/updatenotification/lib/UpdateChecker.php17
-rw-r--r--apps/updatenotification/src/components/root.vue15
-rw-r--r--apps/updatenotification/tests/Settings/AdminTest.php6
-rw-r--r--apps/updatenotification/tests/UpdateCheckerTest.php38
5 files changed, 115 insertions, 34 deletions
diff --git a/apps/updatenotification/lib/Settings/Admin.php b/apps/updatenotification/lib/Settings/Admin.php
index 1696e97d3ae..b859ca79f62 100644
--- a/apps/updatenotification/lib/Settings/Admin.php
+++ b/apps/updatenotification/lib/Settings/Admin.php
@@ -31,6 +31,8 @@ use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\IGroupManager;
+use OCP\IUserSession;
+use OCP\L10N\IFactory;
use OCP\Settings\ISettings;
use OCP\Util;
@@ -43,21 +45,25 @@ class Admin implements ISettings {
private $groupManager;
/** @var IDateTimeFormatter */
private $dateTimeFormatter;
-
- /**
- * @param IConfig $config
- * @param UpdateChecker $updateChecker
- * @param IGroupManager $groupManager
- * @param IDateTimeFormatter $dateTimeFormatter
- */
- public function __construct(IConfig $config,
- UpdateChecker $updateChecker,
- IGroupManager $groupManager,
- IDateTimeFormatter $dateTimeFormatter) {
+ /** @var IUserSession */
+ private $session;
+ /** @var IFactory */
+ private $l10nFactory;
+
+ public function __construct(
+ IConfig $config,
+ UpdateChecker $updateChecker,
+ IGroupManager $groupManager,
+ IDateTimeFormatter $dateTimeFormatter,
+ IUserSession $session,
+ IFactory $l10nFactory
+ ) {
$this->config = $config;
$this->updateChecker = $updateChecker;
$this->groupManager = $groupManager;
$this->dateTimeFormatter = $dateTimeFormatter;
+ $this->session = $session;
+ $this->l10nFactory = $l10nFactory;
}
/**
@@ -93,8 +99,7 @@ class Admin implements ISettings {
'channels' => $channels,
'newVersionString' => empty($updateState['updateVersion']) ? '' : $updateState['updateVersion'],
'downloadLink' => empty($updateState['downloadLink']) ? '' : $updateState['downloadLink'],
- 'changelogURL' => empty($updateState['changelog']) ? false : $updateState['changelog'],
- 'whatsNew' => empty($updateState['whatsNew']) ? false : $updateState['whatsNew'],
+ 'changes' => $this->filterChanges($updateState['changes'] ?? []),
'updaterEnabled' => empty($updateState['updaterEnabled']) ? false : $updateState['updaterEnabled'],
'versionIsEol' => empty($updateState['versionIsEol']) ? false : $updateState['versionIsEol'],
'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL,
@@ -109,6 +114,48 @@ class Admin implements ISettings {
return new TemplateResponse('updatenotification', 'admin', $params, '');
}
+ protected function filterChanges(array $changes) {
+ $filtered = [];
+ if(isset($changes['changelogURL'])) {
+ $filtered['changelogURL'] = $changes['changelogURL'];
+ }
+ if(!isset($changes['whatsNew'])) {
+ return $filtered;
+ }
+
+ $isFirstCall = true;
+ do {
+ $lang = $this->l10nFactory->iterateLanguage($isFirstCall);
+ if($this->findWhatsNewTranslation($lang, $filtered, $changes['whatsNew'])) {
+ return $filtered;
+ }
+ $isFirstCall = false;
+ } while($lang !== 'en');
+
+ return $filtered;
+ }
+
+ protected function getLangTrunk(string $lang):string {
+ $pos = strpos($lang, '_');
+ if($pos !== false) {
+ $lang = substr($lang, 0, $pos);
+ }
+ return $lang;
+ }
+
+ protected function findWhatsNewTranslation(string $lang, array &$result, array $whatsNew): bool {
+ if(isset($whatsNew[$lang])) {
+ $result['whatsNew'] = $whatsNew[$lang];
+ return true;
+ }
+ $trunkedLang = $this->getLangTrunk($lang);
+ if($trunkedLang !== $lang && isset($whatsNew[$trunkedLang])) {
+ $result['whatsNew'] = $whatsNew[$trunkedLang];
+ return true;
+ }
+ return false;
+ }
+
/**
* @param array $groupIds
* @return array
diff --git a/apps/updatenotification/lib/UpdateChecker.php b/apps/updatenotification/lib/UpdateChecker.php
index ec8e119049b..bd03cb442be 100644
--- a/apps/updatenotification/lib/UpdateChecker.php
+++ b/apps/updatenotification/lib/UpdateChecker.php
@@ -25,17 +25,21 @@ declare(strict_types=1);
namespace OCA\UpdateNotification;
+use OC\Updater\ChangesCheck;
use OC\Updater\VersionCheck;
class UpdateChecker {
/** @var VersionCheck */
private $updater;
+ /** @var ChangesCheck */
+ private $changesCheck;
/**
* @param VersionCheck $updater
*/
- public function __construct(VersionCheck $updater) {
+ public function __construct(VersionCheck $updater, ChangesCheck $changesCheck) {
$this->updater = $updater;
+ $this->changesCheck = $changesCheck;
}
/**
@@ -56,11 +60,12 @@ class UpdateChecker {
if (strpos($data['url'], 'https://') === 0) {
$result['downloadLink'] = $data['url'];
}
- if (strpos($data['changelog'], 'https://') === 0) {
- $result['changelog'] = $data['changelog'];
- }
- if (is_array($data['whatsNew']) && count($data['whatsNew']) <= 3) {
- $result['whatsNew'] = $data['whatsNew'];
+ if (strpos($data['changes'], 'https://') === 0) {
+ try {
+ $result['changes'] = $this->changesCheck->check($data['changes'], $data['version']);
+ } catch (\Exception $e) {
+ // no info, not a problem
+ }
}
return $result;
diff --git a/apps/updatenotification/src/components/root.vue b/apps/updatenotification/src/components/root.vue
index 96cce351cac..fcc5a9dd831 100644
--- a/apps/updatenotification/src/components/root.vue
+++ b/apps/updatenotification/src/components/root.vue
@@ -222,7 +222,9 @@
},
whatsNew: function () {
-
+ if(this.whatsNewData.length === 0) {
+ return null;
+ }
var whatsNew = [];
for (var i in this.whatsNewData) {
whatsNew[i] = { icon: 'icon-star-dark', longtext: this.whatsNewData[i] };
@@ -307,7 +309,6 @@
beforeMount: function() {
// Parse server data
var data = JSON.parse($('#updatenotification').attr('data-json'));
- console.warn(data);
this.newVersionString = data.newVersionString;
this.lastCheckedDate = data.lastChecked;
@@ -321,7 +322,15 @@
this.notifyGroups = data.notifyGroups;
this.isDefaultUpdateServerURL = data.isDefaultUpdateServerURL;
this.versionIsEol = data.versionIsEol;
- this.whatsNewData = data.whatsNew;
+ if(data.changes && data.changes.changelogURL) {
+ this.changelogURL = data.changes.changelogURL;
+ }
+ if(data.changes && data.changes.whatsNew) {
+ if(data.changes.whatsNew.admin) {
+ this.whatsNewData = this.whatsNewData.concat(data.changes.whatsNew.admin);
+ }
+ this.whatsNewData = this.whatsNewData.concat(data.changes.whatsNew.regular);
+ }
},
mounted: function () {
this._$el = $(this.$el);
diff --git a/apps/updatenotification/tests/Settings/AdminTest.php b/apps/updatenotification/tests/Settings/AdminTest.php
index 3e069907507..ed9614a3b6b 100644
--- a/apps/updatenotification/tests/Settings/AdminTest.php
+++ b/apps/updatenotification/tests/Settings/AdminTest.php
@@ -99,8 +99,7 @@ class AdminTest extends TestCase {
'updateAvailable' => true,
'updateVersion' => '8.1.2',
'downloadLink' => 'https://downloads.nextcloud.org/server',
- 'changelog' => 'https://nextcloud.com/changelog/#8.1.2',
- 'whatsNew' => ['Autoshare to mother-in-law', 'Faster backend', 'Sparkling frontend'],
+ 'changes' => 'https://updates.nextcloud.com/changelog_server/?version=8.1.2',
'updaterEnabled' => true,
'versionIsEol' => false,
]);
@@ -126,8 +125,7 @@ class AdminTest extends TestCase {
'channels' => $channels,
'newVersionString' => '8.1.2',
'downloadLink' => 'https://downloads.nextcloud.org/server',
- 'changelogURL' => 'https://nextcloud.com/changelog/#8.1.2',
- 'whatsNew' => ['Autoshare to mother-in-law', 'Faster backend', 'Sparkling frontend'],
+ 'changesURL' => 'https://updates.nextcloud.com/changelog_server/?version=8.1.2',
'updaterEnabled' => true,
'versionIsEol' => false,
'isDefaultUpdateServerURL' => true,
diff --git a/apps/updatenotification/tests/UpdateCheckerTest.php b/apps/updatenotification/tests/UpdateCheckerTest.php
index 0a82f950b9a..16861eea54e 100644
--- a/apps/updatenotification/tests/UpdateCheckerTest.php
+++ b/apps/updatenotification/tests/UpdateCheckerTest.php
@@ -25,11 +25,14 @@ declare(strict_types=1);
namespace OCA\UpdateNotification\Tests;
+use OC\Updater\ChangesCheck;
use OC\Updater\VersionCheck;
use OCA\UpdateNotification\UpdateChecker;
use Test\TestCase;
class UpdateCheckerTest extends TestCase {
+ /** @var ChangesCheck|\PHPUnit_Framework_MockObject_MockObject */
+ protected $changesChecker;
/** @var VersionCheck|\PHPUnit_Framework_MockObject_MockObject */
private $updater;
/** @var UpdateChecker */
@@ -39,7 +42,8 @@ class UpdateCheckerTest extends TestCase {
parent::setUp();
$this->updater = $this->createMock(VersionCheck::class);
- $this->updateChecker = new UpdateChecker($this->updater);
+ $this->changesChecker = $this->createMock(ChangesCheck::class);
+ $this->updateChecker = new UpdateChecker($this->updater, $this->changesChecker);
}
public function testGetUpdateStateWithUpdateAndInvalidLink() {
@@ -51,8 +55,7 @@ class UpdateCheckerTest extends TestCase {
'versionstring' => 'Nextcloud 123',
'web'=> 'javascript:alert(1)',
'url'=> 'javascript:alert(2)',
- 'changelog' => 'javascript:alert(3)',
- 'whatsNew' => 'javascript:alert(4)',
+ 'changes' => 'javascript:alert(3)',
'autoupdater'=> '0',
'eol'=> '1',
]);
@@ -67,20 +70,40 @@ class UpdateCheckerTest extends TestCase {
}
public function testGetUpdateStateWithUpdateAndValidLink() {
+ $changes = [
+ 'changelog' => 'https://nextcloud.com/changelog/#123-0-0',
+ 'whatsNew' => [
+ 'en' => [
+ 'regular' => [
+ 'Yardarm heave to brig spyglass smartly pillage',
+ 'Bounty gangway bilge skysail rope\'s end',
+ 'Maroon cutlass spirits nipperkin Plate Fleet',
+ ],
+ 'admin' => [
+ 'Scourge of the seven seas coffer doubloon',
+ 'Brig me splice the main brace',
+ ]
+ ]
+ ]
+ ];
+
$this->updater
->expects($this->once())
->method('check')
->willReturn([
- 'version' => 123,
+ 'version' => '123',
'versionstring' => 'Nextcloud 123',
'web'=> 'https://docs.nextcloud.com/myUrl',
'url'=> 'https://downloads.nextcloud.org/server',
- 'changelog' => 'https://nextcloud.com/changelog/#123.0.0',
- 'whatsNew' => ['Brews coffee', 'Makes appointments', 'Orchestrates Terminators'],
+ 'changes' => 'https://updates.nextcloud.com/changelog_server/?version=123.0.0',
'autoupdater'=> '1',
'eol'=> '0',
]);
+ $this->changesChecker->expects($this->once())
+ ->method('check')
+ ->willReturn($changes);
+
$expected = [
'updateAvailable' => true,
'updateVersion' => 'Nextcloud 123',
@@ -88,8 +111,7 @@ class UpdateCheckerTest extends TestCase {
'versionIsEol' => false,
'updateLink' => 'https://docs.nextcloud.com/myUrl',
'downloadLink' => 'https://downloads.nextcloud.org/server',
- 'changelog' => 'https://nextcloud.com/changelog/#123.0.0',
- 'whatsNew' => ['Brews coffee', 'Makes appointments', 'Orchestrates Terminators'],
+ 'changes' => $changes,
];
$this->assertSame($expected, $this->updateChecker->getUpdateState());
}