Allow approving/denying organisations without tokens (admin override)
This commit is contained in:
@@ -262,6 +262,9 @@ class OrganisationRegistrationController extends SimpleController
|
|||||||
/** @var \UserFrosting\Sprinkle\Core\Alert\AlertStream $ms */
|
/** @var \UserFrosting\Sprinkle\Core\Alert\AlertStream $ms */
|
||||||
$ms = $this->ci->alerts;
|
$ms = $this->ci->alerts;
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Organisations\Repository\OrganisationApprovalRepository */
|
||||||
|
$tokenRepo = $this->ci->repoOrganisationApproval;
|
||||||
|
|
||||||
|
|
||||||
// Access-controlled page
|
// Access-controlled page
|
||||||
if (!$authorizer->checkAccess($currentUser, 'approve_organisation')) {
|
if (!$authorizer->checkAccess($currentUser, 'approve_organisation')) {
|
||||||
@@ -276,15 +279,14 @@ class OrganisationRegistrationController extends SimpleController
|
|||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$approval = $this->ci->repoOrganisationApproval->exists($organisation);
|
// If a token can't be found, create one
|
||||||
if (!$approval) {
|
if (!$tokenRepo->exists($organisation)) {
|
||||||
$ms->addMessageTranslated('danger', 'ORGANISATION.REGISTRATION.TOKEN_NOT_FOUND');
|
$tokenRepo->create($organisation, 1);
|
||||||
return $response->withJson([], 400);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin transaction - DB will be rolled back if an exception occurs
|
// Begin transaction - DB will be rolled back if an exception occurs
|
||||||
Capsule::transaction(function () use ($organisation, $currentUser) {
|
Capsule::transaction(function () use ($organisation, $currentUser, $tokenRepo) {
|
||||||
$this->ci->repoOrganisationApproval->completeForOwner($organisation, [
|
$tokenRepo->completeForOwner($organisation, [
|
||||||
'approver_id' => $currentUser->id,
|
'approver_id' => $currentUser->id,
|
||||||
'approved' => true
|
'approved' => true
|
||||||
]);
|
]);
|
||||||
@@ -426,6 +428,9 @@ class OrganisationRegistrationController extends SimpleController
|
|||||||
/** @var \UserFrosting\Sprinkle\Core\Alert\AlertStream $ms */
|
/** @var \UserFrosting\Sprinkle\Core\Alert\AlertStream $ms */
|
||||||
$ms = $this->ci->alerts;
|
$ms = $this->ci->alerts;
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Organisations\Repository\OrganisationApprovalRepository */
|
||||||
|
$tokenRepo = $this->ci->repoOrganisationApproval;
|
||||||
|
|
||||||
|
|
||||||
// Access-controlled page
|
// Access-controlled page
|
||||||
if (!$authorizer->checkAccess($currentUser, 'approve_organisation')) {
|
if (!$authorizer->checkAccess($currentUser, 'approve_organisation')) {
|
||||||
@@ -440,15 +445,14 @@ class OrganisationRegistrationController extends SimpleController
|
|||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$approval = $this->ci->repoOrganisationApproval->exists($organisation);
|
// If a token can't be found, create one
|
||||||
if (!$approval) {
|
if (!$tokenRepo->exists($organisation)) {
|
||||||
$ms->addMessageTranslated('danger', 'ORGANISATION.REGISTRATION.TOKEN_NOT_FOUND');
|
$tokenRepo->create($organisation, 1);
|
||||||
return $response->withJson([], 400);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin transaction - DB will be rolled back if an exception occurs
|
// Begin transaction - DB will be rolled back if an exception occurs
|
||||||
Capsule::transaction(function () use ($organisation, $currentUser) {
|
Capsule::transaction(function () use ($organisation, $currentUser, $tokenRepo) {
|
||||||
$this->ci->repoOrganisationApproval->completeForOwner($organisation, [
|
$tokenRepo->completeForOwner($organisation, [
|
||||||
'approver_id' => $currentUser->id,
|
'approver_id' => $currentUser->id,
|
||||||
'approved' => false
|
'approved' => false
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user