Skip to content

Commit

Permalink
Merge pull request #2377 from nextcloud/backport/2375/stable25
Browse files Browse the repository at this point in the history
  • Loading branch information
juliushaertl authored Jul 13, 2023
2 parents 99ce39d + 754b819 commit 2b55911
Showing 1 changed file with 54 additions and 5 deletions.
59 changes: 54 additions & 5 deletions lib/Controller/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCA\GroupFolders\Mount\MountProvider;
use OCA\GroupFolders\Service\DelegationService;
use OCA\GroupFolders\Service\FoldersFilter;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\Files\IRootFolder;
Expand Down Expand Up @@ -84,10 +85,28 @@ public function getFolders(): DataResponse {
* @RequireGroupFolderAdmin
*/
public function getFolder(int $id): DataResponse {
return new DataResponse($this->manager->getFolder($id, $this->getRootFolderStorageId()));
$response = $this->checkFolderExists($id);
if ($response) {
return $response;
}

$storageId = $this->getRootFolderStorageId();
return new DataResponse($this->manager->getFolder($id, $storageId));
}

private function checkFolderExists(int $id): ?DataResponse {
$storageId = $this->getRootFolderStorageId();
if ($storageId === null) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$folder = $this->manager->getFolder($id, $storageId);
if ($folder === false) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
return null;
}

private function getRootFolderStorageId(): int {
private function getRootFolderStorageId(): ?int {
return $this->rootFolder->getMountPoint()->getNumericStorageId();
}

Expand All @@ -105,10 +124,12 @@ public function addFolder(string $mountpoint): DataResponse {
* @RequireGroupFolderAdmin
*/
public function removeFolder(int $id): DataResponse {
$folder = $this->mountProvider->getFolder($id);
if ($folder) {
$folder->delete();
$response = $this->checkFolderExists($id);
if ($response) {
return $response;
}
$folder = $this->mountProvider->getFolder($id);
$folder->delete();
$this->manager->removeFolder($id);
return new DataResponse(['success' => true]);
}
Expand All @@ -127,6 +148,10 @@ public function setMountPoint(int $id, string $mountPoint): DataResponse {
* @RequireGroupFolderAdmin
*/
public function addGroup(int $id, string $group): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
return $response;
}
$this->manager->addApplicableGroup($id, $group);
return new DataResponse(['success' => true]);
}
Expand All @@ -136,6 +161,10 @@ public function addGroup(int $id, string $group): DataResponse {
* @RequireGroupFolderAdmin
*/
public function removeGroup(int $id, string $group): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
return $response;
}
$this->manager->removeApplicableGroup($id, $group);
return new DataResponse(['success' => true]);
}
Expand All @@ -145,6 +174,10 @@ public function removeGroup(int $id, string $group): DataResponse {
* @RequireGroupFolderAdmin
*/
public function setPermissions(int $id, string $group, int $permissions): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
return $response;
}
$this->manager->setGroupPermissions($id, $group, $permissions);
return new DataResponse(['success' => true]);
}
Expand All @@ -155,6 +188,10 @@ public function setPermissions(int $id, string $group, int $permissions): DataRe
* @throws \OCP\DB\Exception
*/
public function setManageACL(int $id, string $mappingType, string $mappingId, bool $manageAcl): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
return $response;
}
$this->manager->setManageACL($id, $mappingType, $mappingId, $manageAcl);
return new DataResponse(['success' => true]);
}
Expand All @@ -164,6 +201,10 @@ public function setManageACL(int $id, string $mappingType, string $mappingId, bo
* @RequireGroupFolderAdmin
*/
public function setQuota(int $id, int $quota): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
return $response;
}
$this->manager->setFolderQuota($id, $quota);
return new DataResponse(['success' => true]);
}
Expand All @@ -173,6 +214,10 @@ public function setQuota(int $id, int $quota): DataResponse {
* @RequireGroupFolderAdmin
*/
public function setACL(int $id, bool $acl): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
return $response;
}
$this->manager->setFolderACL($id, $acl);
return new DataResponse(['success' => true]);
}
Expand All @@ -182,6 +227,10 @@ public function setACL(int $id, bool $acl): DataResponse {
* @RequireGroupFolderAdmin
*/
public function renameFolder(int $id, string $mountpoint): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
return $response;
}
$this->manager->renameFolder($id, $mountpoint);
return new DataResponse(['success' => true]);
}
Expand Down

0 comments on commit 2b55911

Please sign in to comment.