datetimestamp added for account activation event
VAN-390
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 2.2.19 on 2021-03-05 13:25
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('student', '0040_usercelebration'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='registration',
|
||||
name='activation_timestamp',
|
||||
field=models.DateTimeField(blank=True, default=None, null=True),
|
||||
),
|
||||
]
|
||||
@@ -905,6 +905,7 @@ class Registration(models.Model):
|
||||
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
activation_key = models.CharField((u'activation key'), max_length=32, unique=True, db_index=True)
|
||||
activation_timestamp = models.DateTimeField(default=None, null=True, blank=True)
|
||||
|
||||
def register(self, user):
|
||||
# MINOR TODO: Switch to crypto-secure key
|
||||
@@ -915,6 +916,8 @@ class Registration(models.Model):
|
||||
def activate(self):
|
||||
self.user.is_active = True
|
||||
self.user.save(update_fields=['is_active'])
|
||||
self.activation_timestamp = datetime.utcnow()
|
||||
self.save()
|
||||
USER_ACCOUNT_ACTIVATED.send_robust(self.__class__, user=self.user)
|
||||
log.info(u'User %s (%s) account is successfully activated.', self.user.username, self.user.email)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
import unittest
|
||||
from uuid import uuid4
|
||||
from datetime import datetime
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
|
||||
@@ -87,6 +88,16 @@ class TestActivateAccount(TestCase):
|
||||
assert self.user.is_active, 'Sanity check for .activate()'
|
||||
mock_signal.send_robust.assert_called_once_with(Registration, user=self.user) # Ensure the signal is emitted
|
||||
|
||||
def test_activation_timestamp(self):
|
||||
""" Assert that activate sets the flag but does not call segment. """
|
||||
# Ensure that the user starts inactive
|
||||
assert not self.user.is_active
|
||||
# Until you explicitly activate it
|
||||
timestamp_before_activation = datetime.utcnow()
|
||||
self.registration.activate()
|
||||
assert self.user.is_active
|
||||
assert self.registration.activation_timestamp > timestamp_before_activation
|
||||
|
||||
def test_account_activation_message(self):
|
||||
"""
|
||||
Verify that account correct activation message is displayed.
|
||||
|
||||
@@ -534,6 +534,7 @@ def activate_account(request, key):
|
||||
USER_ACCOUNT_ACTIVATED,
|
||||
{
|
||||
"user_id": registration.user.id,
|
||||
"activation_timestamp": registration.activation_timestamp
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user