Fix page redirect after changing an organisation name (slug) from the organisation info page (Fixes #9)

This commit is contained in:
2022-02-22 11:43:48 +00:00
parent 5f8e922438
commit e62e71ab6c
2 changed files with 17 additions and 4 deletions

View File

@@ -39,9 +39,13 @@ function attachOrganisationForm() {
// Set up the form for submission
form.ufForm({
validator: page.validators
}).on("submitSuccess.ufForm", function() {
}).on("submitSuccess.ufForm", function(e, data) {
// Reload page on success
if (data.redirect) {
window.location = data.redirect;
} else {
window.location.reload();
}
});
});
}

View File

@@ -268,6 +268,8 @@ class OrganisationController extends SimpleController
return $response->withJson([], 400);
}
$oldSlug = $organisation->slug;
// Begin transaction - DB will be rolled back if an exception occurs
Capsule::transaction(function () use ($data, $organisation, $currentUser) {
// Update the organisation and generate success messages
@@ -290,8 +292,14 @@ class OrganisationController extends SimpleController
'name' => $organisation->name,
]);
if ($oldSlug != $organisation->slug) {
return $response->withJson([
'redirect' => $this->ci->router->pathFor('uri_organisation', ['slug' => $organisation->slug])
], 200);
} else {
return $response->withJson([], 200);
}
}
/**
* Processes the request to merge two organisations.
@@ -997,7 +1005,8 @@ class OrganisationController extends SimpleController
* @throws ForbiddenException If user is not authorized to access page
*/
public function pageInfo(Request $request, Response $response, $args)
{ /** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager $authorizer */
{
/** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager $authorizer */
$authorizer = $this->ci->authorizer;
/** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */