diff --git a/src/Controller/CommunityController.php b/src/Controller/CommunityController.php index 39ffa82..84735b3 100644 --- a/src/Controller/CommunityController.php +++ b/src/Controller/CommunityController.php @@ -49,7 +49,7 @@ class CommunityController implements IAuthenticationRequired public function getCommunityHome(): ?IContent { - if (!$this->checkPermission(\Container::$request->query('communityId'), false, $community, $ownCommunityMember)) { + if (!$this->checkPermission(\Container::$request->query('communitySlug'), false, $community, $ownCommunityMember)) { return null; } @@ -87,7 +87,7 @@ class CommunityController implements IAuthenticationRequired public function getCommunitySettings(): ?IContent { - if (!$this->checkPermission(\Container::$request->query('communityId'), false, $community, $ownCommunityMember)) { + if (!$this->checkPermission(\Container::$request->query('communitySlug'), false, $community, $ownCommunityMember)) { return null; } @@ -106,7 +106,7 @@ class CommunityController implements IAuthenticationRequired public function getCommunityEdit(): ?IContent { - if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) { + if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) { return null; } @@ -124,9 +124,9 @@ class CommunityController implements IAuthenticationRequired ]); } - $communityId = \Container::$request->query('communityId'); - if ($communityId){ - if (!$this->checkPermission($communityId, true, $community, $ownCommunityMember)) { + $communitySlug = \Container::$request->query('communitySlug'); + if ($communitySlug){ + if (!$this->checkPermission($communitySlug, true, $community, $ownCommunityMember)) { return null; } } else { @@ -145,7 +145,7 @@ class CommunityController implements IAuthenticationRequired $community->setName($name); \Container::$persistentDataManager->saveToDb($community); - if (!$communityId) { + if (!$communitySlug) { /** * @var User $user */ @@ -168,13 +168,13 @@ class CommunityController implements IAuthenticationRequired } return new JsonContent([ - 'redirect' => ['target' => \Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()])] + 'redirect' => ['target' => \Container::$routeCollection->getRoute('community')->generateLink(['communitySlug' => $community->getSlug()])] ]); } public function getMembersEdit(): ?IContent { - if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) { + if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) { return null; } @@ -186,7 +186,7 @@ class CommunityController implements IAuthenticationRequired public function saveMember(): ?IContent { - if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) { + if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) { return null; } @@ -225,7 +225,7 @@ class CommunityController implements IAuthenticationRequired public function deleteMember(): ?IContent { - if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) { + if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) { return null; } @@ -250,7 +250,7 @@ class CommunityController implements IAuthenticationRequired public function getCurrenciesEdit(): ?IContent { - if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) { + if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) { return null; } @@ -262,7 +262,7 @@ class CommunityController implements IAuthenticationRequired public function saveCurrency(): ?IContent { - if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) { + if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) { return null; } @@ -298,7 +298,7 @@ class CommunityController implements IAuthenticationRequired public function deleteCurrency(): ?IContent { - if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) { + if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) { return null; } @@ -324,7 +324,7 @@ class CommunityController implements IAuthenticationRequired public function getCurrencyExchangeRates(): ?IContent { - if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) { + if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) { return null; } @@ -345,7 +345,7 @@ class CommunityController implements IAuthenticationRequired public function saveCurrencyExchangeRate(): ?IContent { - if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) { + if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) { return null; } @@ -378,7 +378,7 @@ class CommunityController implements IAuthenticationRequired public function deleteCurrencyExchangeRate(): ?IContent { - if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) { + if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) { return null; } @@ -415,12 +415,12 @@ class CommunityController implements IAuthenticationRequired } private function checkPermission( - int $communityId, + string $communitySlug, bool $needToBeOwner, ?Community &$community, ?CommunityMember &$ownCommunityMember): bool { - $community = $this->communityRepository->getById($communityId); + $community = $this->communityRepository->getBySlug($communitySlug); if ($community === null) { return false; } diff --git a/src/Controller/TransactionController.php b/src/Controller/TransactionController.php index 3f075c9..aafbea0 100644 --- a/src/Controller/TransactionController.php +++ b/src/Controller/TransactionController.php @@ -46,8 +46,8 @@ class TransactionController implements IAuthenticationRequired, ISecured public function authorize(): bool { - $communityId = \Container::$request->query('communityId'); - $this->community = $this->communityRepository->getById($communityId); + $communitySlug = \Container::$request->query('communitySlug'); + $this->community = $this->communityRepository->getBySlug($communitySlug); if ($this->community === null) { return false; } diff --git a/src/Repository/CommunityRepository.php b/src/Repository/CommunityRepository.php index a1b4c96..49f0568 100644 --- a/src/Repository/CommunityRepository.php +++ b/src/Repository/CommunityRepository.php @@ -8,4 +8,9 @@ class CommunityRepository { return \Container::$persistentDataManager->selectFromDbById($id, Community::class); } + + public function getBySlug(string $slug): ?Community + { + return \Container::$persistentDataManager->selectFromDbBySlug($slug, Community::class); + } } diff --git a/views/communities/community.php b/views/communities/community.php index 8055113..b401d27 100644 --- a/views/communities/community.php +++ b/views/communities/community.php @@ -4,11 +4,11 @@
You owe | diff --git a/views/communities/community_currencies.php b/views/communities/community_currencies.php index 2dc9dfa..7c09dbf 100644 --- a/views/communities/community_currencies.php +++ b/views/communities/community_currencies.php @@ -2,8 +2,8 @@ @section(main)||||
- - + + | @@ -35,7 +35,7 @@ | |||
- + |
diff --git a/views/communities/community_edit.php b/views/communities/community_edit.php
index 9655d66..2f6f5bd 100644
--- a/views/communities/community_edit.php
+++ b/views/communities/community_edit.php
@@ -3,7 +3,7 @@
@section(main)
- = $community->getName() ?> »
+ = $community->getName() ?> »
Edit
New community
@@ -12,7 +12,7 @@
|