diff options
-rw-r--r-- | apps/files/appinfo/routes.php | 50 | ||||
-rw-r--r-- | apps/files/js/navigation.js | 95 | ||||
-rw-r--r-- | apps/files/lib/Controller/ApiController.php | 139 | ||||
-rw-r--r-- | lib/private/Authentication/TwoFactorAuth/Manager.php | 4 | ||||
-rw-r--r-- | tests/lib/Authentication/TwoFactorAuth/ManagerTest.php | 82 |
5 files changed, 87 insertions, 283 deletions
diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index 44663d185d1..1147bdf9c4f 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -81,56 +81,6 @@ $application->registerRoutes( 'url' => '/api/v1/toggleShowFolder/{key}', 'verb' => 'POST' ], - [ - 'name' => 'API#getShowQuickaccessSettings', - 'url' => '/api/v1/quickaccess/showsettings', - 'verb' => 'GET', - ], - [ - 'name' => 'API#setShowQuickaccessSettings', - 'url' => '/api/v1/quickaccess/set/showsettings', - 'verb' => 'GET', - ], - [ - 'name' => 'API#setSortingStrategy', - 'url' => '/api/v1/quickaccess/set/SortingStrategy', - 'verb' => 'GET', - ], - [ - 'name' => 'API#setReverseQuickaccess', - 'url' => '/api/v1/quickaccess/set/ReverseList', - 'verb' => 'GET', - ], - [ - 'name' => 'API#getSortingStrategy', - 'url' => '/api/v1/quickaccess/get/SortingStrategy', - 'verb' => 'GET', - ], - [ - 'name' => 'API#getReverseQuickaccess', - 'url' => '/api/v1/quickaccess/get/ReverseList', - 'verb' => 'GET', - ], - [ - 'name' => 'API#getFavoritesFolder', - 'url' => '/api/v1/quickaccess/get/FavoriteFolders/', - 'verb' => 'GET' - ], - [ - 'name' => 'API#setSortingOrder', - 'url' => '/api/v1/quickaccess/set/CustomSortingOrder', - 'verb' => 'GET', - ], - [ - 'name' => 'API#getSortingOrder', - 'url' => '/api/v1/quickaccess/get/CustomSortingOrder', - 'verb' => 'GET', - ], - [ - 'name' => 'API#getNodeType', - 'url' => '/api/v1/quickaccess/get/NodeType', - 'verb' => 'GET', - ], ] ] ); diff --git a/apps/files/js/navigation.js b/apps/files/js/navigation.js index 8ce976a6f53..7a89159c1f0 100644 --- a/apps/files/js/navigation.js +++ b/apps/files/js/navigation.js @@ -40,18 +40,6 @@ $currentContent: null, /** - * Strategy by which the quickaccesslist is sorted - * - * Possible Strategies: - * customorder - * datemodified - * date - * alphabet - * - */ - $sortingStrategy: 'alphabet', - - /** * Key for the quick-acces-list */ $quickAccessListKey: 'sublist-favorites', @@ -67,12 +55,7 @@ this.$currentContent = null; this._setupEvents(); - var scope=this; - $.get(OC.generateUrl("/apps/files/api/v1/quickaccess/get/SortingStrategy"), function (data, status) { - scope.$sortingStrategy=data; - scope.setInitialQuickaccessSettings(); - }); - + this.setInitialQuickaccessSettings(); }, /** @@ -198,56 +181,12 @@ * Sort initially as setup of sidebar for QuickAccess */ setInitialQuickaccessSettings: function () { - - var quickAccesKey = this.$quickAccessListKey; - var list = document.getElementById(quickAccesKey).getElementsByTagName('li'); - - var sort = true; - var reverse = false; - if (this.$sortingStrategy === 'datemodified') { - sort = false; - reverse = false; - - var scope = this; - $.get(OC.generateUrl("/apps/files/api/v1/quickaccess/get/FavoriteFolders/"), function (data, status) { - for (var i = 0; i < data.favoriteFolders.length; i++) { - for (var j = 0; j < list.length; j++) { - if (scope.getCompareValue(list, j, 'alphabet').toLowerCase() === data.favoriteFolders[i].name.toLowerCase()) { - list[j].setAttribute("mtime", data.favoriteFolders[i].mtime); - } - } - } - scope.QuickSort(list, 0, list.length - 1); - scope.reverse(list); - }); - - } else if (this.$sortingStrategy === 'alphabet') { - sort = true; - } else if (this.$sortingStrategy === 'date') { - sort = true; - } else if (this.$sortingStrategy === 'customorder') { - var scope = this; - $.get(OC.generateUrl("/apps/files/api/v1/quickaccess/get/CustomSortingOrder"), function (data, status) { - var ordering = JSON.parse(data); - for (var i = 0; i < ordering.length; i++) { - for (var j = 0; j < list.length; j++) { - if (scope.getCompareValue(list, j, 'alphabet').toLowerCase() === ordering[i].name.toLowerCase()) { - list[j].setAttribute("folderPosition", ordering[i].id); - } - } - } - scope.QuickSort(list, 0, list.length - 1); - }); - sort = false; - } - - if (sort) { + var quickAccessKey = this.$quickAccessListKey; + var quickAccessMenu = document.getElementById(quickAccessKey) + if (quickAccessMenu) { + var list = quickAccessMenu.getElementsByTagName('li'); this.QuickSort(list, 0, list.length - 1); } - if (reverse) { - this.reverse(list); - } - }, /** @@ -296,21 +235,7 @@ * This method allows easy access to the element which is sorted by. */ getCompareValue: function (nodes, int, strategy) { - - if ((typeof strategy === 'undefined')) { - strategy = this.$sortingStrategy; - } - - if (strategy === 'alphabet') { return nodes[int].getElementsByTagName('a')[0].innerHTML.toLowerCase(); - } else if (strategy === 'date') { - return nodes[int].getAttribute('folderPosition').toLowerCase(); - } else if (strategy === 'datemodified') { - return nodes[int].getAttribute('mtime'); - } else if (strategy === 'customorder') { - return nodes[int].getAttribute('folderPosition'); - } - return nodes[int].getElementsByTagName('a')[0].innerHTML.toLowerCase(); }, /** @@ -320,16 +245,6 @@ swap: function (list, j, i) { list[i].before(list[j]); list[j].before(list[i]); - }, - - /** - * Reverse QuickAccess-List - */ - reverse: function (list) { - var len = list.length - 1; - for (var i = 0; i < len / 2; i++) { - this.swap(list, i, len - i); - } } }; diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index fd63d545151..d71b998ffb1 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -200,30 +200,6 @@ class ApiController extends Controller { } /** - * Returns a list of favorites modifed folder. - * - * @NoAdminRequired - * - * @return DataResponse - */ - public function getFavoritesFolder() { - $nodes = $this->userFolder->searchByTag('_$!<Favorite>!$_', $this->userSession->getUser()->getUID()); - - $favorites = []; - $i = 0; - foreach ($nodes as &$node) { - - $favorites[$i]['id'] = $node->getId(); - $favorites[$i]['name'] = $node->getName(); - $favorites[$i]['path'] = $node->getInternalPath(); - $favorites[$i]['mtime'] = $node->getMTime(); - $i++; - } - - return new DataResponse(['favoriteFolders' => $favorites]); - } - - /** * Return a list of share types for outgoing shares * * @param Node $node file node @@ -315,120 +291,5 @@ class ApiController extends Controller { return $response; } - /** - * quickaccess-sorting-strategy - * - * @NoAdminRequired - * - * @param string $strategy - * @return Response - */ - public function setSortingStrategy($strategy) { - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_sorting_strategy', (String)$strategy); - return new Response(); - } - - /** - * Get reverse-state for quickaccess-list - * - * @NoAdminRequired - * - * @return String - */ - public function getSortingStrategy() { - return $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_sorting_strategy', 'alphabet'); - } - - /** - * Toggle for reverse quickaccess-list - * - * @NoAdminRequired - * - * @param bool $reverse - * @return Response - */ - public function setReverseQuickaccess($reverse) { - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_reverse_list', (int)$reverse); - return new Response(); - } - - /** - * Get reverse-state for quickaccess-list - * - * @NoAdminRequired - * - * @return bool - */ - public function getReverseQuickaccess() { - if ($this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_reverse_list', false)) { - return true; - } - return false; - } - - /** - * Set state for show sorting menu - * - * @NoAdminRequired - * - * @param bool $show - * @return Response - */ - public function setShowQuickaccessSettings($show) { - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_show_settings', (int)$show); - return new Response(); - } - - /** - * Get state for show sorting menu - * - * @NoAdminRequired - * - * @return bool - */ - public function getShowQuickaccessSettings() { - if ($this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_show_settings', false)) { - return true; - } - return false; - } - - /** - * Set sorting-order for custom sorting - * - * @NoAdminRequired - * - * @param String $order - * @return Response - */ - public function setSortingOrder($order) { - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_custom_sorting_order', (String)$order); - return new Response(); - } - - /** - * Get sorting-order for custom sorting - * - * @NoAdminRequired - * - * @return String - */ - public function getSortingOrder() { - return $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_custom_sorting_order', ""); - } - - /** - * Get sorting-order for custom sorting - * - * @NoAdminRequired - * - * @param String - * @return String - */ - public function getNodeType($folderpath) { - $node = $this->userFolder->get($folderpath); - return $node->getType(); - } - } diff --git a/lib/private/Authentication/TwoFactorAuth/Manager.php b/lib/private/Authentication/TwoFactorAuth/Manager.php index 0837ec339a5..0ee10ac0eff 100644 --- a/lib/private/Authentication/TwoFactorAuth/Manager.php +++ b/lib/private/Authentication/TwoFactorAuth/Manager.php @@ -104,7 +104,9 @@ class Manager { } $providerStates = $this->providerRegistry->getProviderStates($user); - $enabled = array_filter($providerStates); + $providers = $this->providerLoader->getProviders($user); + $fixedStates = $this->fixMissingProviderStates($providerStates, $providers, $user); + $enabled = array_filter($fixedStates); return $twoFactorEnabled && !empty($enabled); } diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php index e54e4353404..34ce340049a 100644 --- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php @@ -108,7 +108,6 @@ class ManagerTest extends TestCase { $this->fakeProvider = $this->createMock(IProvider::class); $this->fakeProvider->method('getId')->willReturn('email'); - $this->fakeProvider->method('isTwoFactorAuthEnabledForUser')->willReturn(true); $this->backupProvider = $this->getMockBuilder('\OCP\Authentication\TwoFactorAuth\IProvider')->getMock(); $this->backupProvider->method('getId')->willReturn('backup_codes'); @@ -143,7 +142,25 @@ class ManagerTest extends TestCase { ]); } - public function testIsTwoFactorAuthenticated() { + public function testIsTwoFactorAuthenticatedNoProviders() { + $this->user->expects($this->once()) + ->method('getUID') + ->will($this->returnValue('user123')); + $this->config->expects($this->once()) + ->method('getUserValue') + ->with('user123', 'core', 'two_factor_auth_disabled', 0) + ->willReturn(0); + $this->providerRegistry->expects($this->once()) + ->method('getProviderStates') + ->willReturn([]); // No providers registered + $this->providerLoader->expects($this->once()) + ->method('getProviders') + ->willReturn([]); // No providers loadable + + $this->assertFalse($this->manager->isTwoFactorAuthenticated($this->user)); + } + + public function testIsTwoFactorAuthenticatedFailingProviders() { $this->user->expects($this->once()) ->method('getUID') ->will($this->returnValue('user123')); @@ -156,11 +173,70 @@ class ManagerTest extends TestCase { ->willReturn([ 'twofactor_totp' => true, 'twofactor_u2f' => false, - ]); + ]); // Two providers registered, but … + $this->providerLoader->expects($this->once()) + ->method('getProviders') + ->willReturn([]); // … none of them is able to load, however … + // … 2FA is still enforced $this->assertTrue($this->manager->isTwoFactorAuthenticated($this->user)); } + public function providerStatesFixData(): array { + return [ + [false, false], + [true, true], + ]; + } + + /** + * If the 2FA registry has not been populated when a user logs in, + * the 2FA manager has to first fix the state before it checks for + * enabled providers. + * + * If any of these providers is active, 2FA is enabled + * + * @dataProvider providerStatesFixData + */ + public function testIsTwoFactorAuthenticatedFixesProviderStates(bool $providerEnabled, bool $expected) { + $this->user->expects($this->once()) + ->method('getUID') + ->will($this->returnValue('user123')); + $this->config->expects($this->once()) + ->method('getUserValue') + ->with('user123', 'core', 'two_factor_auth_disabled', 0) + ->willReturn(0); + $this->providerRegistry->expects($this->once()) + ->method('getProviderStates') + ->willReturn([]); // Nothing registered yet + $this->providerLoader->expects($this->once()) + ->method('getProviders') + ->willReturn([ + $this->fakeProvider + ]); + $this->fakeProvider->expects($this->once()) + ->method('isTwoFactorAuthEnabledForUser') + ->with($this->user) + ->willReturn($providerEnabled); + if ($providerEnabled) { + $this->providerRegistry->expects($this->once()) + ->method('enableProviderFor') + ->with( + $this->fakeProvider, + $this->user + ); + } else { + $this->providerRegistry->expects($this->once()) + ->method('disableProviderFor') + ->with( + $this->fakeProvider, + $this->user + ); + } + + $this->assertEquals($expected, $this->manager->isTwoFactorAuthenticated($this->user)); + } + public function testGetProvider() { $this->providerRegistry->expects($this->once()) ->method('getProviderStates') |