Skip to content

Commit 21c49b0

Browse files
committed
Chore(deprecation): 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 924814a commit 21c49b0

File tree

4 files changed

+82
-54
lines changed

4 files changed

+82
-54
lines changed

lib/Controller/NotesApiController.php

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717

1818
use OCP\AppFramework\ApiController;
1919
use OCP\AppFramework\Http;
20+
use OCP\AppFramework\Http\Attribute\CORS;
21+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
22+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
2023
use OCP\AppFramework\Http\JSONResponse;
2124
use OCP\AppFramework\Http\StreamResponse;
2225
use OCP\Files\IMimeTypeDetector;
26+
2327
use OCP\IRequest;
2428

2529
class NotesApiController extends ApiController {
@@ -48,10 +52,10 @@ public function __construct(
4852

4953

5054
/**
51-
* @NoAdminRequired
52-
* @CORS
53-
* @NoCSRFRequired
5455
*/
56+
#[NoAdminRequired]
57+
#[CORS]
58+
#[NoCSRFRequired]
5559
public function index(
5660
?string $category = null,
5761
string $exclude = '',
@@ -92,10 +96,11 @@ public function index(
9296

9397

9498
/**
95-
* @NoAdminRequired
96-
* @CORS
97-
* @NoCSRFRequired
99+
*
98100
*/
101+
#[NoAdminRequired]
102+
#[CORS]
103+
#[NoCSRFRequired]
99104
public function get(int $id, string $exclude = '') : JSONResponse {
100105
return $this->helper->handleErrorResponse(function () use ($id, $exclude) {
101106
$exclude = explode(',', $exclude);
@@ -109,10 +114,11 @@ public function get(int $id, string $exclude = '') : JSONResponse {
109114

110115

111116
/**
112-
* @NoAdminRequired
113-
* @CORS
114-
* @NoCSRFRequired
117+
*
115118
*/
119+
#[NoAdminRequired]
120+
#[CORS]
121+
#[NoCSRFRequired]
116122
public function create(
117123
string $category = '',
118124
string $title = '',
@@ -140,11 +146,11 @@ public function create(
140146
}
141147

142148
/**
143-
* @NoAdminRequired
144-
* @CORS
145-
* @NoCSRFRequired
146149
* @deprecated this was used in API v0.2 only, use #create() instead
147150
*/
151+
#[NoAdminRequired]
152+
#[CORS]
153+
#[NoCSRFRequired]
148154
public function createAutoTitle(
149155
string $category = '',
150156
string $content = '',
@@ -158,10 +164,11 @@ public function createAutoTitle(
158164
}
159165

160166
/**
161-
* @NoAdminRequired
162-
* @CORS
163-
* @NoCSRFRequired
167+
*
164168
*/
169+
#[NoAdminRequired]
170+
#[CORS]
171+
#[NoCSRFRequired]
165172
public function update(
166173
int $id,
167174
?string $content = null,
@@ -198,11 +205,11 @@ public function update(
198205
}
199206

200207
/**
201-
* @NoAdminRequired
202-
* @CORS
203-
* @NoCSRFRequired
204208
* @deprecated this was used in API v0.2 only, use #update() instead
205209
*/
210+
#[NoAdminRequired]
211+
#[CORS]
212+
#[NoCSRFRequired]
206213
public function updateAutoTitle(
207214
int $id,
208215
?string $content = null,
@@ -222,10 +229,11 @@ public function updateAutoTitle(
222229
}
223230

224231
/**
225-
* @NoAdminRequired
226-
* @CORS
227-
* @NoCSRFRequired
232+
*
228233
*/
234+
#[NoAdminRequired]
235+
#[CORS]
236+
#[NoCSRFRequired]
229237
public function destroy(int $id) : JSONResponse {
230238
return $this->helper->handleErrorResponse(function () use ($id) {
231239
$this->service->delete($this->helper->getUID(), $id);
@@ -234,10 +242,11 @@ public function destroy(int $id) : JSONResponse {
234242
}
235243

236244
/**
237-
* @NoAdminRequired
238-
* @CORS
239-
* @NoCSRFRequired
245+
*
240246
*/
247+
#[NoAdminRequired]
248+
#[CORS]
249+
#[NoCSRFRequired]
241250
public function setSettings() : JSONResponse {
242251
return $this->helper->handleErrorResponse(function () {
243252
$this->settingsService->setPublic($this->helper->getUID(), $this->request->getParams());
@@ -246,19 +255,20 @@ public function setSettings() : JSONResponse {
246255
}
247256

248257
/**
249-
* @NoAdminRequired
250-
* @CORS
251-
* @NoCSRFRequired
252258
*/
259+
#[NoAdminRequired]
260+
#[CORS]
261+
#[NoCSRFRequired]
253262
public function getSettings() : JSONResponse {
254263
return $this->helper->handleErrorResponse(function () {
255264
return $this->settingsService->getPublic($this->helper->getUID());
256265
});
257266
}
258267
/**
259-
* @NoAdminRequired
260-
* @NoCSRFRequired
268+
*
261269
*/
270+
#[NoAdminRequired]
271+
#[NoCSRFRequired]
262272
public function fail() : JSONResponse {
263273
return $this->helper->handleErrorResponse(function () {
264274
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
@@ -269,11 +279,11 @@ public function fail() : JSONResponse {
269279

270280
/**
271281
* With help from: https://github.com/nextcloud/cookbook
272-
* @NoAdminRequired
273-
* @CORS
274-
* @NoCSRFRequired
275282
* @return JSONResponse|StreamResponse
276283
*/
284+
#[NoAdminRequired]
285+
#[CORS]
286+
#[NoCSRFRequired]
277287
public function getAttachment(int $noteid, string $path): Http\Response {
278288
try {
279289
$targetimage = $this->service->getAttachment(
@@ -297,10 +307,11 @@ public function getAttachment(int $noteid, string $path): Http\Response {
297307
}
298308

299309
/**
300-
* @NoAdminRequired
301-
* @CORS
302-
* @NoCSRFRequired
310+
*
303311
*/
312+
#[NoAdminRequired]
313+
#[CORS]
314+
#[NoCSRFRequired]
304315
public function uploadFile(int $noteid): JSONResponse {
305316
$file = $this->request->getUploadedFile('file');
306317
return $this->helper->handleErrorResponse(function () use ($noteid, $file): array {

lib/Controller/NotesController.php

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616

1717
use OCP\AppFramework\Controller;
1818
use OCP\AppFramework\Http;
19+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
20+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
1921
use OCP\AppFramework\Http\JSONResponse;
2022
use OCP\AppFramework\Http\StreamResponse;
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
@@ -19,6 +19,8 @@
1919
use OCA\Viewer\Event\LoadViewer;
2020
use OCP\App\IAppManager;
2121
use OCP\AppFramework\Controller;
22+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
23+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
2224
use OCP\AppFramework\Http\ContentSecurityPolicy;
2325
use OCP\AppFramework\Http\RedirectResponse;
2426
use OCP\AppFramework\Http\TemplateResponse;
@@ -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
@@ -12,6 +12,7 @@
1212
use OCA\Notes\Service\SettingsService;
1313

1414
use OCP\AppFramework\Controller;
15+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
1516
use OCP\AppFramework\Http\JSONResponse;
1617
use OCP\IRequest;
1718
use OCP\IUserSession;
@@ -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)