diff --git a/composer.json b/composer.json index bfa6365..b62335d 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "esoko/soko-web": "0.10", + "esoko/soko-web": "0.11", "firebase/php-jwt": "^6.4" }, "require-dev": { diff --git a/composer.lock b/composer.lock index d8aecb4..d10597a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,17 +4,92 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "607b383c44826c6307dd79b0362ca320", + "content-hash": "c17dd5eb82ff8f509a17404bd4c471b8", "packages": [ + { + "name": "cocur/slugify", + "version": "v4.3.0", + "source": { + "type": "git", + "url": "https://github.com/cocur/slugify.git", + "reference": "652234ef5f1be844a2ae1c36ad1b4c88b05160f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cocur/slugify/zipball/652234ef5f1be844a2ae1c36ad1b4c88b05160f9", + "reference": "652234ef5f1be844a2ae1c36ad1b4c88b05160f9", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": "^7.1 || ~8.0.0 || ~8.1.0 || ~8.2.0" + }, + "conflict": { + "symfony/config": "<3.4 || >=4,<4.3", + "symfony/dependency-injection": "<3.4 || >=4,<4.3", + "symfony/http-kernel": "<3.4 || >=4,<4.3", + "twig/twig": "<2.12.1" + }, + "require-dev": { + "laravel/framework": "^5.0|^6.0|^7.0|^8.0", + "latte/latte": "~2.2", + "league/container": "^2.2.0", + "mikey179/vfsstream": "~1.6.8", + "mockery/mockery": "^1.3", + "nette/di": "~2.4", + "pimple/pimple": "~1.1", + "plumphp/plum": "~0.1", + "symfony/config": "^3.4 || ^4.3 || ^5.0 || ^6.0", + "symfony/dependency-injection": "^3.4 || ^4.3 || ^5.0 || ^6.0", + "symfony/http-kernel": "^3.4 || ^4.3 || ^5.0 || ^6.0", + "symfony/phpunit-bridge": "^5.4 || ^6.0", + "twig/twig": "^2.12.1 || ~3.0", + "zendframework/zend-modulemanager": "~2.2", + "zendframework/zend-servicemanager": "~2.2", + "zendframework/zend-view": "~2.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "Cocur\\Slugify\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Florian Eckerstorfer", + "email": "florian@eckerstorfer.co", + "homepage": "https://florian.ec" + }, + { + "name": "Ivo Bathke", + "email": "ivo.bathke@gmail.com" + } + ], + "description": "Converts a string into a slug.", + "keywords": [ + "slug", + "slugify" + ], + "support": { + "issues": "https://github.com/cocur/slugify/issues", + "source": "https://github.com/cocur/slugify/tree/v4.3.0" + }, + "time": "2022-12-07T19:48:48+00:00" + }, { "name": "esoko/soko-web", - "version": "0.10", + "version": "v0.11", "source": { "type": "git", "url": "https://git.esoko.eu/esoko/soko-web.git", - "reference": "fd286c9cffadc4a26609bfa00944f8014a2f3f59" + "reference": "78f891fbff0dc8e5de5607529f4c8282f1dff40f" }, "require": { + "cocur/slugify": "^4.3", "phpmailer/phpmailer": "^6.8", "symfony/console": "^5.4", "vlucas/phpdotenv": "^5.5" @@ -33,7 +108,7 @@ "GNU GPL 3.0" ], "description": "Lightweight web framework", - "time": "2023-05-02T10:55:47+00:00" + "time": "2023-05-06T23:52:34+00:00" }, { "name": "firebase/php-jwt", diff --git a/database/migrations/data/20230507_0051_slug_for_communities.php b/database/migrations/data/20230507_0051_slug_for_communities.php new file mode 100644 index 0000000..5be5665 --- /dev/null +++ b/database/migrations/data/20230507_0051_slug_for_communities.php @@ -0,0 +1,12 @@ +selectMultipleFromDb($select, Community::class); + +foreach ($communities as $community) { + $community->generateSlug(); + Container::$persistentDataManager->saveToDb($community); +} diff --git a/database/migrations/structure/20230507_0051_slug_for_communities.sql b/database/migrations/structure/20230507_0051_slug_for_communities.sql new file mode 100644 index 0000000..2ec5162 --- /dev/null +++ b/database/migrations/structure/20230507_0051_slug_for_communities.sql @@ -0,0 +1,3 @@ +ALTER TABLE `communities` +ADD `slug` varchar(255) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL AFTER `id`, +ADD UNIQUE `slug` (`slug`); 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/PersistentData/Model/Community.php b/src/PersistentData/Model/Community.php index b5b279f..8419576 100644 --- a/src/PersistentData/Model/Community.php +++ b/src/PersistentData/Model/Community.php @@ -1,9 +1,9 @@ Currency::class]; + protected static string $slugSource = 'name'; + private string $name = ''; private string $currency = ''; 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 @@
|