Skip to content

Commit

Permalink
[API] update app version check
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano committed Jan 7, 2025
1 parent 21037f3 commit b57cbca
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions features/api/profile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]" via OAuth client "JeMengage Mobile"
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Api/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand Down
10 changes: 9 additions & 1 deletion src/Entity/Adherent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit b57cbca

Please sign in to comment.