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

Remove the trashed state from fileId endpoint #554

Merged
Show file tree
Hide file tree
Changes from 5 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
53 changes: 10 additions & 43 deletions lib/Controller/FilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@

namespace OCA\OpenProject\Controller;

use Exception;
use OCA\Activity\Data;
use OCA\Activity\GroupHelperDisabled;
use OCA\Activity\UserSettings;
use OCA\Files_Trashbin\Trash\ITrashManager;
use OCP\Activity\IManager;
use OCP\App\IAppManager;
use OCP\AppFramework\QueryException;
use OCP\Files\Config\ICachedMountFileInfo;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\FileInfo;
Expand All @@ -33,7 +29,6 @@
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Server;
use Throwable;
use OCP\Files\DavUtil;

class FilesController extends OCSController {
Expand Down Expand Up @@ -67,14 +62,6 @@ class FilesController extends OCSController {
* @var IUserManager
*/
private $userManager;
/**
* @var IAppManager
*/
private $appManager;
/**
* @var ITrashManager
*/
private $trashManager = null;
/**
* @var DavUtil
*/
Expand All @@ -87,7 +74,6 @@ class FilesController extends OCSController {
* @param IUserSession $userSession
* @param IMountProviderCollection $mountCollection
* @param IManager $activityManager
* @param IAppManager $appManager
* @param IDBConnection $connection
* @param ILogger $logger
* @param IUserManager $userManager
Expand All @@ -100,7 +86,6 @@ public function __construct(string $appName,
IUserSession $userSession,
IMountProviderCollection $mountCollection,
IManager $activityManager,
IAppManager $appManager,
IDBConnection $connection,
ILogger $logger,
IUserManager $userManager,
Expand All @@ -114,7 +99,6 @@ public function __construct(string $appName,
$this->connection = $connection;
$this->logger = $logger;
$this->userManager = $userManager;
$this->appManager = $appManager;
$this->davUtils = $davUtils;
}

Expand Down Expand Up @@ -155,20 +139,6 @@ public function getFilesInfo(?array $fileIds): DataResponse {
return new DataResponse($result);
}

/**
* Function to make the trash-manager testable
*
* @param ITrashManager|null $trashManager
* @return void
* @throws QueryException
*/
public function setTrashManager(ITrashManager $trashManager = null): void {
if ($trashManager !== null) {
$this->trashManager = $trashManager;
} elseif ($this->trashManager === null) {
$this->trashManager = \OC::$server->get(ITrashManager::class);
}
}
/**
* @param int $fileId
* @return array<mixed>
Expand All @@ -178,24 +148,12 @@ public function setTrashManager(ITrashManager $trashManager = null): void {
*/
private function compileFileInfo($fileId) {
$file = null;
$trashed = false;

$userFolder = $this->rootFolder->getUserFolder($this->user->getUID());
$files = $userFolder->getById($fileId);
if (is_array($files) && count($files) > 0) {
$file = $files[0];
} elseif ($this->appManager->isEnabledForUser('files_trashbin')) {
try {
$this->setTrashManager();
$file = $this->trashManager->getTrashNodeById(
$this->user, $fileId
);
$trashed = true;
} catch (Exception | Throwable $e) {
$this->logger->error('failed to use the trashManager', ['exception' => $e]);
}
}

$mounts = $this->mountCollection->getMountCache()->getMountsForFileId($fileId);

if ($file !== null && is_array($mounts) && count($mounts) > 0) {
Expand Down Expand Up @@ -249,7 +207,6 @@ private function compileFileInfo($fileId) {
'size' => $file->getSize(),
'owner_name' => $owner->getDisplayName(),
'owner_id' => $owner->getUID(),
'trashed' => $trashed,
'modifier_name' => $modifierName,
'modifier_id' => $modifierId,
'dav_permissions' => $davPermission,
Expand All @@ -258,6 +215,16 @@ private function compileFileInfo($fileId) {
}

if (is_array($mounts) && count($mounts) > 0) {
// if the file is in trashbin send 404
foreach ($mounts as $mount) {
if (str_starts_with($mount->getInternalPath(), 'files_trashbin')) {
return [
'status' => 'Not Found',
'statuscode' => 404,
];
}
}
// if the file is of another user send 403
return [
'status' => 'Forbidden',
'statuscode' => 403,
Expand Down
Loading
Loading