/** * Create the default share provider. * * @return DefaultShareProvider */ protected function defaultShareProvider() { if ($this->defaultProvider === null) { $this->defaultProvider = new DefaultShareProvider($this->serverContainer->getDatabaseConnection(), $this->serverContainer->getUserManager(), $this->serverContainer->getGroupManager(), $this->serverContainer->getRootFolder()); } return $this->defaultProvider; }
/** * Create new LDAPProvider * @param \OCP\IServerContainer $serverContainer * @throws \Exception if user_ldap app was not enabled */ public function __construct(IServerContainer $serverContainer, Helper $helper, DeletedUsersIndex $deletedUsersIndex) { $this->logger = $serverContainer->getLogger(); $this->helper = $helper; $this->deletedUsersIndex = $deletedUsersIndex; foreach ($serverContainer->getUserManager()->getBackends() as $backend) { $this->logger->debug('instance ' . get_class($backend) . ' backend.', ['app' => 'user_ldap']); if ($backend instanceof IUserLDAP) { $this->backend = $backend; return; } } throw new \Exception('To use the LDAPProvider, user_ldap app must be enabled'); }
/** * Creates a share of either a file or a folder, either publicly or with the tester * * @param string $nodeType * @param string|null $shareWith * * @return bool|string */ protected function createShare($nodeType, $shareWith = null) { /** * Pick the file or the folder */ if ($nodeType === 'file') { $sharedNode = $this->sharedFile; } else { $sharedNode = $this->sharedFolder; } $fileInfo = $sharedNode->getFileInfo(); /** * Decide which type of share it is */ $shareType = \OCP\Share::SHARE_TYPE_USER; if ($shareWith === null) { // We need to make sure sharing via link is enabled $this->server->getConfig()->setAppValue('core', 'shareapi_allow_links', 'yes'); // Only password protect the folders if ($nodeType === 'folder') { $shareWith = $this->passwordForFolderShare; } $shareType = \OCP\Share::SHARE_TYPE_LINK; } /** * Share and generate the token if it's a public share */ return Share::shareItem($nodeType, $fileInfo['fileid'], $shareType, $shareWith, \OCP\Constants::PERMISSION_ALL); }
/** * Creates an environment for a logged in user * * @return Environment */ protected function setUserBasedEnv() { $this->coreTestCase->loginAsUser($this->userId); $this->userFolder = $this->server->getUserFolder($this->userId); $environment = $this->instantiateEnvironment(); $environment->setStandardEnv(); return $environment; }
/** * @param array $fileIds * @param \OC_EventSource $eventSource */ public function indexFiles(array $fileIds, \OC_EventSource $eventSource = null) { foreach ($fileIds as $id) { $fileStatus = $this->mapper->getOrCreateFromFileId($id); try { // before we start mark the file as error so we know there // was a problem in case the php execution dies and we don't try // the file again $this->mapper->markError($fileStatus); $nodes = $this->server->getUserFolder()->getById($id); // getById can return more than one id because the containing storage might be mounted more than once // Since we only want to index the file once, we only use the first entry if (isset($nodes[0])) { /** @var File $node */ $node = $nodes[0]; } else { throw new VanishedException($id); } if (!$node instanceof File) { throw new NotIndexedException(); } $path = $node->getPath(); foreach ($this->skippedDirs as $skippedDir) { if (strpos($path, '/' . $skippedDir . '/') !== false || strrpos($path, '/' . $skippedDir) === strlen($path) - (strlen($skippedDir) + 1)) { throw new SkippedException('skipping file ' . $id . ':' . $path); } } if ($eventSource) { $eventSource->send('indexing', $path); } if ($this->indexFile($node, false)) { $this->mapper->markIndexed($fileStatus); } } catch (VanishedException $e) { $this->mapper->markVanished($fileStatus); } catch (NotIndexedException $e) { $this->mapper->markUnIndexed($fileStatus); } catch (SkippedException $e) { $this->mapper->markSkipped($fileStatus); $this->logger->debug($e->getMessage()); } catch (\Exception $e) { //sqlite might report database locked errors when stock filescan is in progress //this also catches db locked exception that might come up when using sqlite $this->logger->error($e->getMessage() . ' Trace:\\n' . $e->getTraceAsString()); $this->mapper->markError($fileStatus); // TODO Add UI to trigger rescan of files with status 'E'rror? if ($eventSource) { $eventSource->send('error', $e->getMessage()); } } } $this->index->commit(); }
/** * Create the federated share provider * * @return FederatedShareProvider */ protected function federatedShareProvider() { if ($this->federatedProvider === null) { /* * Check if the app is enabled */ $appManager = $this->serverContainer->getAppManager(); if (!$appManager->isEnabledForUser('federatedfilesharing')) { return null; } /* * TODO: add factory to federated sharing app */ $l = $this->serverContainer->getL10N('federatedfilessharing'); $addressHandler = new AddressHandler($this->serverContainer->getURLGenerator(), $l); $discoveryManager = new DiscoveryManager($this->serverContainer->getMemCacheFactory(), $this->serverContainer->getHTTPClientService()); $notifications = new Notifications($addressHandler, $this->serverContainer->getHTTPClientService(), $discoveryManager, $this->serverContainer->getJobList()); $tokenHandler = new TokenHandler($this->serverContainer->getSecureRandom()); $this->federatedProvider = new FederatedShareProvider($this->serverContainer->getDatabaseConnection(), $addressHandler, $notifications, $tokenHandler, $l, $this->serverContainer->getLogger(), $this->serverContainer->getLazyRootFolder(), $this->serverContainer->getConfig(), $this->serverContainer->getUserManager()); } return $this->federatedProvider; }
/** * Creates the environment based on the linkItem the token links to * * @param array $linkItem */ public function setTokenBasedEnv($linkItem) { // Resolves reshares down to the last real share $rootLinkItem = Share::resolveReShare($linkItem); $origShareOwner = $rootLinkItem['uid_owner']; $this->userFolder = $this->serverContainer->getUserFolder($origShareOwner); // TODO: Replace with this in 8.2 (https://github.com/owncloud/core/pull/16965) // You get root by calling getRootFolder() on the server container //$this->userFolder = $this->root->getUserFolder($origShareOwner); // This is actually the node ID $this->sharedNodeId = $linkItem['file_source']; $this->fromRootToFolder = $this->buildFromRootToFolder($this->sharedNodeId); $this->folderName = $linkItem['file_target']; $this->userId = $rootLinkItem['uid_owner']; $this->sharePassword = $linkItem['share_with']; }
/** * Creates and returns an instance of the system tag object * mapper * * @return ISystemTagObjectMapper * @since 9.0.0 */ public function getObjectMapper() { return new SystemTagObjectMapper($this->serverContainer->getDatabaseConnection(), $this->getManager(), $this->serverContainer->getEventDispatcher()); }
/** * creates and returns an instance of the ICommentsManager * * @return ICommentsManager * @since 9.0.0 */ public function getManager() { return new Manager($this->serverContainer->getDatabaseConnection(), $this->serverContainer->getLogger(), $this->serverContainer->getConfig()); }
/** * creates and returns an instance of the ILDAPProvider * * @return OCP\LDAP\ILDAPProvider */ public function getLDAPProvider() { $dbConnection = $this->serverContainer->getDatabaseConnection(); $userMapping = new UserMapping($dbConnection); return new LDAPProvider($this->serverContainer, new Helper(), new DeletedUsersIndex($this->serverContainer->getConfig(), $dbConnection, $userMapping)); }
/** * @param $nodeType * @param $nodeId * * @return bool|string */ private function getToken($nodeType, $nodeId) { // We need to make sure sharing via link is enabled $this->server->getConfig()->setAppValue('core', 'shareapi_allow_links', 'yes'); return Share::shareItem($nodeType, $nodeId, \OCP\Share::SHARE_TYPE_LINK, 'sh@red p@ssw0rd', \OCP\Constants::PERMISSION_ALL, 'OCA\\GalleryPlus\\Environment\\Environment'); }