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:
@@ -59,6 +59,7 @@ return [
|
|||||||
'PERMENENT_DELETION_SUCCESSFUL' => 'Successfully permenently deleted organisation <strong>{{name}}</strong>',
|
'PERMENENT_DELETION_SUCCESSFUL' => 'Successfully permenently deleted organisation <strong>{{name}}</strong>',
|
||||||
|
|
||||||
'NOT_A_MEMBER' => 'You are not a member of organisation <strong>{{name}}</strong>.',
|
'NOT_A_MEMBER' => 'You are not a member of organisation <strong>{{name}}</strong>.',
|
||||||
|
'ALREADY_IN_ONE' => 'You are already in an organisation.',
|
||||||
|
|
||||||
'NAME' => [
|
'NAME' => [
|
||||||
1 => 'Organisation name',
|
1 => 'Organisation name',
|
||||||
@@ -74,6 +75,8 @@ return [
|
|||||||
'REGISTER' => 'Register organisation',
|
'REGISTER' => 'Register organisation',
|
||||||
'SUCCESSFUL' => 'Successfully registered organisation <strong>{{name}}</strong>',
|
'SUCCESSFUL' => 'Successfully registered organisation <strong>{{name}}</strong>',
|
||||||
|
|
||||||
|
'ALREADY_IN_ONE' => 'You cannot register a new organisation because you are already in another organisation. (only one organisation allowed)',
|
||||||
|
|
||||||
'CANCEL' => 'Cancel organisation registration',
|
'CANCEL' => 'Cancel organisation registration',
|
||||||
'CANCEL_CONFIRM' => 'Are you sure you want to cancel the registration request for organisation <strong>{{name}}</strong>?',
|
'CANCEL_CONFIRM' => 'Are you sure you want to cancel the registration request for organisation <strong>{{name}}</strong>?',
|
||||||
'CANCEL_YES' => 'Yes, cancel organisation registration',
|
'CANCEL_YES' => 'Yes, cancel organisation registration',
|
||||||
@@ -89,6 +92,8 @@ return [
|
|||||||
'JOIN_REQUEST' => [
|
'JOIN_REQUEST' => [
|
||||||
'SUBMIT_SUCCESSFUL' => 'Request to join organisation <strong>{{name}}</strong> sent',
|
'SUBMIT_SUCCESSFUL' => 'Request to join organisation <strong>{{name}}</strong> sent',
|
||||||
|
|
||||||
|
'ALREADY_IN_ONE' => 'You cannot join another organisation because you are already in one (only one organisation allowed).',
|
||||||
|
|
||||||
'REQUEST' => 'Request to join organisation',
|
'REQUEST' => 'Request to join organisation',
|
||||||
|
|
||||||
'CANCEL' => 'Cancel request to join organisation',
|
'CANCEL' => 'Cancel request to join organisation',
|
||||||
|
|||||||
@@ -80,6 +80,11 @@ class OrganisationMembersController extends SimpleController
|
|||||||
throw new NotFoundException();
|
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
|
// 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();
|
$memberCheck = $organisation->members()->where('user_id', $currentUser->id)->withPivot('flag_approved')->first();
|
||||||
if ($memberCheck) {
|
if ($memberCheck) {
|
||||||
|
|||||||
@@ -57,24 +57,29 @@ class OrganisationRegistrationController extends SimpleController
|
|||||||
/** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager $authorizer */
|
/** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager $authorizer */
|
||||||
$authorizer = $this->ci->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 */
|
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
|
||||||
$classMapper = $this->ci->classMapper;
|
$classMapper = $this->ci->classMapper;
|
||||||
|
|
||||||
/** @var \UserFrosting\Support\Repository\Repository $config */
|
/** @var \UserFrosting\Support\Repository\Repository $config */
|
||||||
$config = $this->ci->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
|
// Access-controlled page
|
||||||
if (!$authorizer->checkAccess($currentUser, 'register_organisation')) {
|
if (!$authorizer->checkAccess($currentUser, 'register_organisation')) {
|
||||||
throw new ForbiddenException();
|
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
|
// Get POST parameters: name, slug, icon, description
|
||||||
$params = $request->getParsedBody();
|
$params = $request->getParsedBody();
|
||||||
|
|
||||||
@@ -580,6 +585,9 @@ class OrganisationRegistrationController extends SimpleController
|
|||||||
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
|
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
|
||||||
$classMapper = $this->ci->classMapper;
|
$classMapper = $this->ci->classMapper;
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Support\Repository\Repository $config */
|
||||||
|
$config = $this->ci->config;
|
||||||
|
|
||||||
/** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */
|
/** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */
|
||||||
$currentUser = $this->ci->currentUser;
|
$currentUser = $this->ci->currentUser;
|
||||||
|
|
||||||
@@ -592,6 +600,10 @@ class OrganisationRegistrationController extends SimpleController
|
|||||||
throw new ForbiddenException();
|
throw new ForbiddenException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($config['organisation']['membership']['single_membership'] && $currentUser->organisations()->count() > 0) {
|
||||||
|
throw new BadRequestException();
|
||||||
|
}
|
||||||
|
|
||||||
// Create a dummy organisation to prepopulate fields
|
// Create a dummy organisation to prepopulate fields
|
||||||
$organisation = $classMapper->createInstance('organisation', []);
|
$organisation = $classMapper->createInstance('organisation', []);
|
||||||
|
|
||||||
|
|||||||
@@ -35,10 +35,12 @@
|
|||||||
<i class="fas fa-minus-square"></i> {{translate("VIEW_DELETED")}}
|
<i class="fas fa-minus-square"></i> {{translate("VIEW_DELETED")}}
|
||||||
</button>
|
</button>
|
||||||
{% elseif checkAccess('register_organisation') %}
|
{% elseif checkAccess('register_organisation') %}
|
||||||
|
{% if (organisationConfig.membership.single_membership == 0) or (current_user.organisations.count == 0) %}
|
||||||
<button type="button" class="btn btn-success js-organisation-register">
|
<button type="button" class="btn btn-success js-organisation-register">
|
||||||
<i class="fas fa-plus-square"></i> {{translate("ORGANISATION.REGISTRATION.REGISTER")}}
|
<i class="fas fa-plus-square"></i> {{translate("ORGANISATION.REGISTRATION.REGISTER")}}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user