diff --git a/assets/avsdev/js/widgets/organisations.js b/assets/avsdev/js/widgets/organisations.js index c87c072..2932299 100644 --- a/assets/avsdev/js/widgets/organisations.js +++ b/assets/avsdev/js/widgets/organisations.js @@ -47,14 +47,14 @@ function attachOrganisationForm() { } /** - * Approve/Reject organisation + * Approve/Deny organisation registration */ -function approveOrganisation(slug, approve, options) { +function approveOrganisationRegistration(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 url = site.uri.public + '/api/organisations/o/' + slug + '/registration/' + (approve ? 'approve' : 'deny'); var debugAjax = (typeof site !== "undefined") && site.debug.ajax; return $.ajax({ @@ -270,14 +270,14 @@ function bindOrganisationButtons(el, options) { el.find('.js-organisation-approveRegistration').click(function(e) { e.preventDefault(); - approveOrganisation($(this).data('slug'), true, options); + approveOrganisationRegistration($(this).data('slug'), true, options); }); // Cancel a registration request - el.find('.js-organisation-rejectRegistration').click(function(e) { + el.find('.js-organisation-denyRegistration').click(function(e) { e.preventDefault(); - approveOrganisation($(this).data('slug'), false, options); + approveOrganisationRegistration($(this).data('slug'), false, options); }); // Delete organisation button diff --git a/locale/en_US/messages.php b/locale/en_US/messages.php index d12f398..8abf378 100644 --- a/locale/en_US/messages.php +++ b/locale/en_US/messages.php @@ -42,14 +42,6 @@ return [ 'DELETE_YES' => 'Yes, delete organisation', 'DELETION_SUCCESSFUL' => 'Successfully deleted organisation {{name}}', - 'REGISTER' => 'Register organisation', - 'REGISTRATION_SUCCESSFUL' => 'Successfully registered organisation {{name}}', - - 'CANCEL_REGISTRATION' => 'Cancel organisation registration', - 'CANCEL_REGISTRATION_CONFIRM' => 'Are you sure you want to cancel the registration request for organisation {{name}}?', - 'CANCEL_REGISTRATION_YES' => 'Yes, cancel organisation registration', - 'CANCEL_REGISTRATION_SUCCESSFUL' => 'Successfully cancelled registration of organisation {{name}}', - 'MEMBER_COUNT' => '# Members (excl admins)', 'ADMIN_COUNT' => '# Admins', @@ -74,13 +66,21 @@ return [ 'SLUG' => [ 'IN_USE' => 'Organisation slug {{slug}} is already in use.', ], - 'APPROVAL' => [ + 'REGISTRATION' => [ + 'REGISTER' => 'Register organisation', + 'SUCCESSFUL' => 'Successfully registered organisation {{name}}', + + 'CANCEL' => 'Cancel organisation registration', + 'CANCEL_CONFIRM' => 'Are you sure you want to cancel the registration request for organisation {{name}}?', + 'CANCEL_YES' => 'Yes, cancel organisation registration', + 'CANCEL_SUCCESSFUL' => 'Successfully cancelled registration of organisation {{name}}', + 'PENDING' => 'This organisation is pending approval!', - 'TOKEN_NOT_FOUND' => 'Approval token does not exist / Organisation is already approved/rejected.', - 'APPROVED' => 'You have successfully approved the organisation {{name}}.', - 'REJECTED' => 'You have successfully rejected the organisation {{name}}.', - 'APPROVE' => 'Approve organisation', - 'REJECT' => 'Reject organisation', + 'TOKEN_NOT_FOUND' => 'Approval token does not exist / Organisation registration has already been approved/denied.', + 'APPROVED' => 'You have successfully approved the registration of organisation {{name}}.', + 'DENIED' => 'You have successfully denied the registration of organisation {{name}}.', + 'APPROVE' => 'Approve organisation registration', + 'DENY' => 'Deny organisation registration', ], ], @@ -106,7 +106,7 @@ return [ 'APPROVED' => 'Approved', 'PENDING' => 'Pending', 'APPROVE' => 'Approve', - 'REJECT' => 'Reject', + 'DENY' => 'Deny', 'VIEW_DELETED' => 'View deleted', 'DELETED' => 'Deleted', diff --git a/routes/organisation-registration.php b/routes/organisation-registration.php index 1852cc1..cf3812a 100644 --- a/routes/organisation-registration.php +++ b/routes/organisation-registration.php @@ -14,16 +14,16 @@ use UserFrosting\Sprinkle\Core\Util\NoCache; */ $app->group('/organisations/registration', function () { $this->get('/approve', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:approveToken'); - $this->get('/reject', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:rejectToken'); + $this->get('/deny', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:denyToken'); })->add('authGuard')->add(new NoCache()); $app->group('/api/organisations', function () { - $this->post('/registeration', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:register'); + $this->post('/registration', '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->put('/deny', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:deny'); $this->delete('', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationRegistrationController:cancel'); })->add('authGuard')->add(new NoCache()); diff --git a/src/Controller/OrganisationRegistrationController.php b/src/Controller/OrganisationRegistrationController.php index d99c907..8a6ec3f 100644 --- a/src/Controller/OrganisationRegistrationController.php +++ b/src/Controller/OrganisationRegistrationController.php @@ -27,7 +27,7 @@ use UserFrosting\Sprinkle\Core\Mail\TwigMailMessage; use UserFrosting\Sprinkle\Core\Mail\EmailRecipient; /** - * Controller class for organisation registration-related requests, including registering, approving, rejecting, etc. + * Controller class for organisation registration-related requests, including registering, approving, denying, etc. * * @author Craig Williams (https://avsdev.uk) */ @@ -143,7 +143,7 @@ class OrganisationRegistrationController extends SimpleController $this->sendApprovalEmail($currentUser, $organisation, $approval->getToken()); } - $ms->addMessageTranslated('success', 'ORGANISATION.REGISTRATION_SUCCESSFUL', $data); + $ms->addMessageTranslated('success', 'ORGANISATION.REGISTRATION.SUCCESSFUL', $data); }); return $response->withJson([], 200); @@ -217,7 +217,7 @@ class OrganisationRegistrationController extends SimpleController /** @var \UserFrosting\Sprinkle\Core\Alert\AlertStream $ms */ $ms = $this->ci->alerts; - $ms->addMessageTranslated('success', 'ORGANISATION.CANCEL_REGISTRATION_SUCCESSFUL', [ + $ms->addMessageTranslated('success', 'ORGANISATION.REGISTRATION.CANCEL_SUCCESSFUL', [ 'name' => $organisationName, ]); @@ -281,7 +281,7 @@ class OrganisationRegistrationController extends SimpleController 'user_id' => $currentUser->id, ]); - $ms->addMessageTranslated('success', 'ORGANISATION.APPROVAL.APPROVED', [ + $ms->addMessageTranslated('success', 'ORGANISATION.REGISTRATION.APPROVED', [ 'name' => $organisation->name ]); @@ -348,7 +348,7 @@ class OrganisationRegistrationController extends SimpleController $verification = $this->ci->repoOrganisationApproval->complete($data['token'], $currentUser, ['approved' => true]); if (!$verification) { - $ms->addMessageTranslated('danger', 'ORGANISATION.APPROVAL.TOKEN_NOT_FOUND'); + $ms->addMessageTranslated('danger', 'ORGANISATION.REGISTRATION.TOKEN_NOT_FOUND'); return $response->withRedirect($this->ci->router->pathFor('dashboard')); } @@ -362,7 +362,7 @@ class OrganisationRegistrationController extends SimpleController 'user_id' => $currentUser->id, ]); - $ms->addMessageTranslated('success', 'ORGANISATION.APPROVAL.APPROVED', [ + $ms->addMessageTranslated('success', 'ORGANISATION.REGISTRATION.APPROVED', [ 'name' => $organisation->name ]); @@ -371,7 +371,7 @@ class OrganisationRegistrationController extends SimpleController } /** - * Rejects an organisation registration request. + * Denies an organisation registration request. * * Processes the request from the email verification link that was emailed to the organisation administrators, checking that: * 1. The token provided matches an organisation in the database; @@ -379,7 +379,7 @@ class OrganisationRegistrationController extends SimpleController * This route requires authorization. * * AuthGuard: true - * Route: /organisations/o/{slug}/reject + * Route: /organisations/o/{slug}/deny * Route Name: {none} * Request type: GET * @@ -387,7 +387,7 @@ class OrganisationRegistrationController extends SimpleController * @param Response $response * @param array $args */ - public function reject(Request $request, Response $response, $args) + public function deny(Request $request, Response $response, $args) { /** @var \UserFrosting\Sprinkle\Core\Alert\AlertStream $ms */ $ms = $this->ci->alerts; @@ -420,16 +420,16 @@ class OrganisationRegistrationController extends SimpleController $requester = $classMapper->getClassMapping('user')::find($verification->requester_id); - $this->sendRejectedEmail($organisation, $requester); + $this->sendDeniedEmail($organisation, $requester); $organisation->delete(); - $this->ci->userActivityLogger->info("User {$currentUser->user_name} rejected the registration request for organisation {$organisation->name}.", [ - 'type' => 'organisation_rejected', + $this->ci->userActivityLogger->info("User {$currentUser->user_name} denied the registration request for organisation {$organisation->name}.", [ + 'type' => 'organisation_approval', 'user_id' => $currentUser->id, ]); - $ms->addMessageTranslated('success', 'ORGANISATION.APPROVAL.REJECTED', [ + $ms->addMessageTranslated('success', 'ORGANISATION.REGISTRATION.DENIED', [ 'name' => $organisation->name ]); @@ -437,7 +437,7 @@ class OrganisationRegistrationController extends SimpleController } /** - * Rejects an organisation registration request. + * Denies an organisation registration request. * * Processes the request from the email verification link that was emailed to the organisation administrators, checking that: * 1. The token provided matches an organisation in the database; @@ -445,7 +445,7 @@ class OrganisationRegistrationController extends SimpleController * This route requires authorization. * * AuthGuard: true - * Route: /organisations/o/{slug}/reject + * Route: /organisations/o/{slug}/deny * Route Name: {none} * Request type: GET * @@ -453,7 +453,7 @@ class OrganisationRegistrationController extends SimpleController * @param Response $response * @param array $args */ - public function rejectToken(Request $request, Response $response, $args) + public function denyToken(Request $request, Response $response, $args) { /** @var \UserFrosting\Sprinkle\Core\Alert\AlertStream $ms */ $ms = $this->ci->alerts; @@ -499,7 +499,7 @@ class OrganisationRegistrationController extends SimpleController $verification = $this->ci->repoOrganisationApproval->complete($data['token'], $currentUser, ['approved' => false]); if ($verification === false) { - $ms->addMessageTranslated('danger', 'ORGANISATION.APPROVAL.TOKEN_NOT_FOUND'); + $ms->addMessageTranslated('danger', 'ORGANISATION.REGISTRATION.TOKEN_NOT_FOUND'); return $response->withRedirect($dashboardPage); } @@ -507,14 +507,14 @@ class OrganisationRegistrationController extends SimpleController $organisation = $classMapper->getClassMapping('organisation')::find($verification->organisation_id); $requester = $classMapper->getClassMapping('user')::find($verification->requester_id); - $this->sendRejectedEmail($organisation, $requester); + $this->sendDeniedEmail($organisation, $requester); - $this->ci->userActivityLogger->info("User {$currentUser->user_name} rejected the registration request for organisation {$organisation->name}.", [ - 'type' => 'organisation_rejected', + $this->ci->userActivityLogger->info("User {$currentUser->user_name} denied the registration request for organisation {$organisation->name}.", [ + 'type' => 'organisation_approval', 'user_id' => $currentUser->id, ]); - $ms->addMessageTranslated('success', 'ORGANISATION.APPROVAL.REJECTED', [ + $ms->addMessageTranslated('success', 'ORGANISATION.REGISTRATION.DENIED', [ 'name' => $organisation->name ]); @@ -572,7 +572,7 @@ class OrganisationRegistrationController extends SimpleController return $this->ci->view->render($response, 'modals/organisation.html.twig', [ 'organisation' => $organisation, 'form' => [ - 'action' => 'api/organisations/registeration', + 'action' => 'api/organisations/registration', 'method' => 'POST', 'fields' => $fields, 'submit_text' => $translator->translate('REGISTER'), @@ -694,14 +694,14 @@ class OrganisationRegistrationController extends SimpleController } /** - * Send rejected email for specified organisation. + * Send denied email for specified organisation. * - * @param UserInterface $requester The user to send the rejection notice to + * @param UserInterface $requester The user to send the denial notice to * @param UserInterface $organisation The organisation to send the email for */ - protected function sendRejectedEmail(OrganisationInterface $organisation, UserInterface $requester) + protected function sendDeniedEmail(OrganisationInterface $organisation, UserInterface $requester) { - $message = new TwigMailMessage($this->ci->view, 'mail/organisation-approval-rejected.html.twig'); + $message = new TwigMailMessage($this->ci->view, 'mail/organisation-approval-denied.html.twig'); $message->from($this->ci->config['address_book.admin']) ->addParams([ diff --git a/src/Database/Models/BaseOrganisationApproval.php b/src/Database/Models/BaseOrganisationApproval.php index bd9a52a..e80caaa 100644 --- a/src/Database/Models/BaseOrganisationApproval.php +++ b/src/Database/Models/BaseOrganisationApproval.php @@ -97,7 +97,7 @@ class BaseOrganisationApproval extends Model } /** - * Get the user associated with this approval or rejection of this request. + * Get the user associated with this approval or denial of this request. * * @return \Illuminate\Database\Eloquent\Relations\belongsTo */ diff --git a/src/Database/Seeds/OrganisationPermissions.php b/src/Database/Seeds/OrganisationPermissions.php index dc2c3b7..4983952 100644 --- a/src/Database/Seeds/OrganisationPermissions.php +++ b/src/Database/Seeds/OrganisationPermissions.php @@ -95,9 +95,9 @@ class OrganisationPermissions extends BaseSeed ]), 'approve_organisation' => new Permission([ 'slug' => 'approve_organisation', - 'name' => 'Approve/Reject organisation', + 'name' => 'Approve/Deny organisation registration', 'conditions' => 'always()', - 'description' => 'Approve/Reject organisation registation request.', + 'description' => 'Approve/Deny organisation registation request.', ]), 'merge_organisations' => new Permission([ 'slug' => 'merge_organisations', diff --git a/src/Repository/OrganisationApprovalRepository.php b/src/Repository/OrganisationApprovalRepository.php index 4354409..55ddccb 100644 --- a/src/Repository/OrganisationApprovalRepository.php +++ b/src/Repository/OrganisationApprovalRepository.php @@ -39,7 +39,8 @@ class OrganisationApprovalRepository extends TokenRepository $hash = hash($this->algorithm, $token); // Find an unexpired, incomplete token for the specified hash - $model = $this->classMapper->getClassMapping($this->modelIdentifier)::where('hash', $hash) + $model = $this->classMapper->getClassMapping($this->modelIdentifier)::query() + ->where('hash', $hash) ->where('completed', false) ->where(function($query) { return $query->where('expires_at', '>', Carbon::now())->orWhereNull('expires_at'); @@ -80,7 +81,8 @@ class OrganisationApprovalRepository extends TokenRepository */ public function completeWithoutToken(OrganisationInterface $organisation, UserInterface $approver, $params = []) { - $model = $this->classMapper->getClassMapping($this->modelIdentifier)::where('organisation_id', $organisation->id) + $model = $this->classMapper->getClassMapping($this->modelIdentifier)::query() + ->where('organisation_id', $organisation->id) ->where('completed', false) ->first(); @@ -132,14 +134,13 @@ class OrganisationApprovalRepository extends TokenRepository $hash = hash($this->algorithm, $model->getToken()); $model->fill([ - 'hash' => $hash, - 'completed' => false, - 'expires_at' => ($timeout >= 0 ? $expiresAt : null), + 'organisation_id' => $organisation->id, + 'requester_id' => $requester->id, + 'hash' => $hash, + 'completed' => false, + 'expires_at' => ($timeout >= 0 ? $expiresAt : null), ]); - $model->organisation_id = $organisation->id; - $model->requester_id = $requester->id; - $model->save(); return $model; @@ -150,7 +151,8 @@ class OrganisationApprovalRepository extends TokenRepository */ public function exists(OrganisationInterface $organisation, UserInterface $requester = null, $token = null) { - $model = $this->classMapper->getClassMapping($this->modelIdentifier)::where('organisation_id', $organisation->id) + $model = $this->classMapper->getClassMapping($this->modelIdentifier)::query() + ->where('organisation_id', $organisation->id) ->where('completed', false) ->where(function($query) { return $query->where('expires_at', '>', Carbon::now())->orWhereNull('expires_at'); @@ -174,7 +176,8 @@ class OrganisationApprovalRepository extends TokenRepository */ protected function removeExisting(OrganisationInterface $organisation, UserInterface $requester = null) { - $model = $this->classMapper->getClassMapping($this->modelIdentifier)::where('organisation_id', $organisation->id); + $model = $this->classMapper->getClassMapping($this->modelIdentifier)::query() + ->where('organisation_id', $organisation->id); if ($requester) { $model->where('requester_id', $requester->id); diff --git a/templates/mail/organisation-approval-rejected.html.twig b/templates/mail/organisation-approval-denied.html.twig similarity index 69% rename from templates/mail/organisation-approval-rejected.html.twig rename to templates/mail/organisation-approval-denied.html.twig index 8135d67..0586e92 100644 --- a/templates/mail/organisation-approval-rejected.html.twig +++ b/templates/mail/organisation-approval-denied.html.twig @@ -1,5 +1,5 @@ {% block subject %} - {{site.title}} - organisation registration rejected + {{site.title}} - organisation registration denied {% endblock %} {% block body %} @@ -7,7 +7,7 @@ Dear {{recipient.first_name}},

- The organisation registration request you submitted at {{site.title}} ({{site.uri.public}}) has been rejected. + The organisation registration request you submitted at {{site.title}} ({{site.uri.public}}) has been denied.

With regards,
diff --git a/templates/mail/organisation-approval-request.html.twig b/templates/mail/organisation-approval-request.html.twig index 0cb2eba..692b694 100644 --- a/templates/mail/organisation-approval-request.html.twig +++ b/templates/mail/organisation-approval-request.html.twig @@ -26,17 +26,17 @@

- You may verify or reject this organisation via the control dashboard ({{site.uri.public}}/organisations). + You may approve or deny this organisation via the control dashboard ({{site.uri.public}}/organisations).

- To verify this organisation immediately you may do so by visiting: {{site.uri.public}}/organisations/approve?token={{token}}. + To approve this organisation immediately you may do so by visiting: {{site.uri.public}}/organisations/approve?token={{token}}.

- To reject this organisation immediately you may do so by visiting: {{site.uri.public}}/organisations/reject?token={{token}}. + To deny this organisation immediately you may do so by visiting: {{site.uri.public}}/organisations/deny?token={{token}}.

{% if approval_expiration %}

- The approcal period for this organisation will expire in {{approval_expiration}} at which point the organisation will be automatically rejected. + The approcal period for this organisation will expire in {{approval_expiration}} at which point the organisation registration will be automatically denied.

{% endif %}

diff --git a/templates/modals/confirm-cancel-organisation-registration.html.twig b/templates/modals/confirm-cancel-organisation-registration.html.twig index eec521f..66f3620 100644 --- a/templates/modals/confirm-cancel-organisation-registration.html.twig +++ b/templates/modals/confirm-cancel-organisation-registration.html.twig @@ -1,16 +1,16 @@ {% extends "modals/modal.html.twig" %} -{% block modal_title %}{{translate("ORGANISATION.CANCEL_REGISTRATION")}}{% endblock %} +{% block modal_title %}{{translate("ORGANISATION.REGISTRATION.CANCEL")}}{% endblock %} {% block modal_body %}

{% include "forms/csrf.html.twig" %}
-

{{translate("ORGANISATION.CANCEL_REGISTRATION_CONFIRM", {name: organisation.name})}}{% if delete_hard %}
{{translate("DELETE_CANNOT_UNDONE")}}{% endif %}

+

{{translate("ORGANISATION.REGISTRATION.CANCEL_CONFIRM", {name: organisation.name})}}{% if delete_hard %}
{{translate("ACTION_CANNOT_UNDONE")}}{% endif %}


- +
diff --git a/templates/pages/organisation.html.twig b/templates/pages/organisation.html.twig index 4d9f739..daed4b5 100644 --- a/templates/pages/organisation.html.twig +++ b/templates/pages/organisation.html.twig @@ -46,8 +46,8 @@
  • - - {{translate('REJECT')}} + + {{translate('DENY')}}
  • {% endif %} @@ -75,12 +75,12 @@ {% if organisation.flag_approved != 1 %}

    - {{ translate('ORGANISATION.APPROVAL.PENDING') }} + {{ translate('ORGANISATION.REGISTRATION.PENDING') }}

    {% if checkAccess('approve_organisation') %} - + {% elseif isOrganisationAdmin(organisation) %} {% endif %} diff --git a/templates/pages/organisations.html.twig b/templates/pages/organisations.html.twig index 8e74727..8f6eecd 100644 --- a/templates/pages/organisations.html.twig +++ b/templates/pages/organisations.html.twig @@ -36,7 +36,7 @@ {% elseif checkAccess('register_organisation') %} {% endif %}
    diff --git a/templates/tables/organisations.html.twig b/templates/tables/organisations.html.twig index 70413f0..3355cda 100644 --- a/templates/tables/organisations.html.twig +++ b/templates/tables/organisations.html.twig @@ -116,12 +116,12 @@ {{#ifx row.flag_approved '==' 0 }}
  • - {% endverbatim %}{{translate("ORGANISATION.APPROVAL.APPROVE")}}{% verbatim %} + {% endverbatim %}{{translate("ORGANISATION.REGISTRATION.APPROVE")}}{% verbatim %}
  • - - {% endverbatim %}{{translate("ORGANISATION.APPROVAL.REJECT")}}{% verbatim %} + + {% endverbatim %}{{translate("ORGANISATION.REGISTRATION.DENY")}}{% verbatim %}
  • {{/ifx }}