summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-06-20 19:14:50 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-07-05 12:43:57 +0200
commit3b835d8076c844adde1014e994256740c790857b (patch)
tree4fe22ac0c02ecc221115fc8844eceb3516df68a1 /apps/files_sharing/lib
parent6a0552224de21e137c3cfa63c589c2b3f65a0987 (diff)
downloadnextcloud-server-3b835d8076c844adde1014e994256740c790857b.tar.gz
nextcloud-server-3b835d8076c844adde1014e994256740c790857b.zip
Js magic for deleted shares
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r--apps/files_sharing/lib/Controller/DeletedShareAPIController.php66
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php1
2 files changed, 62 insertions, 5 deletions
diff --git a/apps/files_sharing/lib/Controller/DeletedShareAPIController.php b/apps/files_sharing/lib/Controller/DeletedShareAPIController.php
index 2e4f4d52d74..bd00d1a261b 100644
--- a/apps/files_sharing/lib/Controller/DeletedShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/DeletedShareAPIController.php
@@ -30,6 +30,8 @@ use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
+use OCP\Files\IRootFolder;
+use OCP\IGroupManager;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\Share\Exceptions\GenericShareException;
@@ -48,25 +50,81 @@ class DeletedShareAPIController extends OCSController {
/** @var IUserManager */
private $userManager;
+ /** @var IGroupManager */
+ private $groupManager;
+
+ /** @var IRootFolder */
+ private $rootFolder;
+
public function __construct(string $appName,
IRequest $request,
ShareManager $shareManager,
string $UserId,
- IUserManager $userManager) {
+ IUserManager $userManager,
+ IGroupManager $groupManager,
+ IRootFolder $rootFolder) {
parent::__construct($appName, $request);
$this->shareManager = $shareManager;
$this->userId = $UserId;
$this->userManager = $userManager;
+ $this->groupManager = $groupManager;
+ $this->rootFolder = $rootFolder;
}
private function formatShare(IShare $share): array {
- return [
+
+ $result = [
'id' => $share->getFullId(),
- 'uid_owner' => $share->getShareOwner(),
- 'displayname_owner' => $this->userManager->get($share->getShareOwner())->getDisplayName(),
+ 'share_type' => $share->getShareType(),
+ 'uid_owner' => $share->getSharedBy(),
+ 'displayname_owner' => $this->userManager->get($share->getSharedBy())->getDisplayName(),
+ 'permissions' => $share->getPermissions(),
+ 'stime' => $share->getShareTime()->getTimestamp(),
+ 'parent' => null,
+ 'expiration' => null,
+ 'token' => null,
+ 'uid_file_owner' => $share->getShareOwner(),
+ 'displayname_file_owner' => $this->userManager->get($share->getShareOwner())->getDisplayName(),
'path' => $share->getTarget(),
];
+ $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
+ $nodes = $userFolder->getById($share->getNodeId());
+ if (empty($nodes)) {
+ // fallback to guessing the path
+ $node = $userFolder->get($share->getTarget());
+ if ($node === null || $share->getTarget() === '') {
+ throw new NotFoundException();
+ }
+ } else {
+ $node = $nodes[0];
+ }
+
+ $result['path'] = $userFolder->getRelativePath($node->getPath());
+ if ($node instanceOf \OCP\Files\Folder) {
+ $result['item_type'] = 'folder';
+ } else {
+ $result['item_type'] = 'file';
+ }
+ $result['mimetype'] = $node->getMimetype();
+ $result['storage_id'] = $node->getStorage()->getId();
+ $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId();
+ $result['item_source'] = $node->getId();
+ $result['file_source'] = $node->getId();
+ $result['file_parent'] = $node->getParent()->getId();
+ $result['file_target'] = $share->getTarget();
+
+ $expiration = $share->getExpirationDate();
+ if ($expiration !== null) {
+ $result['expiration'] = $expiration->format('Y-m-d 00:00:00');
+ }
+
+ $group = $this->groupManager->get($share->getSharedWith());
+ $result['share_with'] = $share->getSharedWith();
+ $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
+
+ return $result;
+
}
/**
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index 35fe3ac81ab..67ff9eae6d3 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -151,7 +151,6 @@ class ShareAPIController extends OCSController {
$node = $recipientNode;
} else {
$nodes = $userFolder->getById($share->getNodeId());
-
if (empty($nodes)) {
// fallback to guessing the path
$node = $userFolder->get($share->getTarget());