Skip to content

Commit

Permalink
shares-circles
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@nextcloud.com>
  • Loading branch information
ArtificialOwl committed Mar 17, 2017
1 parent 3c66ad6 commit 6969401
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 17 deletions.
2 changes: 2 additions & 0 deletions apps/files_sharing/js/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
hasShares = true;
} else if (shareType === OC.Share.SHARE_TYPE_REMOTE) {
hasShares = true;
} else if (shareType === OC.Share.SHARE_TYPE_CIRCLE) {
hasShares = true;
}
});
OCA.Sharing.Util._updateFileActionIcon($tr, hasShares, hasLink);
Expand Down
44 changes: 42 additions & 2 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,12 @@ protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = n
$result['share_with'] = $share->getSharedWith();
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
$result['token'] = $share->getToken();
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) {
$result['share_with_displayname'] = $share->getSharedWith();
$result['share_with'] = explode(' ', $share->getSharedWith(), 2)[0];
}


$result['mail_send'] = $share->getMailSend() ? 1 : 0;

return $result;
Expand Down Expand Up @@ -443,6 +447,19 @@ public function createShare(
\OCP\Constants::PERMISSION_DELETE);
}
$share->setSharedWith($shareWith);
} else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) {
if (!\OCP\App::isEnabled('circles')) {
throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled'));
}

$circle = \OCA\Circles\Api\Circles::detailsCircle($shareWith);

// Valid circle is required to share
if ($circle === null) {
throw new OCSNotFoundException($this->l->t('Please specify a valid circle'));
}
$share->setSharedWith($shareWith);
$share->setPermissions($permissions);
} else {
throw new OCSBadRequestException($this->l->t('Unknown share type'));
}
Expand All @@ -469,10 +486,12 @@ public function createShare(
* @return DataResponse
*/
private function getSharedWithMe($node = null) {

$userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0);
$groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0);
$circleShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $node, -1, 0);

$shares = array_merge($userShares, $groupShares);
$shares = array_merge($userShares, $groupShares, $circleShares);

$shares = array_filter($shares, function (IShare $share) {
return $share->getShareOwner() !== $this->currentUser;
Expand Down Expand Up @@ -592,7 +611,13 @@ public function getShares(
} else {
$mailShares = [];
}
$shares = array_merge($userShares, $groupShares, $linkShares, $mailShares);
if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) {
$circleShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0);
} else {
$circleShares = [];
}

$shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares);

if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
$federatedShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0);
Expand Down Expand Up @@ -784,6 +809,11 @@ protected function canAccessShare(\OCP\Share\IShare $share, $checkGroups = true)
}
}

if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) {
// TODO: have a sanity check like above?
return true;
}

return false;
}

Expand Down Expand Up @@ -832,6 +862,16 @@ private function getShareById($id) {
// Do nothing, just try the other share type
}


try {
if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) {
$share = $this->shareManager->getShareById('ocCircleShare:' . $id);
return $share;
}
} catch (ShareNotFound $e) {
// Do nothing, just try the other share type
}

try {
if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
$share = $this->shareManager->getShareById('ocMailShare:' . $id);
Expand Down
29 changes: 29 additions & 0 deletions apps/files_sharing/lib/Controller/ShareesAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ class ShareesAPIController extends OCSController {
'groups' => [],
'remotes' => [],
'emails' => [],
'circles' => [],
],
'users' => [],
'groups' => [],
'remotes' => [],
'emails' => [],
'lookup' => [],
'circles' => [],
];

protected $reachedEndFor = [];
Expand Down Expand Up @@ -294,6 +296,23 @@ protected function getGroups($search) {
}
}


/**
* @param string $search
*/
protected function getCircles($search) {
$this->result['circles'] = $this->result['exact']['circles'] = [];

$result = \OCA\Circles\Api\Sharees::search($search, $this->limit, $this->offset);
if (array_key_exists('circles', $result['exact'])) {
$this->result['exact']['circles'] = $result['exact']['circles'];
}
if (array_key_exists('circles', $result)) {
$this->result['circles'] = $result['circles'];
}
}


/**
* @param string $search
* @return array
Expand Down Expand Up @@ -453,6 +472,10 @@ public function search($search = '', $itemType = null, $page = 1, $perPage = 200
$shareTypes[] = Share::SHARE_TYPE_EMAIL;
}

if (\OCP\App::isEnabled('circles')) {
$shareTypes[] = Share::SHARE_TYPE_CIRCLE;
}

if (isset($_GET['shareType']) && is_array($_GET['shareType'])) {
$shareTypes = array_intersect($shareTypes, $_GET['shareType']);
sort($shareTypes);
Expand Down Expand Up @@ -512,6 +535,12 @@ protected function searchSharees($search, $itemType, array $shareTypes, $page, $
$this->getGroups($search);
}

// Get circles
if (in_array(Share::SHARE_TYPE_CIRCLE, $shareTypes)) {
$this->getCircles($search);
}


// Get remote
$remoteResults = ['results' => [], 'exact' => [], 'exactIdMatch' => false];
if (in_array(Share::SHARE_TYPE_REMOTE, $shareTypes)) {
Expand Down
3 changes: 3 additions & 0 deletions apps/files_sharing/lib/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ public function __construct(IConfig $config, IManager $shareManager, ILogger $lo
* @return \OCP\Files\Mount\IMountPoint[]
*/
public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) {

$shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1);
$shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1));
$shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_CIRCLE, null, -1));

// filter out excluded shares and group shares that includes self
$shares = array_filter($shares, function (\OCP\Share\IShare $share) use ($user) {
return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID();
Expand Down
18 changes: 12 additions & 6 deletions apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1576,20 +1576,22 @@ public function dataSearchSharees() {
return [
['test', 'folder', [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_GROUP, Share::SHARE_TYPE_REMOTE], 1, 2, false, [], [], ['results' => [], 'exact' => [], 'exactIdMatch' => false],
[
'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'emails' => []],
'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'circles' => [], 'emails' => []],
'users' => [],
'groups' => [],
'remotes' => [],
'emails' => [],
'circles' => [],
'lookup' => [],
], false],
['test', 'folder', [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_GROUP, Share::SHARE_TYPE_REMOTE], 1, 2, false, [], [], ['results' => [], 'exact' => [], 'exactIdMatch' => false],
[
'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'emails' => []],
'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'circles' => [], 'emails' => []],
'users' => [],
'groups' => [],
'remotes' => [],
'emails' => [],
'circles' => [],
'lookup' => [],
], false],
[
Expand All @@ -1601,7 +1603,7 @@ public function dataSearchSharees() {
'results' => [['label' => 'testz@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'testz@remote']]], 'exact' => [], 'exactIdMatch' => false,
],
[
'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'emails' => []],
'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'circles' => [], 'emails' => []],
'users' => [
['label' => 'test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
],
Expand All @@ -1612,6 +1614,7 @@ public function dataSearchSharees() {
['label' => 'testz@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'testz@remote']],
],
'emails' => [],
'circles' => [],
'lookup' => [],
], true,
],
Expand All @@ -1623,7 +1626,7 @@ public function dataSearchSharees() {
'results' => [['label' => 'testz@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'testz@remote']]], 'exact' => [], 'exactIdMatch' => false
],
[
'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'emails' => []],
'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'circles' => [], 'emails' => []],
'users' => [
['label' => 'test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
],
Expand All @@ -1632,6 +1635,7 @@ public function dataSearchSharees() {
['label' => 'testz@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'testz@remote']],
],
'emails' => [],
'circles' => [],
'lookup' => [],
], false,
],
Expand All @@ -1641,13 +1645,14 @@ public function dataSearchSharees() {
['label' => 'test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
], null, null,
[
'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'emails' => []],
'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'circles' => [], 'emails' => []],
'users' => [
['label' => 'test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
],
'groups' => [],
'remotes' => [],
'emails' => [],
'circles' => [],
'lookup' => [],
], false,
],
Expand All @@ -1658,14 +1663,15 @@ public function dataSearchSharees() {
['label' => 'test 2', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']],
], null, null,
[
'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'emails' => []],
'exact' => ['users' => [], 'groups' => [], 'remotes' => [], 'circles' => [], 'emails' => []],
'users' => [
['label' => 'test 1', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
['label' => 'test 2', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']],
],
'groups' => [],
'remotes' => [],
'emails' => [],
'circles' => [],
'lookup' => [],
], true,
],
Expand Down
12 changes: 12 additions & 0 deletions apps/files_sharing/tests/MountProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public function testExcludeShares() {
$this->makeMockShare(4, 101, 'user2', '/share4', 31),
$this->makeMockShare(5, 100, 'user1', '/share4', 31),
];
// tests regarding circles are made in the app itself.
$circleShares = [];
$this->user->expects($this->any())
->method('getUID')
->will($this->returnValue('user1'));
Expand All @@ -124,6 +126,10 @@ public function testExcludeShares() {
->method('getSharedWith')
->with('user1', \OCP\Share::SHARE_TYPE_GROUP, null, -1)
->will($this->returnValue($groupShares));
$this->shareManager->expects($this->at(2))
->method('getSharedWith')
->with('user1', \OCP\Share::SHARE_TYPE_CIRCLE, null, -1)
->will($this->returnValue($circleShares));
$this->shareManager->expects($this->any())
->method('newShare')
->will($this->returnCallback(function() use ($rootFolder, $userManager) {
Expand Down Expand Up @@ -293,6 +299,8 @@ public function testMergeShares($userShares, $groupShares, $expectedShares) {
->method('getUID')
->will($this->returnValue('user1'));

// tests regarding circles are made in the app itself.
$circleShares = [];
$this->shareManager->expects($this->at(0))
->method('getSharedWith')
->with('user1', \OCP\Share::SHARE_TYPE_USER)
Expand All @@ -301,6 +309,10 @@ public function testMergeShares($userShares, $groupShares, $expectedShares) {
->method('getSharedWith')
->with('user1', \OCP\Share::SHARE_TYPE_GROUP, null, -1)
->will($this->returnValue($groupShares));
$this->shareManager->expects($this->at(2))
->method('getSharedWith')
->with('user1', \OCP\Share::SHARE_TYPE_CIRCLE, null, -1)
->will($this->returnValue($circleShares));
$this->shareManager->expects($this->any())
->method('newShare')
->will($this->returnCallback(function() use ($rootFolder, $userManager) {
Expand Down
18 changes: 17 additions & 1 deletion apps/files_sharing/tests/js/sharedbreadcrumviewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ describe('OCA.Sharing.ShareBreadCrumbView tests', function() {
expect(bc.$el.find('.shared').length).toEqual(1);
expect(bc.$el.find('.icon-public').length).toEqual(1);
});
it('Render shared if dir is shared by circle', function() {
var dirInfo = new OC.Files.FileInfo({
id: 42,
path: '/foo',
type: 'dir',
shareTypes: [OC.Share.SHARE_TYPE_CIRCLE]
});
bc.setDirectoryInfo(dirInfo);
bc.setDirectory('/foo');
bc.render();
expect(bc.$el.hasClass('breadcrumb')).toEqual(true);
expect(bc.$el.find('.icon-share').length).toEqual(1);
expect(bc.$el.find('.shared').length).toEqual(1);
expect(bc.$el.find('.icon-public').length).toEqual(0);
});
it('Render shared if dir is shared with remote', function() {
var dirInfo = new OC.Files.FileInfo({
id: 42,
Expand All @@ -145,7 +160,8 @@ describe('OCA.Sharing.ShareBreadCrumbView tests', function() {
OC.Share.SHARE_TYPE_GROUP,
OC.Share.SHARE_TYPE_LINK,
OC.Share.SHARE_TYPE_EMAIL,
OC.Share.SHARE_TYPE_REMOTE
OC.Share.SHARE_TYPE_REMOTE,
OC.Share.SHARE_TYPE_CIRCLE
]
});
bc.setDirectoryInfo(dirInfo);
Expand Down
1 change: 1 addition & 0 deletions core/js/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ OC.Share = _.extend(OC.Share || {}, {
SHARE_TYPE_LINK:3,
SHARE_TYPE_EMAIL:4,
SHARE_TYPE_REMOTE:6,
SHARE_TYPE_CIRCLE:7,

/**
* Regular expression for splitting parts of remote share owners:
Expand Down
4 changes: 4 additions & 0 deletions core/js/sharedialogshareelistview.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'remote') + ')';
} else if (shareType === OC.Share.SHARE_TYPE_EMAIL) {
shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'email') + ')';
} else if (shareType === OC.Share.SHARE_TYPE_CIRCLE) {
}

if (shareType === OC.Share.SHARE_TYPE_GROUP) {
Expand All @@ -166,6 +167,8 @@
shareWithTitle = shareWith + " (" + t('core', 'remote') + ')';
} else if (shareType === OC.Share.SHARE_TYPE_EMAIL) {
shareWithTitle = shareWith + " (" + t('core', 'email') + ')';
} else if (shareType === OC.Share.SHARE_TYPE_CIRCLE) {
shareWithTitle = shareWith;
}

return _.extend(hasPermissionOverride, {
Expand All @@ -183,6 +186,7 @@
modSeed: shareType !== OC.Share.SHARE_TYPE_USER,
isRemoteShare: shareType === OC.Share.SHARE_TYPE_REMOTE,
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
Loading

0 comments on commit 6969401

Please sign in to comment.