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

[stable25] Check for folder existence in FolderController #2377

Merged
merged 1 commit into from
Jul 13, 2023
Merged
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
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);
Antreesy marked this conversation as resolved.
Show resolved Hide resolved
}
$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
Loading