Prevent users from creating more than 1 or being a member of more than 1 organisation in single organisation configuration (Fixes #7)
This commit is contained in:
@@ -80,6 +80,11 @@ class OrganisationMembersController extends SimpleController
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if ($config['organisation']['membership']['single_membership'] && $currentUser->organisations()->count() > 0) {
|
||||
$ms->addMessageTranslated('danger', 'ORGANISATION.JOIN_REQUEST.ALREADY_IN_ONE');
|
||||
return $response->withJson([], 400);
|
||||
}
|
||||
|
||||
// Check if the user is a member of the organisation, pending or no relation at all
|
||||
$memberCheck = $organisation->members()->where('user_id', $currentUser->id)->withPivot('flag_approved')->first();
|
||||
if ($memberCheck) {
|
||||
|
||||
@@ -57,24 +57,29 @@ class OrganisationRegistrationController extends SimpleController
|
||||
/** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager $authorizer */
|
||||
$authorizer = $this->ci->authorizer;
|
||||
|
||||
/** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */
|
||||
$currentUser = $this->ci->currentUser;
|
||||
|
||||
/** @var \UserFrosting\Sprinkle\Core\Alert\AlertStream $ms */
|
||||
$ms = $this->ci->alerts;
|
||||
|
||||
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
|
||||
$classMapper = $this->ci->classMapper;
|
||||
|
||||
/** @var \UserFrosting\Support\Repository\Repository $config */
|
||||
$config = $this->ci->config;
|
||||
|
||||
/** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */
|
||||
$currentUser = $this->ci->currentUser;
|
||||
|
||||
/** @var \UserFrosting\Sprinkle\Core\Alert\AlertStream $ms */
|
||||
$ms = $this->ci->alerts;
|
||||
|
||||
|
||||
// Access-controlled page
|
||||
if (!$authorizer->checkAccess($currentUser, 'register_organisation')) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
if ($config['organisation']['membership']['single_membership'] && $currentUser->organisations()->count() > 0) {
|
||||
$ms->addMessageTranslated('danger', 'ORGANISATION.REGISTRATION.ALREADY_IN_ONE', $data);
|
||||
return $response->withJson([], 400);
|
||||
}
|
||||
|
||||
// Get POST parameters: name, slug, icon, description
|
||||
$params = $request->getParsedBody();
|
||||
|
||||
@@ -580,6 +585,9 @@ class OrganisationRegistrationController extends SimpleController
|
||||
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
|
||||
$classMapper = $this->ci->classMapper;
|
||||
|
||||
/** @var \UserFrosting\Support\Repository\Repository $config */
|
||||
$config = $this->ci->config;
|
||||
|
||||
/** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */
|
||||
$currentUser = $this->ci->currentUser;
|
||||
|
||||
@@ -592,6 +600,10 @@ class OrganisationRegistrationController extends SimpleController
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
if ($config['organisation']['membership']['single_membership'] && $currentUser->organisations()->count() > 0) {
|
||||
throw new BadRequestException();
|
||||
}
|
||||
|
||||
// Create a dummy organisation to prepopulate fields
|
||||
$organisation = $classMapper->createInstance('organisation', []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user