Skip to content

Commit

Permalink
feat: adding pathway retirement
Browse files Browse the repository at this point in the history
* fixing enum usage
* improving tests
* fixing the way we hide retired programs
  • Loading branch information
deborahgu committed Feb 26, 2025
1 parent f5b86a5 commit a138c2d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 14 deletions.
11 changes: 10 additions & 1 deletion credentials/apps/catalog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ class ProgramAdmin(admin.ModelAdmin):
class PathwayAdmin(admin.ModelAdmin):
list_display = ("name", "org_name", "pathway_type", "status", "email", "uuid")
list_filter = ("site", "status")
readonly_fields = ("name", "org_name", "pathway_type", "email", "uuid", "site", "programs")
readonly_fields = (
"name",
"org_name",
"pathway_type",
"email",
"uuid",
"site",
"programs",
"status",
)
search_fields = ("name", "uuid")


Expand Down
14 changes: 14 additions & 0 deletions credentials/apps/catalog/docs/decisions/0002-pathway-status.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Pathway Status
==============

Status
------
Accepted

Background
----------
Course discovery is now allowing pathways to be retired. The `course-discovery` API will continue to expose retired pathways, and it will rely on consumers to expose or process retired pathways as appropriate.

Decision
--------
The catalog app will now synchronize the `Pathway`'s `status` attribute. In the absence of a populated `status` attribute, a pathway will be considered to have the status of `published`.
2 changes: 1 addition & 1 deletion credentials/apps/catalog/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Meta:
name = FuzzyText(prefix="Test Pathway ")
org_name = FuzzyText()
email = factory.Faker("safe_email")
status = PathwayStatus.PUBLISHED
status = PathwayStatus.PUBLISHED.value

@factory.post_generation
def programs(self, create, extracted):
Expand Down
14 changes: 9 additions & 5 deletions credentials/apps/catalog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from django.db import transaction

from credentials.apps.catalog.data import PathwayStatus
from credentials.apps.catalog.models import Course, CourseRun, Organization, Pathway, Program


Expand Down Expand Up @@ -315,9 +316,11 @@ def _parse_course_run(self, course, data):
@transaction.atomic
def _parse_pathway(self, data):
"""
Creates or updates a pathway and links it to connected programs
Creates or updates a pathway and links it to connected programs.
Assumes that the associated programs were parsed before this is run.
* Assumes that the associated programs were parsed before this is run.
* Always re-creates the foreign keys between Pathway and Program on modification.
If the Pathway is retired or unpublished, no relationship is created
Arguments:
data (dict): The pathway data pulled from the API
Expand All @@ -340,8 +343,9 @@ def _parse_pathway(self, data):
self.add_item(self.PATHWAY, str(pathway.uuid))

pathway.programs.clear()
for program_data in data["programs"]:
program = Program.objects.get(site=self.site, uuid=program_data["uuid"])
pathway.programs.add(program)
if pathway.status in ("", PathwayStatus.PUBLISHED.value):
for program_data in data["programs"]:
program = Program.objects.get(site=self.site, uuid=program_data["uuid"])
pathway.programs.add(program)

return pathway
2 changes: 0 additions & 2 deletions credentials/apps/records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from django.utils.translation import gettext as _

from credentials.apps.catalog.api import get_program_and_course_details
from credentials.apps.catalog.data import PathwayStatus
from credentials.apps.core.api import get_user_by_username
from credentials.apps.credentials.api import (
get_credential_dates,
Expand Down Expand Up @@ -105,7 +104,6 @@ def _get_transformed_pathway_data(program, user):
.filter(
user=user,
pathway__in=program_pathways_set,
pathway__status__in=("", PathwayStatus.PUBLISHED),
)
.all()
)
Expand Down
8 changes: 4 additions & 4 deletions credentials/apps/records/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.test.utils import override_settings
from django.urls import reverse

from credentials.apps.catalog.data import PathwayStatus
from credentials.apps.catalog.tests.factories import (
CourseFactory,
CourseRunFactory,
Expand All @@ -34,7 +35,6 @@
UserCredentialFactory,
)
from credentials.apps.records.constants import UserCreditPathwayStatus
from credentials.apps.catalog.data import PathwayStatus
from credentials.apps.records.models import ProgramCertRecord, UserCreditPathway
from credentials.apps.records.tests.factories import (
ProgramCertRecordFactory,
Expand Down Expand Up @@ -211,9 +211,9 @@ def test_email_content_complete(self):
self.assertListEqual([self.pathway.email], email.to)

@ddt.data(
(PathwayStatus.PUBLISHED, 200),
(PathwayStatus.UNPUBLISHED, 404),
(PathwayStatus.RETIRED, 404),
(PathwayStatus.PUBLISHED.value, 200),
(PathwayStatus.UNPUBLISHED.value, 404),
(PathwayStatus.RETIRED.value, 404),
("", 200),
)
@ddt.unpack
Expand Down
2 changes: 1 addition & 1 deletion credentials/apps/records/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def post(self, request, **kwargs):
Pathway,
id=pathway_id,
programs__uuid=program_uuid,
status__in=(PathwayStatus.PUBLISHED, ""),
status__in=(PathwayStatus.PUBLISHED.value, ""),
pathway_type=PathwayType.CREDIT.value,
)
certificate = get_object_or_404(ProgramCertificate, program_uuid=program_uuid, site=request.site)
Expand Down

0 comments on commit a138c2d

Please sign in to comment.