Skip to content

Commit

Permalink
refactor(routes): Use attributes for routing
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Sep 9, 2024
1 parent 749f800 commit 309a633
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 93 deletions.
93 changes: 0 additions & 93 deletions appinfo/routes.php

This file was deleted.

4 changes: 4 additions & 0 deletions lib/Controller/DelegationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand Down Expand Up @@ -41,6 +42,7 @@ public function __construct(
* @RequireGroupFolderAdmin
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/delegation/groups')]
public function getAllGroups(): DataResponse {
// Get all groups
$groups = $this->groupManager->search('');
Expand All @@ -63,6 +65,7 @@ public function getAllGroups(): DataResponse {
* @RequireGroupFolderAdmin
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/delegation/circles')]
public function getAllCircles(): DataResponse {
$circlesEnabled = $this->appManager->isEnabledForUser('circles');
if (!$circlesEnabled) {
Expand Down Expand Up @@ -102,6 +105,7 @@ public function getAllCircles(): DataResponse {
* @RequireGroupFolderAdmin
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/delegation/authorized-groups')]
public function getAuthorizedGroups(string $classname = ""): DataResponse {
$data = [];
$authorizedGroups = $this->authorizedGroupService->findExistingGroupsForClass($classname);
Expand Down
14 changes: 14 additions & 0 deletions lib/Controller/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCA\GroupFolders\Service\FoldersFilter;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
Expand Down Expand Up @@ -89,6 +90,7 @@ private function formatFolder(array $folder): array {
}

#[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,6 +109,7 @@ public function getFolders(bool $applicable = false): DataResponse {
}

#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/folders/{id}')]
public function getFolder(int $id): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand Down Expand Up @@ -145,6 +148,7 @@ private function getRootFolderStorageId(): ?int {
* @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,6 +162,7 @@ public function addFolder(string $mountpoint): DataResponse {
* @RequireGroupFolderAdmin
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'DELETE', url: '/folders/{id}')]
public function removeFolder(int $id): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand All @@ -173,6 +178,7 @@ public function removeFolder(int $id): DataResponse {
* @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]);
Expand All @@ -182,6 +188,7 @@ public function setMountPoint(int $id, string $mountPoint): DataResponse {
* @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,6 +202,7 @@ public function addGroup(int $id, string $group): DataResponse {
* @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,6 +216,7 @@ public function removeGroup(int $id, string $group): DataResponse {
* @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 @@ -222,6 +231,7 @@ public function setPermissions(int $id, string $group, int $permissions): DataRe
* @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,6 +245,7 @@ public function setManageACL(int $id, string $mappingType, string $mappingId, bo
* @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,6 +259,7 @@ public function setQuota(int $id, int $quota): DataResponse {
* @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,6 +273,7 @@ public function setACL(int $id, bool $acl): DataResponse {
* @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 @@ -308,6 +321,7 @@ private function folderDataForXML(array $data): array {
}

#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/folders/{id}/search')]
public function aclMappingSearch(int $id, ?int $fileId, string $search = ''): DataResponse {
$users = [];
$groups = [];
Expand Down

0 comments on commit 309a633

Please sign in to comment.