Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/richdocuments.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2021-03-11 18:43:40 +0300
committerJulius Härtl <jus@bitgrid.net>2021-04-28 11:40:58 +0300
commit3067440843cd86d10f99ee6ed06c90882f87e7aa (patch)
tree9d22fed5e853717b3d0611ebb13abfb1de528989 /lib
parent680a065ec8b4419d43a9859bcde2f87e62712330 (diff)
Skeleton for creating direct tokens for public shares
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/OCSController.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/Controller/OCSController.php b/lib/Controller/OCSController.php
index 0d436c44..ea79e0c5 100644
--- a/lib/Controller/OCSController.php
+++ b/lib/Controller/OCSController.php
@@ -26,12 +26,15 @@ namespace OCA\Richdocuments\Controller;
use OCA\Richdocuments\Db\DirectMapper;
use OCA\Richdocuments\Service\FederationService;
use OCA\Richdocuments\TemplateManager;
+use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
+use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
+use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IRequest;
use OCP\IURLGenerator;
@@ -123,6 +126,50 @@ class OCSController extends \OCP\AppFramework\OCSController {
/**
* @NoAdminRequired
+ * @param $shareToken
+ * @param $path
+ * @param $password
+ * @param $guestName
+ * @param null $remoteUserHost
+ * @param null $remoteUserToken
+ * @return DataResponse
+ * @throws NotFoundException
+ * @throws OCSForbiddenException
+ * @throws \OCP\Share\Exceptions\ShareNotFound
+ */
+ public function createPublic(string $shareToken, string $path = '', string $password = null, string $guestName = null, $remoteUserHost = null, $remoteUserToken = null) {
+ if ($remoteUserHost && $remoteUserToken) {
+ // may be optional depending on the requirements
+ // fetch user details from remote host
+ }
+ $this->shareManager = \OC::$server->getShareManager();
+ $share = $this->shareManager->getShareByToken($shareToken);
+ if ($share->getPassword()) {
+ if (!$this->shareManager->checkPassword($share, $password)) {
+ throw new OCSForbiddenException();
+ }
+ }
+ $node = $share->getNode();
+ if ($node instanceof Folder) {
+ try {
+ $node = $node->get($path);
+ } catch (NotFoundException $e) {
+ throw new OCSForbiddenException();
+ }
+ }
+
+ // create new direct token and link with either $guestName or remote user info
+ $direct = $this->directMapper->newDirect( - );
+
+ return new DataResponse([
+ 'url' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.directView.show', [
+ 'token' => $direct->getToken()
+ ])
+ ]);
+ }
+
+ /**
+ * @NoAdminRequired
*
* @param string $type The template type
* @return DataResponse