Skip to content

Commit 58de096

Browse files
authored
feat: removing visible_date-to-creds updates per-cert (#35113)
* feat: removing visible_date-to-creds updates per-cert The credentials IDA now relies on the course certificate configuration and (if present) `certificate_available_date` for displayability. We no longer need to send `visible_date` updates for every awarded certificate when a course overview changes.
1 parent 3589d96 commit 58de096

12 files changed

Lines changed: 116 additions & 250 deletions

File tree

cms/djangoapps/contentstore/docs/diagrams/visible_date_and_certificate_available_date.dsl renamed to cms/djangoapps/contentstore/docs/diagrams/certificate_available_date.dsl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* This is a high level diagram visualizing how the `CERTIFICATE_AVAILBLE_DATE` and "visible date" attribute updates
3-
* are updated internally and transmit to the Credentials IDA.
2+
* This is a high level diagram visualizing how the `CERTIFICATE_AVAILBLE_DATE` update is
3+
* updated internally and transmitted to the Credentials IDA.
44
*
55
* It is written using Structurizr DSL (https://structurizr.org/).
66
*/
@@ -33,9 +33,7 @@ workspace {
3333
co_app -> modulestore "Retrieves course details from Mongo"
3434
co_app -> monolith_db "Updates CourseOverview record"
3535
co_app -> programs_app "Emits COURSE_CERT_DATE_CHANGED signal"
36-
programs_app -> celery "Enqueue UPDATE_CERTIFICATE_VISIBLE_DATE task"
3736
programs_app -> celery "Enqueue UPDATE_CERTIFICATE_AVAILABLE_DATE task"
38-
celery -> credentials "REST requests to update `visible_date` attributes"
3937
celery -> credentials "REST request to update `certificate_available_date` setting"
4038
}
4139

382 KB
Loading

lms/djangoapps/certificates/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ def _course_uses_available_date(course):
849849
)
850850

851851

852-
def available_date_for_certificate(course, certificate):
852+
def available_date_for_certificate(course, certificate) -> datetime:
853853
"""
854854
Returns the available date to use with a certificate
855855

lms/envs/production.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,8 +1063,6 @@ def get_env_setting(setting):
10631063
'queue': PROGRAM_CERTIFICATES_ROUTING_KEY},
10641064
'openedx.core.djangoapps.programs.tasks.revoke_program_certificates': {
10651065
'queue': PROGRAM_CERTIFICATES_ROUTING_KEY},
1066-
'openedx.core.djangoapps.programs.tasks.update_certificate_visible_date_on_course_update': {
1067-
'queue': PROGRAM_CERTIFICATES_ROUTING_KEY},
10681066
'openedx.core.djangoapps.programs.tasks.update_certificate_available_date_on_course_update': {
10691067
'queue': PROGRAM_CERTIFICATES_ROUTING_KEY},
10701068
'openedx.core.djangoapps.programs.tasks.award_course_certificate': {

openedx/core/djangoapps/catalog/utils.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import datetime
55
import logging
66
import uuid
7+
from typing import TYPE_CHECKING, Any, List, Union
78

89
import pycountry
910
import requests
@@ -31,6 +32,9 @@
3132
from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user
3233
from openedx.core.lib.edx_api_utils import get_api_data
3334

35+
if TYPE_CHECKING:
36+
from django.contrib.sites.models import Site
37+
3438
logger = logging.getLogger(__name__)
3539

3640
missing_details_msg_tpl = "Failed to get details for program {uuid} from the cache."
@@ -98,7 +102,14 @@ def check_catalog_integration_and_get_user(error_message_field):
98102

99103

100104
# pylint: disable=redefined-outer-name
101-
def get_programs(site=None, uuid=None, uuids=None, course=None, catalog_course_uuid=None, organization=None):
105+
def get_programs(
106+
site: "Site" = None,
107+
uuid: str = None,
108+
uuids: List[str] = None,
109+
course: str = None,
110+
catalog_course_uuid: str = None,
111+
organization: str = None,
112+
) -> Union[str, List[str]]:
102113
"""Read programs from the cache.
103114
104115
The cache is populated by a management command, cache_programs.
@@ -112,7 +123,7 @@ def get_programs(site=None, uuid=None, uuids=None, course=None, catalog_course_u
112123
organization (string): short name for specific organization to read from the cache.
113124
114125
Returns:
115-
list of dict, representing programs.
126+
list of str, representing programs.
116127
dict, if a specific program is requested.
117128
"""
118129
if len([arg for arg in (site, uuid, uuids, course, catalog_course_uuid, organization) if arg is not None]) != 1:
@@ -194,7 +205,7 @@ def get_programs_by_type_slug(site, program_type_slug):
194205
return get_programs_by_uuids(uuids)
195206

196207

197-
def get_programs_by_uuids(uuids):
208+
def get_programs_by_uuids(uuids: List[Any]) -> List[str]:
198209
"""
199210
Gets a list of programs for the provided uuids
200211
"""

openedx/core/djangoapps/credentials/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def get_credentials_records_url(program_uuid=None):
3737
return base_url
3838

3939

40-
def get_credentials_api_client(user):
40+
def get_credentials_api_client(user) -> requests.Session:
4141
"""
4242
Returns an authenticated Credentials API client.
4343

openedx/core/djangoapps/programs/docs/decisions/0001-sync-certificate-available-dates.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Sync certificate_available_date and visible_date for certificates
44
Status
55
------
66

7-
Review
7+
Superseded by Credentials ADR `0001 Certificate Available Date`_.
8+
9+
.. _0001 Certificate Available Date: https://github.com/openedx/edx-platform/blob/master/openedx/core/djangoapps/oauth_dispatch/docs/decisions/0005-restricted-application-for-SSO.rst
810

911
Context
1012
-------

openedx/core/djangoapps/programs/signals.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
This module contains signals / handlers related to programs.
33
"""
44

5-
65
import logging
76

87
from django.dispatch import receiver
@@ -14,7 +13,7 @@
1413
COURSE_CERT_AWARDED,
1514
COURSE_CERT_CHANGED,
1615
COURSE_CERT_DATE_CHANGE,
17-
COURSE_CERT_REVOKED
16+
COURSE_CERT_REVOKED,
1817
)
1918

2019
LOGGER = logging.getLogger(__name__)
@@ -39,11 +38,10 @@ def handle_course_cert_awarded(sender, user, course_key, mode, status, **kwargs)
3938
if not is_credentials_enabled():
4039
return
4140

42-
LOGGER.debug(
43-
f"Handling COURSE_CERT_AWARDED: user={user}, course_key={course_key}, mode={mode}, status={status}"
44-
)
41+
LOGGER.debug(f"Handling COURSE_CERT_AWARDED: user={user}, course_key={course_key}, mode={mode}, status={status}")
4542
# import here, because signal is registered at startup, but items in tasks are not yet able to be loaded
4643
from openedx.core.djangoapps.programs.tasks import award_program_certificates
44+
4745
award_program_certificates.delay(user.username)
4846

4947

@@ -68,7 +66,7 @@ def handle_course_cert_changed(sender, user, course_key, mode, status, **kwargs)
6866
Returns:
6967
None
7068
"""
71-
verbose = kwargs.get('verbose', False)
69+
verbose = kwargs.get("verbose", False)
7270
if verbose:
7371
LOGGER.info(
7472
f"Starting handle_course_cert_changed with params: sender [{sender}], user [{user}], course_key "
@@ -87,6 +85,7 @@ def handle_course_cert_changed(sender, user, course_key, mode, status, **kwargs)
8785
LOGGER.debug(f"Handling COURSE_CERT_CHANGED: user={user}, course_key={course_key}, mode={mode}, status={status}")
8886
# import here, because signal is registered at startup, but items in tasks are not yet able to be loaded
8987
from openedx.core.djangoapps.programs.tasks import award_course_certificate
88+
9089
award_course_certificate.delay(user.username, str(course_key))
9190

9291

@@ -112,16 +111,16 @@ def handle_course_cert_revoked(sender, user, course_key, mode, status, **kwargs)
112111
LOGGER.info(f"Handling COURSE_CERT_REVOKED: user={user}, course_key={course_key}, mode={mode}, status={status}")
113112
# import here, because signal is registered at startup, but items in tasks are not yet able to be loaded
114113
from openedx.core.djangoapps.programs.tasks import revoke_program_certificates
114+
115115
revoke_program_certificates.delay(user.username, str(course_key))
116116

117117

118-
@receiver(COURSE_CERT_DATE_CHANGE, dispatch_uid='course_certificate_date_change_handler')
118+
@receiver(COURSE_CERT_DATE_CHANGE, dispatch_uid="course_certificate_date_change_handler")
119119
def handle_course_cert_date_change(sender, course_key, **kwargs): # pylint: disable=unused-argument
120120
"""
121121
When a course run's configuration has been updated, and the system has detected an update related to the display
122122
behavior or availability date of the certificates issued in that course, we should enqueue celery tasks responsible
123123
for:
124-
- updating the `visible_date` attribute of any previously awarded certificates the Credentials IDA manages
125124
- updating the certificate available date of the course run's course certificate configuration in Credentials
126125
127126
Args:
@@ -137,6 +136,7 @@ def handle_course_cert_date_change(sender, course_key, **kwargs): # pylint: dis
137136
LOGGER.info(f"Handling COURSE_CERT_DATE_CHANGE for course {course_key}")
138137
# import here, because signal is registered at startup, but items in tasks are not yet loaded
139138
from openedx.core.djangoapps.programs.tasks import update_certificate_available_date_on_course_update
139+
140140
update_certificate_available_date_on_course_update.delay(str(course_key))
141141

142142

@@ -161,4 +161,5 @@ def handle_course_pacing_change(sender, updated_course_overview, **kwargs): # p
161161
LOGGER.info(f"Handling COURSE_PACING_CHANGED for course {course_id}")
162162
# import here, because signal is registered at startup, but items in tasks are not yet loaded
163163
from openedx.core.djangoapps.programs.tasks import update_certificate_available_date_on_course_update
164+
164165
update_certificate_available_date_on_course_update.delay(course_id)

0 commit comments

Comments
 (0)