fix: Remove unneccesary etag check

Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
pull/52546/head
Marcel Müller 2025-04-29 22:14:25 +07:00
parent f26dc79480
commit 1addd35b78
2 changed files with 2 additions and 41 deletions

@ -47,12 +47,8 @@ class NavigationController extends OCSController {
$navigation = $this->rewriteToAbsoluteUrls($navigation); $navigation = $this->rewriteToAbsoluteUrls($navigation);
} }
$navigation = array_values($navigation); $navigation = array_values($navigation);
$etag = $this->generateETag($navigation);
if ($this->request->getHeader('If-None-Match') === $etag) {
return new DataResponse([], Http::STATUS_NOT_MODIFIED);
}
$response = new DataResponse($navigation); $response = new DataResponse($navigation);
$response->setETag($etag); $response->setETag($this->generateETag($navigation));
return $response; return $response;
} }
@ -74,12 +70,8 @@ class NavigationController extends OCSController {
$navigation = $this->rewriteToAbsoluteUrls($navigation); $navigation = $this->rewriteToAbsoluteUrls($navigation);
} }
$navigation = array_values($navigation); $navigation = array_values($navigation);
$etag = $this->generateETag($navigation);
if ($this->request->getHeader('If-None-Match') === $etag) {
return new DataResponse([], Http::STATUS_NOT_MODIFIED);
}
$response = new DataResponse($navigation); $response = new DataResponse($navigation);
$response->setETag($etag); $response->setETag($this->generateETag($navigation));
return $response; return $response;
} }

@ -7,7 +7,6 @@
namespace Tests\Core\Controller; namespace Tests\Core\Controller;
use OC\Core\Controller\NavigationController; use OC\Core\Controller\NavigationController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataResponse;
use OCP\INavigationManager; use OCP\INavigationManager;
use OCP\IRequest; use OCP\IRequest;
@ -103,34 +102,4 @@ class NavigationControllerTest extends TestCase {
$this->assertEquals('/core/img/settings.svg', $actual->getData()[0]['icon']); $this->assertEquals('/core/img/settings.svg', $actual->getData()[0]['icon']);
} }
} }
public function testGetAppNavigationEtagMatch(): void {
$navigation = [ ['id' => 'files', 'href' => '/index.php/apps/files', 'icon' => 'icon' ] ];
$this->request->expects($this->once())
->method('getHeader')
->with('If-None-Match')
->willReturn(md5(json_encode($navigation)));
$this->navigationManager->expects($this->once())
->method('getAll')
->with('link')
->willReturn($navigation);
$actual = $this->controller->getAppsNavigation();
$this->assertInstanceOf(DataResponse::class, $actual);
$this->assertEquals(Http::STATUS_NOT_MODIFIED, $actual->getStatus());
}
public function testGetSettingsNavigationEtagMatch(): void {
$navigation = [ ['id' => 'logout', 'href' => '/index.php/apps/files', 'icon' => 'icon' ] ];
$this->request->expects($this->once())
->method('getHeader')
->with('If-None-Match')
->willReturn(md5(json_encode([ ['id' => 'logout', 'href' => 'logout', 'icon' => 'icon' ] ])));
$this->navigationManager->expects($this->once())
->method('getAll')
->with('settings')
->willReturn($navigation);
$actual = $this->controller->getSettingsNavigation();
$this->assertInstanceOf(DataResponse::class, $actual);
$this->assertEquals(Http::STATUS_NOT_MODIFIED, $actual->getStatus());
}
} }