Re-jigged some of the registration routes and modified the buttons/links to use them

This commit is contained in:
2022-02-10 14:52:48 +00:00
parent 7c319873b1
commit c3cf97ea50
6 changed files with 86 additions and 16 deletions

View File

@@ -46,6 +46,48 @@ function attachOrganisationForm() {
});
}
/**
* Approve/Reject organisation
*/
function approveOrganisation(slug, approve, options) {
var data = {};
data[site.csrf.keys.name] = site.csrf.name;
data[site.csrf.keys.value] = site.csrf.value;
var url = site.uri.public + '/api/organisations/o/' + slug + '/registration/' + (approve ? 'approve' : 'reject');
var debugAjax = (typeof site !== "undefined") && site.debug.ajax;
return $.ajax({
type: "PUT",
url: url,
data: data,
dataType: debugAjax ? 'html' : 'json',
}).fail(function(jqXHR) {
// Error messages
if (debugAjax && jqXHR.responseText) {
document.write(jqXHR.responseText);
document.close();
} else {
console.log("Error (" + jqXHR.status + "): " + jqXHR.responseText);
// Display errors on failure
// TODO: ufAlerts widget should have a 'destroy' method
if (!$("#alerts-page").data('ufAlerts')) {
$("#alerts-page").ufAlerts();
} else {
$("#alerts-page").ufAlerts('clear');
}
$("#alerts-page").ufAlerts('fetch').ufAlerts('render');
}
return jqXHR;
}).done(function(response) {
if (!approve && options.delete_redirect) window.location.href = options.delete_redirect;
else window.location.reload();
});
}
/**
* Link organisation action buttons, for example in a table or on a specific organisation's page.
* @param {module:jQuery} el jQuery wrapped element to target.
@@ -183,6 +225,20 @@ function bindOrganisationButtons(el, options) {
});
});
// Cancel a registration request
el.find('.js-organisation-approveRegistration').click(function(e) {
e.preventDefault();
approveOrganisation($(this).data('slug'), true, options);
});
// Cancel a registration request
el.find('.js-organisation-rejectRegistration').click(function(e) {
e.preventDefault();
approveOrganisation($(this).data('slug'), false, options);
});
// Delete organisation button
el.find('.js-organisation-delete').click(function(e) {
e.preventDefault();

View File

@@ -71,6 +71,8 @@ return [
'TOKEN_NOT_FOUND' => 'Approval token does not exist / Organisation is already approved/rejected.',
'APPROVED' => 'You have successfully approved the organisation <strong>{{name}}</strong>.',
'REJECTED' => 'You have successfully rejected the organisation <strong>{{name}}</strong>.',
'APPROVE' => 'Approve organisation',
'REJECT' => 'Reject organisation',
],
],

View File

@@ -12,17 +12,20 @@ use UserFrosting\Sprinkle\Core\Util\NoCache;
/*
* Routes for organisation registration workflows.
*/
$app->group('/organisations', function () {
$this->get('/registration/approve', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:approveToken');
$this->get('/registration/reject', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:rejectToken');
$this->post('/o/{slug}/registration/approve', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:approve');
$this->post('/o/{slug}/registration/reject', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:reject');
$app->group('/organisations/registration', function () {
$this->get('/approve', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:approveToken');
$this->get('/reject', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:rejectToken');
})->add('authGuard')->add(new NoCache());
$app->group('/api/organisations', function () {
$this->post('/register', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:register');
$this->delete('/o/{slug}/registration', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:cancel');
$this->post('/registeration', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:register');
})->add('authGuard')->add(new NoCache());
$app->group('/api/organisations/o/{slug}/registration', function () {
$this->put('/approve', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:approve');
$this->put('/reject', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:reject');
$this->delete('', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:cancel');
})->add('authGuard')->add(new NoCache());
$app->group('/modals/organisations', function () {

View File

@@ -285,7 +285,7 @@ class OrganisationRegistrationController extends SimpleController
'name' => $organisation->name
]);
return $response->withRedirect($this->ci->router->pathFor('uri_organisation', ['slug' => $organisation->slug]));
return $response->withJson([], 200);
}
/**
@@ -433,7 +433,7 @@ class OrganisationRegistrationController extends SimpleController
'name' => $organisation->name
]);
return $response->withRedirect($this->ci->router->pathFor('uri_organisations'));
return $response->withJson([], 200);
}
/**
@@ -572,7 +572,7 @@ class OrganisationRegistrationController extends SimpleController
return $this->ci->view->render($response, 'modals/organisation.html.twig', [
'organisation' => $organisation,
'form' => [
'action' => 'api/organisations/register',
'action' => 'api/organisations/registeration',
'method' => 'POST',
'fields' => $fields,
'submit_text' => $translator->translate('REGISTER'),

View File

@@ -57,11 +57,8 @@
</h4>
<div class="text-center">
{% if checkAccess('approve_organisation') %}
<form method="POST">
{% include "forms/csrf.html.twig" %}
<button type="submit" class="btn btn-success" formaction="{{site.uri.public}}/organisations/o/{{organisation.slug}}/registration/approve">{{translate('APPROVE')}}</button>
<button type="submit" class="btn btn-danger" formaction="{{site.uri.public}}/organisations/o/{{organisation.slug}}/registration/reject">{{translate('REJECT')}}</button>
</form>
<button type="button" class="btn btn-success js-organisation-approveRegistration" data-slug="{{organisation.slug}}">{{translate('APPROVE')}}</button>
<button type="button" class="btn btn-danger js-organisation-rejectRegistration" data-slug="{{organisation.slug}}">{{translate('REJECT')}}</button>
{% elseif isOrganisationAdmin(organisation) %}
<button type="button" class="btn btn-danger js-organisation-cancelRegistration" data-slug="{{organisation.slug}}">{{translate('CANCEL_REGISTRATION')}}</button>
{% endif %}

View File

@@ -91,6 +91,18 @@
<i class="fas fa-edit"></i> {% endverbatim %}{{translate("ORGANISATION.EDIT")}}{% verbatim %}
</a>
</li>
{{#ifx row.flag_approved '==' 0 }}
<li>
<a href="#" data-slug="{{row.slug}}" class="js-organisation-approveRegistration">
<i class="fas fa-thumbs-up"></i> {% endverbatim %}{{translate("ORGANISATION.APPROVAL.APPROVE")}}{% verbatim %}
</a>
</li>
<li>
<a href="#" data-slug="{{row.slug}}" class="js-organisation-rejectRegistration">
<i class="fas fa-thumbs-down"></i> {% endverbatim %}{{translate("ORGANISATION.APPROVAL.REJECT")}}{% verbatim %}
</a>
</li>
{{/ifx }}
<li>
<a href="#" data-slug="{{row.slug}}" class="js-organisation-merge">
<i class="fas fa-object-group"></i> {% endverbatim %}{{translate("ORGANISATION.MERGE")}}{% verbatim %}