Compare commits

...

3 Commits

Author SHA1 Message Date
ade02f4736
RVRNEXT-39 add endpoint for community delete
All checks were successful
rvr-nextgen/pipeline/pr-master This commit looks good
2023-06-16 21:38:27 +02:00
bb5b510315
RVRNEXT-39 add delete button for communities 2023-06-16 21:38:27 +02:00
1267cb3d95
RVRNEXT-39 implement community delete 2023-06-16 21:38:26 +02:00
3 changed files with 45 additions and 1 deletions

View File

@ -176,6 +176,43 @@ class CommunityController implements IAuthenticationRequired
]); ]);
} }
public function deleteCommunity(): ?IContent
{
if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) {
return null;
}
if ($this->transactionRepository->countAllByCommunity($community) > 0) {
return new JsonContent([
'error' => ['errorText' => 'There are transactions for this community!']
]);
}
if ($this->eventRepository->countAllByCommunity($community) > 0) {
return new JsonContent([
'error' => ['errorText' => 'There are events for this community!']
]);
}
foreach ($this->communityMemberRepository->getAllByCommunity($community) as $communityMember) {
\Container::$persistentDataManager->deleteFromDb($communityMember);
}
$community->setMainCurrencyId(null);
\Container::$persistentDataManager->saveToDb($community);
foreach ($this->currencyRepository->getAllByCommunity($community) as $currency) {
foreach ($this->currencyExchangeRatesRepository->getAllByCurrency($currency) as $currencyExchangeRate) {
\Container::$persistentDataManager->deleteFromDb($currencyExchangeRate);
}
\Container::$persistentDataManager->deleteFromDb($currency);
}
\Container::$persistentDataManager->deleteFromDb($community);
return new JsonContent(['success' => true]);
}
public function getMembersEdit(): ?IContent public function getMembersEdit(): ?IContent
{ {
if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) { if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) {

View File

@ -25,9 +25,15 @@
<input type="number" class="text big fullWidth" name="main_currency_round_digits" min="0" max="9" required> <input type="number" class="text big fullWidth" name="main_currency_round_digits" min="0" max="9" required>
<?php endif; ?> <?php endif; ?>
<p id="communityFormError" class="formError justify marginTop"></p> <p id="communityFormError" class="formError justify marginTop"></p>
<div class="right marginTop"> <div class="right marginTop" style="font-size: 0;">
<button type="submit" name="submit_button"><?= isset($community) ? '<i class="fa-regular fa-floppy-disk"></i> Save' : '<i class="fa-regular fa-plus"></i> Create' ?></button> <button type="submit" name="submit_button"><?= isset($community) ? '<i class="fa-regular fa-floppy-disk"></i> Save' : '<i class="fa-regular fa-plus"></i> Create' ?></button>
<?php if (isset($community)): ?>
<button type="submit" form="deleteCommunity" name="submit_button" data-confirmation="Are you sure you want to delete this community?" class="red marginLeft"><i class="fa-regular fa-trash-can"></i> Delete</button>
<?php endif; ?>
</div> </div>
</form> </form>
<?php if (isset($community)): ?>
<form id="deleteCommunity" action="<?= Container::$routeCollection->getRoute('community.delete-action')->generateLink(['communitySlug' => $community->getSlug()]) ?>" method="post" data-redirect-on-success="<?= Container::$routeCollection->getRoute('home')->generateLink() ?>"></form>
<?php endif; ?>
</div> </div>
@endsection @endsection

View File

@ -70,6 +70,7 @@ Container::$routeCollection->group('communities', function (RouteCollection $rou
$routeCollection->get('community.settings', 'settings', [CommunityController::class, 'getCommunitySettings']); $routeCollection->get('community.settings', 'settings', [CommunityController::class, 'getCommunitySettings']);
$routeCollection->get('community.edit', 'edit', [CommunityController::class, 'getCommunityEdit']); $routeCollection->get('community.edit', 'edit', [CommunityController::class, 'getCommunityEdit']);
$routeCollection->post('community.edit-action', 'edit', [CommunityController::class, 'saveCommunity']); $routeCollection->post('community.edit-action', 'edit', [CommunityController::class, 'saveCommunity']);
$routeCollection->post('community.delete-action', 'delete', [CommunityController::class, 'deleteCommunity']);
$routeCollection->get('community.members', 'members', [CommunityController::class, 'getMembersEdit']); $routeCollection->get('community.members', 'members', [CommunityController::class, 'getMembersEdit']);
$routeCollection->post('community.members.new-action', 'members/new', [CommunityController::class, 'saveMember']); $routeCollection->post('community.members.new-action', 'members/new', [CommunityController::class, 'saveMember']);
$routeCollection->post('community.members.edit-action', 'members/edit', [CommunityController::class, 'saveMember']); $routeCollection->post('community.members.edit-action', 'members/edit', [CommunityController::class, 'saveMember']);