Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/djangoapps/student/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangoapps.request_cache import clear_cache, get_cache
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
Expand Down Expand Up @@ -728,6 +729,7 @@ def activate(self):
self.user.is_active = True
self._track_activation()
self.user.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)

def _track_activation(self):
Expand Down
13 changes: 13 additions & 0 deletions common/djangoapps/student/tests/test_activate_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ def test_activation_with_keys(self, mock_segment_identify):
expected_segment_mailchimp_list
)

@patch('student.models.USER_ACCOUNT_ACTIVATED')
def test_activation_signal(self, mock_signal):
"""
Verify that USER_ACCOUNT_ACTIVATED is emitted upon account email activation.

Appsembler: This is a custom code to be pushed upstream.
"""
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'

@override_settings(LMS_SEGMENT_KEY="testkey")
@patch('student.models.analytics.identify')
def test_activation_without_mailchimp_key(self, mock_segment_identify):
Expand Down
4 changes: 3 additions & 1 deletion openedx/core/djangoapps/signals/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@
]
)

# 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
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ commands =
bash scripts/upgrade_pysqlite.sh
{env:TRAVIS_FIXES}
pytest \
common/djangoapps/student/tests/test_activate_account.py \
common/djangoapps/util/tests/test_milestones_helpers.py \
common/lib/xmodule/xmodule/modulestore/tests/test_split_mongo_mongo_connection.py

Expand Down