Conversation
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughCentralized activation eligibility into a new Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@authentication/services.py`:
- Around line 138-139: The call that sets user.last_login (user.last_login =
timezone.now(); user.save(update_fields=["last_login"])) affects Django's
default_token_generator and thus invalidates prior activation/reset tokens;
either remove/avoid updating last_login in the token-generation path or
(preferably) add a guard in resend_activation_link_api_view to only send
activation emails to users that pass check_can_activate() so users with an
existing last_login aren't emailed. Locate the token-generation code that sets
last_login and either stop updating last_login there, or modify
resend_activation_link_api_view to call user.check_can_activate() and only send
when it returns True.
🧹 Nitpick comments (1)
authentication/services.py (1)
67-78: Redundant conditions beforecheck_can_activate().At line 77,
check_can_activate()testsnot is_active and not last_login and not is_spam. By this point,is_activeis guaranteedFalse(line 71 returns early if active) andis_spamis guaranteedFalse(line 74 raises). So the only net-new condition added bycheck_can_activate()isnot self.last_login.This works correctly but is misleading — a reader might think the method performs a comprehensive gate here when most of its conditions are already covered. Consider either:
- Using
check_can_activate()as the sole gate (replacing the individual checks), or- Checking
last_logindirectly here instead, for clarity.Option A: Consolidate into a single gate
if not user: raise ValidationError({"token": ["Invalid user"]}) if not default_token_generator.check_token(user, token): raise ValidationError({"token": ["Activation Token is expired or invalid"]}) - # Skip if user is already active - if user.is_active: - return user - - if user.is_spam: - raise ValidationError({"user": ["User is marked as spam"]}) - - if not user.check_can_activate(): + if user.is_active: + return user + + if not user.check_can_activate(): raise ValidationError({"user": ["User can't be activated"]})Option B: Explicit last_login check instead
- if not user.check_can_activate(): - raise ValidationError({"user": ["User can't be activated"]}) + if user.last_login is not None: + raise ValidationError({"user": ["User can't be activated"]})
🧹 Preview Environment Cleaned UpThe preview environment for this PR has been destroyed.
Cleanup triggered by PR close at 2026-02-06T17:49:42Z |
get_tokens_for_userfunction to bumplast_loginfieldSummary by CodeRabbit
Bug Fixes
Refactor