Skip to content

Commit

Permalink
fix(TemplateLayout): core is not an app but the server itself
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Jan 24, 2025
1 parent 31664b3 commit eea91fa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
9 changes: 0 additions & 9 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2576,15 +2576,6 @@
<code><![CDATA[$script]]></code>
</ParamNameMismatch>
</file>
<file src="lib/private/TemplateLayout.php">
<InvalidParamDefault>
<code><![CDATA[string]]></code>
<code><![CDATA[string]]></code>
</InvalidParamDefault>
<InvalidScalarArgument>
<code><![CDATA[$appId]]></code>
</InvalidScalarArgument>
</file>
<file src="lib/private/URLGenerator.php">
<InvalidReturnStatement>
<code><![CDATA[$path]]></code>
Expand Down
17 changes: 11 additions & 6 deletions lib/private/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,18 @@ private function getVersionHashByPath(string $path): string|false {
return false;
}

$appVersion = $this->appManager->getAppVersion($appId);
// For shipped apps the app version is not a single source of truth, we rather also need to consider the Nextcloud version
if ($this->appManager->isShipped($appId)) {
$appVersion .= '-' . self::$versionHash;
}
if ($appId === 'core') {
// core is not a real app but the server itself
$hash = self::$versionHash;
} else {
$appVersion = $this->appManager->getAppVersion($appId);
// For shipped apps the app version is not a single source of truth, we rather also need to consider the Nextcloud version
if ($this->appManager->isShipped($appId)) {
$appVersion .= '-' . self::$versionHash;
}

$hash = substr(md5($appVersion), 0, 8);
$hash = substr(md5($appVersion), 0, 8);
}
self::$cacheBusterCache[$path] = $hash;
}

Expand Down
32 changes: 19 additions & 13 deletions tests/lib/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
use OC\AppConfig;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
use OCP\IURLGenerator;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\ServerVersion;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -463,8 +469,8 @@ public function appConfigValuesProvider() {
* @dataProvider appConfigValuesProvider
*/
public function testEnabledApps($user, $expectedApps, $forceAll): void {
$userManager = \OC::$server->getUserManager();
$groupManager = \OC::$server->getGroupManager();
$userManager = \OCP\Server::get(IUserManager::class);
$groupManager = \OCP\Server::get(IGroupManager::class);
$user1 = $userManager->createUser(self::TEST_USER1, 'NotAnEasyPassword123456+');
$user2 = $userManager->createUser(self::TEST_USER2, 'NotAnEasyPassword123456_');
$user3 = $userManager->createUser(self::TEST_USER3, 'NotAnEasyPassword123456?');
Expand Down Expand Up @@ -512,7 +518,7 @@ public function testEnabledApps($user, $expectedApps, $forceAll): void {
* enabled apps more than once when a user is set.
*/
public function testEnabledAppsCache(): void {
$userManager = \OC::$server->getUserManager();
$userManager = \OCP\Server::get(IUserManager::class);
$user1 = $userManager->createUser(self::TEST_USER1, 'NotAnEasyPassword123456+');

\OC_User::setUserId(self::TEST_USER1);
Expand Down Expand Up @@ -544,8 +550,8 @@ public function testEnabledAppsCache(): void {
private function setupAppConfigMock() {
/** @var AppConfig|MockObject */
$appConfig = $this->getMockBuilder(AppConfig::class)
->setMethods(['getValues'])
->setConstructorArgs([\OC::$server->getDatabaseConnection()])
->onlyMethods(['getValues'])
->setConstructorArgs([\OCP\Server::get(IDBConnection::class)])
->disableOriginalConstructor()
->getMock();

Expand All @@ -561,13 +567,13 @@ private function setupAppConfigMock() {
private function registerAppConfig(AppConfig $appConfig) {
$this->overwriteService(AppConfig::class, $appConfig);
$this->overwriteService(AppManager::class, new AppManager(
\OC::$server->getUserSession(),
\OC::$server->getConfig(),
\OC::$server->getGroupManager(),
\OC::$server->getMemCacheFactory(),
\OC::$server->get(IEventDispatcher::class),
\OC::$server->get(LoggerInterface::class),
\OC::$server->get(IURLGenerator::class),
\OCP\Server::get(IUserSession::class),
\OCP\Server::get(IConfig::class),
\OCP\Server::get(IGroupManager::class),
\OCP\Server::get(ICacheFactory::class),
\OCP\Server::get(IEventDispatcher::class),
\OCP\Server::get(LoggerInterface::class),
\OCP\Server::get(ServerVersion::class),
));
}

Expand Down

0 comments on commit eea91fa

Please sign in to comment.