Completed
Push — master ( 716513...8d5002 )
by
unknown
28:57
created
apps/dashboard/lib/Controller/DashboardApiController.php 1 patch
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -40,197 +40,197 @@
 block discarded – undo
40 40
  */
41 41
 class DashboardApiController extends OCSController {
42 42
 
43
-	public function __construct(
44
-		string $appName,
45
-		IRequest $request,
46
-		private IManager $dashboardManager,
47
-		private IAppConfig $appConfig,
48
-		private IUserConfig $userConfig,
49
-		private ?string $userId,
50
-		private DashboardService $service,
51
-	) {
52
-		parent::__construct($appName, $request);
53
-	}
54
-
55
-	/**
56
-	 * @param string[] $widgetIds Limit widgets to given ids
57
-	 * @return IWidget[]
58
-	 */
59
-	private function getShownWidgets(array $widgetIds): array {
60
-		if (empty($widgetIds)) {
61
-			$systemDefault = $this->appConfig->getAppValueString('layout', 'recommendations,spreed,mail,calendar');
62
-			$widgetIds = explode(',', $this->userConfig->getValueString($this->userId, 'dashboard', 'layout', $systemDefault));
63
-		}
64
-
65
-		return array_filter(
66
-			$this->dashboardManager->getWidgets(),
67
-			static function (IWidget $widget) use ($widgetIds) {
68
-				return in_array($widget->getId(), $widgetIds);
69
-			},
70
-		);
71
-	}
72
-
73
-	/**
74
-	 * Get the items for the widgets
75
-	 *
76
-	 * @param array<string, string> $sinceIds Array indexed by widget Ids, contains date/id from which we want the new items
77
-	 * @param int $limit Limit number of result items per widget
78
-	 * @psalm-param int<1, 30> $limit
79
-	 * @param list<string> $widgets Limit results to specific widgets
80
-	 * @return DataResponse<Http::STATUS_OK, array<string, list<DashboardWidgetItem>>, array{}>
81
-	 *
82
-	 * 200: Widget items returned
83
-	 */
84
-	#[NoAdminRequired]
85
-	#[NoCSRFRequired]
86
-	#[ApiRoute(verb: 'GET', url: '/api/v1/widget-items')]
87
-	public function getWidgetItems(array $sinceIds = [], int $limit = 7, array $widgets = []): DataResponse {
88
-		$items = [];
89
-		$widgets = $this->getShownWidgets($widgets);
90
-		foreach ($widgets as $widget) {
91
-			if ($widget instanceof IAPIWidget) {
92
-				$items[$widget->getId()] = array_map(static function (WidgetItem $item) {
93
-					return $item->jsonSerialize();
94
-				}, $widget->getItems($this->userId, $sinceIds[$widget->getId()] ?? null, $limit));
95
-			}
96
-		}
97
-
98
-		return new DataResponse($items);
99
-	}
100
-
101
-	/**
102
-	 * Get the items for the widgets
103
-	 *
104
-	 * @param array<string, string> $sinceIds Array indexed by widget Ids, contains date/id from which we want the new items
105
-	 * @param int $limit Limit number of result items per widget, not more than 30 are allowed
106
-	 * @psalm-param int<1, 30> $limit
107
-	 * @param list<string> $widgets Limit results to specific widgets
108
-	 * @return DataResponse<Http::STATUS_OK, array<string, DashboardWidgetItems>, array{}>
109
-	 *
110
-	 * 200: Widget items returned
111
-	 */
112
-	#[NoAdminRequired]
113
-	#[NoCSRFRequired]
114
-	#[ApiRoute(verb: 'GET', url: '/api/v2/widget-items')]
115
-	public function getWidgetItemsV2(array $sinceIds = [], int $limit = 7, array $widgets = []): DataResponse {
116
-		$items = [];
117
-		$widgets = $this->getShownWidgets($widgets);
118
-		foreach ($widgets as $widget) {
119
-			if ($widget instanceof IAPIWidgetV2) {
120
-				$items[$widget->getId()] = $widget
121
-					->getItemsV2($this->userId, $sinceIds[$widget->getId()] ?? null, $limit)
122
-					->jsonSerialize();
123
-			}
124
-		}
125
-
126
-		return new DataResponse($items);
127
-	}
128
-
129
-	/**
130
-	 * Get the widgets
131
-	 *
132
-	 * @return DataResponse<Http::STATUS_OK, array<string, DashboardWidget>, array{}>
133
-	 *
134
-	 * 200: Widgets returned
135
-	 */
136
-	#[NoAdminRequired]
137
-	#[NoCSRFRequired]
138
-	#[ApiRoute(verb: 'GET', url: '/api/v1/widgets')]
139
-	public function getWidgets(): DataResponse {
140
-		$widgets = $this->dashboardManager->getWidgets();
141
-
142
-		$items = array_map(function (IWidget $widget) {
143
-			$options = ($widget instanceof IOptionWidget) ? $widget->getWidgetOptions() : WidgetOptions::getDefault();
144
-			$data = [
145
-				'id' => $widget->getId(),
146
-				'title' => $widget->getTitle(),
147
-				'order' => $widget->getOrder(),
148
-				'icon_class' => $widget->getIconClass(),
149
-				'icon_url' => ($widget instanceof IIconWidget) ? $widget->getIconUrl() : '',
150
-				'widget_url' => $widget->getUrl(),
151
-				'item_icons_round' => $options->withRoundItemIcons(),
152
-				'item_api_versions' => [],
153
-				'reload_interval' => 0,
154
-			];
155
-			if ($widget instanceof IButtonWidget) {
156
-				$data += [
157
-					'buttons' => array_map(function (WidgetButton $button) {
158
-						return [
159
-							'type' => $button->getType(),
160
-							'text' => $button->getText(),
161
-							'link' => $button->getLink(),
162
-						];
163
-					}, $widget->getWidgetButtons($this->userId)),
164
-				];
165
-			}
166
-			if ($widget instanceof IReloadableWidget) {
167
-				$data['reload_interval'] = $widget->getReloadInterval();
168
-			}
169
-			if ($widget instanceof IAPIWidget) {
170
-				$data['item_api_versions'][] = 1;
171
-			}
172
-			if ($widget instanceof IAPIWidgetV2) {
173
-				$data['item_api_versions'][] = 2;
174
-			}
175
-			return $data;
176
-		}, $widgets);
177
-
178
-		return new DataResponse($items);
179
-	}
180
-
181
-	/**
182
-	 * Get the layout
183
-	 *
184
-	 * @return DataResponse<Http::STATUS_OK, array{layout: list<string>}, array{}>
185
-	 *
186
-	 * 200: Layout returned
187
-	 */
188
-	#[NoAdminRequired]
189
-	#[ApiRoute(verb: 'GET', url: '/api/v3/layout')]
190
-	public function getLayout(): DataResponse {
191
-		return new DataResponse(['layout' => $this->service->getLayout()]);
192
-	}
193
-
194
-	/**
195
-	 * Update the layout
196
-	 *
197
-	 * @param list<string> $layout The new layout
198
-	 * @return DataResponse<Http::STATUS_OK, array{layout: list<string>}, array{}>
199
-	 *
200
-	 * 200: Statuses updated successfully
201
-	 */
202
-	#[NoAdminRequired]
203
-	#[ApiRoute(verb: 'POST', url: '/api/v3/layout')]
204
-	public function updateLayout(array $layout): DataResponse {
205
-		$this->userConfig->setValueString($this->userId, 'dashboard', 'layout', implode(',', $layout));
206
-		return new DataResponse(['layout' => $layout]);
207
-	}
208
-
209
-	/**
210
-	 * Get the statuses
211
-	 *
212
-	 * @return DataResponse<Http::STATUS_OK, array{statuses: list<string>}, array{}>
213
-	 *
214
-	 * 200: Statuses returned
215
-	 */
216
-	#[NoAdminRequired]
217
-	#[ApiRoute(verb: 'GET', url: '/api/v3/statuses')]
218
-	public function getStatuses(): DataResponse {
219
-		return new DataResponse(['statuses' => $this->service->getStatuses()]);
220
-	}
221
-
222
-	/**
223
-	 * Update the statuses
224
-	 *
225
-	 * @param list<string> $statuses The new statuses
226
-	 * @return DataResponse<Http::STATUS_OK, array{statuses: list<string>}, array{}>
227
-	 *
228
-	 * 200: Statuses updated successfully
229
-	 */
230
-	#[NoAdminRequired]
231
-	#[ApiRoute(verb: 'POST', url: '/api/v3/statuses')]
232
-	public function updateStatuses(array $statuses): DataResponse {
233
-		$this->userConfig->setValueString($this->userId, 'dashboard', 'statuses', implode(',', $statuses));
234
-		return new DataResponse(['statuses' => $statuses]);
235
-	}
43
+    public function __construct(
44
+        string $appName,
45
+        IRequest $request,
46
+        private IManager $dashboardManager,
47
+        private IAppConfig $appConfig,
48
+        private IUserConfig $userConfig,
49
+        private ?string $userId,
50
+        private DashboardService $service,
51
+    ) {
52
+        parent::__construct($appName, $request);
53
+    }
54
+
55
+    /**
56
+     * @param string[] $widgetIds Limit widgets to given ids
57
+     * @return IWidget[]
58
+     */
59
+    private function getShownWidgets(array $widgetIds): array {
60
+        if (empty($widgetIds)) {
61
+            $systemDefault = $this->appConfig->getAppValueString('layout', 'recommendations,spreed,mail,calendar');
62
+            $widgetIds = explode(',', $this->userConfig->getValueString($this->userId, 'dashboard', 'layout', $systemDefault));
63
+        }
64
+
65
+        return array_filter(
66
+            $this->dashboardManager->getWidgets(),
67
+            static function (IWidget $widget) use ($widgetIds) {
68
+                return in_array($widget->getId(), $widgetIds);
69
+            },
70
+        );
71
+    }
72
+
73
+    /**
74
+     * Get the items for the widgets
75
+     *
76
+     * @param array<string, string> $sinceIds Array indexed by widget Ids, contains date/id from which we want the new items
77
+     * @param int $limit Limit number of result items per widget
78
+     * @psalm-param int<1, 30> $limit
79
+     * @param list<string> $widgets Limit results to specific widgets
80
+     * @return DataResponse<Http::STATUS_OK, array<string, list<DashboardWidgetItem>>, array{}>
81
+     *
82
+     * 200: Widget items returned
83
+     */
84
+    #[NoAdminRequired]
85
+    #[NoCSRFRequired]
86
+    #[ApiRoute(verb: 'GET', url: '/api/v1/widget-items')]
87
+    public function getWidgetItems(array $sinceIds = [], int $limit = 7, array $widgets = []): DataResponse {
88
+        $items = [];
89
+        $widgets = $this->getShownWidgets($widgets);
90
+        foreach ($widgets as $widget) {
91
+            if ($widget instanceof IAPIWidget) {
92
+                $items[$widget->getId()] = array_map(static function (WidgetItem $item) {
93
+                    return $item->jsonSerialize();
94
+                }, $widget->getItems($this->userId, $sinceIds[$widget->getId()] ?? null, $limit));
95
+            }
96
+        }
97
+
98
+        return new DataResponse($items);
99
+    }
100
+
101
+    /**
102
+     * Get the items for the widgets
103
+     *
104
+     * @param array<string, string> $sinceIds Array indexed by widget Ids, contains date/id from which we want the new items
105
+     * @param int $limit Limit number of result items per widget, not more than 30 are allowed
106
+     * @psalm-param int<1, 30> $limit
107
+     * @param list<string> $widgets Limit results to specific widgets
108
+     * @return DataResponse<Http::STATUS_OK, array<string, DashboardWidgetItems>, array{}>
109
+     *
110
+     * 200: Widget items returned
111
+     */
112
+    #[NoAdminRequired]
113
+    #[NoCSRFRequired]
114
+    #[ApiRoute(verb: 'GET', url: '/api/v2/widget-items')]
115
+    public function getWidgetItemsV2(array $sinceIds = [], int $limit = 7, array $widgets = []): DataResponse {
116
+        $items = [];
117
+        $widgets = $this->getShownWidgets($widgets);
118
+        foreach ($widgets as $widget) {
119
+            if ($widget instanceof IAPIWidgetV2) {
120
+                $items[$widget->getId()] = $widget
121
+                    ->getItemsV2($this->userId, $sinceIds[$widget->getId()] ?? null, $limit)
122
+                    ->jsonSerialize();
123
+            }
124
+        }
125
+
126
+        return new DataResponse($items);
127
+    }
128
+
129
+    /**
130
+     * Get the widgets
131
+     *
132
+     * @return DataResponse<Http::STATUS_OK, array<string, DashboardWidget>, array{}>
133
+     *
134
+     * 200: Widgets returned
135
+     */
136
+    #[NoAdminRequired]
137
+    #[NoCSRFRequired]
138
+    #[ApiRoute(verb: 'GET', url: '/api/v1/widgets')]
139
+    public function getWidgets(): DataResponse {
140
+        $widgets = $this->dashboardManager->getWidgets();
141
+
142
+        $items = array_map(function (IWidget $widget) {
143
+            $options = ($widget instanceof IOptionWidget) ? $widget->getWidgetOptions() : WidgetOptions::getDefault();
144
+            $data = [
145
+                'id' => $widget->getId(),
146
+                'title' => $widget->getTitle(),
147
+                'order' => $widget->getOrder(),
148
+                'icon_class' => $widget->getIconClass(),
149
+                'icon_url' => ($widget instanceof IIconWidget) ? $widget->getIconUrl() : '',
150
+                'widget_url' => $widget->getUrl(),
151
+                'item_icons_round' => $options->withRoundItemIcons(),
152
+                'item_api_versions' => [],
153
+                'reload_interval' => 0,
154
+            ];
155
+            if ($widget instanceof IButtonWidget) {
156
+                $data += [
157
+                    'buttons' => array_map(function (WidgetButton $button) {
158
+                        return [
159
+                            'type' => $button->getType(),
160
+                            'text' => $button->getText(),
161
+                            'link' => $button->getLink(),
162
+                        ];
163
+                    }, $widget->getWidgetButtons($this->userId)),
164
+                ];
165
+            }
166
+            if ($widget instanceof IReloadableWidget) {
167
+                $data['reload_interval'] = $widget->getReloadInterval();
168
+            }
169
+            if ($widget instanceof IAPIWidget) {
170
+                $data['item_api_versions'][] = 1;
171
+            }
172
+            if ($widget instanceof IAPIWidgetV2) {
173
+                $data['item_api_versions'][] = 2;
174
+            }
175
+            return $data;
176
+        }, $widgets);
177
+
178
+        return new DataResponse($items);
179
+    }
180
+
181
+    /**
182
+     * Get the layout
183
+     *
184
+     * @return DataResponse<Http::STATUS_OK, array{layout: list<string>}, array{}>
185
+     *
186
+     * 200: Layout returned
187
+     */
188
+    #[NoAdminRequired]
189
+    #[ApiRoute(verb: 'GET', url: '/api/v3/layout')]
190
+    public function getLayout(): DataResponse {
191
+        return new DataResponse(['layout' => $this->service->getLayout()]);
192
+    }
193
+
194
+    /**
195
+     * Update the layout
196
+     *
197
+     * @param list<string> $layout The new layout
198
+     * @return DataResponse<Http::STATUS_OK, array{layout: list<string>}, array{}>
199
+     *
200
+     * 200: Statuses updated successfully
201
+     */
202
+    #[NoAdminRequired]
203
+    #[ApiRoute(verb: 'POST', url: '/api/v3/layout')]
204
+    public function updateLayout(array $layout): DataResponse {
205
+        $this->userConfig->setValueString($this->userId, 'dashboard', 'layout', implode(',', $layout));
206
+        return new DataResponse(['layout' => $layout]);
207
+    }
208
+
209
+    /**
210
+     * Get the statuses
211
+     *
212
+     * @return DataResponse<Http::STATUS_OK, array{statuses: list<string>}, array{}>
213
+     *
214
+     * 200: Statuses returned
215
+     */
216
+    #[NoAdminRequired]
217
+    #[ApiRoute(verb: 'GET', url: '/api/v3/statuses')]
218
+    public function getStatuses(): DataResponse {
219
+        return new DataResponse(['statuses' => $this->service->getStatuses()]);
220
+    }
221
+
222
+    /**
223
+     * Update the statuses
224
+     *
225
+     * @param list<string> $statuses The new statuses
226
+     * @return DataResponse<Http::STATUS_OK, array{statuses: list<string>}, array{}>
227
+     *
228
+     * 200: Statuses updated successfully
229
+     */
230
+    #[NoAdminRequired]
231
+    #[ApiRoute(verb: 'POST', url: '/api/v3/statuses')]
232
+    public function updateStatuses(array $statuses): DataResponse {
233
+        $this->userConfig->setValueString($this->userId, 'dashboard', 'statuses', implode(',', $statuses));
234
+        return new DataResponse(['statuses' => $statuses]);
235
+    }
236 236
 }
Please login to merge, or discard this patch.
apps/dashboard/lib/Controller/DashboardController.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -29,59 +29,59 @@
 block discarded – undo
29 29
 #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
30 30
 class DashboardController extends Controller {
31 31
 
32
-	public function __construct(
33
-		string $appName,
34
-		IRequest $request,
35
-		private IInitialState $initialState,
36
-		private IManager $dashboardManager,
37
-		private IConfig $config,
38
-		private IUserConfig $userConfig,
39
-		private IL10N $l10n,
40
-		private ?string $userId,
41
-		private DashboardService $service,
42
-	) {
43
-		parent::__construct($appName, $request);
44
-	}
32
+    public function __construct(
33
+        string $appName,
34
+        IRequest $request,
35
+        private IInitialState $initialState,
36
+        private IManager $dashboardManager,
37
+        private IConfig $config,
38
+        private IUserConfig $userConfig,
39
+        private IL10N $l10n,
40
+        private ?string $userId,
41
+        private DashboardService $service,
42
+    ) {
43
+        parent::__construct($appName, $request);
44
+    }
45 45
 
46
-	/**
47
-	 * @return TemplateResponse
48
-	 */
49
-	#[NoCSRFRequired]
50
-	#[NoAdminRequired]
51
-	#[FrontpageRoute(verb: 'GET', url: '/')]
52
-	public function index(): TemplateResponse {
53
-		Util::addStyle('dashboard', 'dashboard');
54
-		Util::addScript('dashboard', 'main', 'theming');
46
+    /**
47
+     * @return TemplateResponse
48
+     */
49
+    #[NoCSRFRequired]
50
+    #[NoAdminRequired]
51
+    #[FrontpageRoute(verb: 'GET', url: '/')]
52
+    public function index(): TemplateResponse {
53
+        Util::addStyle('dashboard', 'dashboard');
54
+        Util::addScript('dashboard', 'main', 'theming');
55 55
 
56
-		$widgets = array_map(function (IWidget $widget) {
57
-			return [
58
-				'id' => $widget->getId(),
59
-				'title' => $widget->getTitle(),
60
-				'iconClass' => $widget->getIconClass(),
61
-				'iconUrl' => $widget instanceof IIconWidget ? $widget->getIconUrl() : '',
62
-				'url' => $widget->getUrl()
63
-			];
64
-		}, $this->dashboardManager->getWidgets());
56
+        $widgets = array_map(function (IWidget $widget) {
57
+            return [
58
+                'id' => $widget->getId(),
59
+                'title' => $widget->getTitle(),
60
+                'iconClass' => $widget->getIconClass(),
61
+                'iconUrl' => $widget instanceof IIconWidget ? $widget->getIconUrl() : '',
62
+                'url' => $widget->getUrl()
63
+            ];
64
+        }, $this->dashboardManager->getWidgets());
65 65
 
66
-		$this->initialState->provideInitialState('panels', $widgets);
67
-		$this->initialState->provideInitialState('statuses', $this->service->getStatuses());
68
-		$this->initialState->provideInitialState('layout', $this->service->getLayout());
69
-		$this->initialState->provideInitialState('appStoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true));
70
-		$this->initialState->provideInitialState('firstRun', $this->userConfig->getValueBool($this->userId, 'dashboard', 'firstRun', true));
71
-		$this->initialState->provideInitialState('birthdate', $this->service->getBirthdate());
72
-		$this->userConfig->setValueBool($this->userId, 'dashboard', 'firstRun', false);
66
+        $this->initialState->provideInitialState('panels', $widgets);
67
+        $this->initialState->provideInitialState('statuses', $this->service->getStatuses());
68
+        $this->initialState->provideInitialState('layout', $this->service->getLayout());
69
+        $this->initialState->provideInitialState('appStoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true));
70
+        $this->initialState->provideInitialState('firstRun', $this->userConfig->getValueBool($this->userId, 'dashboard', 'firstRun', true));
71
+        $this->initialState->provideInitialState('birthdate', $this->service->getBirthdate());
72
+        $this->userConfig->setValueBool($this->userId, 'dashboard', 'firstRun', false);
73 73
 
74
-		$response = new TemplateResponse('dashboard', 'index', [
75
-			'id-app-content' => '#app-dashboard',
76
-			'id-app-navigation' => null,
77
-			'pageTitle' => $this->l10n->t('Dashboard'),
78
-		]);
74
+        $response = new TemplateResponse('dashboard', 'index', [
75
+            'id-app-content' => '#app-dashboard',
76
+            'id-app-navigation' => null,
77
+            'pageTitle' => $this->l10n->t('Dashboard'),
78
+        ]);
79 79
 
80
-		// For the weather widget we should allow the geolocation
81
-		$featurePolicy = new FeaturePolicy();
82
-		$featurePolicy->addAllowedGeoLocationDomain('\'self\'');
83
-		$response->setFeaturePolicy($featurePolicy);
80
+        // For the weather widget we should allow the geolocation
81
+        $featurePolicy = new FeaturePolicy();
82
+        $featurePolicy->addAllowedGeoLocationDomain('\'self\'');
83
+        $response->setFeaturePolicy($featurePolicy);
84 84
 
85
-		return $response;
86
-	}
85
+        return $response;
86
+    }
87 87
 }
Please login to merge, or discard this patch.
apps/dashboard/lib/Service/DashboardService.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -16,61 +16,61 @@
 block discarded – undo
16 16
 use OCP\IUserManager;
17 17
 
18 18
 class DashboardService {
19
-	public function __construct(
20
-		private IUserConfig $userConfig,
21
-		private IAppConfig $appConfig,
22
-		private ?string $userId,
23
-		private IUserManager $userManager,
24
-		private IAccountManager $accountManager,
25
-	) {
19
+    public function __construct(
20
+        private IUserConfig $userConfig,
21
+        private IAppConfig $appConfig,
22
+        private ?string $userId,
23
+        private IUserManager $userManager,
24
+        private IAccountManager $accountManager,
25
+    ) {
26 26
 
27
-	}
27
+    }
28 28
 
29
-	/**
30
-	 * @return list<string>
31
-	 */
32
-	public function getLayout(): array {
33
-		$systemDefault = $this->appConfig->getAppValueString('layout', 'recommendations,spreed,mail,calendar');
34
-		return array_values(array_filter(
35
-			explode(',', $this->userConfig->getValueString($this->userId, 'dashboard', 'layout', $systemDefault)),
36
-			fn (string $value) => $value !== '')
37
-		);
38
-	}
29
+    /**
30
+     * @return list<string>
31
+     */
32
+    public function getLayout(): array {
33
+        $systemDefault = $this->appConfig->getAppValueString('layout', 'recommendations,spreed,mail,calendar');
34
+        return array_values(array_filter(
35
+            explode(',', $this->userConfig->getValueString($this->userId, 'dashboard', 'layout', $systemDefault)),
36
+            fn (string $value) => $value !== '')
37
+        );
38
+    }
39 39
 
40
-	/**
41
-	 * @return list<string>
42
-	 */
43
-	public function getStatuses(): array {
44
-		$configStatuses = $this->userConfig->getValueString($this->userId, 'dashboard', 'statuses');
45
-		try {
46
-			// Parse the old format
47
-			/** @var array<string, bool> $statuses */
48
-			$statuses = json_decode($configStatuses, true, 512, JSON_THROW_ON_ERROR);
49
-			// We avoid getting an empty array as it will not produce an object in UI's JS
50
-			return array_keys(array_filter($statuses, static fn (bool $value) => $value));
51
-		} catch (JsonException) {
52
-			return array_values(array_filter(explode(',', $configStatuses), fn (string $value) => $value !== ''));
53
-		}
54
-	}
40
+    /**
41
+     * @return list<string>
42
+     */
43
+    public function getStatuses(): array {
44
+        $configStatuses = $this->userConfig->getValueString($this->userId, 'dashboard', 'statuses');
45
+        try {
46
+            // Parse the old format
47
+            /** @var array<string, bool> $statuses */
48
+            $statuses = json_decode($configStatuses, true, 512, JSON_THROW_ON_ERROR);
49
+            // We avoid getting an empty array as it will not produce an object in UI's JS
50
+            return array_keys(array_filter($statuses, static fn (bool $value) => $value));
51
+        } catch (JsonException) {
52
+            return array_values(array_filter(explode(',', $configStatuses), fn (string $value) => $value !== ''));
53
+        }
54
+    }
55 55
 
56
-	public function getBirthdate(): string {
57
-		if ($this->userId === null) {
58
-			return '';
59
-		}
56
+    public function getBirthdate(): string {
57
+        if ($this->userId === null) {
58
+            return '';
59
+        }
60 60
 
61
-		$user = $this->userManager->get($this->userId);
62
-		if ($user === null) {
63
-			return '';
64
-		}
61
+        $user = $this->userManager->get($this->userId);
62
+        if ($user === null) {
63
+            return '';
64
+        }
65 65
 
66
-		$account = $this->accountManager->getAccount($user);
66
+        $account = $this->accountManager->getAccount($user);
67 67
 
68
-		try {
69
-			$birthdate = $account->getProperty(IAccountManager::PROPERTY_BIRTHDATE);
70
-		} catch (PropertyDoesNotExistException) {
71
-			return '';
72
-		}
68
+        try {
69
+            $birthdate = $account->getProperty(IAccountManager::PROPERTY_BIRTHDATE);
70
+        } catch (PropertyDoesNotExistException) {
71
+            return '';
72
+        }
73 73
 
74
-		return $birthdate->getValue();
75
-	}
74
+        return $birthdate->getValue();
75
+    }
76 76
 }
Please login to merge, or discard this patch.
apps/dashboard/tests/DashboardServiceTest.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -21,85 +21,85 @@
 block discarded – undo
21 21
 
22 22
 class DashboardServiceTest extends TestCase {
23 23
 
24
-	private IUserConfig&MockObject $userConfig;
25
-	private IAppConfig&MockObject $appConfig;
26
-	private IUserManager&MockObject $userManager;
27
-	private IAccountManager&MockObject $accountManager;
28
-	private DashboardService $service;
29
-
30
-	protected function setUp(): void {
31
-		parent::setUp();
32
-
33
-		$this->userConfig = $this->createMock(IUserConfig::class);
34
-		$this->appConfig = $this->createMock(IAppConfig::class);
35
-		$this->userManager = $this->createMock(IUserManager::class);
36
-		$this->accountManager = $this->createMock(IAccountManager::class);
37
-
38
-		$this->service = new DashboardService(
39
-			$this->userConfig,
40
-			$this->appConfig,
41
-			'alice',
42
-			$this->userManager,
43
-			$this->accountManager,
44
-		);
45
-	}
46
-
47
-	public function testGetBirthdate(): void {
48
-		$user = $this->createMock(IUser::class);
49
-		$this->userManager->method('get')
50
-			->willReturn($user);
51
-
52
-		$account = new Account($user);
53
-		$account->setProperty(
54
-			IAccountManager::PROPERTY_BIRTHDATE,
55
-			'2024-12-10T00:00:00.000Z',
56
-			IAccountManager::SCOPE_LOCAL,
57
-			IAccountManager::VERIFIED,
58
-		);
59
-
60
-		$this->accountManager->method('getAccount')
61
-			->willReturn($account);
62
-
63
-		$birthdate = $this->service->getBirthdate();
64
-
65
-		$this->assertEquals('2024-12-10T00:00:00.000Z', $birthdate);
66
-	}
67
-
68
-	public function testGetBirthdatePropertyDoesNotExist(): void {
69
-		$user = $this->createMock(IUser::class);
70
-		$this->userManager->method('get')
71
-			->willReturn($user);
72
-
73
-		$account = new Account($user);
74
-		$this->accountManager->method('getAccount')
75
-			->willReturn($account);
76
-
77
-		$birthdate = $this->service->getBirthdate();
78
-
79
-		$this->assertEquals('', $birthdate);
80
-	}
81
-
82
-	public function testGetBirthdateUserNotFound(): void {
83
-		$this->userManager->method('get')
84
-			->willReturn(null);
85
-
86
-		$birthdate = $this->service->getBirthdate();
87
-
88
-		$this->assertEquals('', $birthdate);
89
-	}
90
-
91
-	public function testGetBirthdateNoUserId(): void {
92
-		$service = new DashboardService(
93
-			$this->userConfig,
94
-			$this->appConfig,
95
-			null,
96
-			$this->userManager,
97
-			$this->accountManager,
98
-		);
99
-
100
-		$birthdate = $service->getBirthdate();
101
-
102
-		$this->assertEquals('', $birthdate);
103
-	}
24
+    private IUserConfig&MockObject $userConfig;
25
+    private IAppConfig&MockObject $appConfig;
26
+    private IUserManager&MockObject $userManager;
27
+    private IAccountManager&MockObject $accountManager;
28
+    private DashboardService $service;
29
+
30
+    protected function setUp(): void {
31
+        parent::setUp();
32
+
33
+        $this->userConfig = $this->createMock(IUserConfig::class);
34
+        $this->appConfig = $this->createMock(IAppConfig::class);
35
+        $this->userManager = $this->createMock(IUserManager::class);
36
+        $this->accountManager = $this->createMock(IAccountManager::class);
37
+
38
+        $this->service = new DashboardService(
39
+            $this->userConfig,
40
+            $this->appConfig,
41
+            'alice',
42
+            $this->userManager,
43
+            $this->accountManager,
44
+        );
45
+    }
46
+
47
+    public function testGetBirthdate(): void {
48
+        $user = $this->createMock(IUser::class);
49
+        $this->userManager->method('get')
50
+            ->willReturn($user);
51
+
52
+        $account = new Account($user);
53
+        $account->setProperty(
54
+            IAccountManager::PROPERTY_BIRTHDATE,
55
+            '2024-12-10T00:00:00.000Z',
56
+            IAccountManager::SCOPE_LOCAL,
57
+            IAccountManager::VERIFIED,
58
+        );
59
+
60
+        $this->accountManager->method('getAccount')
61
+            ->willReturn($account);
62
+
63
+        $birthdate = $this->service->getBirthdate();
64
+
65
+        $this->assertEquals('2024-12-10T00:00:00.000Z', $birthdate);
66
+    }
67
+
68
+    public function testGetBirthdatePropertyDoesNotExist(): void {
69
+        $user = $this->createMock(IUser::class);
70
+        $this->userManager->method('get')
71
+            ->willReturn($user);
72
+
73
+        $account = new Account($user);
74
+        $this->accountManager->method('getAccount')
75
+            ->willReturn($account);
76
+
77
+        $birthdate = $this->service->getBirthdate();
78
+
79
+        $this->assertEquals('', $birthdate);
80
+    }
81
+
82
+    public function testGetBirthdateUserNotFound(): void {
83
+        $this->userManager->method('get')
84
+            ->willReturn(null);
85
+
86
+        $birthdate = $this->service->getBirthdate();
87
+
88
+        $this->assertEquals('', $birthdate);
89
+    }
90
+
91
+    public function testGetBirthdateNoUserId(): void {
92
+        $service = new DashboardService(
93
+            $this->userConfig,
94
+            $this->appConfig,
95
+            null,
96
+            $this->userManager,
97
+            $this->accountManager,
98
+        );
99
+
100
+        $birthdate = $service->getBirthdate();
101
+
102
+        $this->assertEquals('', $birthdate);
103
+    }
104 104
 
105 105
 }
Please login to merge, or discard this patch.