summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r--apps/files_sharing/lib/AppInfo/Application.php2
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php93
-rw-r--r--apps/files_sharing/lib/Controller/ShareesAPIController.php16
-rw-r--r--apps/files_sharing/lib/External/Manager.php157
-rw-r--r--apps/files_sharing/lib/Hooks.php2
-rw-r--r--apps/files_sharing/lib/ShareBackend/File.php4
6 files changed, 204 insertions, 70 deletions
diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php
index e6ab4eb2cf1..a7d4755fbf0 100644
--- a/apps/files_sharing/lib/AppInfo/Application.php
+++ b/apps/files_sharing/lib/AppInfo/Application.php
@@ -105,6 +105,8 @@ class Application extends App {
$server->query(\OCP\OCS\IDiscoveryService::class),
$server->getCloudFederationProviderManager(),
$server->getCloudFederationFactory(),
+ $server->getGroupManager(),
+ $server->getUserManager(),
$uid
);
});
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index 67ff9eae6d3..59b763ecf81 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -48,6 +48,7 @@ use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\Files\IRootFolder;
use OCP\Lock\LockedException;
+use OCP\Share;
use OCP\Share\IManager;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\Exceptions\GenericShareException;
@@ -181,15 +182,15 @@ class ShareAPIController extends OCSController {
$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
}
- if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
+ if ($share->getShareType() === Share::SHARE_TYPE_USER) {
$sharedWith = $this->userManager->get($share->getSharedWith());
$result['share_with'] = $share->getSharedWith();
$result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith();
- } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
+ } else if ($share->getShareType() === Share::SHARE_TYPE_GROUP) {
$group = $this->groupManager->get($share->getSharedWith());
$result['share_with'] = $share->getSharedWith();
$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
- } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
+ } else if ($share->getShareType() === Share::SHARE_TYPE_LINK) {
$result['share_with'] = $share->getPassword();
$result['share_with_displayname'] = $share->getPassword();
@@ -197,16 +198,16 @@ class ShareAPIController extends OCSController {
$result['token'] = $share->getToken();
$result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
- } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) {
+ } else if ($share->getShareType() === Share::SHARE_TYPE_REMOTE || $share->getShareType() || Share::SHARE_TYPE_REMOTE_GROUP) {
$result['share_with'] = $share->getSharedWith();
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD');
$result['token'] = $share->getToken();
- } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
+ } else if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) {
$result['share_with'] = $share->getSharedWith();
$result['password'] = $share->getPassword();
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
$result['token'] = $share->getToken();
- } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) {
+ } else if ($share->getShareType() === Share::SHARE_TYPE_CIRCLE) {
// getSharedWith() returns either "name (type, owner)" or
// "name (type, owner) [id]", depending on the Circles app version.
$hasCircleId = (substr($share->getSharedWith(), -1) === ']');
@@ -301,7 +302,7 @@ class ShareAPIController extends OCSController {
throw new OCSNotFoundException($this->l->t('Could not delete share'));
}
- if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP &&
+ if ($share->getShareType() === Share::SHARE_TYPE_GROUP &&
$share->getShareOwner() !== $this->currentUser &&
$share->getSharedBy() !== $this->currentUser) {
$this->shareManager->deleteFromSelf($share, $this->currentUser);
@@ -388,14 +389,14 @@ class ShareAPIController extends OCSController {
$permissions &= ~($permissions & ~$path->getPermissions());
}
- if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
+ if ($shareType === Share::SHARE_TYPE_USER) {
// Valid user is required to share
if ($shareWith === null || !$this->userManager->userExists($shareWith)) {
throw new OCSNotFoundException($this->l->t('Please specify a valid user'));
}
$share->setSharedWith($shareWith);
$share->setPermissions($permissions);
- } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
+ } else if ($shareType === Share::SHARE_TYPE_GROUP) {
if (!$this->shareManager->allowGroupSharing()) {
throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator'));
}
@@ -406,7 +407,7 @@ class ShareAPIController extends OCSController {
}
$share->setSharedWith($shareWith);
$share->setPermissions($permissions);
- } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) {
+ } else if ($shareType === Share::SHARE_TYPE_LINK) {
//Can we even share links?
if (!$this->shareManager->shareApiAllowLinks()) {
throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator'));
@@ -416,7 +417,7 @@ class ShareAPIController extends OCSController {
* For now we only allow 1 link share.
* Return the existing link share if this is a duplicate
*/
- $existingShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0);
+ $existingShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $path, false, 1, 0);
if (!empty($existingShares)) {
return new DataResponse($this->formatShare($existingShares[0]));
}
@@ -457,21 +458,28 @@ class ShareAPIController extends OCSController {
}
}
- } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
+ } else if ($shareType === Share::SHARE_TYPE_REMOTE) {
if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType]));
}
$share->setSharedWith($shareWith);
$share->setPermissions($permissions);
- } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) {
+ } else if ($shareType === Share::SHARE_TYPE_REMOTE_GROUP) {
+ if (!$this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
+ throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType]));
+ }
+
+ $share->setSharedWith($shareWith);
+ $share->setPermissions($permissions);
+ } else if ($shareType === Share::SHARE_TYPE_EMAIL) {
if ($share->getNodeType() === 'file') {
$share->setPermissions(Constants::PERMISSION_READ);
} else {
$share->setPermissions($permissions);
}
$share->setSharedWith($shareWith);
- } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) {
+ } else if ($shareType === Share::SHARE_TYPE_CIRCLE) {
if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) {
throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled'));
}
@@ -512,9 +520,9 @@ class ShareAPIController extends OCSController {
*/
private function getSharedWithMe($node = null, bool $includeTags): DataResponse {
- $userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0);
- $groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0);
- $circleShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $node, -1, 0);
+ $userShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_USER, $node, -1, 0);
+ $groupShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_GROUP, $node, -1, 0);
+ $circleShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_CIRCLE, $node, -1, 0);
$shares = array_merge($userShares, $groupShares, $circleShares);
@@ -554,14 +562,14 @@ class ShareAPIController extends OCSController {
/** @var \OCP\Share\IShare[] $shares */
$shares = [];
foreach ($nodes as $node) {
- $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0));
- $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0));
- $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0));
- if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
- $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0));
+ $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_USER, $node, false, -1, 0));
+ $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_GROUP, $node, false, -1, 0));
+ $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $node, false, -1, 0));
+ if($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
+ $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_EMAIL, $node, false, -1, 0));
}
if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
- $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $node, false, -1, 0));
+ $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $node, false, -1, 0));
}
}
@@ -635,16 +643,16 @@ class ShareAPIController extends OCSController {
}
// Get all shares
- $userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0);
- $groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0);
- $linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0);
- if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
- $mailShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0);
+ $userShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_USER, $path, $reshares, -1, 0);
+ $groupShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0);
+ $linkShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0);
+ if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
+ $mailShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0);
} else {
$mailShares = [];
}
- if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) {
- $circleShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0);
+ if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_CIRCLE)) {
+ $circleShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0);
} else {
$circleShares = [];
}
@@ -652,7 +660,12 @@ class ShareAPIController extends OCSController {
$shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares);
if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
- $federatedShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0);
+ $federatedShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0);
+ $shares = array_merge($shares, $federatedShares);
+ }
+
+ if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
+ $federatedShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE_GROUP, $path, $reshares, -1, 0);
$shares = array_merge($shares, $federatedShares);
}
@@ -711,7 +724,7 @@ class ShareAPIController extends OCSController {
/*
* expirationdate, password and publicUpload only make sense for link shares
*/
- if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
+ if ($share->getShareType() === Share::SHARE_TYPE_LINK) {
$newPermissions = null;
if ($publicUpload === 'true') {
@@ -783,7 +796,7 @@ class ShareAPIController extends OCSController {
$share->setPermissions($permissions);
}
- if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
+ if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) {
if ($password === '') {
$share->setPassword(null);
} else if ($password !== null) {
@@ -806,8 +819,8 @@ class ShareAPIController extends OCSController {
if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) {
/* Check if this is an incomming share */
- $incomingShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0);
- $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0));
+ $incomingShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_USER, $share->getNode(), -1, 0);
+ $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0));
/** @var \OCP\Share\IShare[] $incomingShares */
if (!empty($incomingShares)) {
@@ -846,13 +859,13 @@ class ShareAPIController extends OCSController {
}
// If the share is shared with you (or a group you are a member of)
- if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
+ if ($share->getShareType() === Share::SHARE_TYPE_USER &&
$share->getSharedWith() === $this->currentUser
) {
return true;
}
- if ($checkGroups && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
+ if ($checkGroups && $share->getShareType() === Share::SHARE_TYPE_GROUP) {
$sharedWith = $this->groupManager->get($share->getSharedWith());
$user = $this->userManager->get($this->currentUser);
if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) {
@@ -860,7 +873,7 @@ class ShareAPIController extends OCSController {
}
}
- if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) {
+ if ($share->getShareType() === Share::SHARE_TYPE_CIRCLE) {
// TODO: have a sanity check like above?
return true;
}
@@ -915,7 +928,7 @@ class ShareAPIController extends OCSController {
try {
- if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) {
+ if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_CIRCLE)) {
$share = $this->shareManager->getShareById('ocCircleShare:' . $id, $this->currentUser);
return $share;
}
@@ -924,7 +937,7 @@ class ShareAPIController extends OCSController {
}
try {
- if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
+ if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
$share = $this->shareManager->getShareById('ocMailShare:' . $id, $this->currentUser);
return $share;
}
diff --git a/apps/files_sharing/lib/Controller/ShareesAPIController.php b/apps/files_sharing/lib/Controller/ShareesAPIController.php
index d25f24f6f72..ee95661d4c6 100644
--- a/apps/files_sharing/lib/Controller/ShareesAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareesAPIController.php
@@ -67,12 +67,14 @@ class ShareesAPIController extends OCSController {
'users' => [],
'groups' => [],
'remotes' => [],
+ 'remote_groups' => [],
'emails' => [],
'circles' => [],
],
'users' => [],
'groups' => [],
'remotes' => [],
+ 'remote_groups' => [],
'emails' => [],
'lookup' => [],
'circles' => [],
@@ -153,6 +155,10 @@ class ShareesAPIController extends OCSController {
$shareTypes[] = Share::SHARE_TYPE_REMOTE;
}
+ if ($this->isRemoteGroupSharingAllowed($itemType)) {
+ $shareTypes[] = Share::SHARE_TYPE_REMOTE_GROUP;
+ }
+
if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
$shareTypes[] = Share::SHARE_TYPE_EMAIL;
}
@@ -216,6 +222,16 @@ class ShareesAPIController extends OCSController {
}
}
+ protected function isRemoteGroupSharingAllowed(string $itemType): bool {
+ try {
+ // FIXME: static foo makes unit testing unnecessarily difficult
+ $backend = \OC\Share\Share::getBackend($itemType);
+ return $backend->isShareTypeAllowed(Share::SHARE_TYPE_REMOTE_GROUP);
+ } catch (\Exception $e) {
+ return false;
+ }
+ }
+
/**
* Generates a bunch of pagination links for the current page
diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php
index 02783560afe..6a036b663d9 100644
--- a/apps/files_sharing/lib/External/Manager.php
+++ b/apps/files_sharing/lib/External/Manager.php
@@ -39,6 +39,8 @@ use OCP\Files;
use OCP\Files\Storage\IStorageFactory;
use OCP\Http\Client\IClientService;
use OCP\IDBConnection;
+use OCP\IGroupManager;
+use OCP\IUserManager;
use OCP\Notification\IManager;
use OCP\OCS\IDiscoveryService;
use OCP\Share;
@@ -87,6 +89,12 @@ class Manager {
/** @var ICloudFederationFactory */
private $cloudFederationFactory;
+ /** @var IGroupManager */
+ private $groupManager;
+
+ /** @var IUserManager */
+ private $userManager;
+
/**
* @param IDBConnection $connection
* @param \OC\Files\Mount\Manager $mountManager
@@ -96,6 +104,8 @@ class Manager {
* @param IDiscoveryService $discoveryService
* @param ICloudFederationProviderManager $cloudFederationProviderManager
* @param ICloudFederationFactory $cloudFederationFactory
+ * @param IGroupManager $groupManager
+ * @param IUserManager $userManager
* @param string $uid
*/
public function __construct(IDBConnection $connection,
@@ -106,6 +116,8 @@ class Manager {
IDiscoveryService $discoveryService,
ICloudFederationProviderManager $cloudFederationProviderManager,
ICloudFederationFactory $cloudFederationFactory,
+ IGroupManager $groupManager,
+ IUserManager $userManager,
$uid) {
$this->connection = $connection;
$this->mountManager = $mountManager;
@@ -116,6 +128,8 @@ class Manager {
$this->discoveryService = $discoveryService;
$this->cloudFederationProviderManager = $cloudFederationProviderManager;
$this->cloudFederationFactory = $cloudFederationFactory;
+ $this->groupManager = $groupManager;
+ $this->userManager = $userManager;
}
/**
@@ -126,12 +140,15 @@ class Manager {
* @param string $password
* @param string $name
* @param string $owner
+ * @param int $shareType
* @param boolean $accepted
* @param string $user
* @param int $remoteId
+ * @param int $parent
* @return Mount|null
+ * @throws \Doctrine\DBAL\DBALException
*/
- public function addShare($remote, $token, $password, $name, $owner, $accepted=false, $user = null, $remoteId = -1) {
+ public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted=false, $user = null, $remoteId = -1, $parent = -1) {
$user = $user ? $user : $this->uid;
$accepted = $accepted ? 1 : 0;
@@ -156,6 +173,7 @@ class Manager {
'mountpoint_hash' => $hash,
'accepted' => $accepted,
'remote_id' => $remoteId,
+ 'share_type' => $shareType,
];
$i = 1;
@@ -172,12 +190,7 @@ class Manager {
$mountPoint = Filesystem::normalizePath('/' . $mountPoint);
$hash = md5($mountPoint);
- $query = $this->connection->prepare('
- INSERT INTO `*PREFIX*share_external`
- (`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`)
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
- ');
- $query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId));
+ $this->writeShareToDb($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType);
$options = array(
'remote' => $remote,
@@ -190,6 +203,32 @@ class Manager {
}
/**
+ * write remote share to the database
+ *
+ * @param $remote
+ * @param $token
+ * @param $password
+ * @param $name
+ * @param $owner
+ * @param $user
+ * @param $mountPoint
+ * @param $hash
+ * @param $accepted
+ * @param $remoteId
+ * @param $parent
+ * @param $shareType
+ * @return bool
+ */
+ private function writeShareToDb($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType) {
+ $query = $this->connection->prepare('
+ INSERT INTO `*PREFIX*share_external`
+ (`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`, `parent`, `share_type`)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
+ ');
+ return $query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType));
+ }
+
+ /**
* get share
*
* @param int $id share id
@@ -197,12 +236,27 @@ class Manager {
*/
public function getShare($id) {
$getShare = $this->connection->prepare('
- SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted`
+ SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted`, `parent`, `share_type`, `password`, `mountpoint_hash`
FROM `*PREFIX*share_external`
- WHERE `id` = ? AND `user` = ?');
- $result = $getShare->execute(array($id, $this->uid));
+ WHERE `id` = ?');
+ $result = $getShare->execute(array($id));
+
+ $share = $result ? $getShare->fetch() : [];
+
+ $validShare = is_array($share) && isset($share['share_type']) && isset($share['user']);
+
+ // check if the user is allowed to access it
+ if ($validShare && (int)$share['share_type'] === Share::SHARE_TYPE_USER && $share['user'] === $this->uid) {
+ return $share;
+ } else if ($validShare && (int)$share['share_type'] === Share::SHARE_TYPE_GROUP) {
+ $user = $this->userManager->get($this->uid);
+ if ($this->groupManager->get($share['user'])->inGroup($user)) {
+ return $share;
+ }
+ }
+
+ return false;
- return $result ? $getShare->fetch() : false;
}
/**
@@ -222,15 +276,30 @@ class Manager {
$mountPoint = Files::buildNotExistingFileName($shareFolder, $share['name']);
$mountPoint = Filesystem::normalizePath($mountPoint);
$hash = md5($mountPoint);
+ $userShareAccepted = false;
- $acceptShare = $this->connection->prepare('
+ if((int)$share['share_type'] === Share::SHARE_TYPE_USER) {
+ $acceptShare = $this->connection->prepare('
UPDATE `*PREFIX*share_external`
SET `accepted` = ?,
`mountpoint` = ?,
`mountpoint_hash` = ?
WHERE `id` = ? AND `user` = ?');
- $updated = $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid));
- if ($updated === true) {
+ $userShareAccepted = $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid));
+ } else {
+ $result = $this->writeShareToDb(
+ $share['remote'],
+ $share['share_token'],
+ $share['password'],
+ $share['name'],
+ $share['owner'],
+ $this->uid,
+ $mountPoint, $hash, 1,
+ $share['remote_id'],
+ $id,
+ $share['share_type']);
+ }
+ if ($userShareAccepted === true) {
$this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept');
\OC_Hook::emit(Share::class, 'federated_share_added', ['server' => $share['remote']]);
$result = true;
@@ -252,18 +321,34 @@ class Manager {
public function declineShare($id) {
$share = $this->getShare($id);
+ $result = false;
- if ($share) {
+ if ($share && (int)$share['share_type'] === Share::SHARE_TYPE_USER) {
$removeShare = $this->connection->prepare('
DELETE FROM `*PREFIX*share_external` WHERE `id` = ? AND `user` = ?');
$removeShare->execute(array($id, $this->uid));
$this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline');
$this->processNotification($id);
- return true;
+ $result = true;
+ } else if ($share && (int)$share['share_type'] === Share::SHARE_TYPE_GROUP) {
+ $result = $this->writeShareToDb(
+ $share['remote'],
+ $share['share_token'],
+ $share['password'],
+ $share['name'],
+ $share['owner'],
+ $this->uid,
+ $share['mountpoint'],
+ $share['mountpoint_hash'],
+ 0,
+ $share['remote_id'],
+ $id,
+ $share['share_type']);
+ $this->processNotification($id);
}
- return false;
+ return $result;
}
/**
@@ -297,7 +382,7 @@ class Manager {
$federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING');
$endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares';
- $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT;
+ $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . Share::RESPONSE_FORMAT;
$fields = array('token' => $token);
$client = $this->clientService->newClient();
@@ -430,28 +515,33 @@ class Manager {
$hash = md5($mountPoint);
$getShare = $this->connection->prepare('
- SELECT `remote`, `share_token`, `remote_id`
+ SELECT `remote`, `share_token`, `remote_id`, `share_type`, `id`
FROM `*PREFIX*share_external`
WHERE `mountpoint_hash` = ? AND `user` = ?');
$result = $getShare->execute(array($hash, $this->uid));
- if ($result) {
+ $share = $getShare->fetch();
+ $getShare->closeCursor();
+ if ($result && (int)$share['share_type'] === Share::SHARE_TYPE_USER) {
try {
- $share = $getShare->fetch();
$this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline');
} catch (\Exception $e) {
// if we fail to notify the remote (probably cause the remote is down)
// we still want the share to be gone to prevent undeletable remotes
}
- }
- $getShare->closeCursor();
- $query = $this->connection->prepare('
+ $query = $this->connection->prepare('
DELETE FROM `*PREFIX*share_external`
- WHERE `mountpoint_hash` = ?
- AND `user` = ?
- ');
- $result = (bool)$query->execute(array($hash, $this->uid));
+ WHERE `id` = ?
+ ');
+ $result = (bool)$query->execute(array((int)$share['id']));
+ } else if ($result && (int)$share['share_type'] === Share::SHARE_TYPE_GROUP) {
+ $query = $this->connection->prepare('
+ UPDATE `*PREFIX*share_external`
+ SET `accepted` = ?
+ WHERE `id` = ?');
+ $result = (bool)$query->execute(array(0, (int)$share['id']));
+ }
if($result) {
$this->removeReShares($id);
@@ -537,10 +627,17 @@ class Manager {
* @return array list of open server-to-server shares
*/
private function getShares($accepted) {
+ $user = $this->userManager->get($this->uid);
+ $groups = $this->groupManager->getUserGroups($user);
+ $userGroups = [];
+ foreach ($groups as $group) {
+ $userGroups[] = $group->getGID();
+ }
+
$query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted`
FROM `*PREFIX*share_external`
- WHERE `user` = ?';
- $parameters = [$this->uid];
+ WHERE (`user` = ? OR `user` IN (?))';
+ $parameters = [$this->uid, implode(',',$userGroups)];
if (!is_null($accepted)) {
$query .= ' AND `accepted` = ?';
$parameters[] = (int) $accepted;
diff --git a/apps/files_sharing/lib/Hooks.php b/apps/files_sharing/lib/Hooks.php
index cd66fd7702e..99e876eaaf0 100644
--- a/apps/files_sharing/lib/Hooks.php
+++ b/apps/files_sharing/lib/Hooks.php
@@ -42,6 +42,8 @@ class Hooks {
\OC::$server->query(\OCP\OCS\IDiscoveryService::class),
\OC::$server->getCloudFederationProviderManager(),
\OC::$server->getCloudFederationFactory(),
+ \OC::$server->getGroupManager(),
+ \OC::$server->getUserManager(),
$params['uid']);
$manager->removeUserShares($params['uid']);
diff --git a/apps/files_sharing/lib/ShareBackend/File.php b/apps/files_sharing/lib/ShareBackend/File.php
index bb28c1a33ac..bd32741e67e 100644
--- a/apps/files_sharing/lib/ShareBackend/File.php
+++ b/apps/files_sharing/lib/ShareBackend/File.php
@@ -195,6 +195,10 @@ class File implements \OCP\Share_Backend_File_Dependent {
return $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
}
+ if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) {
+ return $this->federatedShareProvider->isOutgoingServer2serverGroupShareEnabled();
+ }
+
return true;
}