Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor getSharesInDir method and allow new interaction in params #38053

Merged
merged 2 commits into from
Nov 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 21 additions & 57 deletions apps/files_sharing/lib/Controller/Share20OcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,51 +609,6 @@ private function getSharedWithMe($node = null, $includeTags, $requestedShareType
return new Result($formatted);
}

/**
* @param Folder $folder
* @param array $requestedShareTypes a key-value array with the requested share types to
* be returned. The keys of the array are the share types to be returned, and the values
* whether the share type will be returned or not.
* [Share::SHARE_TYPE_USER => true, Share::SHARE_TYPE_GROUP => false]
* @return Result
* @throws NotFoundException
*/
private function getSharesInDir($folder, $requestedShareTypes) {
if (!($folder instanceof Folder)) {
return new Result(null, 400, $this->l->t('Not a directory'));
}

$nodes = $folder->getDirectoryListing();
/** @var IShare[] $shares */
$shares = [];
foreach ($nodes as $node) {
foreach ($requestedShareTypes as $shareType => $requested) {
if (!$requested) {
continue;
}

// if outgoingServer2ServerSharesAllowed is false, remote shares shouldn't be
// returned. This must be checked in the caller method, so the remote share type
// shouldn't be present if outgoing remotes shares aren't allowed.
$shares = \array_merge(
$shares,
$this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), $shareType, $node, false, -1, 0)
);
}
}

$formatted = [];
foreach ($shares as $share) {
try {
$formatted[] = $this->formatShare($share);
} catch (NotFoundException $e) {
//Ignore this share
}
}

return new Result($formatted);
}

/**
* The getShares function.
* For the share type filter, if it isn't provided or is an empty string,
Expand Down Expand Up @@ -745,11 +700,18 @@ public function getShares() {
}

if ($subfiles === 'true') {
$result = $this->getSharesInDir($path, $requestedShareTypes);
if ($path !== null) {
$path->unlock(ILockingProvider::LOCK_SHARED);
if (!($path instanceof Folder)) {
if ($path !== null) {
$path->unlock(ILockingProvider::LOCK_SHARED);
}
return new Result(null, 400, $this->l->t('Not a directory'));
}
return $result;

// we'll get only the folder contents, but not going further in
// this matches the previous behaviour of the deleted "getSharesInDir" method
$nodes = $path->getDirectoryListing();
} else {
$nodes = [$path];
}

if ($reshares === 'true') {
Expand All @@ -759,15 +721,17 @@ public function getShares() {
}

$shares = [];
foreach ($requestedShareTypes as $shareType => $requested) {
if (!$requested) {
continue;
}
foreach ($nodes as $node) {
foreach ($requestedShareTypes as $shareType => $requested) {
if (!$requested) {
continue;
}

$shares = \array_merge(
$shares,
$this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), $shareType, $path, $reshares, -1, 0)
);
$shares = \array_merge(
$shares,
$this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), $shareType, $node, $reshares, -1, 0)
);
}
}

$formatted = [];
Expand Down
10 changes: 10 additions & 0 deletions changelog/unreleased/38053
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Enhancement: getShare API request's "subfiles" parameter allows new interactions

Previously, the "subfiles" parameter required only the "path" parameter, and
the rest of the parameters were ignored.

Now, the "subfiles" parameter still requires the "path" parameter, but it also
interacts with the "reshares" parameter as well as the "share_types" parameter
to provide additional filtering capabilities

https://github.com/owncloud/core/pull/38053