Skip to content

Commit

Permalink
Fix adding group with member limit -1 or 0
Browse files Browse the repository at this point in the history
Fix nextcloud#342

Signed-off-by: Tortue Torche <tortuetorche@users.noreply.github.com>
  • Loading branch information
tortuetorche committed Apr 9, 2020
1 parent 310d4e5 commit 3de12e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/Service/CirclesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,11 @@ public function checkThatCircleIsNotFull(Circle $circle) {
$circle->getUniqueId(), Member::LEVEL_MEMBER, true
);

$limit = $circle->getSetting('members_limit');
$limit = (int) $circle->getSetting('members_limit');
if ($limit === -1) {
return;
}
if ($limit === 0 || $limit === '' || $limit === null) {
if ($limit === 0) {
$limit = $this->configService->getAppValue(ConfigService::CIRCLES_MEMBERS_LIMIT);
}

Expand Down
16 changes: 13 additions & 3 deletions lib/Service/GroupsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class GroupsService {
/** @var IUserManager */
private $userManager;

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

/** @var CirclesRequest */
private $circlesRequest;

Expand All @@ -76,6 +79,7 @@ class GroupsService {
* @param IL10N $l10n
* @param IGroupManager $groupManager
* @param IUserManager $userManager
* @param ConfigService $configService
* @param CirclesRequest $circlesRequest
* @param MembersRequest $membersRequest
* @param CirclesService $circlesService
Expand All @@ -84,14 +88,15 @@ class GroupsService {
*/
public function __construct(
$userId, IL10N $l10n, IGroupManager $groupManager, IUserManager $userManager,
CirclesRequest $circlesRequest,
ConfigService $configService, CirclesRequest $circlesRequest,
MembersRequest $membersRequest, CirclesService $circlesService,
EventsService $eventsService, MiscService $miscService
) {
$this->userId = $userId;
$this->l10n = $l10n;
$this->groupManager = $groupManager;
$this->userManager = $userManager;
$this->configService = $configService;
$this->circlesRequest = $circlesRequest;
$this->membersRequest = $membersRequest;
$this->circlesService = $circlesService;
Expand Down Expand Up @@ -132,8 +137,13 @@ public function linkGroup($circleUniqueId, $groupId) {
$count++;
}

if ($count > $circle->getSetting('members_limit')) {
throw new \Exception('Group contains too many members');
$limit = (int) $circle->getSetting('members_limit');
if ($limit === 0) {
$limit = $this->configService->getAppValue(ConfigService::CIRCLES_MEMBERS_LIMIT);
}

if ($limit !== -1 && $count > $limit) {
throw new \Exception($this->l10n->t('Group contains too many members'));
}

$group = $this->getFreshNewMember($circleUniqueId, $groupId);
Expand Down

0 comments on commit 3de12e6

Please sign in to comment.