Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(dashboard): Replace security annotations with respective attributes #46746

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions apps/dashboard/lib/Controller/DashboardApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use OCA\Dashboard\Service\DashboardService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\Dashboard\IAPIWidget;
Expand Down Expand Up @@ -67,9 +69,6 @@ static function (IWidget $widget) use ($widgetIds) {
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*
* Get the items for the widgets
*
* @param array<string, string> $sinceIds Array indexed by widget Ids, contains date/id from which we want the new items
Expand All @@ -80,6 +79,8 @@ static function (IWidget $widget) use ($widgetIds) {
*
* 200: Widget items returned
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[ApiRoute(verb: 'GET', url: '/api/v1/widget-items')]
public function getWidgetItems(array $sinceIds = [], int $limit = 7, array $widgets = []): DataResponse {
$items = [];
Expand All @@ -96,9 +97,6 @@ public function getWidgetItems(array $sinceIds = [], int $limit = 7, array $widg
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*
* Get the items for the widgets
*
* @param array<string, string> $sinceIds Array indexed by widget Ids, contains date/id from which we want the new items
Expand All @@ -109,6 +107,8 @@ public function getWidgetItems(array $sinceIds = [], int $limit = 7, array $widg
*
* 200: Widget items returned
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[ApiRoute(verb: 'GET', url: '/api/v2/widget-items')]
public function getWidgetItemsV2(array $sinceIds = [], int $limit = 7, array $widgets = []): DataResponse {
$items = [];
Expand All @@ -127,13 +127,12 @@ public function getWidgetItemsV2(array $sinceIds = [], int $limit = 7, array $wi
/**
* Get the widgets
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @return DataResponse<Http::STATUS_OK, array<string, DashboardWidget>, array{}>
*
* 200: Widgets returned
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[ApiRoute(verb: 'GET', url: '/api/v1/widgets')]
public function getWidgets(): DataResponse {
$widgets = $this->dashboardManager->getWidgets();
Expand Down Expand Up @@ -180,11 +179,11 @@ public function getWidgets(): DataResponse {
/**
* Get the layout
*
* @NoAdminRequired
* @return DataResponse<Http::STATUS_OK, array{layout: list<string>}, array{}>
*
* 200: Layout returned
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/api/v3/layout')]
public function getLayout(): DataResponse {
return new DataResponse(['layout' => $this->service->getLayout()]);
Expand All @@ -193,12 +192,12 @@ public function getLayout(): DataResponse {
/**
* Update the layout
*
* @NoAdminRequired
* @param list<string> $layout The new layout
* @return DataResponse<Http::STATUS_OK, array{layout: list<string>}, array{}>
*
* 200: Statuses updated successfully
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'POST', url: '/api/v3/layout')]
public function updateLayout(array $layout): DataResponse {
$this->config->setUserValue($this->userId, 'dashboard', 'layout', implode(',', $layout));
Expand All @@ -208,11 +207,11 @@ public function updateLayout(array $layout): DataResponse {
/**
* Get the statuses
*
* @NoAdminRequired
* @return DataResponse<Http::STATUS_OK, array{statuses: list<string>}, array{}>
*
* 200: Statuses returned
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/api/v3/statuses')]
public function getStatuses(): DataResponse {
return new DataResponse(['statuses' => $this->service->getStatuses()]);
Expand All @@ -221,12 +220,12 @@ public function getStatuses(): DataResponse {
/**
* Update the statuses
*
* @NoAdminRequired
* @param list<string> $statuses The new statuses
* @return DataResponse<Http::STATUS_OK, array{statuses: list<string>}, array{}>
*
* 200: Statuses updated successfully
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'POST', url: '/api/v3/statuses')]
public function updateStatuses(array $statuses): DataResponse {
$this->config->setUserValue($this->userId, 'dashboard', 'statuses', implode(',', $statuses));
Expand Down
6 changes: 4 additions & 2 deletions apps/dashboard/lib/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
Expand Down Expand Up @@ -41,10 +43,10 @@ public function __construct(
}

/**
* @NoCSRFRequired
* @NoAdminRequired
* @return TemplateResponse
*/
#[NoCSRFRequired]
#[NoAdminRequired]
#[FrontpageRoute(verb: 'GET', url: '/')]
public function index(): TemplateResponse {
\OCP\Util::addStyle('dashboard', 'dashboard');
Expand Down
Loading