]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add label for logo link 37472/head
authorChristopher Ng <chrng8@gmail.com>
Wed, 29 Mar 2023 20:36:45 +0000 (13:36 -0700)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Thu, 30 Mar 2023 00:39:15 +0000 (00:39 +0000)
Signed-off-by: Christopher Ng <chrng8@gmail.com>
core/templates/layout.user.php
lib/private/App/AppManager.php
lib/private/TemplateLayout.php
lib/private/URLGenerator.php
lib/public/App/IAppManager.php
tests/lib/App/AppManagerTest.php
tests/lib/UrlGeneratorTest.php

index 11f7656cc91744c16bda3674f22d5dcf0028015a..594226e9188997fa80f423120e765132e5f496a1 100644 (file)
@@ -62,12 +62,9 @@ $getUserAvatar = static function (int $size) use ($_): string {
                        </h1>
                        <div class="header-left">
                                <a href="<?php print_unescaped($_['logoUrl'] ?: link_to('', 'index.php')); ?>"
+                                       aria-label="<?php p($l->t('Go to %s', [$_['logoUrl'] ?: $_['defaultAppName']])); ?>"
                                        id="nextcloud">
-                                       <div class="logo logo-icon">
-                                               <span class="hidden-visually">
-                                                       <?php p($l->t('%s homepage', [$theme->getName()])); ?>
-                                               </span>
-                                       </div>
+                                       <div class="logo logo-icon"></div>
                                </a>
 
                                <nav id="header-left__appmenu"></nav>
index 6d2fe51d0eddf29d0046bc3ff8b899046cc9a851..999b4635f824e5a2f741f5f32ecb5982ad3cf178 100644 (file)
@@ -602,4 +602,28 @@ class AppManager implements IAppManager {
 
                return $this->defaultEnabled;
        }
+
+       public function getDefaultAppForUser(?IUser $user = null): string {
+               // Set fallback to always-enabled files app
+               $appId = 'files';
+               $defaultApps = explode(',', $this->config->getSystemValueString('defaultapp', 'dashboard,files'));
+
+               $user ??= $this->userSession->getUser();
+
+               if ($user !== null) {
+                       $userDefaultApps = explode(',', $this->config->getUserValue($user->getUID(), 'core', 'defaultapp'));
+                       $defaultApps = array_filter(array_merge($userDefaultApps, $defaultApps));
+               }
+
+               // Find the first app that is enabled for the current user
+               foreach ($defaultApps as $defaultApp) {
+                       $defaultApp = \OC_App::cleanAppId(strip_tags($defaultApp));
+                       if ($this->isEnabledForUser($defaultApp, $user)) {
+                               $appId = $defaultApp;
+                               break;
+                       }
+               }
+
+               return $appId;
+       }
 }
index 2a6149df03093cfb1d75da0238701ee79cdd82c0..3ceef29c34d7869de04737d009beec7ca2249305 100644 (file)
@@ -114,10 +114,16 @@ class TemplateLayout extends \OC_Template {
                                $this->assign('enabledThemes', $themesService->getEnabledThemes());
                        }
 
-                       // set logo link target
+                       // Set logo link target
                        $logoUrl = $this->config->getSystemValueString('logo_url', '');
                        $this->assign('logoUrl', $logoUrl);
 
+                       // Set default app name
+                       $defaultApp = \OC::$server->getAppManager()->getDefaultAppForUser();
+                       $defaultAppInfo = \OC::$server->getAppManager()->getAppInfo($defaultApp);
+                       $l10n = \OC::$server->getL10NFactory()->get($defaultApp);
+                       $this->assign('defaultAppName', $l10n->t($defaultAppInfo['name']));
+
                        // Add navigation entry
                        $this->assign('application', '');
                        $this->assign('appid', $appId);
index 7be2895a1ef215cd202646f8acafb43b0d0089c0..a5a3609703b098d79a8ca152332f6c947048eefe 100644 (file)
@@ -311,23 +311,7 @@ class URLGenerator implements IURLGenerator {
                        return $this->getAbsoluteURL($defaultPage);
                }
 
-               $appId = 'files';
-               $defaultApps = explode(',', $this->config->getSystemValue('defaultapp', 'dashboard,files'));
-
-               $userId = $this->userSession->isLoggedIn() ? $this->userSession->getUser()->getUID() : null;
-               if ($userId !== null) {
-                       $userDefaultApps = explode(',', $this->config->getUserValue($userId, 'core', 'defaultapp'));
-                       $defaultApps = array_filter(array_merge($userDefaultApps, $defaultApps));
-               }
-
-               // find the first app that is enabled for the current user
-               foreach ($defaultApps as $defaultApp) {
-                       $defaultApp = \OC_App::cleanAppId(strip_tags($defaultApp));
-                       if (\OC::$server->getAppManager()->isEnabledForUser($defaultApp)) {
-                               $appId = $defaultApp;
-                               break;
-                       }
-               }
+               $appId = $this->getAppManager()->getDefaultAppForUser();
 
                if ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true
                        || getenv('front_controller_active') === 'true') {
index f7c9d8480993943bf34b5bfbf9676cb2b0a866aa..48e3b1464c919c5a1e8c0811697a17df6ec63d81 100644 (file)
@@ -208,4 +208,13 @@ interface IAppManager {
         * @since 17.0.0
         */
        public function getAppRestriction(string $appId): array;
+
+       /**
+        * Returns the id of the user's default app
+        *
+        * If `user` is not passed, the currently logged in user will be used
+        *
+        * @since 25.0.6
+        */
+       public function getDefaultAppForUser(?IUser $user = null): string;
 }
index de515837406ffa6d54b3a63d013e33c23b1c09cb..e8326b9ebe9f82fa5d3615c61065e444edc0783b 100644 (file)
@@ -601,4 +601,47 @@ class AppManagerTest extends TestCase {
                $this->assertEquals([], $this->manager->getAppRestriction('test2'));
                $this->assertEquals(['foo'], $this->manager->getAppRestriction('test3'));
        }
+
+       public function provideDefaultApps(): array {
+               return [
+                       // none specified, default to files
+                       [
+                               '',
+                               'files',
+                       ],
+                       // unexisting or inaccessible app specified, default to files
+                       [
+                               'unexist',
+                               'files',
+                       ],
+                       // non-standard app
+                       [
+                               'settings',
+                               'settings',
+                       ],
+                       // non-standard app with fallback
+                       [
+                               'unexist,settings',
+                               'settings',
+                       ],
+               ];
+       }
+
+       /**
+        * @dataProvider provideDefaultApps
+        */
+       public function testGetDefaultAppForUser($defaultApps, $expectedApp) {
+               $user = $this->newUser('user1');
+
+               $this->userSession->expects($this->once())
+                       ->method('getUser')
+                       ->willReturn($user);
+
+               $this->config->expects($this->once())
+                       ->method('getSystemValueString')
+                       ->with('defaultapp', $this->anything())
+                       ->willReturn($defaultApps);
+
+               $this->assertEquals($expectedApp, $this->manager->getDefaultAppForUser());
+       }
 }
index 7fdbb7fb37ea76206e2906111bf8285f0a501d1c..615ae5094be71bdbccc47feff1de43930714ac8d 100644 (file)
@@ -13,7 +13,6 @@ use OCP\ICacheFactory;
 use OCP\IConfig;
 use OCP\IRequest;
 use OCP\IURLGenerator;
-use OCP\IUser;
 use OCP\IUserSession;
 
 /**
@@ -217,21 +216,16 @@ class UrlGeneratorTest extends \Test\TestCase {
                ];
        }
 
-       private function mockLinkToDefaultPageUrl(string $defaultAppConfig = '', bool $ignoreFrontControllerConfig = false) {
-               $this->config->expects($this->exactly(2))
-                       ->method('getSystemValue')
-                       ->withConsecutive(
-                               ['defaultapp', $this->anything()],
-                               ['htaccess.IgnoreFrontController', $this->anything()],
-                       )
-                       ->will($this->onConsecutiveCalls(
-                               $defaultAppConfig,
-                               $ignoreFrontControllerConfig
-                       ));
+       private function mockLinkToDefaultPageUrl(bool $ignoreFrontControllerConfig = false) {
                $this->config->expects($this->once())
                        ->method('getAppValue')
                        ->with('core', 'defaultpage')
                        ->willReturn('');
+
+               $this->config->expects($this->once())
+                       ->method('getSystemValue')
+                       ->with('htaccess.IgnoreFrontController', $this->anything())
+                       ->willReturn($ignoreFrontControllerConfig);
        }
 
        public function testLinkToDefaultPageUrlWithRedirectUrlWithoutFrontController() {
@@ -247,7 +241,7 @@ class UrlGeneratorTest extends \Test\TestCase {
                putenv('front_controller_active=false');
 
                $_REQUEST['redirect_url'] = 'myRedirectUrl.com@foo.com:a';
-               $this->assertSame('http://localhost' . \OC::$WEBROOT . '/index.php/apps/files/', $this->urlGenerator->linkToDefaultPageUrl());
+               $this->assertSame('http://localhost' . \OC::$WEBROOT . '/index.php/apps/dashboard/', $this->urlGenerator->linkToDefaultPageUrl());
        }
 
        public function testLinkToDefaultPageUrlWithRedirectUrlRedirectBypassWithFrontController() {
@@ -256,70 +250,16 @@ class UrlGeneratorTest extends \Test\TestCase {
                putenv('front_controller_active=true');
 
                $_REQUEST['redirect_url'] = 'myRedirectUrl.com@foo.com:a';
-               $this->assertSame('http://localhost' . \OC::$WEBROOT . '/apps/files/', $this->urlGenerator->linkToDefaultPageUrl());
+               $this->assertSame('http://localhost' . \OC::$WEBROOT . '/apps/dashboard/', $this->urlGenerator->linkToDefaultPageUrl());
        }
 
        public function testLinkToDefaultPageUrlWithRedirectUrlWithIgnoreFrontController() {
                $this->mockBaseUrl();
-               $this->mockLinkToDefaultPageUrl('', true);
+               $this->mockLinkToDefaultPageUrl(true);
                putenv('front_controller_active=false');
 
                $_REQUEST['redirect_url'] = 'myRedirectUrl.com@foo.com:a';
-               $this->assertSame('http://localhost' . \OC::$WEBROOT . '/apps/files/', $this->urlGenerator->linkToDefaultPageUrl());
-       }
-
-       /**
-        * @dataProvider provideDefaultApps
-        */
-       public function testLinkToDefaultPageUrlWithDefaultApps($defaultAppConfig, $expectedPath) {
-               $userId = $this->getUniqueID();
-
-               /** @var \PHPUnit\Framework\MockObject\MockObject|IUser $userMock */
-               $userMock = $this->createMock(IUser::class);
-               $userMock->expects($this->once())
-                       ->method('getUID')
-                       ->willReturn($userId);
-
-               $this->mockBaseUrl();
-               $this->mockLinkToDefaultPageUrl($defaultAppConfig);
-
-               $this->config->expects($this->once())
-                       ->method('getUserValue')
-                       ->with($userId, 'core', 'defaultapp')
-                       ->willReturn('');
-               $this->userSession->expects($this->once())
-                       ->method('isLoggedIn')
-                       ->willReturn(true);
-               $this->userSession->expects($this->once())
-                       ->method('getUser')
-                       ->willReturn($userMock);
-
-               $this->assertEquals('http://localhost' . \OC::$WEBROOT . $expectedPath, $this->urlGenerator->linkToDefaultPageUrl());
-       }
-
-       public function provideDefaultApps(): array {
-               return [
-                       // none specified, default to files
-                       [
-                               '',
-                               '/index.php/apps/files/',
-                       ],
-                       // unexisting or inaccessible app specified, default to files
-                       [
-                               'unexist',
-                               '/index.php/apps/files/',
-                       ],
-                       // non-standard app
-                       [
-                               'settings',
-                               '/index.php/apps/settings/',
-                       ],
-                       // non-standard app with fallback
-                       [
-                               'unexist,settings',
-                               '/index.php/apps/settings/',
-                       ],
-               ];
+               $this->assertSame('http://localhost' . \OC::$WEBROOT . '/apps/dashboard/', $this->urlGenerator->linkToDefaultPageUrl());
        }
 
        public function imagePathProvider(): array {