Skip to content

Commit

Permalink
start to get fed group shares into the share dialog
Browse files Browse the repository at this point in the history
Signed-off-by: Bjoern Schiessle <[email protected]>
  • Loading branch information
schiessle committed Jul 4, 2018
1 parent d10ca57 commit 4854965
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 5 deletions.
10 changes: 10 additions & 0 deletions apps/files_sharing/lib/Controller/ShareesAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ class ShareesAPIController extends OCSController {
'users' => [],
'groups' => [],
'remotes' => [],
'remote_groups' => [],
'emails' => [],
'circles' => [],
],
'users' => [],
'groups' => [],
'remotes' => [],
'remote_groups' => [],
'emails' => [],
'lookup' => [],
'circles' => [],
Expand Down Expand Up @@ -153,6 +155,10 @@ public function search(string $search = '', string $itemType = null, int $page =
$shareTypes[] = Share::SHARE_TYPE_REMOTE;
}

if ($this->isRemoteGroupSharingAllowed($itemType)) {
$shareTypes[] = Share::SHARE_TYPE_REMOTE_GROUP;
}

if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
$shareTypes[] = Share::SHARE_TYPE_EMAIL;
}
Expand Down Expand Up @@ -216,6 +222,10 @@ protected function isRemoteSharingAllowed(string $itemType): bool {
}
}

protected function isRemoteGroupSharingAllowed(string $itemType): bool {
return true;
}


/**
* Generates a bunch of pagination links for the current page
Expand Down
1 change: 1 addition & 0 deletions core/js/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ OC.Share = _.extend(OC.Share || {}, {
SHARE_TYPE_REMOTE:6,
SHARE_TYPE_CIRCLE:7,
SHARE_TYPE_GUEST:8,
SHARE_TYPE_REMOTE_GROUP:9,

/**
* Regular expression for splitting parts of remote share owners:
Expand Down
8 changes: 7 additions & 1 deletion core/js/sharedialogshareelistview.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@
shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'group') + ')';
} else if (shareType === OC.Share.SHARE_TYPE_REMOTE) {
shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'remote') + ')';
} else if (shareType === OC.Share.SHARE_TYPE_REMOTE_GROUP) {
shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'remote group') + ')';
} else if (shareType === OC.Share.SHARE_TYPE_EMAIL) {
shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'email') + ')';
} else if (shareType === OC.Share.SHARE_TYPE_CIRCLE) {
Expand All @@ -207,7 +209,10 @@
shareWithTitle = shareWith + " (" + t('core', 'group') + ')';
} else if (shareType === OC.Share.SHARE_TYPE_REMOTE) {
shareWithTitle = shareWith + " (" + t('core', 'remote') + ')';
} else if (shareType === OC.Share.SHARE_TYPE_EMAIL) {
} else if (shareType === OC.Share.SHARE_TYPE_REMOTE_GROUP) {
shareWithTitle = shareWith + " (" + t('core', 'remote group') + ')';
}
else if (shareType === OC.Share.SHARE_TYPE_EMAIL) {
shareWithTitle = shareWith + " (" + t('core', 'email') + ')';
} else if (shareType === OC.Share.SHARE_TYPE_CIRCLE) {
shareWithTitle = shareWith;
Expand Down Expand Up @@ -243,6 +248,7 @@
shareId: this.model.get('shares')[shareIndex].id,
modSeed: shareType !== OC.Share.SHARE_TYPE_USER && shareType !== OC.Share.SHARE_TYPE_CIRCLE,
isRemoteShare: shareType === OC.Share.SHARE_TYPE_REMOTE,
isRemoteGroupShare: shareType === OC.Share.SHARE_TYPE_REMOTE_GROUP,
isMailShare: shareType === OC.Share.SHARE_TYPE_EMAIL,
isCircleShare: shareType === OC.Share.SHARE_TYPE_CIRCLE,
isFileSharedByMail: shareType === OC.Share.SHARE_TYPE_EMAIL && !this.model.isFolder(),
Expand Down
26 changes: 22 additions & 4 deletions core/js/sharedialogview.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
this.configModel.on('change:isRemoteShareAllowed', function() {
view.render();
});
this.configModel.on('change:isRemoteGroupShareAllowed', function() {
view.render();
});
this.model.on('change:permissions', function() {
view.render();
});
Expand Down Expand Up @@ -161,7 +164,7 @@
},
function (result) {
if (result.ocs.meta.statuscode === 100) {
var filter = function(users, groups, remotes, emails, circles) {
var filter = function(users, groups, remotes, remote_groups, emails, circles) {
if (typeof(emails) === 'undefined') {
emails = [];
}
Expand All @@ -172,6 +175,7 @@
var usersLength;
var groupsLength;
var remotesLength;
var remoteGroupsLength;
var emailsLength;
var circlesLength;

Expand Down Expand Up @@ -228,6 +232,14 @@
break;
}
}
} else if (share.share_type === OC.Share.SHARE_TYPE_REMOTE_GROUP) {
remoteGroupsLength = remote_groups.length;
for (j = 0; j < remoteGroupsLength; j++) {
if (remote_groups[j].value.shareWith === share.share_with) {
remote_groups.splice(j, 1);
break;
}
}
} else if (share.share_type === OC.Share.SHARE_TYPE_EMAIL) {
emailsLength = emails.length;
for (j = 0; j < emailsLength; j++) {
Expand All @@ -252,13 +264,15 @@
result.ocs.data.exact.users,
result.ocs.data.exact.groups,
result.ocs.data.exact.remotes,
result.ocs.data.exact.remote_groups,
result.ocs.data.exact.emails,
result.ocs.data.exact.circles
);

var exactUsers = result.ocs.data.exact.users;
var exactGroups = result.ocs.data.exact.groups;
var exactRemotes = result.ocs.data.exact.remotes;
var exactRemoteGroups = result.ocs.data.exact.remote_groups;
var exactEmails = [];
if (typeof(result.ocs.data.emails) !== 'undefined') {
exactEmails = result.ocs.data.exact.emails;
Expand All @@ -268,19 +282,21 @@
exactCircles = result.ocs.data.exact.circles;
}

var exactMatches = exactUsers.concat(exactGroups).concat(exactRemotes).concat(exactEmails).concat(exactCircles);
var exactMatches = exactUsers.concat(exactGroups).concat(exactRemotes).concat(exactRemoteGroups).concat(exactEmails).concat(exactCircles);

filter(
result.ocs.data.users,
result.ocs.data.groups,
result.ocs.data.remotes,
result.ocs.data.remote_groups,
result.ocs.data.emails,
result.ocs.data.circles
);

var users = result.ocs.data.users;
var groups = result.ocs.data.groups;
var remotes = result.ocs.data.remotes;
var remoteGroups = result.ocs.data.remote_groups;
var lookup = result.ocs.data.lookup;
var emails = [];
if (typeof(result.ocs.data.emails) !== 'undefined') {
Expand All @@ -291,7 +307,7 @@
circles = result.ocs.data.circles;
}

var suggestions = exactMatches.concat(users).concat(groups).concat(remotes).concat(emails).concat(circles).concat(lookup);
var suggestions = exactMatches.concat(users).concat(groups).concat(remotes).concat(remoteGroups).concat(emails).concat(circles).concat(lookup);

deferred.resolve(suggestions, exactMatches);
} else {
Expand Down Expand Up @@ -414,7 +430,9 @@
if (item.value.shareType === OC.Share.SHARE_TYPE_GROUP) {
text = t('core', '{sharee} (group)', { sharee: text }, undefined, { escape: false });
} else if (item.value.shareType === OC.Share.SHARE_TYPE_REMOTE) {
text = t('core', '{sharee} (remote)', { sharee: text }, undefined, { escape: false });
text = t('core', '{sharee} (remote)', {sharee: text}, undefined, {escape: false});
} else if (item.value.shareType === OC.Share.SHARE_TYPE_REMOTE_GROUP) {
text = t('core', '{sharee} (remote group)', { sharee: text }, undefined, { escape: false });
} else if (item.value.shareType === OC.Share.SHARE_TYPE_EMAIL) {
text = t('core', '{sharee} (email)', { sharee: text }, undefined, { escape: false });
} else if (item.value.shareType === OC.Share.SHARE_TYPE_CIRCLE) {
Expand Down
78 changes: 78 additions & 0 deletions lib/private/Collaboration/Collaborators/RemoteGroupPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* @copyright Copyright (c) 2017 Arthur Schiwon <[email protected]>
*
* @author Arthur Schiwon <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OC\Collaboration\Collaborators;


use OCP\Collaboration\Collaborators\ISearchPlugin;
use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\Collaboration\Collaborators\SearchResultType;
use OCP\Contacts\IManager;
use OCP\Federation\ICloudFederationProviderManager;
use OCP\Federation\ICloudIdManager;
use OCP\IConfig;
use OCP\Share;

class RemoteGroupPlugin implements ISearchPlugin {
protected $shareeEnumeration;

/** @var ICloudIdManager */
private $cloudIdManager;
/** @var IConfig */
private $config;
/** @var bool */
private $enabled = false;

public function __construct(ICloudFederationProviderManager $cloudFederationProviderManager, ICloudIdManager $cloudIdManager) {
try {
$fileSharingProvider = $cloudFederationProviderManager->getCloudFederationProvider('file');
$supportedShareTypes = $fileSharingProvider->getSupportedShareTypes();
if (in_array('group', $supportedShareTypes)) {
$this->enabled = true;
}
} catch (\Exception $e) {
// do nothing, just don't enable federated group shares
}
$this->cloudIdManager = $cloudIdManager;
}

public function search($search, $limit, $offset, ISearchResult $searchResult) {
$result = ['wide' => [], 'exact' => []];
$resultType = new SearchResultType('remote_groups');

if ($this->enabled && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) {
$result['exact'][] = [
'label' => $search,
'value' => [
'shareType' => Share::SHARE_TYPE_REMOTE_GROUP,
'shareWith' => $search,
],
];
}

$searchResult->addResultSet($resultType, $result['wide'], $result['exact']);

return true;
}

}
2 changes: 2 additions & 0 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
use OC\Authentication\Token\IProvider;
use OC\Collaboration\Collaborators\GroupPlugin;
use OC\Collaboration\Collaborators\MailPlugin;
use OC\Collaboration\Collaborators\RemoteGroupPlugin;
use OC\Collaboration\Collaborators\RemotePlugin;
use OC\Collaboration\Collaborators\UserPlugin;
use OC\Command\CronBus;
Expand Down Expand Up @@ -1066,6 +1067,7 @@ public function __construct($webRoot, \OC\Config $config) {
$instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
$instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);

return $instance;
});
Expand Down

0 comments on commit 4854965

Please sign in to comment.