11
11
* @author Janis Köhr <janis.koehr@novatec-gmbh.de>
12
12
* @author John Molakvoæ <skjnldsv@protonmail.com>
13
13
* @author Roeland Jago Douma <roeland@famdouma.nl>
14
+ * @author Kate Döen <kate.doeen@nextcloud.com>
14
15
*
15
16
* @license GNU AGPL version 3 or any later version
16
17
*
32
33
33
34
use OCA \Theming \AppInfo \Application ;
34
35
use OCA \Theming \ITheme ;
36
+ use OCA \Theming \ResponseDefinitions ;
35
37
use OCA \Theming \Service \BackgroundService ;
36
38
use OCA \Theming \Service \ThemesService ;
37
39
use OCA \Theming \ThemingDefaults ;
48
50
use OCP \IUserSession ;
49
51
use OCP \PreConditionNotMetException ;
50
52
53
+ /**
54
+ * @psalm-import-type ThemingBackground from ResponseDefinitions
55
+ */
51
56
class UserThemeController extends OCSController {
52
57
53
58
protected ?string $ userId = null ;
54
-
59
+
55
60
private IConfig $ config ;
56
61
private IUserSession $ userSession ;
57
62
private ThemesService $ themesService ;
@@ -84,8 +89,11 @@ public function __construct(string $appName,
84
89
* Enable theme
85
90
*
86
91
* @param string $themeId the theme ID
87
- * @return DataResponse
88
- * @throws OCSBadRequestException|PreConditionNotMetException
92
+ * @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
93
+ * @throws OCSBadRequestException Enabling theme is not possible
94
+ * @throws PreConditionNotMetException
95
+ *
96
+ * 200: Theme enabled successfully
89
97
*/
90
98
public function enableTheme (string $ themeId ): DataResponse {
91
99
$ theme = $ this ->validateTheme ($ themeId );
@@ -101,8 +109,11 @@ public function enableTheme(string $themeId): DataResponse {
101
109
* Disable theme
102
110
*
103
111
* @param string $themeId the theme ID
104
- * @return DataResponse
105
- * @throws OCSBadRequestException|PreConditionNotMetException
112
+ * @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
113
+ * @throws OCSBadRequestException Disabling theme is not possible
114
+ * @throws PreConditionNotMetException
115
+ *
116
+ * 200: Theme disabled successfully
106
117
*/
107
118
public function disableTheme (string $ themeId ): DataResponse {
108
119
$ theme = $ this ->validateTheme ($ themeId );
@@ -119,7 +130,8 @@ public function disableTheme(string $themeId): DataResponse {
119
130
*
120
131
* @param string $themeId the theme ID
121
132
* @return ITheme
122
- * @throws OCSBadRequestException|PreConditionNotMetException
133
+ * @throws OCSBadRequestException
134
+ * @throws PreConditionNotMetException
123
135
*/
124
136
private function validateTheme (string $ themeId ): ITheme {
125
137
if ($ themeId === '' || !$ themeId ) {
@@ -143,6 +155,12 @@ private function validateTheme(string $themeId): ITheme {
143
155
/**
144
156
* @NoAdminRequired
145
157
* @NoCSRFRequired
158
+ *
159
+ * Get the background image
160
+ * @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>|NotFoundResponse<Http::STATUS_NOT_FOUND, array{}>
161
+ *
162
+ * 200: Background image returned
163
+ * 404: Background image not found
146
164
*/
147
165
public function getBackground (): Http \Response {
148
166
$ file = $ this ->backgroundService ->getBackground ();
@@ -156,6 +174,10 @@ public function getBackground(): Http\Response {
156
174
157
175
/**
158
176
* @NoAdminRequired
177
+ *
178
+ * Delete the background
179
+ *
180
+ * @return JSONResponse<Http::STATUS_OK, ThemingBackground, array{}>
159
181
*/
160
182
public function deleteBackground (): JSONResponse {
161
183
$ currentVersion = (int )$ this ->config ->getUserValue ($ this ->userId , Application::APP_ID , 'userCacheBuster ' , '0 ' );
@@ -169,6 +191,16 @@ public function deleteBackground(): JSONResponse {
169
191
170
192
/**
171
193
* @NoAdminRequired
194
+ *
195
+ * Set the background
196
+ *
197
+ * @param string $type Type of background
198
+ * @param string $value Path of the background image
199
+ * @param string|null $color Color for the background
200
+ * @return JSONResponse<Http::STATUS_OK, ThemingBackground, array{}>|JSONResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_INTERNAL_SERVER_ERROR, array{error: string}, array{}>
201
+ *
202
+ * 200: Background set successfully
203
+ * 400: Setting background is not possible
172
204
*/
173
205
public function setBackground (string $ type = BackgroundService::BACKGROUND_DEFAULT , string $ value = '' , string $ color = null ): JSONResponse {
174
206
$ currentVersion = (int )$ this ->config ->getUserValue ($ this ->userId , Application::APP_ID , 'userCacheBuster ' , '0 ' );
0 commit comments