From eada39c2bdaab7b9227a33dc1adacdd67485cbf4 Mon Sep 17 00:00:00 2001 From: Marcos Zuriaga Date: Mon, 3 Oct 2016 22:55:33 +0200 Subject: [PATCH] Sharing public link creation API endpoint --- appinfo/routes.php | 1 + controller/sharecontroller.php | 18 ++++++++++++++++++ lib/Service/ShareService.php | 5 +++++ 3 files changed, 24 insertions(+) diff --git a/appinfo/routes.php b/appinfo/routes.php index 3922dea9..1d6839fa 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -58,6 +58,7 @@ return [ ['name' => 'share#getVaultItems', 'url' => '/api/v2/sharing/vault/{vault_guid}/get', 'verb' => 'GET'], ['name' => 'share#getRevisions', 'url' => '/api/v2/sharing/revisions/{item_guid}', 'verb' => 'GET'], ['name' => 'share#getCredentialData', 'url' => '/api/v2/sharing/credential/{credential_guid}', 'verb' => 'GET'], + ['name' => 'share#createPublicShare', 'url' => '/api/v2/sharing/sharing/public', 'verb' => 'POST'], //Internal API ['name' => 'internal#remind', 'url' => '/api/internal/notifications/remind/{credential_id}', 'verb' => 'POST'], diff --git a/controller/sharecontroller.php b/controller/sharecontroller.php index 32ed3712..85528a18 100644 --- a/controller/sharecontroller.php +++ b/controller/sharecontroller.php @@ -12,6 +12,7 @@ namespace OCA\Passman\Controller; use OCA\Passman\Db\ShareRequest; +use OCA\Passman\Db\SharingACL; use OCA\Passman\Db\Vault; use OCA\Passman\Service\CredentialService; use OCA\Passman\Service\NotificationService; @@ -68,6 +69,23 @@ class ShareController extends ApiController { $this->notificationService = $notificationService; } + /** + * @param $item_id + * @param $item_guid + * @param $permissions + * @param $expire_timestamp + * @NoAdminRequired + */ + public function createPublicShare($item_id, $item_guid, $permissions, $expire_timestamp) { + $acl = new SharingACL(); + + $acl->setItemId($item_id); + $acl->setVaultGuid($item_guid); + $acl->setPermissions($permissions); + $acl->setExpire($expire_timestamp); + + $this->shareService($acl); + } /** * @NoAdminRequired diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index 1010d996..0cdcd009 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -67,6 +67,11 @@ class ShareService { return $requests; } + public function createACLEntry(SharingACL $acl){ + if ($acl->getCreated() == null) $acl->setCreated((new \DateTime())->getTimestamp()); + return $this->sharingACL->createACLEntry($acl); + } + /** * Applies the given share, defaults to no expire * @param $item_guid