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(routes): Use attributes for routing #3182

Merged
merged 3 commits into from
Sep 9, 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
92 changes: 0 additions & 92 deletions appinfo/routes.php

This file was deleted.

11 changes: 8 additions & 3 deletions lib/Controller/DelegationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use OCA\GroupFolders\Service\DelegationService;
use OCA\Settings\Service\AuthorizedGroupService;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IConfig;
Expand All @@ -37,9 +39,10 @@ public function __construct(
/**
* Returns the list of all groups
*
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/delegation/groups')]
public function getAllGroups(): DataResponse {
// Get all groups
$groups = $this->groupManager->search('');
Expand All @@ -59,9 +62,10 @@ public function getAllGroups(): DataResponse {
/**
* Returns the list of all visible circles
*
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/delegation/circles')]
public function getAllCircles(): DataResponse {
$circlesEnabled = $this->appManager->isEnabledForUser('circles');
if (!$circlesEnabled) {
Expand Down Expand Up @@ -98,9 +102,10 @@ public function getAllCircles(): DataResponse {
* - OCA\GroupFolders\Settings\Admin : It's reference to fields in Admin Priveleges.
* - OCA\GroupFolders\Controller\DelegationController : It's just to specific the subadmins.
* They can only manage groupfolders in which they are added in the Advanced Permissions (groups only)
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/delegation/authorized-groups')]
public function getAuthorizedGroups(string $classname = ""): DataResponse {
$data = [];
$authorizedGroups = $this->authorizedGroupService->findExistingGroupsForClass($classname);
Expand Down
47 changes: 28 additions & 19 deletions lib/Controller/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use OCA\GroupFolders\Service\DelegationService;
use OCA\GroupFolders\Service\FoldersFilter;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
Expand Down Expand Up @@ -87,9 +89,8 @@ private function formatFolder(array $folder): array {
return $folder;
}

/**
* @NoAdminRequired
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/folders')]
public function getFolders(bool $applicable = false): DataResponse {
$folders = $this->manager->getAllFoldersWithSize($this->getRootFolderStorageId());
$folders = array_map([$this, 'formatFolder'], $folders);
Expand All @@ -107,9 +108,8 @@ public function getFolders(bool $applicable = false): DataResponse {
return new DataResponse($folders);
}

/**
* @NoAdminRequired
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/folders/{id}')]
public function getFolder(int $id): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand Down Expand Up @@ -145,9 +145,10 @@ private function getRootFolderStorageId(): ?int {

/**
* @RequireGroupFolderAdmin
* @NoAdminRequired
* @throws OCSNotFoundException
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'POST', url: '/folders')]
public function addFolder(string $mountpoint): DataResponse {
$id = $this->manager->createFolder(trim($mountpoint));
$folder = $this->manager->getFolder($id, $this->rootFolder->getMountPoint()->getNumericStorageId());
Expand All @@ -158,9 +159,10 @@ public function addFolder(string $mountpoint): DataResponse {
}

/**
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'DELETE', url: '/folders/{id}')]
public function removeFolder(int $id): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand All @@ -173,18 +175,20 @@ public function removeFolder(int $id): DataResponse {
}

/**
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'PUT', url: '/folders/{id}')]
public function setMountPoint(int $id, string $mountPoint): DataResponse {
$this->manager->renameFolder($id, trim($mountPoint));
return new DataResponse(['success' => true]);
}

/**
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'POST', url: '/folders/{id}/groups')]
public function addGroup(int $id, string $group): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand All @@ -195,9 +199,10 @@ public function addGroup(int $id, string $group): DataResponse {
}

/**
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'DELETE', url: '/folders/{id}/groups/{group}', requirements: ['group' => '.+'])]
public function removeGroup(int $id, string $group): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand All @@ -208,9 +213,10 @@ public function removeGroup(int $id, string $group): DataResponse {
}

/**
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'POST', url: '/folders/{id}/groups/{group}', requirements: ['group' => '.+'])]
public function setPermissions(int $id, string $group, int $permissions): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand All @@ -221,10 +227,11 @@ public function setPermissions(int $id, string $group, int $permissions): DataRe
}

/**
* @NoAdminRequired
* @RequireGroupFolderAdmin
* @throws \OCP\DB\Exception
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'POST', url: '/folders/{id}/manageACL')]
public function setManageACL(int $id, string $mappingType, string $mappingId, bool $manageAcl): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand All @@ -235,9 +242,10 @@ public function setManageACL(int $id, string $mappingType, string $mappingId, bo
}

/**
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'POST', url: '/folders/{id}/quota')]
public function setQuota(int $id, int $quota): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand All @@ -248,9 +256,10 @@ public function setQuota(int $id, int $quota): DataResponse {
}

/**
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'POST', url: '/folders/{id}/acl')]
public function setACL(int $id, bool $acl): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand All @@ -261,9 +270,10 @@ public function setACL(int $id, bool $acl): DataResponse {
}

/**
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'POST', url: '/folders/{id}/mountpoint')]
public function renameFolder(int $id, string $mountpoint): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand Down Expand Up @@ -310,9 +320,8 @@ private function folderDataForXML(array $data): array {
return $data;
}

/**
* @NoAdminRequired
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/folders/{id}/search')]
public function aclMappingSearch(int $id, ?int $fileId, string $search = ''): DataResponse {
$users = [];
$groups = [];
Expand Down
4 changes: 2 additions & 2 deletions src/components/SharingSidebarView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
<script>
import axios from '@nextcloud/axios'
import { showError } from '@nextcloud/dialogs'
import { generateUrl } from '@nextcloud/router'
import { generateOcsUrl } from '@nextcloud/router'
import NcAvatar from '@nextcloud/vue/dist/Components/NcAvatar.js'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'
Expand Down Expand Up @@ -276,7 +276,7 @@ export default {
}
searchRequestCancelSource = axios.CancelToken.source()
this.isSearching = true
axios.get(generateUrl(`apps/groupfolders/folders/${this.groupFolderId}/search`) + '?format=json&search=' + query, {
axios.get(generateOcsUrl(`apps/groupfolders/folders/${this.groupFolderId}/search`) + '?format=json&search=' + query, {
cancelToken: searchRequestCancelSource.token,
}).then((result) => {
this.isSearching = false
Expand Down
4 changes: 2 additions & 2 deletions src/settings/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { generateUrl } from '@nextcloud/router'
import { generateUrl, generateOcsUrl } from '@nextcloud/router'
import { OCSResult, AxiosOCSResult } from 'NC'
import axios from '@nextcloud/axios'
import Thenable = JQuery.Thenable;
Expand Down Expand Up @@ -47,7 +47,7 @@ export interface Folder {
export class Api {

getUrl(endpoint: string): string {
return OC.generateUrl(`apps/groupfolders/${endpoint}`)
return generateOcsUrl(`apps/groupfolders/${endpoint}`)
}

listFolders(): Thenable<Folder[]> {
Expand Down
2 changes: 0 additions & 2 deletions src/settings/Nextcloud.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ declare namespace OC {
}
}

function generateUrl(url: string, parameters?: { [key: string]: string }, options?: EscapeOptions)

function linkToOCS(service: string, version: number): string;

function linkToRemote(path: string): string;
Expand Down
Loading