198 Commits

Author SHA1 Message Date
Tarun Tak
18d5abb2f6 chore: Replace pytz with zoneinfo for UTC handling - Part 1 (#37523)
First PR to replace pytz with zoneinfo for UTC handling across codebase.

This PR migrates all UTC timezone handling from pytz to Python’s standard
library zoneinfo. The pytz library is now deprecated, and its documentation
recommends using zoneinfo for all new code. This update modernizes our
codebase, removes legacy pytz usage, and ensures compatibility with
current best practices for timezone management in Python 3.9+. No functional
changes to timezone logic - just a direct replacement for UTC handling.

https://github.com/openedx/edx-platform/issues/33980
2025-10-28 16:23:22 -04:00
Justin Hynes
17122eb442 refactor: remove PII from log messages in programs tasks (#35623)
* refactor: remove PII from log messages in programs tasks

[APER-3723]

Refactors a number of log statements from the Celery tasks in the Programs Django app. This removes username (considered PII) from the log statements and opts to use LMS User ID instead.

* fix: quality
2024-10-15 08:33:36 -04:00
Juliana Kang
51d538cbe7 fix: Remove B2C Subscriptions (#35303)
REV-3697
2024-09-04 14:01:45 -04:00
Deborah Kaplan
58de0964ca 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.
2024-07-17 08:43:12 -04:00
Deborah Kaplan
c6301b3709 feat: removing the job runners in advance of removing the code (#35115)
* @justinhynes  pointed out that the task queues  might be populated with the to-be-removed task during a blue-green deployment, and it makes sense to remove the  job that queues up  the tasks slated for removal _before_ removing the code for those tasks.
* fixed a mock import order: 2 mocks were brought in an opposite order, but until this change, they
always had the same result  so nobody had noticed.

FIXES: APER-3535
2024-07-12 17:34:42 +00:00
Deborah Kaplan
8c40057c10 feat: switching to celery native backoff for cert awarding (#35009)
* feat: switching to celery native backoff for cert awarding

Our homegrown backoff/retry was good enough for a while, but we ran into
a huge disabling event when too many changes were made simultaneously.
Since this code was first written, celery has built in good back
off/retry functionality, including jitter, to make sure that all the
retries don't happen simultaneously.

* Switches to using celery native backoff
* Refactors a huge try/catch block so the exception handling is on
  smaller subsets of code

FIXES: APER-3510

* feat: switching to celery native backoff for cert awarding

* Fixed the grammar in a couple of comments
* fixed a couple of lending errors

FIXES: APER-3510

* feat: limiting PII in logs per code review

per code review

FIXES: APER-3510

* feat: code review feedback

* removing some more PII from logs, even where it was not requested
* circuit breaker returned from grading attempt if course key is bad
* add missing tests for that functionality

FIXES: APER-3510

* feat:  improved logging

per code review, adding a log message explaining certificate mode
issues

FIXES: APER-3510

* feat:  fixing a bad string

lint error, and left off the format string modifier

FIXES: APER-3510

* feat: style

linter error

FIXES: APER-3510
2024-06-26 11:45:28 -04:00
Justin Hynes
7f62080c95 refactor: update logs, remove direct use of CredentialsApiConfig model (#34393)
[APER-3229]

In a previous PR, I created a new utility function named `is_credentials_enabled()` that can be used to determine if use of the Credentials IDA is enabled by config in an Open edX instance.

This PR is some additional cleanup that replaces the direct import and use of the `CredentialsApiConfig` model with the new utility function.

I took some additional time to update some existing log messages to include more info while reducing our need to log PII. I've removed as much use of a learner's username as possible, replacing it with logging the learner's LMS User Id instead.
2024-03-26 08:29:11 -04:00
Justin Hynes
8d7a13f358 feat: update task and signals responsible for cert available dates in Credentials
[APER-3229]

The monolith and the Credentials IDA keep independent records of a course runs certificate availability/visibility preferences. This PR aims to improve the communication between the monolith and the Credentiala IDA to keep the availability date/preference in sync with the monoliths records.

The current code is too strict and actually prevents valid updates in some configurations.

Additionally, the Credentials IDA doesn't understand the concept of "course pacing" (instructor-paced vs self-paced) and has troubles with courses with an availability date of "end". Instead of having to add the concept of course pacing (and syncing more data between the two systems), this PR proposes sending the end date of a course as the "certificate available date" to Credentials.

This way, the Credentials IDA can manage the visibility of awarded credentials in a course run with a display behavior of "end" using the existing feature set and models of the Credentials service.
2024-03-18 12:30:40 +00:00
Deborah Kaplan
adae7e3e25 feat: relinting
Trying with new autoformat settings.

FIXES: APER-3146
2024-01-30 17:39:57 +00:00
Deborah Kaplan
bde84117c3 feat: linting error
* unused import
* format

FIXES: APER-3146
2024-01-30 16:36:14 +00:00
Deborah Kaplan
918f32ab40 feat: fixed one test
* fixed one test to accommodate a slightly modified workflow
* allowed the automated linter  to match current standards

Note:  as part of this process, I realized a lot of the tests in `programs/tests/test_tasks.py` are somewhat problematic. Some aren't real unit tests (allow calls to something other than the system under test), at least one for that reason it won't run on local at all, and some mock the wrong part of the system  or just don't match current flow.  I'm not modifying them as part of this, but they should be looked at.

FIXES: APER-3146
2024-01-30 15:53:29 +00:00
Deborah Kaplan
ae3ce9c498 feat: fix exception handling in program cert revocation
To determine whether or not we need to  revoke any program certificates, we first run get_revokable_program_uuids. This calls get_certified_programs, which calls get_credentials, which uses the OpenEdx Core  utility method get_api_data. get_api_data makes the API call inside a try block, does raise_for_status  also inside the try block, and then catches the exception, logs it, and returns an empty result to the caller.

This means that on a failure to call the credentials API, get_credentials can’t  tell the difference between a failure to hit the API (because credentials is, as it sometimes is during a notify_programs run, overloaded), or a learner with no program certificates. In this particular case, this is absolute failure, incorrect behavior.

* Adds a new flag, `raise_on_error`  which will make `get_api_data` log the exception and then re-raise the HTTPError,  defaulting to false in order to avoid changing the behavior on any other callers
* Also: my editor reformatted all of the touched files to our modern code standards, and it seemed appropriate to let it do that.
* Also: added type hints in some cases, because they helped me write the code and debug. Our test suite definitely  reports mypy  results on type errors so we are verifying that hints are correct.

FIXES: APER-3146
2024-01-26 22:20:30 +00:00
Nawfal Ahmed
6a5c1bbf44 feat: update subscription enrollment alert (#32414) 2023-06-12 13:07:43 +00:00
Juliana Kang
c67408b9c5 fix: Modify nextPaymentDate in program details subscriptions (#32310)
PON-247
2023-05-26 10:50:39 -04:00
Mohammad Ahtasham ul Hassan
acc9dac627 fix: fix manage subs url, add orders and subs url (#32126)
* fix: fix manage subs url, add orders and subs url
2023-05-16 09:35:22 +05:00
Mohammad Ahtasham ul Hassan
2a7b400770 fix: fix buy_subscription_url to use get method (#32079)
* fix: fix buy_subscription_url to use get method
2023-04-18 15:31:32 +05:00
Mohammad Ahtasham ul Hassan
e973266b2f feat: fetch program subscription details (#32023)
* feat: fetch program subscription details
2023-04-14 16:33:12 +05:00
Justin Hynes
8fd59044f9 fix: improve Celery task that sends certificate availability date data to Credentials IDA
[APER-1941]

We are aware of a product issue that causes a `certificate_available_date` (CAD) to be set for self-paced courses (and thus copied to the course-run's (course) certificate configuration) that causes an issue with learners' Program Records to be inaccurate. The stored CAD in Credentials is causing these certificates to be marked as "unearned" on the Program Record in Credentials, as the IDA believes the learner should *not* have access to them yet (but these certificates are available in the LMS).

A management command was recently introduced in Studio that can be used to clean/remove the `certificate_available_date` data from a course-run in Mongo. These updates aren't making it to the Credentials IDA because of an issue with our logic in the `update_certificate_visible_date_on_course_update` Celery task. This task assumes that we only want to send updates for *Instructor-Paced* courses that have a Certificate Display Behavior set to `end_with_date`. In reality, we need updates to pass to Credentials for _some_ self-paced courses with bad data.

This PR hopes to update our infrastructure to allow these updates to flow to Credentials.

* Improve logging for failed requests to the Credentials IDA's `course_certificates` endpoint when updating a course certificate configuration.
* Update docstrings and comments where appropriate
* Split the logic of the update_certificate_visible_date_on_course_update task into two tasks. The former task will continue to _just_ handle visible_date attribute updates. The latter (new) task will be dedicated to making the REST API call that updates the `certificate_available_date` data in Credentials.
* Update the `handle_course_cert_date_change` function wqhen the COURSE_CERT_DATE_CHANGE signal is received to queue both the "visible_date" and "certificate available date" Celery tasks.
* Update existing tests for the task changes.
2022-09-29 14:42:22 -04:00
Eugene Dyudyunov
289e682b8f FC-0001: Remove old EdxRestAPIClient usage across the platform (#30301)
* refactor: remove EdxRestAPIClient

* test: update tests according to EdxRestAPIClient removal

* fix: remove unused import
2022-05-09 12:48:26 -04:00
Michael Terry
cb1bb7fa64 test: switch default test store to the split store
It's long past time that the default test modulestore was Split,
instead of Old Mongo. This commit switches the default store and
fixes some tests that now fail:
- Tests that didn't expect MFE to be enabled (because we don't
  enable MFE for Old Mongo) - opt out of MFE for those
- Tests that hardcoded old key string formats
- Lots of other random little differences

In many places, I didn't spend much time trying to figure out how to
properly fix the test, and instead just set the modulestore to Old
Mongo.

For those tests that I didn't spend time investigating, I've set
the modulestore to TEST_DATA_MONGO_AMNESTY_MODULESTORE - search for
that string to find further work.
2022-02-04 14:32:50 -05:00
Jawayria
7663592aa6 chore: Applied lint-amnesty on openedx/core/djangoapps 2021-12-09 13:37:27 +05:00
edX requirements bot
bb20b17428 Python Requirements Update (#29516)
* chore: Updating Python Requirements

* fix: fix pylint issues

Co-authored-by: Mohammad Ahtasham ul Hassan <mohammad.ahtasham@arbisoft.com>
2021-12-08 14:13:27 +05:00
Usama Sadiq
780a6f3c2d Revert "chore: install codejail from pypi (#29481)" (#29501)
This reverts commit 21551095ac.
2021-12-02 22:19:15 +05:00
Mohammad Ahtasham ul Hassan
21551095ac chore: install codejail from pypi (#29481)
* chore: install codejail from pypi

* chore: Updating Python Requirements

* chore: Updating Python Requirements

* fix: fixed failing tests

* fix: fixed pytest failures

* fix: fixed failing test bug

* Update mocks.py

Co-authored-by: edX requirements bot <testeng+edx-requirements-bot@edx.org>
2021-12-02 17:07:29 +05:00
Olivia Ruiz-Knott
5678b9e036 Merge pull request #28715 from edx/ork/MICROBA-1488_change-override-to-datetime-field
feat: Change override date to datetime
2021-09-13 09:23:46 -06:00
oliviaruizknott
59fefa10eb feat: Change override date to datetime
When first building the Certificate Date Override feature, I set up the
CertificateDateOverride model to store the override dates as Dates
instead of DateTimes.

Turns out this is not how edX typically handles dates, and it’s causing
some minor headaches around needing to convert values. Also, using just
Dates causes timezone issues.

MICROBA-1488
2021-09-10 14:42:36 -06:00
Albert (AJ) St. Aubin
a235f497ac feat: Remove email sent with program cert award.
[MICROBA-1466]
2021-09-10 13:57:52 -04:00
Albert (AJ) St. Aubin
a28f54bf4a feat: Added lms_user_id and email to data sent to Credentials for Program certs
[MICROBA-1466]
2021-09-08 15:05:09 -04:00
oliviaruizknott
e99029659c feat: Send date override to credentials
When sending a GeneratedCertificate to Credentials, send the associated
CertificateDateOverride (if there is one), or else None. This
will be triggered after any save of a GeneratedCertificate, and after
any save or deletion of a single CertificateDateOverride.

Credentials will eventually store its own copy of this date override, or
edit or remove exiting date overrides.
2021-08-17 12:22:27 -06:00
Matt Tuchfarber
d53d8e45a5 refactor: Merge the openedx certs app with lms one (#28435)
* refactor: Merge the openedx certs app with lms one

Move the certs API from openedx into the lms certificates app.
Functionally, this is a no-op. Cleanup will happen in a subsequent
commit. This is simply a move.
2021-08-11 10:25:55 -04:00
Matt Tuchfarber
622d56026c Certificate Display Settings revamp (round 2) (#28286)
feat: reimagine certificate display settings

The course settings `certificate_available_date` (CAD) and
`certificates_display_behavior` (CDB) were previously
acting indedependantly of one another. They now work in
tandem. This change:
- limits CDB to a dropdown
- removes "early_with_info" and adds "end_with_date"
- only takes CAD into account if "end_with_date" is selected
- Moves CDB to the main course schedule settings page
- updates CourseOverview model and CourseDetails objects to
validate these fields and choose sane defaults if they aren't
expected values

This work was previously done in bd9e7dd (complete with bugs), so this
version is toggleable via the ENABLE_V2_CERT_DISPLAY_SETTINGS setting
2021-08-02 11:30:15 -04:00
Matt Tuchfarber
63cb6a97ff Revert "feat: Reimagine certificate_availability_date and certificates_display_behavior" 2021-07-07 16:53:05 -04:00
Matt Tuchfarber
2a7106acfb feat: reimagine certificate display settings
The course settings `certificate_available_date` (CAD) and
`certificates_display_behavior` (CDB) were previously acting indedependantly
of one another. They now work in tandem. This change:
- limits CDB to a dropdown
- removes "early_with_info" and adds "end_with_date"
- only takes CAD into account if "end_with_date" is selected
- Moves CDB to the main course schedule settings page
- updates CourseOverview to validate these fields and choose sane
defaults if they aren't expected values

Certificates will now show under the following circumstances:
"Immediately upon passing"
certificate_availability_date = null
certificates_display_behavior = "early_no_info"

"End date of course"
certificate_availability_date = null
certificates_display_behavior = "end"

"A date after the course end date"
certificate_availability_date = <date>
certificates_display_behavior = "end_with_date"
2021-07-06 16:45:23 -04:00
Matt Hughes
8023a09191 fix: deleted courses do not break program details page
Sometimes learners have certificates in old course runs which've been
deleted. When this happens loading the learner's program progress can
result in 500 errors. This corrects those by choosing to count any
non-existent course the learner has certificates for as counting
towards program completion, effectively assuming that availability
dates have passed for all such courses.

Also fixes an error with a condition related to how we determine
whether an enrolled course is considered "in progress". The previous
version of the code had a bug that would result in a lot more courses
being marked "in progress" for the purpose of program completion than
actually were.

JIRA:EDUCATOR-5787
2021-06-09 10:58:00 -04:00
Thomas Tracy
84c953948b MB-1167: calling course certificates api from LMS (#27552)
* [feat] calling course certificates api from LMS

Now that CourseCertificates in credentials have a field for the
available_date, we need to make sure we are always updating that field
when it changes in studio. This PR adds a call to a new Credentials API
that will update the field each time the date change signal fires.
2021-05-12 15:42:08 -04:00
Usama Sadiq
4f4be6538a BOM-2477: pylint warnings lint-amnesty (#27585) 2021-05-11 17:22:40 +05:00
Albert (AJ) St. Aubin
ee71594714 refactor!: Remove backpopulate_program_credentials in favor of using
notify_credentials command

In this PR we are removing a management command that has performance issues and duplicates logic not available in the notify_credentials management command.
2021-05-05 12:22:38 -04:00
Justin Hynes
35cfca0be1 Merge pull request #27357 from edx/jhynes/microba-1164_revoke-program-certs-bugfix
fix: fix bug with `revoke_program_certificates` task
2021-04-22 07:38:32 -04:00
Albert (AJ) St. Aubin
a1fe3d58dc [bug] Corrected issue where program dash showed incorrect completed
count

[MICROBA-1163]

This change will correct an issue in the Program Dashboard where a user
would see a course as completed, but not see their Certificate because
it was not available to them yet.
2021-04-21 16:03:33 -04:00
Justin Hynes
a7bc9d1cc1 fix: fix bug with revoke_program_certificates task
[MICROBA-1164]
* cast `course_key` as a string when scheduling the `revoke_program_certificates` task
* Update existing unit tests
* Move test utility method in test_tasks.py out from the middle of the test cases
* Fix spelling in test function name
2021-04-21 14:43:03 -04:00
M. Zulqarnain
91d33611b1 refactor: pyupgrade in profile_images, programs, safe_sessions (#26953) 2021-03-22 17:51:13 +05:00
Régis Behmo
ae7d4994bf fix: deprecated waffle switch usage in test method 2021-03-19 17:08:57 +01:00
Matt Tuchfarber
ed8604534c (feat) Enable course cert sync for all courses
Removes waffle flag restriction for syncing certificate available dates
to the credentials service.
2021-03-16 14:31:11 -04:00
Matt Tuchfarber
a82489db8e fix tests 2021-03-12 14:59:44 -05:00
Matt Tuchfarber
6c97dfe1e5 Move cert date signals to avoid race conditions
COURSE_CERT_DATE_CHANGE was being called before saving the new data in
the course overview. The listeners were expecting to pull the data out
of the course overview, and thus were only right about half the time.
This moves the signal to trigger after the course publish signals are
handled.
2021-03-04 15:57:21 -05:00
Justin Hynes
03d788fc5b Log error when failing to award program certificate 2021-02-25 10:25:49 -05:00
Aarif
cfcb9330b3 replaced unittest assertions pytest assertions (#26568) 2021-02-22 12:24:33 +05:00
edX requirements bot
a2635e9821 Python Requirements Update (#26463)
* Updating Python Requirements

* change namespaced_switch_name to name

Co-authored-by: Zulqarnain <muhammad.zulqarnain@arbisoft.com>
2021-02-10 16:25:34 +05:00
Matt Tuchfarber
64032faae7 Make credentials celery tasks errors consistent
In order to better alert off of tasks that failed after maximum retries,
this makes the the error for each task consistent with itself.
2021-02-08 13:55:35 -05:00
M. Zulqarnain
e159ab8e4d Pylint amnesty in openedx plugin_api, profile_images and programs apps (#26377) 2021-02-04 17:10:38 +05:00