Added functionality to permenently delete or restore deleted organisations
This commit is contained in:
@@ -8,20 +8,31 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
if ($("#widget-organisations").length) {
|
||||||
|
$("#widget-organisations").ufTable({
|
||||||
|
dataUrl: site.uri.public + "/api/organisations",
|
||||||
|
useLoadingTransition: site.uf_table.use_loading_transition
|
||||||
|
});
|
||||||
|
|
||||||
$("#widget-organisations").ufTable({
|
// Bind creation button
|
||||||
dataUrl: site.uri.public + "/api/organisations",
|
bindOrganisationCreationButton($("#widget-organisations"));
|
||||||
useLoadingTransition: site.uf_table.use_loading_transition
|
|
||||||
});
|
|
||||||
|
|
||||||
// Bind creation button
|
// Bind registration button
|
||||||
bindOrganisationCreationButton($("#widget-organisations"));
|
bindOrganisationRegistrationButton($("#widget-organisations"));
|
||||||
|
|
||||||
// Bind registration button
|
// Bind table buttons
|
||||||
bindOrganisationRegistrationButton($("#widget-organisations"));
|
$("#widget-organisations").on("pagerComplete.ufTable", function () {
|
||||||
|
bindOrganisationButtons($(this));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$("#widget-deleted-organisations").ufTable({
|
||||||
|
dataUrl: site.uri.public + "/api/organisations/deleted",
|
||||||
|
useLoadingTransition: site.uf_table.use_loading_transition
|
||||||
|
});
|
||||||
|
|
||||||
// Bind table buttons
|
// Bind table buttons
|
||||||
$("#widget-organisations").on("pagerComplete.ufTable", function () {
|
$("#widget-deleted-organisations").on("pagerComplete.ufTable", function () {
|
||||||
bindOrganisationButtons($(this));
|
bindOrganisationButtons($(this));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -88,6 +88,47 @@ function approveOrganisation(slug, approve, options) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore a deleted organisation
|
||||||
|
*/
|
||||||
|
function restoreOrganisation(slug, 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 + '/restore';
|
||||||
|
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) {
|
||||||
|
window.location.reload();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link organisation action buttons, for example in a table or on a specific organisation's page.
|
* 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.
|
* @param {module:jQuery} el jQuery wrapped element to target.
|
||||||
@@ -263,6 +304,53 @@ function bindOrganisationButtons(el, options) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// View the deleted organisations page
|
||||||
|
el.find('.js-organisation-viewDeleted').click(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
window.location.href = site.uri.public + '/organisations/deleted';
|
||||||
|
});
|
||||||
|
|
||||||
|
// Permenetly delete organisation button
|
||||||
|
el.find('.js-organisation-permenentDelete').click(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
$("body").ufModal({
|
||||||
|
sourceUrl: site.uri.public + "/modals/organisations/confirm-permenent-delete",
|
||||||
|
ajaxParams: {
|
||||||
|
slug: $(this).data('slug')
|
||||||
|
},
|
||||||
|
msgTarget: $("#alerts-page")
|
||||||
|
});
|
||||||
|
|
||||||
|
$("body").on('renderSuccess.ufModal', function() {
|
||||||
|
var modal = $(this).ufModal('getModal');
|
||||||
|
var form = modal.find('.js-form');
|
||||||
|
|
||||||
|
form.ufForm()
|
||||||
|
.on("submitSuccess.ufForm", function() {
|
||||||
|
// Navigate or reload page on success
|
||||||
|
if (options.delete_redirect) window.location.href = options.delete_redirect;
|
||||||
|
else window.location.reload();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Permenetly delete organisation button
|
||||||
|
el.find('.js-organisation-restore').click(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
restoreOrganisation($(this).data('slug'), options);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Return from the deleted organisations page
|
||||||
|
el.find('.js-organisation-return').click(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
window.location.href = site.uri.public + '/organisations';
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function bindOrganisationCreationButton(el) {
|
function bindOrganisationCreationButton(el) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ return [
|
|||||||
2 => 'Organisations',
|
2 => 'Organisations',
|
||||||
|
|
||||||
'PAGE_DESCRIPTION' => 'A listing of the organisations for your site. Provides management tools for editing and deleting organisations.',
|
'PAGE_DESCRIPTION' => 'A listing of the organisations for your site. Provides management tools for editing and deleting organisations.',
|
||||||
|
'DELETED_PAGE_DESCRIPTION' => 'A listing of the deleted organisations for your site. Provides management tools for restoring and permenently deleting organisations.',
|
||||||
'INFO_PAGE' => 'Organisation information page for {{name}}',
|
'INFO_PAGE' => 'Organisation information page for {{name}}',
|
||||||
'SUMMARY' => 'Organisation Summary',
|
'SUMMARY' => 'Organisation Summary',
|
||||||
|
|
||||||
@@ -56,6 +57,13 @@ return [
|
|||||||
'MANAGE' => 'Manage Organisations',
|
'MANAGE' => 'Manage Organisations',
|
||||||
'ASSIGN_NEW' => 'Assign to organisation',
|
'ASSIGN_NEW' => 'Assign to organisation',
|
||||||
|
|
||||||
|
'RESTORE_DELETED' => 'Restore organisation',
|
||||||
|
'RESTORE_SUCCESSFUL' => 'Successfully restored organistion <strong>{{name}}</strong>',
|
||||||
|
'PERMENENT_DELETE' => 'Permenetly delete organisation',
|
||||||
|
'PERMENENT_DELETE_CONFIRM' => 'Are you sure you want to <strong>permenently</strong> delete the organisation <strong>{{name}}</strong>?',
|
||||||
|
'PERMENENT_DELETE_YES' => 'Yes, permenently delete organisation',
|
||||||
|
'PERMENENT_DELETION_SUCCESSFUL' => 'Successfully permenently deleted organisation <strong>{{name}}</strong>',
|
||||||
|
|
||||||
'NAME' => [
|
'NAME' => [
|
||||||
1 => 'Organisation name',
|
1 => 'Organisation name',
|
||||||
|
|
||||||
@@ -101,4 +109,11 @@ return [
|
|||||||
'PENDING' => 'Pending',
|
'PENDING' => 'Pending',
|
||||||
'APPROVE' => 'Approve',
|
'APPROVE' => 'Approve',
|
||||||
'REJECT' => 'Reject',
|
'REJECT' => 'Reject',
|
||||||
|
|
||||||
|
'VIEW_DELETED' => 'View deleted',
|
||||||
|
'DELETED' => 'Deleted',
|
||||||
|
|
||||||
|
'RETURN' => 'Return',
|
||||||
|
|
||||||
|
'ACTION_CANNOT_UNDONE' => 'This action cannot be undone!',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ $app->group('/organisations', function () {
|
|||||||
|
|
||||||
$this->get('/o/{slug}', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationController:pageInfo')
|
$this->get('/o/{slug}', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationController:pageInfo')
|
||||||
->setName('uri_organisation');
|
->setName('uri_organisation');
|
||||||
|
|
||||||
|
$this->get('/deleted', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationController:pageListDeleted');
|
||||||
})->add('authGuard')->add(new NoCache());
|
})->add('authGuard')->add(new NoCache());
|
||||||
|
|
||||||
$app->group('/api/organisations', function () {
|
$app->group('/api/organisations', function () {
|
||||||
@@ -34,6 +36,13 @@ $app->group('/api/organisations', function () {
|
|||||||
|
|
||||||
|
|
||||||
$this->post('/merge', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationController:merge');
|
$this->post('/merge', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationController:merge');
|
||||||
|
|
||||||
|
|
||||||
|
$this->get('/deleted', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationController:getListDeleted');
|
||||||
|
|
||||||
|
$this->put('/o/{slug}/restore', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationController:restore');
|
||||||
|
|
||||||
|
$this->delete('/o/{slug}/permenent', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationController:deletePermenent');
|
||||||
})->add('authGuard')->add(new NoCache());
|
})->add('authGuard')->add(new NoCache());
|
||||||
|
|
||||||
$app->group('/modals/organisations', function () {
|
$app->group('/modals/organisations', function () {
|
||||||
@@ -44,6 +53,9 @@ $app->group('/modals/organisations', function () {
|
|||||||
$this->get('/merge', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationController:getModalMerge');
|
$this->get('/merge', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationController:getModalMerge');
|
||||||
|
|
||||||
$this->get('/confirm-delete', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationController:getModalConfirmDelete');
|
$this->get('/confirm-delete', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationController:getModalConfirmDelete');
|
||||||
|
|
||||||
|
|
||||||
|
$this->get('/confirm-permenent-delete', 'UserFrosting\Sprinkle\Organisations\Controller\OrganisationController:getModalConfirmPermenentDelete');
|
||||||
})->add('authGuard')->add(new NoCache());
|
})->add('authGuard')->add(new NoCache());
|
||||||
|
|
||||||
// TODO: add route for accepting members
|
// TODO: add route for accepting members
|
||||||
|
|||||||
@@ -474,6 +474,145 @@ class OrganisationController extends SimpleController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the request to permenently delete a deleted organisation.
|
||||||
|
*
|
||||||
|
* Permenently deletes the specified organisation.
|
||||||
|
* Before doing so, checks that:
|
||||||
|
* 1. The user has permission to delete this organisation;
|
||||||
|
* 2. The submitted data is valid.
|
||||||
|
* This route requires authentication (and should generally be limited to admins or the root user).
|
||||||
|
*
|
||||||
|
* Request type: DELETE
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param Response $response
|
||||||
|
* @param array $args
|
||||||
|
*
|
||||||
|
* @throws NotFoundException If organisation is not found
|
||||||
|
* @throws ForbiddenException If user is not authorized to access page
|
||||||
|
* @throws BadRequestException
|
||||||
|
*/
|
||||||
|
public function deletePermenent(Request $request, Response $response, $args)
|
||||||
|
{
|
||||||
|
$organisation = $this->getOrganisationFromParams($args, true);
|
||||||
|
|
||||||
|
// If the organisation doesn't exist, return 404
|
||||||
|
if (!$organisation) {
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager $authorizer */
|
||||||
|
$authorizer = $this->ci->authorizer;
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */
|
||||||
|
$currentUser = $this->ci->currentUser;
|
||||||
|
|
||||||
|
// Access-controlled page
|
||||||
|
if (!$authorizer->checkAccess($currentUser, 'permenent_delete_organisation', [
|
||||||
|
'organisation' => $organisation,
|
||||||
|
])) {
|
||||||
|
throw new ForbiddenException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Support\Repository\Repository $config */
|
||||||
|
$config = $this->ci->config;
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
|
||||||
|
$classMapper = $this->ci->classMapper;
|
||||||
|
|
||||||
|
$organisationName = $organisation->name;
|
||||||
|
|
||||||
|
// Begin transaction - DB will be rolled back if an exception occurs
|
||||||
|
Capsule::transaction(function () use ($organisation, $organisationName, $currentUser) {
|
||||||
|
$organisation->delete(true);
|
||||||
|
unset($organisation);
|
||||||
|
|
||||||
|
// Create activity record
|
||||||
|
$this->ci->userActivityLogger->info("User {$currentUser->user_name} permenetly deleted organisation {$organisationName}.", [
|
||||||
|
'type' => 'organisation_delete',
|
||||||
|
'user_id' => $currentUser->id,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Core\Alert\AlertStream $ms */
|
||||||
|
$ms = $this->ci->alerts;
|
||||||
|
|
||||||
|
$ms->addMessageTranslated('success', 'ORGANISATION.PERMENENT_DELETION_SUCCESSFUL', [
|
||||||
|
'name' => $organisationName,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $response->withJson([], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restores a deleted organisation
|
||||||
|
*
|
||||||
|
* Before doing so, checks that:
|
||||||
|
* 1. The user has permission to restore this organisation;
|
||||||
|
* 2. The submitted data is valid.
|
||||||
|
* This route requires authentication (and should generally be limited to admins or the root user).
|
||||||
|
*
|
||||||
|
* Request type: PUT
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param Response $response
|
||||||
|
* @param array $args
|
||||||
|
*
|
||||||
|
* @throws NotFoundException If organisation is not found
|
||||||
|
* @throws ForbiddenException If user is not authorized to access page
|
||||||
|
* @throws BadRequestException
|
||||||
|
*/
|
||||||
|
public function restore(Request $request, Response $response, $args)
|
||||||
|
{
|
||||||
|
$organisation = $this->getOrganisationFromParams($args, true);
|
||||||
|
|
||||||
|
// If the organisation doesn't exist, return 404
|
||||||
|
if (!$organisation) {
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager $authorizer */
|
||||||
|
$authorizer = $this->ci->authorizer;
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */
|
||||||
|
$currentUser = $this->ci->currentUser;
|
||||||
|
|
||||||
|
// Access-controlled page
|
||||||
|
if (!$authorizer->checkAccess($currentUser, 'restore_organisation', [
|
||||||
|
'organisation' => $organisation,
|
||||||
|
])) {
|
||||||
|
throw new ForbiddenException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Support\Repository\Repository $config */
|
||||||
|
$config = $this->ci->config;
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
|
||||||
|
$classMapper = $this->ci->classMapper;
|
||||||
|
|
||||||
|
// Begin transaction - DB will be rolled back if an exception occurs
|
||||||
|
Capsule::transaction(function () use ($organisation, $currentUser) {
|
||||||
|
$organisation->restore();
|
||||||
|
|
||||||
|
// Create activity record
|
||||||
|
$this->ci->userActivityLogger->info("User {$currentUser->user_name} restored deleted organisation {$organisation->name}.", [
|
||||||
|
'type' => 'organisation_restore',
|
||||||
|
'user_id' => $currentUser->id,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Core\Alert\AlertStream $ms */
|
||||||
|
$ms = $this->ci->alerts;
|
||||||
|
|
||||||
|
$ms->addMessageTranslated('success', 'ORGANISATION.RESTORE_SUCCESSFUL', [
|
||||||
|
'name' => $organisation->name,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $response->withJson([], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of Organisations.
|
* Returns a list of Organisations.
|
||||||
*
|
*
|
||||||
@@ -514,6 +653,49 @@ class OrganisationController extends SimpleController
|
|||||||
return $sprunje->toResponse($response);
|
return $sprunje->toResponse($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of Organisations.
|
||||||
|
*
|
||||||
|
* Generates a list of organisations, optionally paginated, sorted and/or filtered.
|
||||||
|
* This page requires authentication.
|
||||||
|
*
|
||||||
|
* Request type: GET
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param Response $response
|
||||||
|
* @param array $args
|
||||||
|
*
|
||||||
|
* @throws ForbiddenException If user is not authorized to access page
|
||||||
|
*/
|
||||||
|
public function getListDeleted(Request $request, Response $response, $args)
|
||||||
|
{
|
||||||
|
// GET parameters
|
||||||
|
$params = $request->getQueryParams();
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager $authorizer */
|
||||||
|
$authorizer = $this->ci->authorizer;
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */
|
||||||
|
$currentUser = $this->ci->currentUser;
|
||||||
|
|
||||||
|
// Access-controlled page
|
||||||
|
if (!$authorizer->checkAccess($currentUser, 'uri_deleted_organisations')) {
|
||||||
|
throw new ForbiddenException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
|
||||||
|
$classMapper = $this->ci->classMapper;
|
||||||
|
|
||||||
|
$sprunje = $classMapper->createInstance('organisation_sprunje', $classMapper, $params);
|
||||||
|
$sprunje->extendQuery(function ($query) use ($user) {
|
||||||
|
return $query->onlyTrashed();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Be careful how you consume this data - it has not been escaped and contains untrusted user-supplied content.
|
||||||
|
// For example, if you plan to insert it into an HTML DOM, you must escape it on the client side (or use client-side templating).
|
||||||
|
return $sprunje->toResponse($response);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get deletion confirmation modal.
|
* Get deletion confirmation modal.
|
||||||
*
|
*
|
||||||
@@ -561,6 +743,53 @@ class OrganisationController extends SimpleController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get permenent deletion confirmation modal.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param Response $response
|
||||||
|
* @param array $args
|
||||||
|
*
|
||||||
|
* @throws NotFoundException If organisation is not found
|
||||||
|
* @throws ForbiddenException If user is not authorized to access page
|
||||||
|
* @throws BadRequestException
|
||||||
|
*/
|
||||||
|
public function getModalConfirmPermenentDelete(Request $request, Response $response, $args)
|
||||||
|
{
|
||||||
|
// GET parameters
|
||||||
|
$params = $request->getQueryParams();
|
||||||
|
|
||||||
|
$organisation = $this->getOrganisationFromParams($params, true);
|
||||||
|
|
||||||
|
// If the organisation no longer exists, forward to main organisation listing page
|
||||||
|
if (!$organisation) {
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager $authorizer */
|
||||||
|
$authorizer = $this->ci->authorizer;
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */
|
||||||
|
$currentUser = $this->ci->currentUser;
|
||||||
|
|
||||||
|
// Access-controlled page
|
||||||
|
if (!$authorizer->checkAccess($currentUser, 'permenent_delete_organisation', [
|
||||||
|
'organisation' => $organisation,
|
||||||
|
])) {
|
||||||
|
throw new ForbiddenException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
|
||||||
|
$classMapper = $this->ci->classMapper;
|
||||||
|
|
||||||
|
return $this->ci->view->render($response, 'modals/confirm-permenent-delete-organisation.html.twig', [
|
||||||
|
'organisation' => $organisation,
|
||||||
|
'form' => [
|
||||||
|
'action' => "api/organisations/o/{$organisation->slug}/permenent",
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the modal form for creating a new organisation.
|
* Renders the modal form for creating a new organisation.
|
||||||
*
|
*
|
||||||
@@ -872,6 +1101,37 @@ class OrganisationController extends SimpleController
|
|||||||
return $this->ci->view->render($response, 'pages/organisations.html.twig');
|
return $this->ci->view->render($response, 'pages/organisations.html.twig');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the organisation listing page for deleted organisations.
|
||||||
|
*
|
||||||
|
* This page renders a table of organisations, with dropdown menus for admin actions for each organisation.
|
||||||
|
* Actions typically include: restore organisation, permenently delete etd.
|
||||||
|
* This page requires authentication.
|
||||||
|
*
|
||||||
|
* Request type: GET
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param Response $response
|
||||||
|
* @param array $args
|
||||||
|
*
|
||||||
|
* @throws ForbiddenException If user is not authorized to access page
|
||||||
|
*/
|
||||||
|
public function pageListDeleted(Request $request, Response $response, $args)
|
||||||
|
{
|
||||||
|
/** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager $authorizer */
|
||||||
|
$authorizer = $this->ci->authorizer;
|
||||||
|
|
||||||
|
/** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */
|
||||||
|
$currentUser = $this->ci->currentUser;
|
||||||
|
|
||||||
|
// Access-controlled page
|
||||||
|
if (!$authorizer->checkAccess($currentUser, 'uri_deleted_organisations')) {
|
||||||
|
throw new ForbiddenException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->ci->view->render($response, 'pages/deleted-organisations.html.twig');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get organisation from params.
|
* Get organisation from params.
|
||||||
@@ -882,7 +1142,7 @@ class OrganisationController extends SimpleController
|
|||||||
*
|
*
|
||||||
* @return Organisation
|
* @return Organisation
|
||||||
*/
|
*/
|
||||||
protected function getOrganisationFromParams($params)
|
protected function getOrganisationFromParams($params, $withTrashed = false)
|
||||||
{
|
{
|
||||||
// Load the request schema
|
// Load the request schema
|
||||||
$schema = new RequestSchema('schema://requests/organisation/get-by-slug.yaml');
|
$schema = new RequestSchema('schema://requests/organisation/get-by-slug.yaml');
|
||||||
@@ -908,9 +1168,14 @@ class OrganisationController extends SimpleController
|
|||||||
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
|
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
|
||||||
$classMapper = $this->ci->classMapper;
|
$classMapper = $this->ci->classMapper;
|
||||||
|
|
||||||
|
$query = $classMapper->getClassMapping('organisation')::where('slug', $data['slug']);
|
||||||
|
|
||||||
|
if ($withTrashed) {
|
||||||
|
$query->withTrashed();
|
||||||
|
}
|
||||||
|
|
||||||
// Get the organisation
|
// Get the organisation
|
||||||
$organisation = $classMapper->getClassMapping('organisation')::where('slug', $data['slug'])
|
$organisation = $query->first();
|
||||||
->first();
|
|
||||||
|
|
||||||
return $organisation;
|
return $organisation;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,6 +99,18 @@ class OrganisationPermissions extends BaseSeed
|
|||||||
'conditions' => 'always()',
|
'conditions' => 'always()',
|
||||||
'description' => 'Delete an organisation.',
|
'description' => 'Delete an organisation.',
|
||||||
]),
|
]),
|
||||||
|
'restore_organisation' => new Permission([
|
||||||
|
'slug' => 'restore_organisation',
|
||||||
|
'name' => 'Restore organisation',
|
||||||
|
'conditions' => 'always()',
|
||||||
|
'description' => 'Restore a deleted organisation.',
|
||||||
|
]),
|
||||||
|
'permenent_delete_organisation' => new Permission([
|
||||||
|
'slug' => 'permenent_delete_organisation',
|
||||||
|
'name' => 'Permenently delete organisation',
|
||||||
|
'conditions' => 'always()',
|
||||||
|
'description' => 'Permenently delete an organisation.',
|
||||||
|
]),
|
||||||
'uri_organisation' => new Permission([
|
'uri_organisation' => new Permission([
|
||||||
'slug' => 'uri_organisation',
|
'slug' => 'uri_organisation',
|
||||||
'name' => 'View organisation',
|
'name' => 'View organisation',
|
||||||
@@ -117,9 +129,16 @@ class OrganisationPermissions extends BaseSeed
|
|||||||
'conditions' => 'always()',
|
'conditions' => 'always()',
|
||||||
'description' => 'View a page containing a list of organisations.',
|
'description' => 'View a page containing a list of organisations.',
|
||||||
]),
|
]),
|
||||||
|
'uri_deleted_organisations' => new Permission([
|
||||||
|
'slug' => 'uri_deleted_organisations',
|
||||||
|
'name' => 'Deleted organisation management page',
|
||||||
|
'conditions' => 'always()',
|
||||||
|
'description' => 'View a page containing a list of deleted organisations.',
|
||||||
|
]),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save permissions.
|
* Save permissions.
|
||||||
*
|
*
|
||||||
@@ -175,6 +194,9 @@ class OrganisationPermissions extends BaseSeed
|
|||||||
$permissions['delete_organisation']->id,
|
$permissions['delete_organisation']->id,
|
||||||
$permissions['uri_organisations']->id,
|
$permissions['uri_organisations']->id,
|
||||||
$permissions['uri_organisation']->id,
|
$permissions['uri_organisation']->id,
|
||||||
|
$permissions['uri_deleted_organisations']->id,
|
||||||
|
$permissions['restore_organisation']->id,
|
||||||
|
$permissions['permenent_delete_organisation']->id,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{% extends "modals/modal.html.twig" %}
|
||||||
|
|
||||||
|
{% block modal_title %}{{translate("ORGANISATION.PERMENENT_DELETE")}}{% endblock %}
|
||||||
|
|
||||||
|
{% block modal_body %}
|
||||||
|
<form class="js-form" method="delete" action="{{site.uri.public}}/{{form.action}}">
|
||||||
|
{% include "forms/csrf.html.twig" %}
|
||||||
|
<div class="js-form-alerts">
|
||||||
|
</div>
|
||||||
|
<h4>{{translate("ORGANISATION.PERMENENT_DELETE_CONFIRM", {name: organisation.name})}}<br><small>{{translate("ACTION_CANNOT_UNDONE")}}</small></h4>
|
||||||
|
<br>
|
||||||
|
<div class="btn-group-action">
|
||||||
|
<button type="submit" class="btn btn-danger btn-lg btn-block">{{translate("ORGANISATION.PERMENENT_DELETE_YES")}}</button>
|
||||||
|
<button type="button" class="btn btn-default btn-lg btn-block" data-dismiss="modal">{{translate("CANCEL")}}</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
50
templates/pages/deleted-organisations.html.twig
Normal file
50
templates/pages/deleted-organisations.html.twig
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
{% extends "pages/abstract/dashboard.html.twig" %}
|
||||||
|
|
||||||
|
{% block stylesheets_page %}
|
||||||
|
<!-- Page-specific CSS asset bundle -->
|
||||||
|
{{ assets.css('css/form-widgets') | raw }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{# Overrides blocks in head of base template #}
|
||||||
|
{% block page_title %}{{ translate("DELETED") }} {{ translate("ORGANISATION", 2) }}{% endblock %}
|
||||||
|
|
||||||
|
{% block page_description %}{{ translate("ORGANISATION.DELETED_PAGE_DESCRIPTION") }}{% endblock %}
|
||||||
|
|
||||||
|
{% block body_matter %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div id="widget-deleted-organisations" class="box box-primary">
|
||||||
|
<div class="box-header">
|
||||||
|
<h3 class="box-title"><i class="fas fa-fw fa-sitemap"></i> {{ translate("DELETED") }} {{translate('ORGANISATION', 2)}}</h3>
|
||||||
|
{% include "tables/table-tool-menu.html.twig" %}
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
{% include "tables/deleted-organisations.html.twig" with {
|
||||||
|
"table" : {
|
||||||
|
"id" : "table-organisations"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
</div>
|
||||||
|
<div class="box-footer">
|
||||||
|
<button type="button" class="btn btn-success js-organisation-return">
|
||||||
|
<i class="fas fa-arrow-left"></i> {{translate("RETURN")}}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
{% block scripts_page %}
|
||||||
|
<!-- Include validation rules -->
|
||||||
|
<script>
|
||||||
|
{% include "pages/partials/page.js.twig" %}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Include form widgets JS -->
|
||||||
|
{{ assets.js('js/form-widgets') | raw }}
|
||||||
|
|
||||||
|
<!-- Include page-specific JS -->
|
||||||
|
{{ assets.js('js/pages/organisations') | raw }}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@@ -31,8 +31,10 @@
|
|||||||
<button type="button" class="btn btn-success js-organisation-create">
|
<button type="button" class="btn btn-success js-organisation-create">
|
||||||
<i class="fas fa-plus-square"></i> {{translate("ORGANISATION.CREATE")}}
|
<i class="fas fa-plus-square"></i> {{translate("ORGANISATION.CREATE")}}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
<button type="button" class="btn btn-danger js-organisation-viewDeleted">
|
||||||
{% if checkAccess('register_organisation') %}
|
<i class="fas fa-minus-square"></i> {{translate("VIEW_DELETED")}}
|
||||||
|
</button>
|
||||||
|
{% elseif checkAccess('register_organisation') %}
|
||||||
<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.REGISTER")}}
|
<i class="fas fa-plus-square"></i> {{translate("ORGANISATION.REGISTER")}}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
104
templates/tables/deleted-organisations.html.twig
Normal file
104
templates/tables/deleted-organisations.html.twig
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
{# This partial template renders a table of organisations, to be populated with rows via an AJAX request.
|
||||||
|
# This extends a generic template for paginated tables.
|
||||||
|
#
|
||||||
|
# Note that this template contains a "skeleton" table with an empty table body, and then a block of Handlebars templates which are used
|
||||||
|
# to render the table cells with the data from the AJAX request.
|
||||||
|
#}
|
||||||
|
|
||||||
|
{% extends "tables/table-paginated.html.twig" %}
|
||||||
|
|
||||||
|
{% block table %}
|
||||||
|
<table id="{{table.id}}" class="tablesorter table table-bordered table-hover table-striped" data-sortlist="{{table.sortlist}}">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="sorter-metatext" data-column-name="name" data-column-template="#organisation-table-column-info" data-priority="1">{{translate('ORGANISATION')}} <i class="fas fa-sort"></i></th>
|
||||||
|
<th class="sorter-metatext" data-column-name="description" data-column-template="#organisation-table-column-description" data-priority="2">{{translate("DESCRIPTION")}} <i class="fas fa-sort"></i></th>
|
||||||
|
<th class="filter-select filter-metatext" data-column-name="status" data-column-template="#user-table-column-status" data-priority="2">{{translate("STATUS")}} <i class="fas fa-sort"></i></th>
|
||||||
|
<th class="sorter-metanum" data-column-name="member_count" data-column-template="#organisation-table-column-memberCount" data-priority="2">{{translate("ORGANISATION.MEMBER_COUNT")}} <i class="fas fa-sort"></i></th>
|
||||||
|
<th class="sorter-metanum" data-column-name="admin_count" data-column-template="#organisation-table-column-adminCount" data-priority="2">{{translate("ORGANISATION.ADMIN_COUNT")}} <i class="fas fa-sort"></i></th>
|
||||||
|
<th data-column-template="#organisation-table-column-actions" data-sorter="false" data-filter="false" data-priority="1">{{translate("ACTIONS")}}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block table_cell_templates %}
|
||||||
|
{# This contains a series of <script> blocks, each of which is a client-side Handlebars template.
|
||||||
|
# Note that these are NOT Twig templates, although the syntax is similar. We wrap them in the `verbatim` tag,
|
||||||
|
# so that Twig will output them directly into the DOM instead of trying to treat them like Twig templates.
|
||||||
|
#
|
||||||
|
# These templates require handlebars-helpers.js, moment.js
|
||||||
|
#}
|
||||||
|
{% verbatim %}
|
||||||
|
<script id="organisation-table-column-info" type="text/x-handlebars-template">
|
||||||
|
<td data-text="{{row.name}}">
|
||||||
|
<strong>
|
||||||
|
<a href="{{site.uri.public}}/organisations/o/{{row.slug}}">{{row.name}}</a>
|
||||||
|
</strong>
|
||||||
|
</td>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id="organisation-table-column-description" type="text/x-handlebars-template">
|
||||||
|
<td>
|
||||||
|
{{row.description}}
|
||||||
|
</td>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id="user-table-column-status" type="text/x-handlebars-template">
|
||||||
|
<td
|
||||||
|
{{#ifx row.flag_approved '==' 1 }}
|
||||||
|
data-text="approved"
|
||||||
|
{{ else }}
|
||||||
|
data-text="pending"
|
||||||
|
{{/ifx }}
|
||||||
|
>
|
||||||
|
{{#ifx row.flag_approved '==' 1 }}
|
||||||
|
<span>
|
||||||
|
{% endverbatim %}{{translate("APPROVED")}}{% verbatim %}
|
||||||
|
</span>
|
||||||
|
{{ else }}
|
||||||
|
<span class="text-danger">
|
||||||
|
{% endverbatim %}{{translate("PENDING")}}{% verbatim %}
|
||||||
|
</span>
|
||||||
|
{{/ifx }}
|
||||||
|
</td>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id="organisation-table-column-memberCount" type="text/x-handlebars-template">
|
||||||
|
<td>
|
||||||
|
{{row.member_count}}
|
||||||
|
</td>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id="organisation-table-column-adminCount" type="text/x-handlebars-template">
|
||||||
|
<td>
|
||||||
|
{{row.admin_count}}
|
||||||
|
</td>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id="organisation-table-column-actions" type="text/x-handlebars-template">
|
||||||
|
<td>
|
||||||
|
<div class="btn-group">
|
||||||
|
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
|
||||||
|
{% endverbatim %}{{translate("ACTIONS")}}{% verbatim %}
|
||||||
|
<span class="caret"></span>
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu dropdown-menu-right" role="menu">
|
||||||
|
<li>
|
||||||
|
<a href="#" data-slug="{{row.slug}}" class="js-organisation-restore">
|
||||||
|
<i class="fas fa-trash-restore"></i> {% endverbatim %}{{translate("ORGANISATION.RESTORE_DELETED")}}{% verbatim %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#" data-slug="{{row.slug}}" class="js-organisation-permenentDelete">
|
||||||
|
<i class="fas fa-trash-alt"></i> {% endverbatim %}{{translate("ORGANISATION.PERMENENT_DELETE")}}{% verbatim %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</script>
|
||||||
|
{% endverbatim %}
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user