X Tutup
Skip to content

Commit 7792b5a

Browse files
authored
Merge pull request #38053 from owncloud/getshare_params
Refactor getSharesInDir method and allow new interaction in params
2 parents 15615dc + deb88b5 commit 7792b5a

File tree

2 files changed

+31
-57
lines changed

2 files changed

+31
-57
lines changed

apps/files_sharing/lib/Controller/Share20OcsController.php

Lines changed: 21 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -609,51 +609,6 @@ private function getSharedWithMe($node = null, $includeTags, $requestedShareType
609609
return new Result($formatted);
610610
}
611611

612-
/**
613-
* @param Folder $folder
614-
* @param array $requestedShareTypes a key-value array with the requested share types to
615-
* be returned. The keys of the array are the share types to be returned, and the values
616-
* whether the share type will be returned or not.
617-
* [Share::SHARE_TYPE_USER => true, Share::SHARE_TYPE_GROUP => false]
618-
* @return Result
619-
* @throws NotFoundException
620-
*/
621-
private function getSharesInDir($folder, $requestedShareTypes) {
622-
if (!($folder instanceof Folder)) {
623-
return new Result(null, 400, $this->l->t('Not a directory'));
624-
}
625-
626-
$nodes = $folder->getDirectoryListing();
627-
/** @var IShare[] $shares */
628-
$shares = [];
629-
foreach ($nodes as $node) {
630-
foreach ($requestedShareTypes as $shareType => $requested) {
631-
if (!$requested) {
632-
continue;
633-
}
634-
635-
// if outgoingServer2ServerSharesAllowed is false, remote shares shouldn't be
636-
// returned. This must be checked in the caller method, so the remote share type
637-
// shouldn't be present if outgoing remotes shares aren't allowed.
638-
$shares = \array_merge(
639-
$shares,
640-
$this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), $shareType, $node, false, -1, 0)
641-
);
642-
}
643-
}
644-
645-
$formatted = [];
646-
foreach ($shares as $share) {
647-
try {
648-
$formatted[] = $this->formatShare($share);
649-
} catch (NotFoundException $e) {
650-
//Ignore this share
651-
}
652-
}
653-
654-
return new Result($formatted);
655-
}
656-
657612
/**
658613
* The getShares function.
659614
* For the share type filter, if it isn't provided or is an empty string,
@@ -745,11 +700,18 @@ public function getShares() {
745700
}
746701

747702
if ($subfiles === 'true') {
748-
$result = $this->getSharesInDir($path, $requestedShareTypes);
749-
if ($path !== null) {
750-
$path->unlock(ILockingProvider::LOCK_SHARED);
703+
if (!($path instanceof Folder)) {
704+
if ($path !== null) {
705+
$path->unlock(ILockingProvider::LOCK_SHARED);
706+
}
707+
return new Result(null, 400, $this->l->t('Not a directory'));
751708
}
752-
return $result;
709+
710+
// we'll get only the folder contents, but not going further in
711+
// this matches the previous behaviour of the deleted "getSharesInDir" method
712+
$nodes = $path->getDirectoryListing();
713+
} else {
714+
$nodes = [$path];
753715
}
754716

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

761723
$shares = [];
762-
foreach ($requestedShareTypes as $shareType => $requested) {
763-
if (!$requested) {
764-
continue;
765-
}
724+
foreach ($nodes as $node) {
725+
foreach ($requestedShareTypes as $shareType => $requested) {
726+
if (!$requested) {
727+
continue;
728+
}
766729

767-
$shares = \array_merge(
768-
$shares,
769-
$this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), $shareType, $path, $reshares, -1, 0)
770-
);
730+
$shares = \array_merge(
731+
$shares,
732+
$this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), $shareType, $node, $reshares, -1, 0)
733+
);
734+
}
771735
}
772736

773737
$formatted = [];

changelog/unreleased/38053

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Enhancement: getShare API request's "subfiles" parameter allows new interactions
2+
3+
Previously, the "subfiles" parameter required only the "path" parameter, and
4+
the rest of the parameters were ignored.
5+
6+
Now, the "subfiles" parameter still requires the "path" parameter, but it also
7+
interacts with the "reshares" parameter as well as the "share_types" parameter
8+
to provide additional filtering capabilities
9+
10+
https://github.com/owncloud/core/pull/38053

0 commit comments

Comments
 (0)
X Tutup