Skip to content

Commit 6331f17

Browse files
authored
Merge pull request #12119 from nextcloud/add_circle_to_caldav_and_filepanel-15
Add Circle to Caldav and Filepanel
2 parents 804a151 + de8e026 commit 6331f17

File tree

7 files changed

+77
-11
lines changed

7 files changed

+77
-11
lines changed

apps/dav/lib/Connector/Sabre/FilesReportPlugin.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
namespace OCA\DAV\Connector\Sabre;
2626

2727
use OC\Files\View;
28+
use OCP\App\IAppManager;
2829
use Sabre\DAV\Exception\PreconditionFailed;
2930
use Sabre\DAV\Exception\BadRequest;
3031
use Sabre\DAV\ServerPlugin;
@@ -46,6 +47,7 @@ class FilesReportPlugin extends ServerPlugin {
4647
const NS_OWNCLOUD = 'http://owncloud.org/ns';
4748
const REPORT_NAME = '{http://owncloud.org/ns}filter-files';
4849
const SYSTEMTAG_PROPERTYNAME = '{http://owncloud.org/ns}systemtag';
50+
const CIRCLE_PROPERTYNAME = '{http://owncloud.org/ns}circle';
4951

5052
/**
5153
* Reference to main server object
@@ -96,6 +98,11 @@ class FilesReportPlugin extends ServerPlugin {
9698
*/
9799
private $userFolder;
98100

101+
/**
102+
* @var IAppManager
103+
*/
104+
private $appManager;
105+
99106
/**
100107
* @param Tree $tree
101108
* @param View $view
@@ -105,6 +112,7 @@ class FilesReportPlugin extends ServerPlugin {
105112
* @param IUserSession $userSession
106113
* @param IGroupManager $groupManager
107114
* @param Folder $userFolder
115+
* @param IAppManager $appManager
108116
*/
109117
public function __construct(Tree $tree,
110118
View $view,
@@ -113,7 +121,8 @@ public function __construct(Tree $tree,
113121
ITagManager $fileTagger,
114122
IUserSession $userSession,
115123
IGroupManager $groupManager,
116-
Folder $userFolder
124+
Folder $userFolder,
125+
IAppManager $appManager
117126
) {
118127
$this->tree = $tree;
119128
$this->fileView = $view;
@@ -123,6 +132,7 @@ public function __construct(Tree $tree,
123132
$this->userSession = $userSession;
124133
$this->groupManager = $groupManager;
125134
$this->userFolder = $userFolder;
135+
$this->appManager = $appManager;
126136
}
127137

128138
/**
@@ -256,14 +266,19 @@ protected function processFilterRules($filterRules) {
256266
$ns = '{' . $this::NS_OWNCLOUD . '}';
257267
$resultFileIds = null;
258268
$systemTagIds = [];
269+
$circlesIds = [];
259270
$favoriteFilter = null;
260271
foreach ($filterRules as $filterRule) {
261272
if ($filterRule['name'] === $ns . 'systemtag') {
262273
$systemTagIds[] = $filterRule['value'];
263274
}
275+
if ($filterRule['name'] === self::CIRCLE_PROPERTYNAME) {
276+
$circlesIds[] = $filterRule['value'];
277+
}
264278
if ($filterRule['name'] === $ns . 'favorite') {
265279
$favoriteFilter = true;
266280
}
281+
267282
}
268283

269284
if ($favoriteFilter !== null) {
@@ -282,6 +297,15 @@ protected function processFilterRules($filterRules) {
282297
}
283298
}
284299

300+
if (!empty($circlesIds)) {
301+
$fileIds = $this->getCirclesFileIds($circlesIds);
302+
if (empty($resultFileIds)) {
303+
$resultFileIds = $fileIds;
304+
} else {
305+
$resultFileIds = array_intersect($fileIds, $resultFileIds);
306+
}
307+
}
308+
285309
return $resultFileIds;
286310
}
287311

@@ -328,6 +352,19 @@ private function getSystemTagFileIds($systemTagIds) {
328352
return $resultFileIds;
329353
}
330354

355+
/**
356+
* @suppress PhanUndeclaredClassMethod
357+
* @param array $circlesIds
358+
* @return array
359+
*/
360+
private function getCirclesFileIds(array $circlesIds) {
361+
if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) {
362+
return [];
363+
}
364+
return \OCA\Circles\Api\v1\Circles::getFilesForCircles($circlesIds);
365+
}
366+
367+
331368
/**
332369
* Prepare propfind response for the given nodes
333370
*

apps/dav/lib/Connector/Sabre/Principal.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
use OCP\IUserSession;
4646
use OCP\Share\IManager as IShareManager;
4747
use Sabre\DAV\Exception;
48-
use \Sabre\DAV\PropPatch;
48+
use Sabre\DAV\PropPatch;
4949
use Sabre\DAVACL\PrincipalBackend\BackendInterface;
5050

5151
class Principal implements BackendInterface {
@@ -145,7 +145,11 @@ public function getPrincipalByPath($path) {
145145
return $this->userToPrincipal($user);
146146
}
147147
} else if ($prefix === 'principals/circles') {
148-
return $this->circleToPrincipal($name);
148+
try {
149+
return $this->circleToPrincipal($name);
150+
} catch (QueryException $e) {
151+
return null;
152+
}
149153
}
150154
return null;
151155
}
@@ -406,6 +410,7 @@ public function getPrincipalPrefix() {
406410
/**
407411
* @param string $circleUniqueId
408412
* @return array|null
413+
* @throws \OCP\AppFramework\QueryException
409414
* @suppress PhanUndeclaredClassMethod
410415
* @suppress PhanUndeclaredClassCatch
411416
*/
@@ -438,9 +443,9 @@ protected function circleToPrincipal($circleUniqueId) {
438443
* Returns the list of circles a principal is a member of
439444
*
440445
* @param string $principal
441-
* @param bool $needGroups
442446
* @return array
443447
* @throws Exception
448+
* @throws \OCP\AppFramework\QueryException
444449
* @suppress PhanUndeclaredClassMethod
445450
*/
446451
public function getCircleMembership($principal):array {
@@ -458,13 +463,13 @@ public function getCircleMembership($principal):array {
458463
$circles = \OCA\Circles\Api\v1\Circles::joinedCircles($name, true);
459464

460465
$circles = array_map(function($circle) {
461-
/** @var \OCA\Circles\Model\Circle $group */
466+
/** @var \OCA\Circles\Model\Circle $circle */
462467
return 'principals/circles/' . urlencode($circle->getUniqueId());
463468
}, $circles);
464469

465470
return $circles;
466-
467471
}
472+
468473
return [];
469474
}
470475

apps/dav/lib/Connector/Sabre/ServerFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ public function createServer($baseUri,
180180
\OC::$server->getTagManager(),
181181
$this->userSession,
182182
\OC::$server->getGroupManager(),
183-
$userFolder
183+
$userFolder,
184+
\OC::$server->getAppManager()
184185
));
185186
// custom properties plugin must be the last one
186187
$server->addPlugin(

apps/dav/lib/Server.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ public function __construct(IRequest $request, $baseUri) {
271271
\OC::$server->getTagManager(),
272272
$userSession,
273273
\OC::$server->getGroupManager(),
274-
$userFolder
274+
$userFolder,
275+
\OC::$server->getAppManager()
275276
));
276277
$lazySearchBackend->setBackend(new \OCA\DAV\Files\FileSearchBackend(
277278
$this->server->tree,

apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public function setUp() {
8686
->withAnyParameters()
8787
->willReturn([]);
8888

89+
$this->principal->expects($this->any())->method('getCircleMembership')
90+
->withAnyParameters()
91+
->willReturn([]);
92+
8993
$this->backend = new CalDavBackend(
9094
$db,
9195
$this->principal,
@@ -112,6 +116,11 @@ public function tearDown() {
112116
$this->principal->expects($this->any())->method('getGroupMembership')
113117
->withAnyParameters()
114118
->willReturn([]);
119+
120+
$this->principal->expects($this->any())->method('getCircleMembership')
121+
->withAnyParameters()
122+
->willReturn([]);
123+
115124
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
116125
foreach ($books as $book) {
117126
$this->backend->deleteCalendar($book['id']);

apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
use OCA\DAV\Connector\Sabre\Directory;
3030
use OCA\DAV\Connector\Sabre\FilesReportPlugin as FilesReportPluginImplementation;
31+
use OCP\App\IAppManager;
3132
use OCP\Files\File;
3233
use OCP\IConfig;
3334
use OCP\IPreview;
@@ -81,6 +82,9 @@ class FilesReportPluginTest extends \Test\TestCase {
8182
/** @var IPreview|\PHPUnit_Framework_MockObject_MockObject * */
8283
private $previewManager;
8384

85+
/** @var IAppManager|\PHPUnit_Framework_MockObject_MockObject * */
86+
private $appManager;
87+
8488
public function setUp() {
8589
parent::setUp();
8690
$this->tree = $this->getMockBuilder(Tree::class)
@@ -112,6 +116,10 @@ public function setUp() {
112116
->disableOriginalConstructor()
113117
->getMock();
114118

119+
$this->appManager = $this->getMockBuilder(IAppManager::class)
120+
->disableOriginalConstructor()
121+
->getMock();
122+
115123
$this->tagManager = $this->createMock(ISystemTagManager::class);
116124
$this->tagMapper = $this->createMock(ISystemTagObjectMapper::class);
117125
$this->userSession = $this->createMock(IUserSession::class);
@@ -140,7 +148,8 @@ public function setUp() {
140148
$privateTagManager,
141149
$this->userSession,
142150
$this->groupManager,
143-
$this->userFolder
151+
$this->userFolder,
152+
$this->appManager
144153
);
145154
}
146155

core/js/files/client.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@
503503

504504
/**
505505
* Fetches a flat list of files filtered by a given filter criteria.
506-
* (currently only system tags is supported)
506+
* (currently system tags and circles are supported)
507507
*
508508
* @param {Object} filter filter criteria
509509
* @param {Object} [filter.systemTagIds] list of system tag ids to filter by
@@ -525,7 +525,8 @@
525525
properties = options.properties;
526526
}
527527

528-
if (!filter || (!filter.systemTagIds && _.isUndefined(filter.favorite))) {
528+
if (!filter ||
529+
(!filter.systemTagIds && _.isUndefined(filter.favorite) && !filter.circlesIds) ) {
529530
throw 'Missing filter argument';
530531
}
531532

@@ -551,6 +552,9 @@
551552
_.each(filter.systemTagIds, function(systemTagIds) {
552553
body += ' <oc:systemtag>' + escapeHTML(systemTagIds) + '</oc:systemtag>\n';
553554
});
555+
_.each(filter.circlesIds, function(circlesIds) {
556+
body += ' <oc:circle>' + escapeHTML(circlesIds) + '</oc:circle>\n';
557+
});
554558
if (filter.favorite) {
555559
body += ' <oc:favorite>' + (filter.favorite ? '1': '0') + '</oc:favorite>\n';
556560
}

0 commit comments

Comments
 (0)