-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
14 changed files
with
227 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
""" | ||
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, | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.