/** * @NoAdminRequired * * @param int $id * @return JSONResponse */ public function create($id) { if ($this->incomingShareEnabled) { $this->externalManager->acceptShare($id); } return new JSONResponse(); }
/** * Accept a remote share * * @param array $params contains the shareID 'id' which should be accepted * @return \OC_OCS_Result */ public static function acceptShare($params) { $externalManager = new Manager(\OC::$server->getDatabaseConnection(), Filesystem::getMountManager(), Filesystem::getLoader(), \OC::$server->getHTTPHelper(), \OC::$server->getNotificationManager(), \OC_User::getUser()); if ($externalManager->acceptShare($params['id'])) { return new \OC_OCS_Result(); } return new \OC_OCS_Result(null, 404, "wrong share ID, share doesn't exist."); }
/** * Accept a remote share * * @param array $params contains the shareID 'id' which should be accepted * @return \OC_OCS_Result */ public static function acceptShare($params) { $externalManager = new Manager(\OC::$server->getDatabaseConnection(), Filesystem::getMountManager(), Filesystem::getLoader(), \OC::$server->getHTTPHelper(), \OC::$server->getNotificationManager(), \OC_User::getUser()); if ($externalManager->acceptShare((int) $params['id'])) { return new \OC_OCS_Result(); } // Make sure the user has no notification for something that does not exist anymore. $externalManager->processNotification((int) $params['id']); return new \OC_OCS_Result(null, 404, "wrong share ID, share doesn't exist."); }
public function testAddShare() { $shareData1 = ['remote' => 'http://localhost', 'token' => 'token1', 'password' => '', 'name' => '/SharedFolder', 'owner' => 'foobar', 'accepted' => false, 'user' => $this->uid]; $shareData2 = $shareData1; $shareData2['token'] = 'token2'; $shareData3 = $shareData1; $shareData3['token'] = 'token3'; // Add a share for "user" $this->assertSame(null, call_user_func_array([$this->manager, 'addShare'], $shareData1)); $openShares = $this->manager->getOpenShares(); $this->assertCount(1, $openShares); $this->assertExternalShareEntry($shareData1, $openShares[0], 1, '{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); \Test_Helper::invokePrivate($this->manager, 'setupMounts'); $this->assertNotMount('SharedFolder'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); // Add a second share for "user" with the same name $this->assertSame(null, call_user_func_array([$this->manager, 'addShare'], $shareData2)); $openShares = $this->manager->getOpenShares(); $this->assertCount(2, $openShares); $this->assertExternalShareEntry($shareData1, $openShares[0], 1, '{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); // New share falls back to "-1" appendix, because the name is already taken $this->assertExternalShareEntry($shareData2, $openShares[1], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1'); \Test_Helper::invokePrivate($this->manager, 'setupMounts'); $this->assertNotMount('SharedFolder'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1'); // Accept the first share $this->manager->acceptShare($openShares[0]['id']); // Check remaining shares - Accepted $acceptedShares = \Test_Helper::invokePrivate($this->manager, 'getShares', [true]); $this->assertCount(1, $acceptedShares); $shareData1['accepted'] = true; $this->assertExternalShareEntry($shareData1, $acceptedShares[0], 1, $shareData1['name']); // Check remaining shares - Open $openShares = $this->manager->getOpenShares(); $this->assertCount(1, $openShares); $this->assertExternalShareEntry($shareData2, $openShares[0], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1'); \Test_Helper::invokePrivate($this->manager, 'setupMounts'); $this->assertMount($shareData1['name']); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1'); // Add another share for "user" with the same name $this->assertSame(null, call_user_func_array([$this->manager, 'addShare'], $shareData3)); $openShares = $this->manager->getOpenShares(); $this->assertCount(2, $openShares); $this->assertExternalShareEntry($shareData2, $openShares[0], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1'); // New share falls back to the original name (no "-\d", because the name is not taken) $this->assertExternalShareEntry($shareData3, $openShares[1], 3, '{{TemporaryMountPointName#' . $shareData3['name'] . '}}'); \Test_Helper::invokePrivate($this->manager, 'setupMounts'); $this->assertMount($shareData1['name']); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1'); // Decline the third share $this->manager->declineShare($openShares[1]['id']); \Test_Helper::invokePrivate($this->manager, 'setupMounts'); $this->assertMount($shareData1['name']); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1'); // Check remaining shares - Accepted $acceptedShares = \Test_Helper::invokePrivate($this->manager, 'getShares', [true]); $this->assertCount(1, $acceptedShares); $shareData1['accepted'] = true; $this->assertExternalShareEntry($shareData1, $acceptedShares[0], 1, $shareData1['name']); // Check remaining shares - Open $openShares = $this->manager->getOpenShares(); $this->assertCount(1, $openShares); $this->assertExternalShareEntry($shareData2, $openShares[0], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1'); \Test_Helper::invokePrivate($this->manager, 'setupMounts'); $this->assertMount($shareData1['name']); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1'); $this->manager->removeUserShares($this->uid); $this->assertEmpty(\Test_Helper::invokePrivate($this->manager, 'getShares', [null]), 'Asserting all shares for the user have been deleted'); $this->mountManager->clear(); \Test_Helper::invokePrivate($this->manager, 'setupMounts'); $this->assertNotMount($shareData1['name']); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1'); }
/** * @NoAdminRequired * @NoOutgoingFederatedSharingRequired * * @param int $id * @return JSONResponse */ public function create($id) { $this->externalManager->acceptShare($id); return new JSONResponse(); }