From 54d901e45e6dd9af5d44408dc9f08770a0934f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 7 May 2023 01:42:49 +0200 Subject: [PATCH 1/4] RVRNEXT-24 update soko-web --- composer.json | 2 +- composer.lock | 83 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 80 insertions(+), 5 deletions(-) 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", From 829588150a2418432479b2c0d04a53b0f84beb76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 7 May 2023 01:43:14 +0200 Subject: [PATCH 2/4] RVRNEXT-24 add migration for slug for communities --- .../data/20230507_0051_slug_for_communities.php | 12 ++++++++++++ .../structure/20230507_0051_slug_for_communities.sql | 3 +++ 2 files changed, 15 insertions(+) create mode 100644 database/migrations/data/20230507_0051_slug_for_communities.php create mode 100644 database/migrations/structure/20230507_0051_slug_for_communities.sql 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`); From 5dc4350b20bff421c84af214fdae5db8e7b8c008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 7 May 2023 01:43:45 +0200 Subject: [PATCH 3/4] RVRNEXT-24 modify model Community to have slug --- src/PersistentData/Model/Community.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 = ''; From b43ed720404b2db903534a4d7d0d6e18124f164e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 7 May 2023 01:50:57 +0200 Subject: [PATCH 4/4] RVRNEXT-24 replace id-based search to slug-based for communities --- src/Controller/CommunityController.php | 38 +++++++++---------- src/Controller/TransactionController.php | 4 +- src/Repository/CommunityRepository.php | 5 +++ views/communities/community.php | 6 +-- views/communities/community_currencies.php | 10 ++--- views/communities/community_edit.php | 4 +- views/communities/community_members.php | 10 ++--- views/communities/community_settings.php | 8 ++-- views/communities/currency_exchange_rates.php | 10 ++--- views/communities/transaction_edit.php | 12 +++--- views/communities/transactions.php | 28 +++++++------- views/home.php | 2 +- web.php | 2 +- 13 files changed, 72 insertions(+), 67 deletions(-) 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 @@

getName() ?> - [edit] + [edit]

-

Settings

+

Settings

@@ -27,7 +27,7 @@ $mainCurrencyRoundDigits = $community->getMainCurrency()->getRoundDigits(); ?>

Finances

- Transactions + Transactions 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)

- getName() ?> » - Settings » + getName() ?> » + Settings » Edit currencies

@@ -18,8 +18,8 @@
You owe
-
-
+
+
@@ -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)

- getName() ?> » + getName() ?> » Edit New community @@ -12,7 +12,7 @@
getRoute('community.edit-action')->generateLink(['communityId' => $community->getId()]) : + Container::$routeCollection->getRoute('community.edit-action')->generateLink(['communitySlug' => $community->getSlug()]) : Container::$routeCollection->getRoute('community.new-action')->generateLink(); ?>
diff --git a/views/communities/community_members.php b/views/communities/community_members.php index 1bdbccc..0fcc42d 100644 --- a/views/communities/community_members.php +++ b/views/communities/community_members.php @@ -6,8 +6,8 @@ @section(main)

- getName() ?> » - Settings » + getName() ?> » + Settings » Edit members

@@ -23,8 +23,8 @@ getUserId() !== Container::$request->user()->getUniqueId(); ?>

- -
+
+
getUser()->getDisplayName() ?>
@@ -40,7 +40,7 @@
-
+
diff --git a/views/communities/community_settings.php b/views/communities/community_settings.php index 1708d67..bf1f49b 100644 --- a/views/communities/community_settings.php +++ b/views/communities/community_settings.php @@ -2,7 +2,7 @@ @section(main)

- getName() ?> » + getName() ?> » Settings

@@ -11,7 +11,7 @@

Members - [edit] + [edit]

@@ -22,7 +22,7 @@

Currencies - [edit] + [edit]

@@ -30,7 +30,7 @@ getId() === $community->getMainCurrencyId()): ?> getCode() ?> - getCode() ?> + getCode() ?>

diff --git a/views/communities/currency_exchange_rates.php b/views/communities/currency_exchange_rates.php index 0fc62b9..abd5cb4 100644 --- a/views/communities/currency_exchange_rates.php +++ b/views/communities/currency_exchange_rates.php @@ -2,8 +2,8 @@ @section(main)

- getName() ?> » - Settings » + getName() ?> » + Settings » Exchange rates for getCode() ?>

@@ -24,8 +24,8 @@
-
-
+
+
@@ -44,7 +44,7 @@
-
+
diff --git a/views/communities/transaction_edit.php b/views/communities/transaction_edit.php index 1bbbb6e..76c3392 100644 --- a/views/communities/transaction_edit.php +++ b/views/communities/transaction_edit.php @@ -2,8 +2,8 @@ @section(main)

- getName() ?> » - Transactions » + getName() ?> » + Transactions » Edit transaction @@ -13,10 +13,10 @@
getRoute('community.transactions.edit-action')->generateLink(['communityId' => $community->getId(), 'transactionId' => $transaction->getId()]) : - Container::$routeCollection->getRoute('community.transactions.new-action')->generateLink(['communityId' => $community->getId()]); + Container::$routeCollection->getRoute('community.transactions.edit-action')->generateLink(['communitySlug' => $community->getSlug(), 'transactionId' => $transaction->getId()]) : + Container::$routeCollection->getRoute('community.transactions.new-action')->generateLink(['communitySlug' => $community->getSlug()]); ?> -
+

Payer