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