Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/circles.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2017-10-09 18:47:21 +0300
committerMaxence Lange <maxence@artificial-owl.com>2017-10-09 18:47:21 +0300
commit7e876f441b4dbf02ea02c579566c8ded8552c9b9 (patch)
tree65a1d42a9314323acabb303e8a3121aad9879a63 /lib
parent797d598aed51943b7fe036ee8f624018280d001e (diff)
specify userId on listCircles()
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Api/Sharees.php5
-rw-r--r--lib/Api/v1/Circles.php37
-rw-r--r--lib/Controller/CirclesController.php2
-rw-r--r--lib/Service/CirclesService.php11
4 files changed, 47 insertions, 8 deletions
diff --git a/lib/Api/Sharees.php b/lib/Api/Sharees.php
index 6e6b4f97..2755f93c 100644
--- a/lib/Api/Sharees.php
+++ b/lib/Api/Sharees.php
@@ -61,9 +61,12 @@ class Sharees {
// public static function search($search, $limit, $offset) {
public static function search($search) {
$c = self::getContainer();
+ $userId = \OC::$server->getUserSession()
+ ->getUser()
+ ->getUID();
$data = $c->query(CirclesService::class)
- ->listCircles(Circle::CIRCLES_ALL, $search, Member::LEVEL_MEMBER);
+ ->listCircles($userId, Circle::CIRCLES_ALL, $search, Member::LEVEL_MEMBER);
$result = array(
'exact' => ['circles'],
'circles' => []
diff --git a/lib/Api/v1/Circles.php b/lib/Api/v1/Circles.php
index d43c068e..60202849 100644
--- a/lib/Api/v1/Circles.php
+++ b/lib/Api/v1/Circles.php
@@ -164,14 +164,21 @@ class Circles {
* @param mixed $type
* @param string $name
* @param int $level
+ * @param string $userId
*
* @return Circle[]
*/
- public static function listCircles($type, $name = '', $level = 0) {
+ public static function listCircles($type, $name = '', $level = 0, $userId = '') {
$c = self::getContainer();
+ if ($userId === '') {
+ $userId = \OC::$server->getUserSession()
+ ->getUser()
+ ->getUID();
+ }
+
return $c->query(CirclesService::class)
- ->listCircles($type, $name, $level);
+ ->listCircles($userId, $type, $name, $level);
}
@@ -180,10 +187,32 @@ class Circles {
*
* Return all the circle the current user is a member.
*
+ * @param string $userId
+ *
* @return Circle[]
*/
- public static function joinedCircles() {
- return self::listCircles(Circle::CIRCLES_ALL, '', Member::LEVEL_MEMBER);
+ public static function joinedCircles($userId = '') {
+ return self::listCircles(Circle::CIRCLES_ALL, '', Member::LEVEL_MEMBER, $userId);
+ }
+
+
+ /**
+ * Circles::joinedCircleIds();
+ *
+ * Return all the circleIds the user is a member, if empty user, using current user.
+ *
+ * @param $userId
+ *
+ * @return array
+ */
+ public static function joinedCircleIds($userId = '') {
+ $circleIds = [];
+ $circles = self::listCircles(Circle::CIRCLES_ALL, '', Member::LEVEL_MEMBER, $userId);
+ foreach ($circles as $circle) {
+ $circleIds[] = $circle->getUniqueId();
+ }
+
+ return $circleIds;
}
diff --git a/lib/Controller/CirclesController.php b/lib/Controller/CirclesController.php
index 3fda607c..1ea2e3d2 100644
--- a/lib/Controller/CirclesController.php
+++ b/lib/Controller/CirclesController.php
@@ -73,7 +73,7 @@ class CirclesController extends BaseController {
public function listing($type, $name = '', $level = 0) {
try {
- $data = $this->circlesService->listCircles($type, $name, $level);
+ $data = $this->circlesService->listCircles($this->userId, $type, $name, $level);
return $this->success(['type' => $type, 'data' => $data]);
} catch (CircleTypeDisabledException $e) {
diff --git a/lib/Service/CirclesService.php b/lib/Service/CirclesService.php
index 343d8a5f..2440df0e 100644
--- a/lib/Service/CirclesService.php
+++ b/lib/Service/CirclesService.php
@@ -27,6 +27,7 @@
namespace OCA\Circles\Service;
+use Exception;
use OCA\Circles\AppInfo\Application;
use OCA\Circles\Db\CirclesRequest;
use OCA\Circles\Db\FederatedLinksRequest;
@@ -144,16 +145,22 @@ class CirclesService {
/**
* list Circles depends on type (or all) and name (parts) and minimum level.
*
+ * @param string $userId
* @param mixed $type
* @param string $name
* @param int $level
*
* @return Circle[]
* @throws CircleTypeDisabledException
+ * @throws Exception
*/
- public function listCircles($type, $name = '', $level = 0) {
+ public function listCircles($userId, $type, $name = '', $level = 0) {
$type = $this->convertTypeStringToBitValue($type);
+ if ($userId === '') {
+ throw new Exception('UserID cannot be null');
+ }
+
if (!$this->configService->isCircleAllowed((int)$type)) {
throw new CircleTypeDisabledException(
$this->l10n->t('You cannot display this type of circle')
@@ -161,7 +168,7 @@ class CirclesService {
}
$data = [];
- $result = $this->circlesRequest->getCircles($this->userId, $type, $name, $level);
+ $result = $this->circlesRequest->getCircles($userId, $type, $name, $level);
foreach ($result as $item) {
$data[] = $item;
}