Files
edx-platform/lms/djangoapps/verify_student/signals/signals.py
Isaac Lee 575e240961 feat: add idv events to api (#35468)
* feat: add idv events to api

- moved what was in signals.py to a handlers.py (which is what their file should have been called)

* chore: quality

* fix: rename test file + imports

* fix: change handler reverse url in other tests

* fix: refactor signals and handlers pattern

- following OEP-49 pattern for signals directory
- user removed as param for update function
- event now emitted after save

* fix: unpin edx-name-affirmation

* chore: add init to signals dir

* fix: compile requirements

* chore: quality

* chore: fix some imports

* chore: quality

* test: added signal emissions to test_api

* chore: lint
2024-09-17 15:59:33 -04:00

110 lines
2.9 KiB
Python

"""
Signal definitions and functions to send those signals for the verify_student application.
"""
from django.dispatch import Signal
from openedx_events.learning.data import UserData, UserPersonalData, VerificationAttemptData
from openedx_events.learning.signals import (
IDV_ATTEMPT_CREATED,
IDV_ATTEMPT_PENDING,
IDV_ATTEMPT_APPROVED,
IDV_ATTEMPT_DENIED,
)
# Signal for emitting IDV submission and review updates
# providing_args = ["attempt_id", "user_id", "status", "full_name", "profile_name"]
idv_update_signal = Signal()
def _create_user_data(user):
"""
Helper function to create a UserData object.
"""
user_data = UserData(
id=user.id,
is_active=user.is_active,
pii=UserPersonalData(
username=user.username,
email=user.email,
name=user.get_full_name()
)
)
return user_data
def emit_idv_attempt_created_event(attempt_id, user, status, name, expiration_date):
"""
Emit the IDV_ATTEMPT_CREATED Open edX event.
"""
user_data = _create_user_data(user)
# .. event_implemented_name: IDV_ATTEMPT_CREATED
IDV_ATTEMPT_CREATED.send_event(
idv_attempt=VerificationAttemptData(
attempt_id=attempt_id,
user=user_data,
status=status,
name=name,
expiration_date=expiration_date,
)
)
return user_data
def emit_idv_attempt_pending_event(attempt_id, user, status, name, expiration_date):
"""
Emit the IDV_ATTEMPT_PENDING Open edX event.
"""
user_data = _create_user_data(user)
# .. event_implemented_name: IDV_ATTEMPT_PENDING
IDV_ATTEMPT_PENDING.send_event(
idv_attempt=VerificationAttemptData(
attempt_id=attempt_id,
user=user_data,
status=status,
name=name,
expiration_date=expiration_date,
)
)
return user_data
def emit_idv_attempt_approved_event(attempt_id, user, status, name, expiration_date):
"""
Emit the IDV_ATTEMPT_APPROVED Open edX event.
"""
user_data = _create_user_data(user)
# .. event_implemented_name: IDV_ATTEMPT_APPROVED
IDV_ATTEMPT_APPROVED.send_event(
idv_attempt=VerificationAttemptData(
attempt_id=attempt_id,
user=user_data,
status=status,
name=name,
expiration_date=expiration_date,
)
)
return user_data
def emit_idv_attempt_denied_event(attempt_id, user, status, name, expiration_date):
"""
Emit the IDV_ATTEMPT_DENIED Open edX event.
"""
user_data = _create_user_data(user)
# .. event_implemented_name: IDV_ATTEMPT_DENIED
IDV_ATTEMPT_DENIED.send_event(
idv_attempt=VerificationAttemptData(
attempt_id=attempt_id,
user=user_data,
status=status,
name=name,
expiration_date=expiration_date,
)
)