Skip to content
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

Add allow_listed_circles option #399

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 11 additions & 2 deletions lib/Api/Sharees.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Member;
use OCA\Circles\Service\CirclesService;
use OCA\Circles\Service\ConfigService;
use OCA\Circles\Service\MiscService;
use OCP\Share;

Expand Down Expand Up @@ -61,12 +62,20 @@ protected static function getContainer() {
// public static function search($search, $limit, $offset) {
public static function search($search) {
$c = self::getContainer();

$type = Circle::CIRCLES_ALL;
$circlesAreVisible = $c->query(ConfigService::class)
->isListedCirclesAllowed();
if (!$circlesAreVisible) {
$type = $type - Circle::CIRCLES_CLOSED - Circle::CIRCLES_PUBLIC;
}

$userId = \OC::$server->getUserSession()
->getUser()
->getUID();

$data = $c->query(CirclesService::class)
->listCircles($userId, Circle::CIRCLES_ALL, $search, Member::LEVEL_MEMBER);
->listCircles($userId, $type, $search, Member::LEVEL_MEMBER);
$result = array(
'exact' => ['circles'],
'circles' => []
Expand Down Expand Up @@ -111,4 +120,4 @@ private static function addResultEntry(&$result, $entry, $exact = false) {

}

}
}
38 changes: 38 additions & 0 deletions lib/Api/v1/Circles.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCA\Circles\Model\Member;
use OCA\Circles\Model\SharingFrame;
use OCA\Circles\Service\CirclesService;
use OCA\Circles\Service\ConfigService;
use OCA\Circles\Service\FederatedLinkService;
use OCA\Circles\Service\MembersService;
use OCA\Circles\Service\MiscService;
Expand Down Expand Up @@ -181,6 +182,43 @@ public static function leaveCircle($circleUniqueId) {
public static function listCircles($type, $name = '', $level = 0, $userId = '', $forceAll = false) {
$c = self::getContainer();

$configService = $c->query(ConfigService::class);
$circlesAreVisible = $configService->isListedCirclesAllowed();
$circlesAllowed = (int)$configService->getAppValue(ConfigService::CIRCLES_ALLOW_CIRCLES);

if (!$circlesAreVisible) {
switch (true) {
case ($type === Circle::CIRCLES_CLOSED):
case ($type === Circle::CIRCLES_PUBLIC):
case (Circle::CIRCLES_CLOSED + Circle::CIRCLES_PUBLIC === $circlesAllowed):
return [];
break;
case ($type === Circle::CIRCLES_ALL &&
$circlesAllowed === Circle::CIRCLES_ALL
):
$type = $type - Circle::CIRCLES_CLOSED - Circle::CIRCLES_PUBLIC;
break;
case ($type > Circle::CIRCLES_CLOSED &&
$type < Circle::CIRCLES_PUBLIC &&
$circlesAllowed === Circle::CIRCLES_ALL
):
$type = $type - Circle::CIRCLES_CLOSED;
break;
case ($type > Circle::CIRCLES_PUBLIC &&
$type < (Circle::CIRCLES_PUBLIC + Circle::CIRCLES_CLOSED) &&
$circlesAllowed === Circle::CIRCLES_ALL
):
$type = $type - Circle::CIRCLES_PUBLIC;
break;
case ($type > (Circle::CIRCLES_PUBLIC + Circle::CIRCLES_CLOSED) &&
$type < Circle::CIRCLES_ALL &&
$circlesAllowed === Circle::CIRCLES_ALL
):
$type = $type - Circle::CIRCLES_PUBLIC - Circle::CIRCLES_CLOSED;
break;
}
}

if ($userId === '') {
$userId = \OC::$server->getUserSession()
->getUser()
Expand Down
19 changes: 19 additions & 0 deletions lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ConfigService {
const CIRCLES_ALLOW_FEDERATED_CIRCLES = 'allow_federated';
const CIRCLES_MEMBERS_LIMIT = 'members_limit';
const CIRCLES_ACCOUNTS_ONLY = 'accounts_only';
const CIRCLES_ALLOW_LISTED_CIRCLES = 'allow_listed_circles';
const CIRCLES_ALLOW_LINKED_GROUPS = 'allow_linked_groups';
const CIRCLES_ALLOW_NON_SSL_LINKS = 'allow_non_ssl_links';
const CIRCLES_NON_SSL_LOCAL = 'local_is_non_ssl';
Expand All @@ -66,6 +67,7 @@ class ConfigService {
self::CIRCLES_NON_SSL_LOCAL => '0',
self::CIRCLES_ACTIVITY_ON_CREATION => '1',
self::CIRCLES_SKIP_INVITATION_STEP => '0'
self::CIRCLES_ALLOW_LISTED_CIRCLES => '1',
];

/** @var string */
Expand All @@ -86,6 +88,9 @@ class ConfigService {
/** @var int */
private $allowedCircle = -1;

/** @var int */
private $allowedListedCircles = -1;

/** @var int */
private $allowedLinkedGroups = -1;

Expand Down Expand Up @@ -139,6 +144,20 @@ public function isCircleAllowed($type) {
return ((int)$type & (int)$this->allowedCircle);
}

/**
* returns if the circles are allowed to be listed outside the Circles application.
*
* @return bool
*/
public function isListedCirclesAllowed() {
if ($this->allowedListedCircles === -1) {
$this->allowedListedCircles =
(int)$this->getAppValue(self::CIRCLES_ALLOW_LISTED_CIRCLES);
}

return ($this->allowedListedCircles === 1);
}


/**
* @return bool
Expand Down