356 Commits

Author SHA1 Message Date
Daniel Wong
cd6faeb966 Follow-up to PR 36789 (#37751)
* refactor(certificates): replace direct model imports with data classes and APIs

* fix: use Certificates API to create certificates

* docs: update docstring for get_certificate_for_user

* fix: remove trailing whitespace

---------

Co-authored-by: coder1918 <ram.chandra@wgu.edu>
Co-authored-by: Deborah Kaplan <deborahgu@users.noreply.github.com>
2026-01-08 13:03:46 -05:00
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
Maxwell Frank
7fc88d5a25 feat: extend program dash endpoint to b2c (#37387) 2025-10-01 11:38:05 -04:00
Deborah Kaplan
896ca99c79 chore: calling other djangoapps from API instead of model (#36448)
switching  from calling other djangoapps via direct model access to
calling from API. This included  adding an API in the Student app.

FIXES: APER-3972
2025-03-28 12:14:21 -04:00
Mubbshar Anwar
f32b08b753 feat: add new param in url (#36458)
Add new param in ecommerce url to calculate program price based on course keys

SONIC-918
2025-03-28 14:19:36 +05:00
Deborah Kaplan
ce8d3211f9 chore: improving programs rest API docs, type hints (#36438)
* chore:  improving programs rest API docs, type hints

reformatting the docstrings  so they appear correctly in the  openAPI
docs.
* moving them into the `GET`
* some cleanup and simplification of language
* removing real data that refers to specific hosts

regenerated the open API documentation.

also adding type hints to the API and telling `mypy`  to check this
file.  This was primarily because these models are confusing enough in
order to verify that the documentation was correct I had to do a lot of
jumping through the code.

FIXES: APER-3950
2025-03-25 09:39:25 -04:00
Deborah Kaplan
3136134be8 chore: move the program dashboard APIs (#36420)
Moves the Program Dashboard APIs out of the deprecated remnants of the legacy learner dashboard, into the Programs djangoapp.

Keeps the old legacy routes for this API, left over from the deprecated remnants of the legacy learner dashboard, alongside future-proofed routes which will work when the deprecated, legacy Program Dashboard is eventually replaced with functionality in the Learner Dashboard MFE.

FIXES: APER-3949
2025-03-24 12:06:52 -04:00
Muhammad Noyan Aziz
ca463f918d SONIC-917: Added pluggable_override on `get_program_price_info` util (#36382)
* feat: add override for one click purchase eligibility

* refactor: remove extra line

* chore: move service worker inside util

* refactor: pylint issue

* fix: pylint errors

* fix: pycodestyle

---------

Co-authored-by: Muhammad Noyan  Aziz <noyan.aziz@A006-01474.local>
2025-03-20 15:37:17 +05:00
Brian Mesick
e478975105 chore: Add missing PII annotations, update safelist
PII Annotations are very out of date, this commit adds most that were
missing in edx-platform, and some additional annotations to the
safelist. It is not comprehensive, several other upstream Open edX
packages also need to be updated. It also does not include removing
annotations that have been moved upstream, or been removed entirely.
Those are separate follow-on tasks.
2024-11-05 12:58:36 -05: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
Mohammad Ahtasham ul Hassan
6a63cfcaa4 feat: add override option to upgrade CTA utils and add course_run_key identifier (#35441)
* feat: add override option to upgrade CTAs and send course_run_key identifier
2024-09-16 13:15:51 +05:00
Juliana Kang
51d538cbe7 fix: Remove B2C Subscriptions (#35303)
REV-3697
2024-09-04 14:01:45 -04:00
Deborah Kaplan
a9355852ed test: improve logging for periodic error (#35141)
we have a periodic error that makes no sense when the certificate
available date is none. This improves logging for the API call. Because
the only thing being changed is a course certificate, there is no risk
of PII being exposed in the new logging.
2024-07-18 15:33:15 -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
360159c642 feat: linting before touching all these files (#35108)
* feat:  linting before touching all these files

All these files are old enough, relative either to our current linting
rules or our current linter automation,  that modifying anything in them
either makes the linter cranky or wants to reformat  the entire file.
Rather than mixing cleanup with code changes, this commit just lints
this set of files to our current standards.
2024-07-10 14:29:53 -04:00
Deborah Kaplan
7124559906 feat: updating readmes for program/cert/creds apps (#35104)
The LMS `certificates` app `README`  has been, and the
openedx core `credentials` and `programs` READMEs  have been created.
This will clarify not only what the limited responsibilities
of each of these django apps is, but also the way they interact with
each other.

FIXES: APER-2929
2024-07-10 10:34:16 -04: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
Dmytro
03a490f7cd feat: add ability to notify credentials about honor certificates (#32633) 2024-04-04 07:56:02 -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
b75f8b0ed1 feat: tweaks from code review
wording, switching to using a constant, fixing a string concat

FIXES: APER-3146
2024-01-30 21:34:56 +00:00
Deborah Kaplan
f7a9efbf6b feat: lint
autoformat errors

FIXES: APER-3146
2024-01-30 18:59:13 +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
Feanil Patel
8691aa78e1 fix: Don't set default_app_config.
From the warning: Django now detects this configuration automatically.
You can remove default_app_config.

This also removes two warnings from shell startup.
2023-09-01 14:41:34 -04:00
Awais Qureshi
4da29d914d chore: adding migrations related with django-history. (#32935) 2023-08-08 16:04:06 +05:00
Nawfal Ahmed
80d151b404 feat: add marketing url to subscription upsell (#32560) 2023-06-23 12:54:15 +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
Pooja Kulkarni
9245bc0f76 refactor: rename descriptor -> block within openedx/core/djangoapps
Co-authored-by: Agrendalath <piotr@surowiec.it>
2023-04-26 17:10:54 +02: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
Usama Sadiq
4734f9f16e fix: bump pylint version (#31084) 2022-10-27 12:19:09 +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
oliviaruizknott
74780ad4c0 fix: send COURSE_CERT_DATE_CHANGE signal on_commit
**Previously**
When a course administrator changed the `certificates_display_behavior` (presumably to `end_with_date`) AND set the `certificate_available_date` in Studio, the `certificate_available_date` was not syncing to Credentials.

This was because we chose to send the `certificate_available_date` only if the course is self-paced and the `certificate_display_behavior` is set to `end_with_date`. [See PR #28275](https://github.com/openedx/edx-platform/pull/28275). However, we were checking those two conditions by looking at the relevant `CourseOverview`, which was not yet truly saved to reflect the updated display behavior at the time of the check due to atomic requests. [Read more about atomic requests and transactions here](https://docs.djangoproject.com/en/4.0/topics/db/transactions/#tying-transactions-to-http-requests-1); we have `ATOMIC_REQUESTS` set to `TRUE` in our codebase. Because the `certificate_display_behavior` was not (yet) `end_with_date`, the post to Credentials was not being fired.

**Solution**
To fix, this commit sends the `COURSE_CERT_DATE_CHANGE` signal `on_commit` instead, which waits until the transaction has completed and the update to the `CourseOverview` has been truly applied to the database. [Read more about `on_commit` here](https://docs.djangoproject.com/en/4.0/topics/db/transactions/#django.db.transaction.on_commit). Now, when the relevant `CourseOverview` is read, it will have the updated `certificate_display_behavior`.

See the [Django docs for how to test on_commit callbacks here](https://docs.djangoproject.com/en/3.2/topics/testing/tools/#django.test.TestCase.captureOnCommitCallbacks); this seems to be our first time using the built-in method.

This commit also cleans up some previous code that was meant to get around the problem caused by atomic requests, that is now unneccessary with this fix. It essentially reverses the work done in [PR #26991](https://github.com/openedx/edx-platform/pull/26991): we no longer need to explicitly pass the `certificate_available_date` since we can trust the `CourseOverview` to be properly updated.

**Rejected Solutions**
A. Simply publish the `COURSE_CERT_DATE_CHANGE` signal `on_commit`; no other changes. Rejected because: This would fix the problem, but leaves a lot of unnecessary code and some puzzling inconsistencies. I prefer the solution above because we are cleaning up behind ourselves.

B. Pass the new `certificate_display_behavior` along with the `certificate_available_date`; read those direclty instead of checking the (not-yet-properly-updated) `CourseOverview`. Rejected because: The pattern of passing the new `certificate_available_date` down through all these methods was put in place to get around the atomic requests problem. I believe `on_commit` to be a better solution to getting around that problem. I’d like to move away from passing data down through several functions / methods.

C. Start the celery task `on_commit` (rather than send the signal `on_commit`). Rejected because: The signal receiver basically only starts the celery task, and I find the break to be a bit more readable when sending the signal. No need to split hairs here.

D. Remove the check for pacing and display behavior; send the updated `certificate_available_date` every time there is a change, no matter what the current display behavior is. Rejected because: We intentionally added this check in [PR #28275](https://github.com/openedx/edx-platform/pull/28275) because the task was not behaving as expected without it (specifically around self-paced courses). I assume this is still necessary.

**Relevant Prior Work**
The following PRs--in order--show how this section (and other relevant sections) of the code have been changed over time:
1. [Move cert date signals to avoid race conditions #26841](https://github.com/openedx/edx-platform/pull/26841)
2. [feat: Pass date in cert date update signal #26991](https://github.com/openedx/edx-platform/pull/26991)
3. [Fix certificate available date sync #28275](https://github.com/openedx/edx-platform/pull/28275)
4. [fix: Correct an issue where cert available date was not sent to Crede… #28524](https://github.com/openedx/edx-platform/pull/28524)

MICROBA-1818
2022-05-26 14:09:00 -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
Eugene Dyudyunov
8bd43207ca refactor!: switch from LegacyWaffle* to modern waffles (#30330)
This is a first stage for removing the LegacyWaffle* classes.

LegacyWaffleFlag usage replaced with WaffleFlag;
LegacyWaffleSwitche usage replaced with WaffleSwitch;
New CourseWaffleFlag added to the temporary module __future__ as FutureCourseWaffleFlag;
Updated all the imports to use CourseWaffleFlag from the __future__ module;

BREAKING CHANGE: A number of toggle related constants (e.g. ENABLE_ACCESSIBILITY_POLICY_PAGE)
changed types. They were strings, and are now toggle instances (e.g. WaffleSwitch). Although the entire
refactor should be self-contained in edx-platform, if any plugins or dependencies were directly
using these constants, they will break. If this is the case, try to find a better publicized way of
exposing those toggles.
2022-05-05 12:03:10 -04:00
muhammad-ammar
c35025fd9d feat: api to fetch all programs where an enterprise learner is enrolled 2022-03-04 17:42:30 +05:00
Sameen Fatima
0d9e845f1b feat: Created an API to fetch progress details about a learner's program (#29975) 2022-03-04 16:11:28 +05:00
Ahtisham Shahid
75d8448ef5 refactor: Moved ProgramDiscussion/Live Configuration Models to program's app (#29871)
refactor: Moved ProgramDiscussion/Live Configuration Models to program's app
2022-02-09 15:43:22 +05: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
M. Zulqarnain
834dabb399 feat: New codemods on OpenedX 2 (#28777) 2021-10-28 16:45:53 +05:00