Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add allow_adding_any_group_members option to allow or not adding gr…
…oup members from any users

Default to `1`.

When value is set to `0` it's only possible to add groups where the
current user is a member or for global administrators.

Fix #128

Signed-off-by: Tortue Torche <[email protected]>
  • Loading branch information
tortuetorche committed Apr 9, 2020
commit bfaf31fec1a17bb074ada17375187f331218798a
28 changes: 25 additions & 3 deletions lib/Search/LocalGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,48 @@

namespace OCA\Circles\Search;

use OC;
use OCA\Circles\ISearch;
use OCA\Circles\Model\Member;
use OCA\Circles\Model\SearchResult;
use OCP\IUser;
use OCA\Circles\Service\ConfigService;

class LocalGroups implements ISearch {

/** @var ConfigService */
private $configService;

/**
* @param ConfigService $configService
*/
public function __construct(ConfigService $configService)
{
$this->configService = $configService;
}

/**
* {@inheritdoc}
*/
public function search($search) {

$result = [];
$groupManager = \OC::$server->getGroupManager();
$groupManager = OC::$server->getGroupManager();

$groups = $groupManager->search($search);
$user = OC::$server->getUserSession()->getUser();
foreach ($groups as $group) {
$result[] = new SearchResult($group->getGID(), Member::TYPE_GROUP);
if ($this->configService->isAddingAnyGroupMembersAllowed() ||
(
$user instanceof IUser &&
($group->inGroup($user) || $groupManager->isAdmin($user->getUID()))
)
) {
$result[] = new SearchResult($group->getGID(), Member::TYPE_GROUP);
}
}

return $result;
}

}
}
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_ANY_GROUP_MEMBERS = 'allow_adding_any_group_members';
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_ANY_GROUP_MEMBERS => '1',
];

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

/** @var int */
private $allowAddingAnyGroupMembers = -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 current user is allowed to add any group members.
* even if he isn't a member of these groups
*
* @return bool
*/
public function isAddingAnyGroupMembersAllowed() {
if ($this->allowAddingAnyGroupMembers === -1) {
$this->allowAddingAnyGroupMembers =
(int)$this->getAppValue(self::CIRCLES_ALLOW_ANY_GROUP_MEMBERS);
}

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

/**
* @return bool
Expand Down
16 changes: 14 additions & 2 deletions lib/Service/MembersService.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
use OCA\Circles\Exceptions\ModeratorIsNotHighEnoughException;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Member;
use OCP\IGroup;
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;


Expand Down Expand Up @@ -387,8 +389,18 @@ private function verifyIdentContact(&$ident, $type) {
*/
private function addGroupMembers(Circle $circle, $groupId) {

$group = OC::$server->getGroupManager()
->get($groupId);
$groupManager = OC::$server->getGroupManager();
$group = $groupManager->get($groupId);

$user = OC::$server->getUserSession()->getUser();

if (!$this->configService->isAddingAnyGroupMembersAllowed() &&
$group instanceof IGroup && $user instanceof IUser &&
!$group->inGroup($user) && !$groupManager->isAdmin($user->getUID())
) {
$group = null;
}

if ($group === null) {
throw new GroupDoesNotExistException($this->l10n->t('This group does not exist'));
}
Expand Down