Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/Api/v1/Circles.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,12 @@ public static function leaveCircle($circleUniqueId) {
* @param int $level
* @param string $userId
*
* @param bool $forceAll
*
* @return Circle[]
* @throws QueryException
*/
public static function listCircles($type, $name = '', $level = 0, $userId = '') {
public static function listCircles($type, $name = '', $level = 0, $userId = '', $forceAll = false) {
$c = self::getContainer();

if ($userId === '') {
Expand All @@ -186,7 +188,7 @@ public static function listCircles($type, $name = '', $level = 0, $userId = '')
}

return $c->query(CirclesService::class)
->listCircles($userId, $type, $name, $level);
->listCircles($userId, $type, $name, $level, $forceAll);
}


Expand All @@ -196,12 +198,13 @@ public static function listCircles($type, $name = '', $level = 0, $userId = '')
* Return all the circle the current user is a member.
*
* @param string $userId
* @param bool $forceAll
*
* @return Circle[]
* @throws QueryException
*/
public static function joinedCircles($userId = '') {
return self::listCircles(Circle::CIRCLES_ALL, '', Member::LEVEL_MEMBER, $userId);
public static function joinedCircles($userId = '', $forceAll = false) {
return self::listCircles(Circle::CIRCLES_ALL, '', Member::LEVEL_MEMBER, $userId, $forceAll);
}


Expand Down Expand Up @@ -236,15 +239,16 @@ public static function joinedCircleIds($userId = '') {
* return as well.
*
* @param string $circleUniqueId
* @param bool $forceAll
*
* @return Circle
* @throws QueryException
*/
public static function detailsCircle($circleUniqueId) {
public static function detailsCircle($circleUniqueId, $forceAll = false) {
$c = self::getContainer();

return $c->query(CirclesService::class)
->detailsCircle($circleUniqueId);
->detailsCircle($circleUniqueId, $forceAll);
}


Expand Down
15 changes: 10 additions & 5 deletions lib/Db/CirclesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

use OCA\Circles\Exceptions\CircleAlreadyExistsException;
use OCA\Circles\Exceptions\CircleDoesNotExistException;
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Member;

Expand Down Expand Up @@ -132,10 +133,12 @@ public function forceGetCircleByName($name) {
* @param int $type
* @param string $name
* @param int $level
* @param bool $forceAll
*
* @return Circle[]
* @throws ConfigNoCircleAvailableException
*/
public function getCircles($userId, $type = 0, $name = '', $level = 0) {
public function getCircles($userId, $type = 0, $name = '', $level = 0, $forceAll = false) {
if ($type === 0) {
$type = Circle::CIRCLES_ALL;
}
Expand All @@ -148,7 +151,7 @@ public function getCircles($userId, $type = 0, $name = '', $level = 0) {
if ($level > 0) {
$this->limitToLevel($qb, $level, ['u', 'g']);
}
$this->limitRegardingCircleType($qb, $userId, -1, $type, $name);
$this->limitRegardingCircleType($qb, $userId, -1, $type, $name, $forceAll);

$circles = [];
$cursor = $qb->execute();
Expand All @@ -167,11 +170,13 @@ public function getCircles($userId, $type = 0, $name = '', $level = 0) {
*
* @param string $circleUniqueId
* @param string $viewerId
* @param bool $forceAll
*
* @return Circle
* @throws CircleDoesNotExistException
* @throws ConfigNoCircleAvailableException
*/
public function getCircle($circleUniqueId, $viewerId) {
public function getCircle($circleUniqueId, $viewerId, $forceAll = false) {
$qb = $this->getCirclesSelectSql();

$this->limitToShortenUniqueId($qb, $circleUniqueId, Circle::SHORT_UNIQUE_ID_LENGTH);
Expand All @@ -180,7 +185,7 @@ public function getCircle($circleUniqueId, $viewerId) {
$this->leftJoinOwner($qb);
$this->leftJoinNCGroupAndUser($qb, $viewerId, '`c`.`unique_id`');

$this->limitRegardingCircleType($qb, $viewerId, $circleUniqueId, Circle::CIRCLES_ALL, '');
$this->limitRegardingCircleType($qb, $viewerId, $circleUniqueId, Circle::CIRCLES_ALL, '', $forceAll);

$cursor = $qb->execute();
$data = $cursor->fetch();
Expand Down Expand Up @@ -352,4 +357,4 @@ public function getCircleFromUniqueId($uniqueId) {
}


}
}
32 changes: 20 additions & 12 deletions lib/Db/CirclesRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,18 @@ protected function limitToNonPersonalCircle(IQueryBuilder &$qb) {

/**
* @param IQueryBuilder $qb
* @param string $circleUniqueId
* @param $userId
* @param string $circleUniqueId
* @param $type
* @param $name
* @param bool $forceAll
*
* @throws ConfigNoCircleAvailableException
*/
protected function limitRegardingCircleType(
IQueryBuilder &$qb, $userId, $circleUniqueId, $type, $name
IQueryBuilder &$qb, $userId, $circleUniqueId, $type, $name, $forceAll = false
) {
$orTypes = $this->generateLimit($qb, $circleUniqueId, $userId, $type, $name);
$orTypes = $this->generateLimit($qb, $circleUniqueId, $userId, $type, $name, $forceAll);
if (sizeof($orTypes) === 0) {
throw new ConfigNoCircleAvailableException(
$this->l10n->t(
Expand All @@ -126,12 +127,15 @@ protected function limitRegardingCircleType(
* @param $userId
* @param $type
* @param $name
* @param bool $forceAll
*
* @return array
*/
private function generateLimit(IQueryBuilder &$qb, $circleUniqueId, $userId, $type, $name) {
private function generateLimit(
IQueryBuilder &$qb, $circleUniqueId, $userId, $type, $name, $forceAll = false
) {
$orTypes = [];
array_push($orTypes, $this->generateLimitPersonal($qb, $userId, $type));
array_push($orTypes, $this->generateLimitPersonal($qb, $userId, $type, $forceAll));
array_push($orTypes, $this->generateLimitSecret($qb, $circleUniqueId, $type, $name));
array_push($orTypes, $this->generateLimitClosed($qb, $type));
array_push($orTypes, $this->generateLimitPublic($qb, $type));
Expand All @@ -144,20 +148,24 @@ private function generateLimit(IQueryBuilder &$qb, $circleUniqueId, $userId, $ty
* @param IQueryBuilder $qb
* @param int|string $userId
* @param int $type
* @param bool $forceAll
*
* @return \OCP\DB\QueryBuilder\ICompositeExpression
*/
private function generateLimitPersonal(IQueryBuilder $qb, $userId, $type) {
private function generateLimitPersonal(IQueryBuilder $qb, $userId, $type, $forceAll = false) {
if (!(Circle::CIRCLES_PERSONAL & (int)$type)) {
return null;
}
$expr = $qb->expr();

/** @noinspection PhpMethodParametersCountMismatchInspection */
return $expr->andX(
$expr->eq('c.type', $qb->createNamedParameter(Circle::CIRCLES_PERSONAL)),
$expr->eq('o.user_id', $qb->createNamedParameter((string)$userId))
);
$andX = $expr->andX();
$andX->add($expr->eq('c.type', $qb->createNamedParameter(Circle::CIRCLES_PERSONAL)));

if (!$forceAll) {
$andX->add($expr->eq('o.user_id', $qb->createNamedParameter((string)$userId)));
}

return $andX;
}


Expand Down Expand Up @@ -420,4 +428,4 @@ protected function parseCirclesSelectSql($data) {
}


}
}
15 changes: 9 additions & 6 deletions lib/Service/CirclesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,13 @@ public function createCircle($type, $name) {
* @param string $name
* @param int $level
*
* @param bool $forceAll
*
* @return Circle[]
* @throws CircleTypeDisabledException
* @throws Exception
*/
public function listCircles($userId, $type, $name = '', $level = 0) {
public function listCircles($userId, $type, $name = '', $level = 0, $forceAll = false) {
$type = $this->convertTypeStringToBitValue($type);

if ($userId === '') {
Expand All @@ -195,7 +197,7 @@ public function listCircles($userId, $type, $name = '', $level = 0) {
}

$data = [];
$result = $this->circlesRequest->getCircles($userId, $type, $name, $level);
$result = $this->circlesRequest->getCircles($userId, $type, $name, $level, $forceAll);
foreach ($result as $item) {
$data[] = $item;
}
Expand All @@ -208,14 +210,15 @@ public function listCircles($userId, $type, $name = '', $level = 0) {
* returns details on circle and its members if this->userId is a member itself.
*
* @param string $circleUniqueId
* @param bool $forceAll
*
* @return Circle
* @throws \Exception
* @throws Exception
*/
public function detailsCircle($circleUniqueId) {
public function detailsCircle($circleUniqueId, $forceAll = false) {

try {
$circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId);
$circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId, $forceAll);
if ($this->viewerIsAdmin()
|| $circle->getHigherViewer()
->isLevel(Member::LEVEL_MEMBER)
Expand Down Expand Up @@ -568,7 +571,7 @@ public function checkThatCircleIsNotFull(Circle $circle) {
$limit = $this->configService->getAppValue(ConfigService::CIRCLES_MEMBERS_LIMIT);
}

if (sizeof($members) >= $limit) {
if (sizeof($members) >= $limit) {
throw new MembersLimitException(
'This circle already reach its limit on the number of members'
);
Expand Down