Created infrastructure to show circles' shared files
There is a proposal to allow users to filter files shared to circles. This commit is needed to provide the infrastucture for it. Issue: https://github.com/nextcloud/circles/issues/137 Changes to comply to https://github.com/coletivoEITA/circles/pull/2 Polishing: get files shared to circles in caldav Signed-off-by: Vinicius Cubas Brand <viniciuscb@gmail.com> Signed-off-by: Maxence Lange <maxence@artificial-owl.com> Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
parent
f0c85a0f5f
commit
9bb13fb05f
|
@ -46,6 +46,7 @@ class FilesReportPlugin extends ServerPlugin {
|
||||||
const NS_OWNCLOUD = 'http://owncloud.org/ns';
|
const NS_OWNCLOUD = 'http://owncloud.org/ns';
|
||||||
const REPORT_NAME = '{http://owncloud.org/ns}filter-files';
|
const REPORT_NAME = '{http://owncloud.org/ns}filter-files';
|
||||||
const SYSTEMTAG_PROPERTYNAME = '{http://owncloud.org/ns}systemtag';
|
const SYSTEMTAG_PROPERTYNAME = '{http://owncloud.org/ns}systemtag';
|
||||||
|
const CIRCLE_PROPERTYNAME = '{http://owncloud.org/ns}circle';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference to main server object
|
* Reference to main server object
|
||||||
|
@ -256,14 +257,19 @@ class FilesReportPlugin extends ServerPlugin {
|
||||||
$ns = '{' . $this::NS_OWNCLOUD . '}';
|
$ns = '{' . $this::NS_OWNCLOUD . '}';
|
||||||
$resultFileIds = null;
|
$resultFileIds = null;
|
||||||
$systemTagIds = [];
|
$systemTagIds = [];
|
||||||
|
$circlesIds = [];
|
||||||
$favoriteFilter = null;
|
$favoriteFilter = null;
|
||||||
foreach ($filterRules as $filterRule) {
|
foreach ($filterRules as $filterRule) {
|
||||||
if ($filterRule['name'] === $ns . 'systemtag') {
|
if ($filterRule['name'] === $ns . 'systemtag') {
|
||||||
$systemTagIds[] = $filterRule['value'];
|
$systemTagIds[] = $filterRule['value'];
|
||||||
}
|
}
|
||||||
|
if ($filterRule['name'] === self::CIRCLE_PROPERTYNAME) {
|
||||||
|
$circlesIds[] = $filterRule['value'];
|
||||||
|
}
|
||||||
if ($filterRule['name'] === $ns . 'favorite') {
|
if ($filterRule['name'] === $ns . 'favorite') {
|
||||||
$favoriteFilter = true;
|
$favoriteFilter = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($favoriteFilter !== null) {
|
if ($favoriteFilter !== null) {
|
||||||
|
@ -282,6 +288,15 @@ class FilesReportPlugin extends ServerPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($circlesIds)) {
|
||||||
|
$fileIds = $this->getCirclesFileIds($circlesIds);
|
||||||
|
if (empty($resultFileIds)) {
|
||||||
|
$resultFileIds = $fileIds;
|
||||||
|
} else {
|
||||||
|
$resultFileIds = array_intersect($fileIds, $resultFileIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $resultFileIds;
|
return $resultFileIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,6 +343,19 @@ class FilesReportPlugin extends ServerPlugin {
|
||||||
return $resultFileIds;
|
return $resultFileIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @suppress PhanUndeclaredClassMethod
|
||||||
|
* @param array $circlesIds
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getCirclesFileIds(array $circlesIds) {
|
||||||
|
if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
return \OCA\Circles\Api\v1\Circles::getFilesForCircles($circlesIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare propfind response for the given nodes
|
* Prepare propfind response for the given nodes
|
||||||
*
|
*
|
||||||
|
|
|
@ -45,7 +45,7 @@ use OCP\IUserManager;
|
||||||
use OCP\IUserSession;
|
use OCP\IUserSession;
|
||||||
use OCP\Share\IManager as IShareManager;
|
use OCP\Share\IManager as IShareManager;
|
||||||
use Sabre\DAV\Exception;
|
use Sabre\DAV\Exception;
|
||||||
use \Sabre\DAV\PropPatch;
|
use Sabre\DAV\PropPatch;
|
||||||
use Sabre\DAVACL\PrincipalBackend\BackendInterface;
|
use Sabre\DAVACL\PrincipalBackend\BackendInterface;
|
||||||
|
|
||||||
class Principal implements BackendInterface {
|
class Principal implements BackendInterface {
|
||||||
|
@ -145,7 +145,11 @@ class Principal implements BackendInterface {
|
||||||
return $this->userToPrincipal($user);
|
return $this->userToPrincipal($user);
|
||||||
}
|
}
|
||||||
} else if ($prefix === 'principals/circles') {
|
} else if ($prefix === 'principals/circles') {
|
||||||
|
try {
|
||||||
return $this->circleToPrincipal($name);
|
return $this->circleToPrincipal($name);
|
||||||
|
} catch (QueryException $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -406,6 +410,7 @@ class Principal implements BackendInterface {
|
||||||
/**
|
/**
|
||||||
* @param string $circleUniqueId
|
* @param string $circleUniqueId
|
||||||
* @return array|null
|
* @return array|null
|
||||||
|
* @throws \OCP\AppFramework\QueryException
|
||||||
* @suppress PhanUndeclaredClassMethod
|
* @suppress PhanUndeclaredClassMethod
|
||||||
* @suppress PhanUndeclaredClassCatch
|
* @suppress PhanUndeclaredClassCatch
|
||||||
*/
|
*/
|
||||||
|
@ -438,9 +443,9 @@ class Principal implements BackendInterface {
|
||||||
* Returns the list of circles a principal is a member of
|
* Returns the list of circles a principal is a member of
|
||||||
*
|
*
|
||||||
* @param string $principal
|
* @param string $principal
|
||||||
* @param bool $needGroups
|
|
||||||
* @return array
|
* @return array
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
* @throws \OCP\AppFramework\QueryException
|
||||||
* @suppress PhanUndeclaredClassMethod
|
* @suppress PhanUndeclaredClassMethod
|
||||||
*/
|
*/
|
||||||
public function getCircleMembership($principal):array {
|
public function getCircleMembership($principal):array {
|
||||||
|
@ -458,13 +463,13 @@ class Principal implements BackendInterface {
|
||||||
$circles = \OCA\Circles\Api\v1\Circles::joinedCircles($name, true);
|
$circles = \OCA\Circles\Api\v1\Circles::joinedCircles($name, true);
|
||||||
|
|
||||||
$circles = array_map(function($circle) {
|
$circles = array_map(function($circle) {
|
||||||
/** @var \OCA\Circles\Model\Circle $group */
|
/** @var \OCA\Circles\Model\Circle $circle */
|
||||||
return 'principals/circles/' . urlencode($circle->getUniqueId());
|
return 'principals/circles/' . urlencode($circle->getUniqueId());
|
||||||
}, $circles);
|
}, $circles);
|
||||||
|
|
||||||
return $circles;
|
return $circles;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,6 +86,10 @@ class PublicCalendarRootTest extends TestCase {
|
||||||
->withAnyParameters()
|
->withAnyParameters()
|
||||||
->willReturn([]);
|
->willReturn([]);
|
||||||
|
|
||||||
|
$this->principal->expects($this->any())->method('getCircleMembership')
|
||||||
|
->withAnyParameters()
|
||||||
|
->willReturn([]);
|
||||||
|
|
||||||
$this->backend = new CalDavBackend(
|
$this->backend = new CalDavBackend(
|
||||||
$db,
|
$db,
|
||||||
$this->principal,
|
$this->principal,
|
||||||
|
@ -112,6 +116,11 @@ class PublicCalendarRootTest extends TestCase {
|
||||||
$this->principal->expects($this->any())->method('getGroupMembership')
|
$this->principal->expects($this->any())->method('getGroupMembership')
|
||||||
->withAnyParameters()
|
->withAnyParameters()
|
||||||
->willReturn([]);
|
->willReturn([]);
|
||||||
|
|
||||||
|
$this->principal->expects($this->any())->method('getCircleMembership')
|
||||||
|
->withAnyParameters()
|
||||||
|
->willReturn([]);
|
||||||
|
|
||||||
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
|
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
|
||||||
foreach ($books as $book) {
|
foreach ($books as $book) {
|
||||||
$this->backend->deleteCalendar($book['id']);
|
$this->backend->deleteCalendar($book['id']);
|
||||||
|
|
|
@ -503,7 +503,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches a flat list of files filtered by a given filter criteria.
|
* Fetches a flat list of files filtered by a given filter criteria.
|
||||||
* (currently only system tags is supported)
|
* (currently system tags and circles are supported)
|
||||||
*
|
*
|
||||||
* @param {Object} filter filter criteria
|
* @param {Object} filter filter criteria
|
||||||
* @param {Object} [filter.systemTagIds] list of system tag ids to filter by
|
* @param {Object} [filter.systemTagIds] list of system tag ids to filter by
|
||||||
|
@ -525,7 +525,8 @@
|
||||||
properties = options.properties;
|
properties = options.properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filter || (!filter.systemTagIds && _.isUndefined(filter.favorite))) {
|
if (!filter ||
|
||||||
|
(!filter.systemTagIds && _.isUndefined(filter.favorite) && !filter.circlesIds) ) {
|
||||||
throw 'Missing filter argument';
|
throw 'Missing filter argument';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,6 +552,9 @@
|
||||||
_.each(filter.systemTagIds, function(systemTagIds) {
|
_.each(filter.systemTagIds, function(systemTagIds) {
|
||||||
body += ' <oc:systemtag>' + escapeHTML(systemTagIds) + '</oc:systemtag>\n';
|
body += ' <oc:systemtag>' + escapeHTML(systemTagIds) + '</oc:systemtag>\n';
|
||||||
});
|
});
|
||||||
|
_.each(filter.circlesIds, function(circlesIds) {
|
||||||
|
body += ' <oc:circle>' + escapeHTML(circlesIds) + '</oc:circle>\n';
|
||||||
|
});
|
||||||
if (filter.favorite) {
|
if (filter.favorite) {
|
||||||
body += ' <oc:favorite>' + (filter.favorite ? '1': '0') + '</oc:favorite>\n';
|
body += ' <oc:favorite>' + (filter.favorite ? '1': '0') + '</oc:favorite>\n';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue