Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions core/templates/layout.user.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,9 @@
</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>
Expand Down
24 changes: 24 additions & 0 deletions lib/private/App/AppManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -827,4 +827,28 @@ public function getDefaultEnabledApps():array {

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'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultapp ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not seem to be updatable from the web UI but added in db86bea probably for admins to set with

occ user:setting admin core defaultapp files

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually support users setting their own default app?
Also my main concern was more about the string itself. What does "defaultApp" refers too? There is no app named like that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually support users setting their own default app?

Can only be set by an admin from what I can see

Also my main concern was more about the string itself. What does "defaultApp" refers too? There is no app named like that?

Probably thought the string was the default fallback? 'defaultapp' is actually passed as the key argument for

public function getUserValue($userId, $appName, $key, $default = '');

$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;
}
}
8 changes: 7 additions & 1 deletion lib/private/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,16 @@ public function __construct($renderAs, $appId = '') {
$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);
Expand Down
18 changes: 1 addition & 17 deletions lib/private/URLGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,23 +311,7 @@ public function linkToDefaultPageUrl(): string {
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') {
Expand Down
9 changes: 9 additions & 0 deletions lib/public/App/IAppManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,13 @@ public function getEnabledAppsForGroup(IGroup $group): array;
* @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;
}
43 changes: 43 additions & 0 deletions tests/lib/App/AppManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,4 +617,47 @@ public function testGetAppRestriction() {
$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());
}
}
80 changes: 10 additions & 70 deletions tests/lib/UrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;

/**
Expand Down Expand Up @@ -216,21 +215,16 @@ public function provideOCSRoutes() {
];
}

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() {
Expand All @@ -246,7 +240,7 @@ public function testLinkToDefaultPageUrlWithRedirectUrlRedirectBypassWithoutFron
putenv('front_controller_active=false');

$_REQUEST['redirect_url'] = '[email protected]: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() {
Expand All @@ -255,70 +249,16 @@ public function testLinkToDefaultPageUrlWithRedirectUrlRedirectBypassWithFrontCo
putenv('front_controller_active=true');

$_REQUEST['redirect_url'] = '[email protected]: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'] = '[email protected]: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 {
Expand Down