Skip to content

feat: reject unenrolments if less than 48h to the event occurrence#505

Merged
nikomakela merged 1 commit into
mainfrom
KK-1436-reject-unenrolments-48h
Jun 3, 2025
Merged

feat: reject unenrolments if less than 48h to the event occurrence#505
nikomakela merged 1 commit into
mainfrom
KK-1436-reject-unenrolments-48h

Conversation

@nikomakela

Copy link
Copy Markdown
Contributor

KK-1436.

Configure KUKKUU_ENROLMENT_UNENROL_HOURS_BEFORE with environment variable and use it to limit unenrolments too late before an occurrence start time. The default value is set to 48h. Use 0 as a value to disable this new feature.

The UI changes are implemented in
City-of-Helsinki/kukkuu-ui#693.

@nikomakela nikomakela self-assigned this May 29, 2025
@nikomakela nikomakela added the Comodori Team Comodori's projected work. label May 29, 2025
@terovirtanen

Copy link
Copy Markdown
Contributor

KUKKUU-API branch is deployed to platta: https://kukkuu-pr505.api.dev.hel.ninja 🚀🚀🚀

@terovirtanen

Copy link
Copy Markdown
Contributor

TestCafe result is success for https://kukkuu-pr505.api.dev.hel.ninja 😆🎉🎉🎉

@nikomakela nikomakela force-pushed the KK-1436-reject-unenrolments-48h branch from 5ec6294 to bf2d67d Compare May 30, 2025 06:29
@terovirtanen

Copy link
Copy Markdown
Contributor

KUKKUU-API branch is deployed to platta: https://kukkuu-pr505.api.dev.hel.ninja 🚀🚀🚀

@terovirtanen

Copy link
Copy Markdown
Contributor

TestCafe result is success for https://kukkuu-pr505.api.dev.hel.ninja 😆🎉🎉🎉

Comment thread events/tests/test_api.py

@freeze_time("2024-01-01 12:00:00")
def test_cannot_unenrol_within_48_hours(guardian_api_client, child_with_user_guardian):
# Create occurrence 47 hours in future (within 48 hour limit)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about setting the explicit value for the environment variable here so the test is robust against local .env file changes?

Suggested change
# Create occurrence 47 hours in future (within 48 hour limit)
settings.KUKKUU_ENROLMENT_UNENROL_HOURS_BEFORE = 48
# Create occurrence 47 hours in future (within 48 hour limit)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it, it's testing the default behaviour and that's what I think we should use. I have not added the environment variable to pipeline configurations at all, so I'm trusting in default value.

@karisal-anders karisal-anders Jun 2, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the tests assume that the value is always set to 48 then how about adding a simple test case for that? I mean a test case just for testing that KUKKUU_ENROLMENT_UNENROL_HOURS_BEFORE is 48. Otherwise there is a hidden dependency that one can not override the environment variable to any other value in any environment when running the tests or these cases will fail. They will do so with the added test case also though, but at least then the dependency on the value being 48 in environment would be documented by it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added settings.KUKKUU_ENROLMENT_UNENROL_HOURS_BEFORE = 48

Comment thread events/tests/test_api.py

@freeze_time("2024-01-01 12:00:00")
def test_can_unenrol_outside_48_hours(guardian_api_client, child_with_user_guardian):
# Create occurrence 49 hours in future (outside 48 hour limit)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about setting the explicit value for the environment variable here so the test is robust against local .env file changes?

Suggested change
# Create occurrence 49 hours in future (outside 48 hour limit)
settings.KUKKUU_ENROLMENT_UNENROL_HOURS_BEFORE = 48
# Create occurrence 49 hours in future (outside 48 hour limit)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikomakela nikomakela Jun 3, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added settings.KUKKUU_ENROLMENT_UNENROL_HOURS_BEFORE = 48

@karisal-anders karisal-anders left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The KUKKUU_ENROLMENT_UNENROL_HOURS_BEFORE variable could be explicitly set in the test cases that need it to be set to 48 for the test case to pass for added robustness but otherwise looks ok.

I assume Ratkaisutoimisto would want to code review this PR on their own before merging is possible.

@nikomakela nikomakela marked this pull request as ready for review June 2, 2025 06:46
@nikomakela nikomakela requested a review from a team as a code owner June 2, 2025 06:46
@nikomakela

Copy link
Copy Markdown
Contributor Author

Before merging this, the City-of-Helsinki/kukkuu-ui#693 should be merged, so also the UI reacts to this change.

@tuomas777

Copy link
Copy Markdown
Contributor

The KUKKUU_ENROLMENT_UNENROL_HOURS_BEFORE variable could be explicitly set in the test cases that need it to be set to 48 for the test case to pass for added robustness but otherwise looks ok.

I assume Ratkaisutoimisto would want to code review this PR on their own before merging is possible.

I agree with Kari, the tests shouldn't be counting on same value that can be overridden by .env, that can be very annoying in local development 🙂

Comment thread events/schema.py Outdated

# Get the unenrol hours limit from settings, 0 means no time limit
# (only past occurrences are not allowed to unenrol).
hours_before = getattr(settings, "KUKKUU_ENROLMENT_UNENROL_HOURS_BEFORE", 48)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can trust the settings default value and let it fail / error if it for some reason is None

KK-1436.

Configure `KUKKUU_ENROLMENT_UNENROL_HOURS_BEFORE` with environment
variable and use it to limit unenrolments too late before an occurrence
start time. The default value is set to 48h. Use 0 as a value to disable
this new feature.

The UI changes are implemented in
City-of-Helsinki/kukkuu-ui#693.
@nikomakela nikomakela force-pushed the KK-1436-reject-unenrolments-48h branch from bf2d67d to 79ad9bc Compare June 3, 2025 09:04
@nikomakela nikomakela requested review from nicobav and tuomas777 June 3, 2025 09:10
@sonarqubecloud

sonarqubecloud Bot commented Jun 3, 2025

Copy link
Copy Markdown

@terovirtanen

Copy link
Copy Markdown
Contributor

KUKKUU-API branch is deployed to platta: https://kukkuu-pr505.api.dev.hel.ninja 🚀🚀🚀

@terovirtanen

Copy link
Copy Markdown
Contributor

TestCafe result is success for https://kukkuu-pr505.api.dev.hel.ninja 😆🎉🎉🎉

@nikomakela nikomakela merged commit f196eba into main Jun 3, 2025
23 checks passed
@nikomakela nikomakela deleted the KK-1436-reject-unenrolments-48h branch June 3, 2025 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Comodori Team Comodori's projected work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants