-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Create infrastructure to allow files to be shared with circles #6959
Changes from 5 commits
9357b99
253b263
fff74e1
87c60b6
3e623e1
e840dc5
70069e2
7063683
38bfba8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ class FilesReportPlugin extends ServerPlugin { | |
const NS_OWNCLOUD = 'http://owncloud.org/ns'; | ||
const REPORT_NAME = '{http://owncloud.org/ns}filter-files'; | ||
const SYSTEMTAG_PROPERTYNAME = '{http://owncloud.org/ns}systemtag'; | ||
const CIRCLE_PROPERTYNAME = '{http://nextcloud.com/ns}circle'; | ||
|
||
/** | ||
* Reference to main server object | ||
|
@@ -255,14 +256,19 @@ protected function processFilterRules($filterRules) { | |
$ns = '{' . $this::NS_OWNCLOUD . '}'; | ||
$resultFileIds = null; | ||
$systemTagIds = []; | ||
$circlesIds = []; | ||
$favoriteFilter = null; | ||
foreach ($filterRules as $filterRule) { | ||
if ($filterRule['name'] === $ns . 'systemtag') { | ||
$systemTagIds[] = $filterRule['value']; | ||
} | ||
if ($filterRule['name'] === $ns . 'circle') { | ||
$circlesIds[] = $filterRule['value']; | ||
} | ||
if ($filterRule['name'] === $ns . 'favorite') { | ||
$favoriteFilter = true; | ||
} | ||
|
||
} | ||
|
||
if ($favoriteFilter !== null) { | ||
|
@@ -281,6 +287,15 @@ protected function processFilterRules($filterRules) { | |
} | ||
} | ||
|
||
if (!empty($circlesIds)) { | ||
$fileIds = $this->getCirclesFileIds($circlesIds); | ||
if (empty($resultFileIds)) { | ||
$resultFileIds = $fileIds; | ||
} else { | ||
$resultFileIds = array_intersect($fileIds, $resultFileIds); | ||
} | ||
} | ||
|
||
return $resultFileIds; | ||
} | ||
|
||
|
@@ -327,6 +342,13 @@ private function getSystemTagFileIds($systemTagIds) { | |
return $resultFileIds; | ||
} | ||
|
||
private function getCirclesFileIds($circlesIds) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PHPDocs on the function parameters and the return value would be awesome. Also is |
||
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 | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
* @author Thomas Müller <thomas.mueller@tmit.eu> | ||
* @author Thomas Tanghus <thomas@tanghus.net> | ||
* @author Vincent Petry <pvince81@owncloud.com> | ||
* @author Vinicius Cubas Brand <vinicius@eita.org.br> | ||
* @author Daniel Tygel <dtygel@eita.org.br> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
|
@@ -52,6 +54,9 @@ class Principal implements BackendInterface { | |
/** @var bool */ | ||
private $hasGroups; | ||
|
||
/** @var bool */ | ||
private $hasCircles; | ||
|
||
/** | ||
* @param IUserManager $userManager | ||
* @param IGroupManager $groupManager | ||
|
@@ -63,7 +68,7 @@ public function __construct(IUserManager $userManager, | |
$this->userManager = $userManager; | ||
$this->groupManager = $groupManager; | ||
$this->principalPrefix = trim($principalPrefix, '/'); | ||
$this->hasGroups = ($principalPrefix === 'principals/users/'); | ||
$this->hasGroups = $this->hasCircles = ($principalPrefix === 'principals/users/'); | ||
} | ||
|
||
/** | ||
|
@@ -108,6 +113,8 @@ public function getPrincipalByPath($path) { | |
if (!is_null($user)) { | ||
return $this->userToPrincipal($user); | ||
} | ||
} else if ($prefix === 'principals/circles') { | ||
return $this->circleToPrincipal($name); | ||
} | ||
return null; | ||
} | ||
|
@@ -232,4 +239,66 @@ public function getPrincipalPrefix() { | |
return $this->principalPrefix; | ||
} | ||
|
||
/** | ||
* @param string $circleUniqueId | ||
* @return array|null | ||
*/ | ||
protected function circleToPrincipal($circleUniqueId) { | ||
if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) { | ||
return null; | ||
} | ||
|
||
$circle = \OCA\Circles\Api\v1\Circles::detailsCircle($circleUniqueId); | ||
|
||
if (!$circle) { | ||
return null; | ||
} | ||
|
||
$principal = [ | ||
'uri' => 'principals/circles/' . $circleUniqueId, | ||
'{DAV:}displayname' => $circle->getName(), | ||
]; | ||
|
||
return $principal; | ||
} | ||
|
||
/** | ||
* Returns the list of circles a principal is a member of | ||
* | ||
* @param string $principal | ||
* @param bool $needGroups | ||
* @return array | ||
* @throws Exception | ||
*/ | ||
public function getCircleMembership($principal) { | ||
if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) { | ||
return []; | ||
} | ||
|
||
list($prefix, $name) = URLUtil::splitPath($principal); | ||
|
||
if ($this->hasCircles && $prefix === $this->principalPrefix) { | ||
$user = $this->userManager->get($name); | ||
if (!$user) { | ||
throw new Exception('Principal not found'); | ||
} | ||
|
||
$userSession = \OC::$server->getUserSession(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we inject the current user in the constructor instead? |
||
$currentUser = $userSession->getUser(); | ||
|
||
$userSession->setUser($user); | ||
$circles = \OCA\Circles\Api\v1\Circles::joinedCircles(); | ||
$userSession->setUser($currentUser); | ||
|
||
$circles = array_map(function($circle) { | ||
/** @var \OCA\Circles\Model\Circle $group */ | ||
return 'principals/circles/' . urlencode($circle->getUniqueId()); | ||
}, $circles); | ||
|
||
return $circles; | ||
|
||
} | ||
return []; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -454,7 +454,7 @@ | |
|
||
/** | ||
* 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.systemTagIds] list of system tag ids to filter by | ||
|
@@ -476,7 +476,8 @@ | |
properties = options.properties; | ||
} | ||
|
||
if (!filter || (!filter.systemTagIds && _.isUndefined(filter.favorite))) { | ||
if (!filter || | ||
(!filter.systemTagIds && _.isUndefined(filter.favorite) && !filter.circlesIds) ) { | ||
throw 'Missing filter argument'; | ||
} | ||
|
||
|
@@ -502,6 +503,9 @@ | |
_.each(filter.systemTagIds, function(systemTagIds) { | ||
body += ' <oc:systemtag>' + escapeHTML(systemTagIds) + '</oc:systemtag>\n'; | ||
}); | ||
_.each(filter.circlesIds, function(circlesIds) { | ||
body += ' <oc:circle>' + escapeHTML(circlesIds) + '</oc:circle>\n'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nc? |
||
}); | ||
if (filter.favorite) { | ||
body += ' <oc:favorite>' + (filter.favorite ? '1': '0') + '</oc:favorite>\n'; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's
CIRCLE_PROPERTYNAME
now