From b57cbca37473ee448085844adddb2a2d5b373eb6 Mon Sep 17 00:00:00 2001 From: Dimitri Gritsajuk Date: Tue, 7 Jan 2025 16:34:25 +0100 Subject: [PATCH] [API] update app version check --- features/api/profile.feature | 3 +++ src/Controller/Api/ProfileController.php | 2 +- src/Entity/Adherent.php | 10 +++++++++- .../FeedProcessor/AuthorTransformationProcessor.php | 2 +- .../FeedProcessor/ImageTransformationProcessor.php | 2 +- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/features/api/profile.feature b/features/api/profile.feature index d915e84798c..d3472a160fa 100644 --- a/features/api/profile.feature +++ b/features/api/profile.feature @@ -1660,6 +1660,9 @@ Feature: And I add "X-App-Version" header equal to "v5.10.0" When I send a "POST" request to "/api/v3/profile/unregister" Then the response status code should be 200 + When I add "X-App-Version" header equal to "v5.10.0#10" + And I send a "POST" request to "/api/v3/profile/unregister" + Then the response status code should be 200 Scenario: As a logged-in user with new app version I can not unregister with empty body Given I am logged with "michelle.dufour@example.ch" via OAuth client "JeMengage Mobile" diff --git a/src/Controller/Api/ProfileController.php b/src/Controller/Api/ProfileController.php index ff760594531..f4dabf009b1 100644 --- a/src/Controller/Api/ProfileController.php +++ b/src/Controller/Api/ProfileController.php @@ -291,7 +291,7 @@ public function terminateMembershipAction( /** @var Adherent $user */ $validationGroups = [$user->isRenaissanceAdherent() ? 'unregister_adherent' : 'unregister_user']; - if ($user->getAuthAppVersion() >= 5110) { + if ($user->getAuthAppVersion() >= 5110000) { $validationGroups[] = 'unregister'; } diff --git a/src/Entity/Adherent.php b/src/Entity/Adherent.php index bcf039bdf24..0feb93c6976 100644 --- a/src/Entity/Adherent.php +++ b/src/Entity/Adherent.php @@ -2114,7 +2114,15 @@ public function setAuthAppCode(?string $authAppCode): void public function getAuthAppVersion(): int { - return (int) str_replace(['v', '.'], '', (string) $this->authAppVersion); + $parts = preg_split('/[.#]/', str_replace('v', '', (string) $this->authAppVersion)); + + return (int) \sprintf( + '%02d%02d%02d%02d', + $parts[0] ?? 0, + $parts[1] ?? 0, + $parts[2] ?? 0, + $parts[3] ?? 0 + ); } public function setAuthAppVersion(?string $authAppVersion): void diff --git a/src/JeMengage/Timeline/FeedProcessor/AuthorTransformationProcessor.php b/src/JeMengage/Timeline/FeedProcessor/AuthorTransformationProcessor.php index ba55a18adf1..7f7046269ff 100644 --- a/src/JeMengage/Timeline/FeedProcessor/AuthorTransformationProcessor.php +++ b/src/JeMengage/Timeline/FeedProcessor/AuthorTransformationProcessor.php @@ -8,7 +8,7 @@ class AuthorTransformationProcessor extends AbstractFeedProcessor { public function process(array $item, Adherent $user): array { - if ($user->getAuthAppVersion() < 540) { + if ($user->getAuthAppVersion() < 5040000) { if (\is_array($item['author'])) { $item['author'] = implode(' ', array_filter([ $item['author']['first_name'] ?? '', diff --git a/src/JeMengage/Timeline/FeedProcessor/ImageTransformationProcessor.php b/src/JeMengage/Timeline/FeedProcessor/ImageTransformationProcessor.php index 25156c2a618..f57efe2e4f1 100644 --- a/src/JeMengage/Timeline/FeedProcessor/ImageTransformationProcessor.php +++ b/src/JeMengage/Timeline/FeedProcessor/ImageTransformationProcessor.php @@ -8,7 +8,7 @@ class ImageTransformationProcessor extends AbstractFeedProcessor { public function process(array $item, Adherent $user): array { - if ($user->getAuthAppVersion() < 5130) { + if ($user->getAuthAppVersion() < 5130000) { if (\is_array($item['image'])) { $item['image'] = $item['image']['url'] ?? null; }