X Tutup
Skip to content
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
8 changes: 8 additions & 0 deletions apps/files_sharing/lib/Controller/ShareesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,14 @@ public function search($search = '', $itemType = null, $page = 1, $perPage = 200
'message' => 'Invalid page'];
}

$sharingDisabledForUser = $this->shareManager->sharingDisabledForUser(
$this->userSession->getUser()->getUID()
);
// Return empty dataset if User is excluded from sharing
if ($sharingDisabledForUser) {
return new DataResponse(['data' => $this->result]);
}

$shareTypes = [
Share::SHARE_TYPE_USER,
];
Expand Down
56 changes: 56 additions & 0 deletions apps/files_sharing/tests/API/ShareesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1901,4 +1901,60 @@ public function testGetUserWithSearchAttributes() {
$this->assertEquals($expected, $result['users']);
$this->assertCount((int) 1, $this->invokePrivate($this->sharees, 'reachedEndFor'));
}

/**
* Test with User from an excluded group
*
*/
public function testExcludedGroups() {
$user = $this->getUserMock(self::getUniqueID(), 'test');
$this->session
->expects($this->once())
->method('getUser')
->willReturn($user);

$this->shareManager
->expects($this->once())
->method('sharingDisabledForUser')
->with($user->getUID())
->willReturn(true);

/** @var ShareesController | \PHPUnit_Framework_MockObject_MockObject $sharees */
$sharees = $this->getMockBuilder(ShareesController::class)
->setConstructorArgs([
'files_sharing',
$this->getMockBuilder(IRequest::class)->disableOriginalConstructor()->getMock(),
$this->groupManager,
$this->userManager,
$this->contactsManager,
$this->config,
$this->session,
$this->getMockBuilder(IURLGenerator::class)->disableOriginalConstructor()->getMock(),
$this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock(),
$this->shareManager,
$this->sharingBlacklist,
$this->getMockBuilder(FederatedShareProvider::class)->disableOriginalConstructor()->getMock()
])
->setMethods(['getUsers', 'getGroups', 'getRemote'])
->getMock();

$sharees
->expects($this->never())
->method('getUsers');
$sharees
->expects($this->never())
->method('getGroups');
$sharees
->expects($this->never())
->method('getRemote');

$result = $sharees->search($user->getUID(), 'file');
$data = $result->getData();
self::assertEmpty($data['data']['exact']['users']);
self::assertEmpty($data['data']['exact']['groups']);
self::assertEmpty($data['data']['exact']['remotes']);
self::assertEmpty($data['data']['users']);
self::assertEmpty($data['data']['groups']);
self::assertEmpty($data['data']['remotes']);
}
}
60 changes: 60 additions & 0 deletions tests/acceptance/features/apiSharees/sharees.feature
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,66 @@ Feature: sharees
| 1 | 100 | 200 |
| 2 | 200 | 200 |

Scenario Outline: Try to search for users and groups when in a group that is excluded from sharing (could match both users and groups)
Given using OCS API version "<ocs-api-version>"
And parameter "shareapi_exclude_groups" of app "core" has been set to "yes"
And parameter "shareapi_exclude_groups_list" of app "core" has been set to '["ShareeGroup2"]'
When user "user1" gets the sharees using the sharing API with parameters
| search | sharee |
| itemType | file |
Then the OCS status code should be "<ocs-status>"
And the HTTP status code should be "<http-status>"
And the "exact users" sharees returned should be empty
And the "users" sharees returned should be empty
And the "exact groups" sharees returned should be empty
And the "groups" sharees returned should be empty
And the "exact remotes" sharees returned should be empty
And the "remotes" sharees returned should be empty
Examples:
| ocs-api-version | ocs-status | http-status |
| 1 | 100 | 200 |
| 2 | 200 | 200 |

Scenario Outline: Try to search for users and groups when in a group that is excluded from sharing (exact match to a user)
Given using OCS API version "<ocs-api-version>"
And parameter "shareapi_exclude_groups" of app "core" has been set to "yes"
And parameter "shareapi_exclude_groups_list" of app "core" has been set to '["ShareeGroup2"]'
When user "user1" gets the sharees using the sharing API with parameters
| search | sharee1 |
| itemType | file |
Then the OCS status code should be "<ocs-status>"
And the HTTP status code should be "<http-status>"
And the "exact users" sharees returned should be empty
And the "users" sharees returned should be empty
And the "exact groups" sharees returned should be empty
And the "groups" sharees returned should be empty
And the "exact remotes" sharees returned should be empty
And the "remotes" sharees returned should be empty
Examples:
| ocs-api-version | ocs-status | http-status |
| 1 | 100 | 200 |
| 2 | 200 | 200 |

Scenario Outline: Try to search for users and groups when in a group that is excluded from sharing (exact match to a group)
Given using OCS API version "<ocs-api-version>"
And parameter "shareapi_exclude_groups" of app "core" has been set to "yes"
And parameter "shareapi_exclude_groups_list" of app "core" has been set to '["ShareeGroup2"]'
When user "user1" gets the sharees using the sharing API with parameters
| search | ShareeGroup |
| itemType | file |
Then the OCS status code should be "<ocs-status>"
And the HTTP status code should be "<http-status>"
And the "exact users" sharees returned should be empty
And the "users" sharees returned should be empty
And the "exact groups" sharees returned should be empty
And the "groups" sharees returned should be empty
And the "exact remotes" sharees returned should be empty
And the "remotes" sharees returned should be empty
Examples:
| ocs-api-version | ocs-status | http-status |
| 1 | 100 | 200 |
| 2 | 200 | 200 |

Scenario Outline: Search with exact match
Given using OCS API version "<ocs-api-version>"
When user "user1" gets the sharees using the sharing API with parameters
Expand Down
12 changes: 11 additions & 1 deletion tests/acceptance/features/bootstrap/ShareesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,17 @@ public function theShareesReturnedShouldBeEmpty($shareeType) {
$respondedArray = $this->getArrayOfShareesResponded(
$this->featureContext->getResponse(), $shareeType
);
PHPUnit_Framework_Assert::assertEmpty($respondedArray);
if (isset($respondedArray[0])) {
// [0] is display name and [2] is user or group id
$firstEntry = $respondedArray[0][0] . " (" . $respondedArray[0][2] . ")";
} else {
$firstEntry = "";
}

PHPUnit_Framework_Assert::assertEmpty(
$respondedArray,
"'$shareeType' array should be empty, but it starts with $firstEntry"
);
}

/**
Expand Down
X Tutup