Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
integration tests
Signed-off-by: Maxence Lange <[email protected]>
add tests on non-owner pov

Signed-off-by: Maxence Lange <[email protected]>
duplicate

Signed-off-by: Maxence Lange <[email protected]>
small fixes

Signed-off-by: Maxence Lange <[email protected]>
removed tags

Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl authored and rullzer committed Dec 3, 2019
commit ccf7d87c11112b63851940a6b157f07f954bd9ef
20 changes: 12 additions & 8 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use OCA\Files_Sharing\Exceptions\SharingRightsException;
use OCA\Files_Sharing\External\Storage;
use OCA\Files\Helper;
use OCA\Files_Sharing\External\Storage;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
Expand Down Expand Up @@ -641,9 +640,14 @@ private function getSharesInDir(Node $folder): array {

// filter out duplicate shares
$known = [];
return array_filter($shares, function($share) use (&$known) {
if (in_array($share->getId(), $known)) {
return false;


$formatted = $miniFormatted = [];
$resharingRight = false;
$known = [];
foreach ($shares as $share) {
if (in_array($share->getId(), $known) || $share->getSharedWith() === $this->currentUser) {
continue;
}

try {
Expand Down Expand Up @@ -673,7 +677,6 @@ private function getSharesInDir(Node $folder): array {
* The getShares function.
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $shared_with_me
* @param string $reshares
Expand Down Expand Up @@ -762,7 +765,9 @@ private function getFormattedShares(
try {
/** @var IShare $share */
$format = $this->formatShare($share, $node);
$formatted[] = $format;
if ($share->getSharedWith() !== $this->currentUser) {
$formatted[] = $format;
}

// let's also build a list of shares created
// by the current user only, in case
Expand All @@ -773,7 +778,7 @@ private function getFormattedShares(

// check if one of those share is shared with me
// and if I have resharing rights on it
if (!$resharingRight && $this->shareProviderResharingRights($this->currentUser, $share, $path)) {
if (!$resharingRight && $this->shareProviderResharingRights($this->currentUser, $share, $node)) {
$resharingRight = true;
}
} catch (InvalidPathException | NotFoundException $e) {
Expand Down Expand Up @@ -1479,7 +1484,6 @@ private function hasResharingRights($viewer, $node): bool {
* @throws InvalidPathException
*/
private function shareProviderResharingRights(string $userId, IShare $share, $node): bool {

if ($share->getShareOwner() === $userId) {
return true;
}
Expand Down
80 changes: 80 additions & 0 deletions build/integration/sharing_features/sharing-v1.feature
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,84 @@ Feature: sharing
And User "user2" should be included in the response
And User "user3" should not be included in the response

Scenario: getting inherited shares of a file
Given user "user0" exists
And user "user1" exists
And user "user2" exists
And user "user3" exists
# will be shared with user1
And User "user0" created a folder "/first"
# will be shared with user1, user2
And User "user0" created a folder "/first/second"
# will be shared with user1, user3
And User "user0" uploads file "data/textfile.txt" to "/first/test1.txt"
# will be shared with user1, user2, user3
And User "user0" uploads file "data/textfile.txt" to "/first/second/test2.txt"
And As an "user0"
And creating a share with
| path | /first |
| shareType | 0 |
| shareWith | user1 |
| permissions | 16 |
And As an "user1"
And accepting last share
# And folder "first" of user "user0" is shared with user "user1"
# And creating a share with
# | path | /first/second |
# | shareType | 0 |
# | shareWith | user2 |
# | permissions | 16 |
And folder "first/second" of user "user0" is shared with user "user2"
# And As an "user1"
# And creating a share with
# | path | /first/test1.txt |
# | shareType | 0 |
# | shareWith | user3 |
# | permissions | 8 |
And file "first/test1.txt" of user "user0" is shared with user "user3"
# And As an "user2"
# And creating a share with
# | path | /second/test2.txt |
# | shareType | 0 |
# | shareWith | user3 |
# | permissions | 8 |
And file "first/second/test2.txt" of user "user0" is shared with user "user3"
# get inherited shares from the owner PoV
And As an "user0"
When sending "GET" to "/apps/files_sharing/api/v1/shares/inherited?path=first/second/test2.txt"
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And User "user0" should not be included in the response
And User "user1" should be included in the response
And User "user2" should be included in the response
And User "user3" should be included in the response
When sending "GET" to "/apps/files_sharing/api/v1/shares/inherited?path=first/test1.txt"
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And User "user0" should not be included in the response
And User "user1" should be included in the response
And User "user2" should not be included in the response
And User "user3" should be included in the response
# get inherited shares from the a user with no shares rights
And As an "user2"
When sending "GET" to "/apps/files_sharing/api/v1/shares/inherited?path=first/test1.txt"
Then the OCS status code should be "404"
And the HTTP status code should be "200"
# get inherited shares from the PoV of a user with resharing rights (user1)
And As an "user1"
When sending "GET" to "/apps/files_sharing/api/v1/shares/inherited?path=first/second/test2.txt"
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And User "user0" should not be included in the response
And User "user1" should not be included in the response
And User "user2" should be included in the response
And User "user3" should be included in the response
When sending "GET" to "/apps/files_sharing/api/v1/shares/inherited?path=first/test1.txt"
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And User "user0" should not be included in the response
And User "user1" should not be included in the response
And User "user2" should not be included in the response
And User "user3" should be included in the response

# See sharing-v1-part2.feature