Add USER_ACCOUNT_ACTIVATED signal (#23296)

Plugins can listen to USER_ACCOUNT_ACTIVATED signal to perform custom logic.
This commit is contained in:
Omar Al-Ithawi
2020-09-21 16:57:32 +03:00
committed by GitHub
parent cf735e411d
commit fc0eb71918
3 changed files with 16 additions and 1 deletions

View File

@@ -70,6 +70,7 @@ from openedx.core.djangoapps.enrollments.api import (
get_enrollment_attributes,
set_enrollment_attributes
)
from openedx.core.djangoapps.signals.signals import USER_ACCOUNT_ACTIVATED
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.xmodule_django.models import NoneToEmptyManager
from openedx.core.djangolib.model_mixins import DeletableByUserValue
@@ -839,6 +840,7 @@ class Registration(models.Model):
def activate(self):
self.user.is_active = True
self.user.save(update_fields=['is_active'])
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)

View File

@@ -70,6 +70,17 @@ class TestActivateAccount(TestCase):
self.assertTrue(self.user.is_active)
self.assertFalse(mock_segment_identify.called)
@patch('student.models.USER_ACCOUNT_ACTIVATED')
def test_activation_signal(self, mock_signal):
"""
Verify that USER_ACCOUNT_ACTIVATED is emitted upon account email activation.
"""
assert not self.user.is_active, 'Ensure that the user starts inactive'
assert not mock_signal.send_robust.call_count, 'Ensure no signal is fired before activation'
self.registration.activate() # Until you explicitly activate it
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_account_activation_message(self):
"""
Verify that account correct activation message is displayed.

View File

@@ -33,5 +33,7 @@ COURSE_GRADE_NOW_FAILED = Signal(
]
)
# Signal that indicates that a user has become verified
# Signal that indicates that a user has become verified for certificate purposes
LEARNER_NOW_VERIFIED = Signal(providing_args=['user'])
USER_ACCOUNT_ACTIVATED = Signal(providing_args=["user"]) # Signal indicating email verification