]> source.dussan.org Git - nextcloud-server.git/commitdiff
Respect updater kill switch and fall back to download button
authorJoas Schilling <coding@schilljs.com>
Tue, 27 Sep 2016 12:47:59 +0000 (14:47 +0200)
committerJoas Schilling <coding@schilljs.com>
Tue, 27 Sep 2016 12:59:23 +0000 (14:59 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/updatenotification/js/admin.js
apps/updatenotification/lib/Controller/AdminController.php
apps/updatenotification/lib/UpdateChecker.php
apps/updatenotification/templates/admin.php
apps/updatenotification/tests/Controller/AdminControllerTest.php
apps/updatenotification/tests/UpdateCheckerTest.php

index 3ca45a191d4cc949dadecee15b98cf066ec13732..91d9f80b60523f615ccde799b27249243c417e72 100644 (file)
@@ -35,6 +35,11 @@ $(document).ready(function(){
                                                body.removeAttr('id');
                                                body.attr('id', 'body-settings');
                                        }
+                               },
+                               error: function(){
+                                       OC.Notification.showTemporary(t('updatenotification', 'Could not start updater, please try the manual update'));
+                                       $('#oca_updatenotification_button').addClass('hidden');
+                                       $('#oca_updatenotification_section .button').removeClass('hidden');
                                }
                        });
                });
index 9f10f1b32f287cec89ba9a9abca366d1dcf6532f..56f41ebf3eeccead10572e8f966c3ed56ad8af62 100644 (file)
@@ -107,11 +107,13 @@ class AdminController extends Controller implements ISettings {
                $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
 
                $params = [
-                       'isNewVersionAvailable' => ($updateState === []) ? false : true,
+                       'isNewVersionAvailable' => !empty($updateState['updateAvailable']),
                        'lastChecked' => $lastUpdateCheck,
                        'currentChannel' => $currentChannel,
                        'channels' => $channels,
-                       'newVersionString' => ($updateState === []) ? '' : $updateState['updateVersion'],
+                       'newVersionString' => (empty($updateState['updateVersion'])) ? '' : $updateState['updateVersion'],
+                       'downloadLink' => (empty($updateState['downloadLink'])) ? '' : $updateState['downloadLink'],
+                       'updaterEnabled' => $updateState['updaterEnabled'],
 
                        'notify_groups' => implode('|', $notifyGroups),
                ];
index dd51831007c995c7abc0650b16f74a585eb4ddba..040a6c3a6ac9e2fd925775244b9f09bfbd9924ab 100644 (file)
@@ -46,9 +46,13 @@ class UpdateChecker {
                if(isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
                        $result['updateAvailable'] = true;
                        $result['updateVersion'] = $data['versionstring'];
+                       $result['updaterEnabled'] = $data['autoupdater'] === '1';
                        if(substr($data['web'], 0, 8) === 'https://') {
                                $result['updateLink'] = $data['web'];
                        }
+                       if(substr($data['url'], 0, 8) === 'https://') {
+                               $result['downloadLink'] = $data['url'];
+                       }
 
                        return $result;
                }
index 68ef1d423b4de8f8874c6c83184eecbf546d624f..78337eb313bcd7b81f830a7a38f871694b79a155 100644 (file)
        $currentChannel = $_['currentChannel'];
 ?>
 <form id="oca_updatenotification_section" class="followupsection">
-       <?php if($isNewVersionAvailable === true): ?>
+       <?php if($isNewVersionAvailable === true) { ?>
                <strong><?php p($l->t('A new version is available: %s', [$newVersionString])); ?></strong>
-               <input type="button" id="oca_updatenotification_button" value="<?php p($l->t('Open updater')) ?>">
-       <?php else: ?>
+               <?php if ($_['updaterEnabled']) { ?>
+                       <input type="button" id="oca_updatenotification_button" value="<?php p($l->t('Open updater')) ?>">
+               <?php } ?>
+               <?php if (!empty($_['downloadLink'])) { ?>
+                       <a href="<?php p($_['downloadLink']); ?>" class="button<?php if ($_['updaterEnabled']) { p(' hidden'); } ?>"><?php p($l->t('Download now')) ?></a>
+               <?php } ?>
+       <?php } else { ?>
                <strong><?php print_unescaped($l->t('Your version is up to date.')); ?></strong>
                <span class="icon-info svg" title="<?php p($l->t('Checked on %s', [$lastCheckedDate])) ?>"></span>
-       <?php endif; ?>
+       <?php } ?>
 
        <p>
                <label for="release-channel"><?php p($l->t('Update channel:')) ?></label>
index cf99679e680af86f03e11b2e0d2946254d694f75..336da09ec7a40f53ce5bb1f6e0e4003ea8ccd784 100644 (file)
@@ -110,7 +110,12 @@ class AdminControllerTest extends TestCase {
                $this->updateChecker
                        ->expects($this->once())
                        ->method('getUpdateState')
-                       ->willReturn(['updateVersion' => '8.1.2']);
+                       ->willReturn([
+                               'updateAvailable' => true,
+                               'updateVersion' => '8.1.2',
+                               'downloadLink' => 'https://downloads.nextcloud.org/server',
+                               'updaterEnabled' => true,
+                       ]);
 
                $params = [
                        'isNewVersionAvailable' => true,
@@ -118,6 +123,8 @@ class AdminControllerTest extends TestCase {
                        'currentChannel' => \OCP\Util::getChannel(),
                        'channels' => $channels,
                        'newVersionString' => '8.1.2',
+                       'downloadLink' => 'https://downloads.nextcloud.org/server',
+                       'updaterEnabled' => true,
                        'notify_groups' => 'admin',
                ];
 
@@ -154,7 +161,7 @@ class AdminControllerTest extends TestCase {
                $this->updateChecker
                        ->expects($this->once())
                        ->method('getUpdateState')
-                       ->willReturn([]);
+                       ->willReturn(['updaterEnabled' => false]);
 
                $params = [
                        'isNewVersionAvailable' => false,
@@ -162,6 +169,8 @@ class AdminControllerTest extends TestCase {
                        'currentChannel' => \OCP\Util::getChannel(),
                        'channels' => $channels,
                        'newVersionString' => '',
+                       'downloadLink' => '',
+                       'updaterEnabled' => 0,
                        'notify_groups' => 'admin',
                ];
 
index ce19cc60f2c7c0febd2b97dfe8d8efa2e7aa6764..c5c3034dd7224a4829e50696002331aa5b83dce3 100644 (file)
@@ -50,11 +50,13 @@ class UpdateCheckerTest extends TestCase {
                                'versionstring' => 'Nextcloud 123',
                                'web'=> 'javascript:alert(1)',
                                'url'=> 'javascript:alert(2)',
+                               'autoupdater'=> '0',
                        ]);
 
                $expected = [
                        'updateAvailable' => true,
                        'updateVersion' => 'Nextcloud 123',
+                       'updaterEnabled' => false,
                ];
                $this->assertSame($expected, $this->updateChecker->getUpdateState());
        }
@@ -68,12 +70,15 @@ class UpdateCheckerTest extends TestCase {
                                'versionstring' => 'Nextcloud 123',
                                'web'=> 'https://docs.nextcloud.com/myUrl',
                                'url'=> 'https://downloads.nextcloud.org/server',
+                               'autoupdater'=> '1',
                        ]);
 
                $expected = [
                        'updateAvailable' => true,
                        'updateVersion' => 'Nextcloud 123',
+                       'updaterEnabled' => true,
                        'updateLink' => 'https://docs.nextcloud.com/myUrl',
+                       'downloadLink' => 'https://downloads.nextcloud.org/server',
                ];
                $this->assertSame($expected, $this->updateChecker->getUpdateState());
        }