-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(task-processor): Add recurring task to clean password reset (#3153)
- Loading branch information
1 parent
9178604
commit 6898253
Showing
6 changed files
with
61 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class CustomAuthAppConfig(AppConfig): | ||
name = "custom_auth" | ||
|
||
def ready(self) -> None: | ||
from custom_auth import tasks # noqa F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from datetime import timedelta | ||
|
||
from django.conf import settings | ||
from django.utils import timezone | ||
|
||
from custom_auth.models import UserPasswordResetRequest | ||
from task_processor.decorators import register_recurring_task | ||
|
||
|
||
@register_recurring_task( | ||
run_every=timedelta(seconds=settings.PASSWORD_RESET_EMAIL_COOLDOWN), | ||
) | ||
def clean_up_user_password_reset_request(): | ||
UserPasswordResetRequest.objects.filter( | ||
requested_at__lt=timezone.now() | ||
- timedelta(seconds=settings.PASSWORD_RESET_EMAIL_COOLDOWN) | ||
).delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from datetime import timedelta | ||
|
||
from django.utils import timezone | ||
from pytest_django.fixtures import SettingsWrapper | ||
|
||
from custom_auth.models import UserPasswordResetRequest | ||
from custom_auth.tasks import clean_up_user_password_reset_request | ||
from users.models import FFAdminUser | ||
|
||
|
||
def test_clean_up_user_password_reset_request( | ||
settings: SettingsWrapper, test_user: FFAdminUser, freezer | ||
): | ||
# Given | ||
settings.PASSWORD_RESET_EMAIL_COOLDOWN = 10 | ||
now = timezone.now() | ||
|
||
# A user password reset request should be deleted | ||
UserPasswordResetRequest.objects.create(user=test_user) | ||
|
||
freezer.move_to(now + timedelta(seconds=11)) | ||
|
||
# A user password reset request should not be deleted | ||
new_user_password_reset_request = UserPasswordResetRequest.objects.create( | ||
user=test_user | ||
) | ||
# When | ||
clean_up_user_password_reset_request() | ||
|
||
# Then | ||
assert UserPasswordResetRequest.objects.count() == 1 | ||
assert ( | ||
UserPasswordResetRequest.objects.first().id | ||
== new_user_password_reset_request.id | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6898253
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
flagsmith-frontend-staging – ./frontend
flagsmith-frontend-staging-git-main-flagsmith.vercel.app
staging.flagsmith.com
flagsmith-staging-frontend.vercel.app
flagsmith-frontend-staging-flagsmith.vercel.app
6898253
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
flagsmith-frontend-preview – ./frontend
flagsmith-frontend-preview-git-main-flagsmith.vercel.app
flagsmith-frontend-preview-flagsmith.vercel.app
flagsmith-frontend-production-native.vercel.app
6898253
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
docs – ./docs
docs.flagsmith.com
docs-flagsmith.vercel.app
docs.bullet-train.io
docs-git-main-flagsmith.vercel.app