Skip to content

Commit ad9f5e2

Browse files
committed
Switch from annotations to method attributes
Annotations are deprecated and cause a lot of log messages Signed-off-by: oli-ver <oli-ver@users.noreply.github.com>
1 parent 4a9bc60 commit ad9f5e2

File tree

4 files changed

+76
-48
lines changed

4 files changed

+76
-48
lines changed

lib/Controller/NotesApiController.php

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@
1818
use OCP\AppFramework\ApiController;
1919
use OCP\AppFramework\Http;
2020
use OCP\AppFramework\Http\JSONResponse;
21+
use OCP\AppFramework\Http\Attribute\CORS;
22+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
23+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
24+
2125
use OCP\IRequest;
2226

27+
2328
class NotesApiController extends ApiController {
2429
private NotesService $service;
2530
private MetaService $metaService;
@@ -43,10 +48,10 @@ public function __construct(
4348

4449

4550
/**
46-
* @NoAdminRequired
47-
* @CORS
48-
* @NoCSRFRequired
4951
*/
52+
#[NoAdminRequired]
53+
#[CORS]
54+
#[NoCSRFRequired]
5055
public function index(
5156
?string $category = null,
5257
string $exclude = '',
@@ -87,10 +92,11 @@ public function index(
8792

8893

8994
/**
90-
* @NoAdminRequired
91-
* @CORS
92-
* @NoCSRFRequired
95+
*
9396
*/
97+
#[NoAdminRequired]
98+
#[CORS]
99+
#[NoCSRFRequired]
94100
public function get(int $id, string $exclude = '') : JSONResponse {
95101
return $this->helper->handleErrorResponse(function () use ($id, $exclude) {
96102
$exclude = explode(',', $exclude);
@@ -104,10 +110,11 @@ public function get(int $id, string $exclude = '') : JSONResponse {
104110

105111

106112
/**
107-
* @NoAdminRequired
108-
* @CORS
109-
* @NoCSRFRequired
113+
*
110114
*/
115+
#[NoAdminRequired]
116+
#[CORS]
117+
#[NoCSRFRequired]
111118
public function create(
112119
string $category = '',
113120
string $title = '',
@@ -135,11 +142,11 @@ public function create(
135142
}
136143

137144
/**
138-
* @NoAdminRequired
139-
* @CORS
140-
* @NoCSRFRequired
141145
* @deprecated this was used in API v0.2 only, use #create() instead
142146
*/
147+
#[NoAdminRequired]
148+
#[CORS]
149+
#[NoCSRFRequired]
143150
public function createAutoTitle(
144151
string $category = '',
145152
string $content = '',
@@ -153,10 +160,11 @@ public function createAutoTitle(
153160
}
154161

155162
/**
156-
* @NoAdminRequired
157-
* @CORS
158-
* @NoCSRFRequired
163+
*
159164
*/
165+
#[NoAdminRequired]
166+
#[CORS]
167+
#[NoCSRFRequired]
160168
public function update(
161169
int $id,
162170
?string $content = null,
@@ -193,11 +201,11 @@ public function update(
193201
}
194202

195203
/**
196-
* @NoAdminRequired
197-
* @CORS
198-
* @NoCSRFRequired
199204
* @deprecated this was used in API v0.2 only, use #update() instead
200205
*/
206+
#[NoAdminRequired]
207+
#[CORS]
208+
#[NoCSRFRequired]
201209
public function updateAutoTitle(
202210
int $id,
203211
?string $content = null,
@@ -217,10 +225,11 @@ public function updateAutoTitle(
217225
}
218226

219227
/**
220-
* @NoAdminRequired
221-
* @CORS
222-
* @NoCSRFRequired
228+
*
223229
*/
230+
#[NoAdminRequired]
231+
#[CORS]
232+
#[NoCSRFRequired]
224233
public function destroy(int $id) : JSONResponse {
225234
return $this->helper->handleErrorResponse(function () use ($id) {
226235
$this->service->delete($this->helper->getUID(), $id);
@@ -229,10 +238,11 @@ public function destroy(int $id) : JSONResponse {
229238
}
230239

231240
/**
232-
* @NoAdminRequired
233-
* @CORS
234-
* @NoCSRFRequired
241+
*
235242
*/
243+
#[NoAdminRequired]
244+
#[CORS]
245+
#[NoCSRFRequired]
236246
public function setSettings() : JSONResponse {
237247
return $this->helper->handleErrorResponse(function () {
238248
$this->settingsService->setPublic($this->helper->getUID(), $this->request->getParams());
@@ -241,19 +251,20 @@ public function setSettings() : JSONResponse {
241251
}
242252

243253
/**
244-
* @NoAdminRequired
245-
* @CORS
246-
* @NoCSRFRequired
247254
*/
255+
#[NoAdminRequired]
256+
#[CORS]
257+
#[NoCSRFRequired]
248258
public function getSettings() : JSONResponse {
249259
return $this->helper->handleErrorResponse(function () {
250260
return $this->settingsService->getPublic($this->helper->getUID());
251261
});
252262
}
253263
/**
254-
* @NoAdminRequired
255-
* @NoCSRFRequired
264+
*
256265
*/
266+
#[NoAdminRequired]
267+
#[NoCSRFRequired]
257268
public function fail() : JSONResponse {
258269
return $this->helper->handleErrorResponse(function () {
259270
return new JSONResponse([], Http::STATUS_BAD_REQUEST);

lib/Controller/NotesController.php

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
use OCP\AppFramework\Http;
1919
use OCP\AppFramework\Http\JSONResponse;
2020
use OCP\AppFramework\Http\StreamResponse;
21+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
22+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
23+
2124
use OCP\Files\IMimeTypeDetector;
2225
use OCP\Files\Lock\ILock;
2326
use OCP\Files\Lock\ILockManager;
@@ -57,8 +60,9 @@ public function __construct(
5760
}
5861

5962
/**
60-
* @NoAdminRequired
63+
*
6164
*/
65+
#[NoAdminRequired]
6266
public function index(int $pruneBefore = 0) : JSONResponse {
6367
return $this->helper->handleErrorResponse(function () use ($pruneBefore) {
6468
$userId = $this->helper->getUID();
@@ -105,8 +109,9 @@ public function index(int $pruneBefore = 0) : JSONResponse {
105109

106110

107111
/**
108-
* @NoAdminRequired
112+
*
109113
*/
114+
#[NoAdminRequired]
110115
public function dashboard() : JSONResponse {
111116
return $this->helper->handleErrorResponse(function () {
112117
$maxItems = 6;
@@ -137,8 +142,9 @@ public function dashboard() : JSONResponse {
137142

138143

139144
/**
140-
* @NoAdminRequired
145+
*
141146
*/
147+
#[NoAdminRequired]
142148
public function get(int $id) : JSONResponse {
143149
return $this->helper->handleErrorResponse(function () use ($id) {
144150
$note = $this->notesService->get($this->helper->getUID(), $id);
@@ -160,8 +166,9 @@ public function get(int $id) : JSONResponse {
160166

161167

162168
/**
163-
* @NoAdminRequired
169+
*
164170
*/
171+
#[NoAdminRequired]
165172
public function create(string $category = '', string $content = '', string $title = '') : JSONResponse {
166173
return $this->helper->handleErrorResponse(function () use ($category, $content, $title) {
167174
$note = $this->notesService->create($this->helper->getUID(), $title, $category);
@@ -174,8 +181,9 @@ public function create(string $category = '', string $content = '', string $titl
174181

175182

176183
/**
177-
* @NoAdminRequired
184+
*
178185
*/
186+
#[NoAdminRequired]
179187
public function undo(
180188
int $id,
181189
string $title,
@@ -213,8 +221,9 @@ public function undo(
213221

214222

215223
/**
216-
* @NoAdminRequired
224+
*
217225
*/
226+
#[NoAdminRequired]
218227
public function autotitle(int $id) : JSONResponse {
219228
return $this->helper->handleErrorResponse(function () use ($id) {
220229
$note = $this->notesService->get($this->helper->getUID(), $id);
@@ -231,8 +240,9 @@ public function autotitle(int $id) : JSONResponse {
231240

232241

233242
/**
234-
* @NoAdminRequired
243+
*
235244
*/
245+
#[NoAdminRequired]
236246
public function update(int $id, string $content) : JSONResponse {
237247
return $this->helper->handleErrorResponse(function () use ($id, $content) {
238248
$note = $this->helper->getNoteWithETagCheck($id, $this->request);
@@ -243,8 +253,9 @@ public function update(int $id, string $content) : JSONResponse {
243253

244254

245255
/**
246-
* @NoAdminRequired
256+
*
247257
*/
258+
#[NoAdminRequired]
248259
public function updateProperty(
249260
int $id,
250261
string $property,
@@ -308,8 +319,9 @@ public function updateProperty(
308319

309320

310321
/**
311-
* @NoAdminRequired
322+
*
312323
*/
324+
#[NoAdminRequired]
313325
public function destroy(int $id) : JSONResponse {
314326
return $this->helper->handleErrorResponse(function () use ($id) {
315327
$this->notesService->delete($this->helper->getUID(), $id);
@@ -319,10 +331,10 @@ public function destroy(int $id) : JSONResponse {
319331

320332
/**
321333
* With help from: https://github.com/nextcloud/cookbook
322-
* @NoAdminRequired
323-
* @NoCSRFRequired
324334
* @return JSONResponse|StreamResponse
325335
*/
336+
#[NoAdminRequired]
337+
#[NoCSRFRequired]
326338
public function getAttachment(int $noteid, string $path): Http\Response {
327339
try {
328340
$targetimage = $this->notesService->getAttachment(
@@ -348,8 +360,9 @@ public function getAttachment(int $noteid, string $path): Http\Response {
348360
}
349361

350362
/**
351-
* @NoAdminRequired
363+
*
352364
*/
365+
#[NoAdminRequired]
353366
public function uploadFile(int $noteid): JSONResponse {
354367
$file = $this->request->getUploadedFile('file');
355368
return $this->helper->handleErrorResponse(function () use ($noteid, $file) {

lib/Controller/PageController.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
use OCP\AppFramework\Http\ContentSecurityPolicy;
2323
use OCP\AppFramework\Http\RedirectResponse;
2424
use OCP\AppFramework\Http\TemplateResponse;
25+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
26+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
2527
use OCP\AppFramework\Services\IInitialState;
2628
use OCP\EventDispatcher\IEventDispatcher;
2729
use OCP\IConfig;
@@ -58,10 +60,10 @@ public function __construct(
5860

5961

6062
/**
61-
* @NoAdminRequired
62-
* @NoCSRFRequired
6363
* @suppress PhanUndeclaredClassReference, PhanTypeMismatchArgument, PhanUndeclaredClassMethod
6464
*/
65+
#[NoAdminRequired]
66+
#[NoCSRFRequired]
6567
public function index() : TemplateResponse {
6668
$devMode = !is_file(dirname(__FILE__) . '/../../js/notes-main.js');
6769
$response = new TemplateResponse(
@@ -100,9 +102,10 @@ public function index() : TemplateResponse {
100102
}
101103

102104
/**
103-
* @NoAdminRequired
104-
* @NoCSRFRequired
105+
*
105106
*/
107+
#[NoAdminRequired]
108+
#[NoCSRFRequired]
106109
public function create() : RedirectResponse {
107110
$note = $this->notesService->create($this->userSession->getUser()->getUID(), '', '');
108111
$note->setContent('');

lib/Controller/SettingsController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use OCP\AppFramework\Controller;
1515
use OCP\AppFramework\Http\JSONResponse;
16+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
1617
use OCP\IRequest;
1718
use OCP\IUserSession;
1819

@@ -36,9 +37,9 @@ private function getUID(): string {
3637
}
3738

3839
/**
39-
* @NoAdminRequired
4040
* @throws \OCP\PreConditionNotMetException
4141
*/
42+
#[NoAdminRequired]
4243
public function set(): JSONResponse {
4344
$this->service->set(
4445
$this->getUID(),
@@ -48,15 +49,15 @@ public function set(): JSONResponse {
4849
}
4950

5051
/**
51-
* @NoAdminRequired
5252
*/
53+
#[NoAdminRequired]
5354
public function get(): JSONResponse {
5455
return new JSONResponse($this->service->getAll($this->getUID()));
5556
}
5657

5758
/**
58-
* @NoAdminRequired
5959
*/
60+
#[NoAdminRequired]
6061
public function migrate(): JSONResponse {
6162
$this->service->delete($this->getUID(), 'editorHint');
6263
return new JSONResponse();

0 commit comments

Comments
 (0)