Skip to content

Commit 6d8149b

Browse files
authored
Merge pull request #1683 from nextcloud/update-attribute-s
fix: Update attributes
2 parents a115911 + 417095c commit 6d8149b

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

appinfo/routes.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@
2020
'postfix' => 'welcome',
2121
],
2222
[
23-
'name' => 'page#create',
23+
'name' => 'page#createGet', // deprecated, use createPost instead
2424
'url' => '/new',
2525
'verb' => 'GET',
2626
],
27+
[
28+
'name' => 'page#createPost',
29+
'url' => '/new',
30+
'verb' => 'POST',
31+
],
2732
[
2833
'name' => 'page#index',
2934
'url' => '/note/{id}',

lib/Controller/NotesApiController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ public function getAttachment(int $noteid, string $path): Http\Response {
298298
$response = new StreamResponse($fileHandle);
299299
$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurldecode($targetimage->getName()) . '"');
300300
$response->addHeader('Content-Type', $this->mimeTypeDetector->getSecureMimeType($targetimage->getMimeType()));
301-
$response->addHeader('Cache-Control', 'public, max-age=604800');
301+
$response->addHeader('Vary', 'Authorization, Cookie');
302+
$response->cacheFor(3600);
302303
return $response;
303304
} catch (\Exception $e) {
304305
$this->helper->logException($e);

lib/Controller/NotesController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ public function getAttachment(int $noteid, string $path): Http\Response {
351351
'Content-Type',
352352
$this->mimeTypeDetector->getSecureMimeType($targetimage->getMimeType())
353353
);
354-
$response->addHeader('Cache-Control', 'public, max-age=604800');
354+
$response->addHeader('Vary', 'Authorization, Cookie');
355+
$response->cacheFor(3600);
355356
return $response;
356357
} catch (\Exception $e) {
357358
$this->helper->logException($e);

lib/Controller/PageController.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use OCP\AppFramework\Controller;
2222
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
2323
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
24+
use OCP\AppFramework\Http\Attribute\UserRateLimit;
2425
use OCP\AppFramework\Http\ContentSecurityPolicy;
2526
use OCP\AppFramework\Http\RedirectResponse;
2627
use OCP\AppFramework\Http\TemplateResponse;
@@ -30,6 +31,7 @@
3031
use OCP\IRequest;
3132
use OCP\IURLGenerator;
3233
use OCP\IUserSession;
34+
use Psr\Log\LoggerInterface;
3335

3436
class PageController extends Controller {
3537
private NotesService $notesService;
@@ -38,6 +40,7 @@ class PageController extends Controller {
3840
private IURLGenerator $urlGenerator;
3941
private IEventDispatcher $eventDispatcher;
4042
private IInitialState $initialState;
43+
private LoggerInterface $logger;
4144

4245
public function __construct(
4346
string $AppName,
@@ -48,6 +51,7 @@ public function __construct(
4851
IURLGenerator $urlGenerator,
4952
IEventDispatcher $eventDispatcher,
5053
IInitialState $initialState,
54+
LoggerInterface $logger,
5155
) {
5256
parent::__construct($AppName, $request);
5357
$this->notesService = $notesService;
@@ -56,6 +60,7 @@ public function __construct(
5660
$this->urlGenerator = $urlGenerator;
5761
$this->eventDispatcher = $eventDispatcher;
5862
$this->initialState = $initialState;
63+
$this->logger = $logger;
5964
}
6065

6166

@@ -102,12 +107,25 @@ public function index() : TemplateResponse {
102107
}
103108

104109
/**
105-
*
110+
* @deprecated Use createPost() instead. This endpoint will be removed in a future version.
106111
*/
107112
#[NoAdminRequired]
108113
#[NoCSRFRequired]
109-
public function create() : RedirectResponse {
110-
$note = $this->notesService->create($this->userSession->getUser()->getUID(), '', '');
114+
#[UserRateLimit(limit: 20, period: 60)]
115+
public function createGet() : RedirectResponse {
116+
$this->logger->debug('Deprecated GET /new endpoint used', [
117+
'user' => $this->userSession->getUser()?->getUID(),
118+
'remote_addr' => $this->request->getRemoteAddress(),
119+
'user_agent' => $this->request->getHeader('User-Agent')
120+
]);
121+
return $this->createPost();
122+
}
123+
124+
#[NoAdminRequired]
125+
#[NoCSRFRequired]
126+
#[UserRateLimit(limit: 20, period: 60)]
127+
public function createPost() : RedirectResponse {
128+
$note = $this->notesService->create($this->userSession->getUser()?->getUID() ?? '', '', '');
111129
$note->setContent('');
112130
$url = $this->urlGenerator->linkToRoute('notes.page.indexnote', [ 'id' => $note->getId() ]);
113131
return new RedirectResponse($url . '?new');

0 commit comments

Comments
 (0)