Skip to content

Commit

Permalink
[Tags] update year tag pattern (#11354)
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano authored Jan 23, 2025
1 parent ca3c4f5 commit 0c3998f
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 117 deletions.
9 changes: 5 additions & 4 deletions features/api/adherent_messages.feature
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,11 @@ Feature:
"adherent:a_jour_2025": "Adhérent - À jour 2025",
"adherent:a_jour_2025:primo": "Adhérent - À jour 2025 - Primo-adhérent",
"adherent:a_jour_2025:recotisation": "Adhérent - À jour 2025 - Recotisation",
"adherent:a_jour_2025:elu_a_jour": "Adhérent - À jour 2025 - Car à jour de cotisation élu",
"adherent:a_jour_2024": "Adhérent - À jour 2024",
"adherent:a_jour_2023": "Adhérent - À jour 2023",
"adherent:a_jour_2022": "Adhérent - À jour 2022",
"adherent:a_jour_2025:elu_a_jour": "Adhérent - À jour 2025 - Élu à jour",
"adherent:plus_a_jour": "Adhérent - Plus à jour",
"adherent:plus_a_jour:annee_2024": "Adhérent - Plus à jour - À jour 2024",
"adherent:plus_a_jour:annee_2023": "Adhérent - Plus à jour - À jour 2023",
"adherent:plus_a_jour:annee_2022": "Adhérent - Plus à jour - À jour 2022",
"sympathisant": "Sympathisant",
"sympathisant:adhesion_incomplete": "Sympathisant - Adhésion incomplète",
"sympathisant:compte_em": "Sympathisant - Ancien compte En Marche",
Expand Down
52 changes: 24 additions & 28 deletions features/api/adherents.feature
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,10 @@ Feature:
"nationality": "FR",
"tags": [
{
"code": "adherent:a_jour_2025",
"label": "À jour 2025",
"code": "adherent:a_jour_2025:recotisation",
"label": "Adhérent à jour 2025",
"type": "adherent"
},
{
"code": "elu:cotisation_ok:exempte",
"label": "Exempté de cotisation",
"type": "elu"
},
{
"type": "role",
"label": "Délégué de circonscription",
Expand Down Expand Up @@ -471,15 +466,10 @@ Feature:
"nationality": "FR",
"tags": [
{
"code": "adherent:a_jour_2025",
"label": "À jour 2025",
"code": "adherent:a_jour_2025:recotisation",
"label": "Adhérent à jour 2025",
"type": "adherent"
},
{
"code": "elu:cotisation_ok:exempte",
"label": "Exempté de cotisation",
"type": "elu"
},
{
"type": "role",
"label": "Délégué de circonscription",
Expand Down Expand Up @@ -659,15 +649,10 @@ Feature:
"nationality": "FR",
"tags": [
{
"code": "adherent:a_jour_2025",
"label": "À jour 2025",
"code": "adherent:a_jour_2025:recotisation",
"label": "Adhérent à jour 2025",
"type": "adherent"
},
{
"code": "elu:cotisation_ok:exempte",
"label": "Exempté de cotisation",
"type": "elu"
},
{
"type": "role",
"label": "Délégué de circonscription",
Expand Down Expand Up @@ -931,10 +916,11 @@ Feature:
"adherent:a_jour_2025": "Adhérent - À jour 2025",
"adherent:a_jour_2025:primo": "Adhérent - À jour 2025 - Primo-adhérent",
"adherent:a_jour_2025:recotisation": "Adhérent - À jour 2025 - Recotisation",
"adherent:a_jour_2025:elu_a_jour": "Adhérent - À jour 2025 - Car à jour de cotisation élu",
"adherent:a_jour_2024": "Adhérent - À jour 2024",
"adherent:a_jour_2023": "Adhérent - À jour 2023",
"adherent:a_jour_2022": "Adhérent - À jour 2022",
"adherent:a_jour_2025:elu_a_jour": "Adhérent - À jour 2025 - Élu à jour",
"adherent:plus_a_jour": "Adhérent - Plus à jour",
"adherent:plus_a_jour:annee_2024": "Adhérent - Plus à jour - À jour 2024",
"adherent:plus_a_jour:annee_2023": "Adhérent - Plus à jour - À jour 2023",
"adherent:plus_a_jour:annee_2022": "Adhérent - Plus à jour - À jour 2022",
"sympathisant": "Sympathisant",
"sympathisant:adhesion_incomplete": "Sympathisant - Adhésion incomplète",
"sympathisant:compte_em": "Sympathisant - Ancien compte En Marche",
Expand Down Expand Up @@ -1174,6 +1160,11 @@ Feature:
"phone": "+33 1 87 26 42 36",
"nationality": "FR",
"tags": [
{
"code": "adherent:a_jour_2025:recotisation",
"label": "Adhérent à jour 2025",
"type": "adherent"
},
{
"type": "role",
"label": "Président assemblée départementale",
Expand Down Expand Up @@ -1244,6 +1235,11 @@ Feature:
"phone": "+33 1 87 26 42 36",
"nationality": "FR",
"tags": [
{
"code": "adherent:a_jour_2025:recotisation",
"label": "Adhérent à jour 2025",
"type": "adherent"
},
{
"type": "role",
"label": "Président assemblée départementale",
Expand Down Expand Up @@ -1307,7 +1303,7 @@ Feature:
"""
{
"adherent": 6,
"sympathizer": 2
"sympathizer": 3
}
"""
When I send a "GET" request to "/api/v3/adherents/count?scope=president_departmental_assembly&since=2022"
Expand All @@ -1317,7 +1313,7 @@ Feature:
{
"adherent": 6,
"adherent_since": 5,
"sympathizer": 2
"sympathizer": 3
}
"""
When I send a "POST" request to "/api/v3/adherents/count?scope=president_departmental_assembly" with body:
Expand All @@ -1328,7 +1324,7 @@ Feature:
And the JSON should be equal to:
"""
{
"adherent": 2,
"adherent": 3,
"sympathizer": 1
}
"""
10 changes: 5 additions & 5 deletions features/api/committees.feature
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Feature:
"created_at": "@[email protected]()",
"updated_at": "@[email protected]()",
"name": "Second Comité des 3 communes",
"members_count": 2,
"members_count": 3,
"members_em_count": 0,
"sympathizers_count": 0
}
Expand All @@ -61,7 +61,7 @@ Feature:
And the JSON should be equal to:
"""
{
"members_count": 2,
"members_count": 3,
"members_em_count": 0,
"sympathizers_count": 0,
"description": "Un petit comité avec seulement 3 communes",
Expand Down Expand Up @@ -115,7 +115,7 @@ Feature:
And the JSON should be equal to:
"""
{
"members_count": 2,
"members_count": 3,
"members_em_count": 0,
"sympathizers_count": 0,
"description": "Un petit comité avec seulement 3 communes",
Expand Down Expand Up @@ -172,7 +172,7 @@ Feature:
And the JSON should be equal to:
"""
{
"members_count": 2,
"members_count": 3,
"members_em_count": 0,
"sympathizers_count": 0,
"description": "my desc",
Expand Down Expand Up @@ -228,7 +228,7 @@ Feature:
And the JSON should be equal to:
"""
{
"members_count": 2,
"members_count": 3,
"members_em_count": 0,
"sympathizers_count": 0,
"description": "my desc",
Expand Down
9 changes: 5 additions & 4 deletions features/api/elected_representatives.feature
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,11 @@ Feature:
"adherent:a_jour_2025": "Adhérent - À jour 2025",
"adherent:a_jour_2025:primo": "Adhérent - À jour 2025 - Primo-adhérent",
"adherent:a_jour_2025:recotisation": "Adhérent - À jour 2025 - Recotisation",
"adherent:a_jour_2025:elu_a_jour": "Adhérent - À jour 2025 - Car à jour de cotisation élu",
"adherent:a_jour_2024": "Adhérent - À jour 2024",
"adherent:a_jour_2023": "Adhérent - À jour 2023",
"adherent:a_jour_2022": "Adhérent - À jour 2022",
"adherent:a_jour_2025:elu_a_jour": "Adhérent - À jour 2025 - Élu à jour",
"adherent:plus_a_jour": "Adhérent - Plus à jour",
"adherent:plus_a_jour:annee_2024": "Adhérent - Plus à jour - À jour 2024",
"adherent:plus_a_jour:annee_2023": "Adhérent - Plus à jour - À jour 2023",
"adherent:plus_a_jour:annee_2022": "Adhérent - Plus à jour - À jour 2022",
"sympathisant": "Sympathisant",
"sympathisant:adhesion_incomplete": "Sympathisant - Adhésion incomplète",
"sympathisant:compte_em": "Sympathisant - Ancien compte En Marche",
Expand Down
2 changes: 1 addition & 1 deletion features/api/events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@ Feature:
| gisele-berthoux@caramail.com | delegated_b24fea43-ecd8-4bf4-b500-6f97886ab77c | DELETE | /0e5f9f02-fa33-4c2c-a700-4235d752315b/image |

Scenario: As connected user I can subscribe to an event
Given I am logged with "[email protected]" via OAuth client "JeMengage Mobile" with scope "jemarche_app"
Given I am logged with "[email protected]" via OAuth client "JeMengage Mobile" with scope "jemarche_app"
When I send a "POST" request to "/api/v3/events/2b7238f9-10ca-4a39-b8a4-ad7f438aa95f/subscribe"
Then the response status code should be 400
And the JSON should be equal to:
Expand Down
6 changes: 3 additions & 3 deletions features/api/profile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ Feature:
"name": "Comité des 3 communes"
},
{
"members_count": 2,
"members_count": 3,
"sympathizers_count": 0,
"members_em_count": 0,
"description": "Un petit comité avec seulement 3 communes",
Expand Down Expand Up @@ -1655,7 +1655,7 @@ Feature:
"""

Scenario: As a logged-in user I can unregister
Given I am logged with "[email protected]" via OAuth client "JeMengage Mobile"
Given I am logged with "[email protected]" via OAuth client "JeMengage Mobile"
When I send a "POST" request to "/api/v3/profile/unregister" with body:
"""
{
Expand Down Expand Up @@ -1728,7 +1728,7 @@ Feature:
"type": "committee",
"uuid": "@uuid@",
"name": "Second Comité des 3 communes",
"members_count": 2,
"members_count": 3,
"assembly_committees_count": 2,
"can_change_committee": true,
"message": null
Expand Down
2 changes: 1 addition & 1 deletion features/api/statutory_message.feature
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Feature:
"label": "Message statutaire de test",
"subject": "Voici un message statutaire",
"status": "draft",
"recipient_count": 2,
"recipient_count": 3,
"preview_link": null,
"source": "api",
"author": {
Expand Down
8 changes: 7 additions & 1 deletion features/api/user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ Feature:
"total": 7,
"last_month": 7
},
"tags": [],
"tags": [
{
"code": "adherent:a_jour_2025:recotisation",
"label": "Adhérent à jour 2025",
"type": "adherent"
}
],
"cadre_access": true,
"cadre_auth_path": "/oauth/v2/auth?scope=jemengage_admin&response_type=code&client_id=4498e44f-f214-110d-8b76-98a83f9d2b0c&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth",
"instances": {
Expand Down
18 changes: 16 additions & 2 deletions src/Adherent/Tag/TagEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class TagEnum extends Enum
public const ADHERENT_YEAR_RECOTISATION_TAG_PATTERN = self::ADHERENT_YEAR_TAG_PATTERN.':recotisation';
public const ADHERENT_YEAR_ELU_TAG_PATTERN = self::ADHERENT_YEAR_TAG_PATTERN.':elu_a_jour';

public const ADHERENT_NOT_UP_TO_DATE = self::ADHERENT.':plus_a_jour';
public const ADHERENT_NOT_UP_TO_DATE_TAG_PATTERN = self::ADHERENT_NOT_UP_TO_DATE.':annee_%s';

public const SYMPATHISANT = 'sympathisant';
public const SYMPATHISANT_COMPTE_EM = 'sympathisant:compte_em';
public const SYMPATHISANT_COMPTE_AVECVOUS_JEMENGAGE = 'sympathisant:compte_avecvous_jemengage';
Expand Down Expand Up @@ -50,6 +53,7 @@ public static function getAdherentTags(bool $adherentOnly = false): array
\sprintf(self::ADHERENT_YEAR_PRIMO_TAG_PATTERN, $currentYear),
\sprintf(self::ADHERENT_YEAR_RECOTISATION_TAG_PATTERN, $currentYear),
\sprintf(self::ADHERENT_YEAR_ELU_TAG_PATTERN, $currentYear),
self::ADHERENT_NOT_UP_TO_DATE,
],
array_map(
fn (int $year) => self::getAdherentYearTag($year),
Expand Down Expand Up @@ -90,9 +94,19 @@ public static function getStaticTags(): array
];
}

public static function getAdherentYearTag(?int $year = null, string $tag = self::ADHERENT_YEAR_TAG_PATTERN): string
public static function getAdherentYearTag(?int $year = null, ?string $tag = null): string
{
return \sprintf($tag, $year ?? date('Y'));
$currentYear = date('Y');

if (!$tag) {
if (!$year || $currentYear == $year) {
$tag = self::ADHERENT_YEAR_TAG_PATTERN;
} else {
$tag = self::ADHERENT_NOT_UP_TO_DATE_TAG_PATTERN;
}
}

return \sprintf($tag, $year ?? $currentYear);
}

public static function includesTag(string $searchTag, array $previousTags): bool
Expand Down
25 changes: 9 additions & 16 deletions src/Adherent/Tag/TagGenerator/AdherentStatusTagGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ public function generate(Adherent $adherent, array $previousTags): array
return [\sprintf(TagEnum::ADHERENT_YEAR_RECOTISATION_TAG_PATTERN, $currentYear)];
}

if (
\count($adherent->getConfirmedPayments())
|| $adherent->hasRecentContribution()
) {
if (\count($adherent->getConfirmedPayments()) || $adherent->hasRecentContribution()) {
return [\sprintf(TagEnum::ADHERENT_YEAR_ELU_TAG_PATTERN, $currentYear)];
}

Expand All @@ -57,10 +54,8 @@ public function generate(Adherent $adherent, array $previousTags): array
&& $totalContributionPaymentsByYear[$currentYear] >= 30
&& (
!$adherent->findElectedRepresentativeMandates(true)
|| (
$adherent->exemptFromCotisation
|| ContributionStatusEnum::NOT_ELIGIBLE === $adherent->getContributionStatus()
)
|| $adherent->exemptFromCotisation
|| ContributionStatusEnum::NOT_ELIGIBLE === $adherent->getContributionStatus()
)
) {
return [\sprintf(TagEnum::ADHERENT_YEAR_ELU_TAG_PATTERN, $currentYear)];
Expand All @@ -71,27 +66,25 @@ public function generate(Adherent $adherent, array $previousTags): array
array_keys($countCotisationByYear),
array_keys($totalContributionPaymentsByYear)
));

unset($allYears[$currentYear]);
sort($allYears);
$allYears = array_reverse($allYears);
rsort($allYears);

foreach ($allYears as $year) {
if (\array_key_exists($year, $countCotisationByYear)) {
return [\sprintf(TagEnum::ADHERENT_YEAR_TAG_PATTERN, $year)];
return [TagEnum::getAdherentYearTag($year)];
}

if (
\array_key_exists($year, $totalContributionPaymentsByYear)
&& $totalContributionPaymentsByYear[$year] >= 30
&& (
!$adherent->findElectedRepresentativeMandates(true)
|| (
$adherent->exemptFromCotisation
|| ContributionStatusEnum::NOT_ELIGIBLE === $adherent->getContributionStatus()
)
|| $adherent->exemptFromCotisation
|| ContributionStatusEnum::NOT_ELIGIBLE === $adherent->getContributionStatus()
)
) {
return [\sprintf(TagEnum::ADHERENT_YEAR_TAG_PATTERN, $year)];
return [TagEnum::getAdherentYearTag($year)];
}
}
}
Expand Down
Loading

0 comments on commit 0c3998f

Please sign in to comment.