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

group shares should respect to users auto accept preference #34850

Merged
merged 1 commit into from
Mar 29, 2019
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
29 changes: 22 additions & 7 deletions apps/files_sharing/lib/Controller/Share20OcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,20 +379,20 @@ public function createShare() {

$shareWith = $this->request->getParam('shareWith', null);

$autoAccept = false;
$globalAutoAcceptValue = $this->config->getAppValue('core', 'shareapi_auto_accept_share', 'yes');
if ($globalAutoAcceptValue === 'yes') {
$autoAccept = $this->config->getUserValue($shareWith, 'files_sharing', 'auto_accept_share', $globalAutoAcceptValue) === 'yes';
}
$globalAutoAccept = $this->config->getAppValue('core', 'shareapi_auto_accept_share', 'yes') === 'yes';
if ($shareType === Share::SHARE_TYPE_USER) {
$userAutoAccept = false;
if ($globalAutoAccept) {
$userAutoAccept = $this->config->getUserValue($shareWith, 'files_sharing', 'auto_accept_share', 'yes') === 'yes';
}
// Valid user is required to share
if ($shareWith === null || !$this->userManager->userExists($shareWith)) {
$share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
return new Result(null, 404, $this->l->t('Please specify a valid user'));
}
$share->setSharedWith($shareWith);
$share->setPermissions($permissions);
if ($autoAccept) {
if ($userAutoAccept) {
$share->setState(Share::STATE_ACCEPTED);
} else {
$share->setState(Share::STATE_PENDING);
Expand All @@ -413,7 +413,7 @@ public function createShare() {
}
$share->setSharedWith($shareWith);
$share->setPermissions($permissions);
if ($autoAccept) {
if ($globalAutoAccept) {
$share->setState(Share::STATE_ACCEPTED);
} else {
$share->setState(Share::STATE_PENDING);
Expand Down Expand Up @@ -501,6 +501,21 @@ public function createShare() {

try {
$share = $this->shareManager->createShare($share);
/**
* If auto accept enabled by admin and it is a group share,
* create sub-share for auto accept disabled users in pending state.
*/
if ($share->getShareType() === Share::SHARE_TYPE_GROUP && $globalAutoAccept) {
$subShare = $share;
$group = $this->groupManager->get($share->getSharedWith());
foreach ($group->getUsers() as $user) {
$userAutoAccept = $this->config->getUserValue($user->getUID(), 'files_sharing', 'auto_accept_share', 'yes') === 'yes';
if (!$userAutoAccept) {
$subShare->setState(Share::STATE_PENDING);
$this->shareManager->updateShareForRecipient($subShare, $user->getUID());
}
}
}
} catch (GenericShareException $e) {
$code = $e->getCode() === 0 ? 403 : $e->getCode();
$share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ private function getGroupMock(array $attrs) {
if (isset($attrs['displayname'])) {
$groupMock->method('getDisplayName')->willReturn($attrs['displayname']);
}
$groupMock->method('getUsers')->willReturn([]);
return $groupMock;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ Feature: accept/decline shares coming from internal users
Then folder "simple-folder-renamed" should be in state "" in the shared-with-you page on the webUI
And folder "simple-folder-renamed" should be listed in the files page on the webUI

@issue-34705
Scenario: User-based accepting is disabled while global is enabled
Given the setting "Automatically accept new incoming local user shares" in the section "Sharing" has been enabled
And user "user1" has logged in using the webUI
Expand All @@ -247,14 +246,11 @@ Feature: accept/decline shares coming from internal users
And user "user2" shares folder "/simple-folder" with group "grp1" using the sharing API
And user "user2" shares file "/testimage.jpg" with user "user1" using the sharing API
And the user browses to the files page
Then folder "simple-folder (2)" should be listed on the webUI
#Then folder "simple-folder (2)" should not be listed on the webUI
Then folder "simple-folder (2)" should not be listed on the webUI
And file "testimage (2).jpg" should not be listed on the webUI
And folder "simple-folder (2)" should be listed in the shared-with-you page on the webUI
#But folder "simple-folder" should be listed in the shared-with-you page on the webUI
But folder "simple-folder" should be listed in the shared-with-you page on the webUI
And file "testimage.jpg" should be listed in the shared-with-you page on the webUI
And folder "simple-folder (2)" should be in state "" in the shared-with-you page on the webUI
#And folder "simple-folder" should be in state "Pending" in the shared-with-you page on the webUI
And folder "simple-folder" should be in state "Pending" in the shared-with-you page on the webUI
And file "testimage.jpg" should be in state "Pending" in the shared-with-you page on the webUI

Scenario: User-based accepting is enabled while global is enabled
Expand Down