I’m testing sharing with read and create file permission. So first, I logged in as owner
, call shareFolder()
and then setReadPermission()
. The folder is shared successully, but setReadPermission()
returns an error: Node for share not found, fileid: 1394
. If I logged in as assgined_to
, the permission changed to readonly. I think it’s because I delete folder many times to test sharing, so there’s cache or trashbin something. What should I fix?
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function shareFolder()
{
try {
$owner = $this->request->getParam(“owner”);
$assigned_to = $this->request->getParam(“assigned_to”);
$work_id = $this->request->getParam(“work_id”);
$userFolder = $this->rootFolder->getUserFolder($owner);
$this->authorizationService->hasAccessWork($work_id);if (!$userFolder->nodeExists("QLCV")) { $userFolder->newFolder("QLCV"); } $qlcvFolder = $userFolder->get("QLCV"); if (!$qlcvFolder->nodeExists($work_id)) { $qlcvFolder->newFolder($work_id); $workFolder = $qlcvFolder->get($work_id); $share = $this->shareManager->newShare(); $share->setSharedBy($owner); $share->setSharedWith($assigned_to); $share->setNode($workFolder); $share->setShareType(IShare::TYPE_USER); $share->setPermissions( Constants::PERMISSION_READ | Constants::PERMISSION_CREATE ); $this->shareManager->createShare($share); } return new JSONResponse([ "success" => true, ]); } catch (\Exception $e) { return new JSONResponse( ["error" => $e->getMessage()], $e->getCode() ); } } /** * @NoAdminRequired * @NoCSRFRequired */ public function setReadPermission($work_id, $assigned_to, $owner) { try { $this->authorizationService->hasAccessWork($work_id); $userFolder = $this->rootFolder->getUserFolder($owner); $qlcvFolder = $userFolder->get("QLCV"); if ($qlcvFolder->nodeExists($work_id)) { $workFolder = $qlcvFolder->get($work_id); $shares = $this->shareManager->getSharesBy( $owner, IShare::TYPE_USER ); foreach ($shares as $share) { if ( $share->getNode()->getId() === $workFolder->getId() && $share->getSharedWith() === $assigned_to ) { $share->setPermissions(Constants::PERMISSION_READ); $this->shareManager->updateShare($share); return new JSONResponse([ "success" => true, ]); } } } return new JSONResponse( [ "success" => false, ], Http::STATUS_BAD_REQUEST ); } catch (\Exception $e) { return new JSONResponse( ["error" => $e->getMessage()], $e->getCode() ); } }