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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for folder existence in FolderController #2375

Merged
merged 2 commits into from
May 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 49 additions & 6 deletions lib/Controller/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ public function getFolders(bool $applicable = false): DataResponse {
* @NoAdminRequired
*/
public function getFolder(int $id): DataResponse {
$storageId = $this->getRootFolderStorageId();
if ($storageId === null) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
$response = $this->checkFolderExists($id);
if ($response) {
return $response;
}

$storageId = $this->getRootFolderStorageId();
$folder = $this->manager->getFolder($id, $storageId);
if (!$this->delegationService->hasApiAccess()) {
$folder = $this->filterNonAdminFolder($folder);
Expand All @@ -139,6 +140,18 @@ public function getFolder(int $id): DataResponse {
return new DataResponse($this->formatFolder($folder));
}

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 {
return $this->rootFolder->getMountPoint()->getNumericStorageId();
}
Expand All @@ -157,10 +170,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 @@ -179,6 +194,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 @@ -188,6 +207,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 @@ -197,6 +220,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 @@ -207,6 +234,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 @@ -216,6 +247,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 @@ -225,6 +260,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 @@ -234,6 +273,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