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_adding_any_group_members option #398

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
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be added as a parameter of the __construct(). can you do the same with IGroupManager ?

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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be added as a parameter of the __construct(). can you do the same with IGroupManager ?


if (!$this->configService->isAddingAnyGroupMembersAllowed() &&
$group instanceof IGroup && $user instanceof IUser &&
!$group->inGroup($user) && !$groupManager->isAdmin($user->getUID())
) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a fan of this condition; let's assume that user is not null, I prefer having an unhandled exception than a failed condition. something like if ($group !== null && [...]->isAddingAnyGroupMembersAllowed() && not in group && not admin)

$group = null;
}

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