Skip to content

Release 0.41.0 #2440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Release Notes
=============

Version 0.41.0
--------------

- fix video etl (#2438)
- fix popular search (#2436)
- B2B Provisioning: Add interstitial page to process redemption code retrieval (#2422)

Version 0.40.1 (Released August 18, 2025)
--------------

Expand Down
2 changes: 1 addition & 1 deletion frontends/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"ol-test-utilities": "0.0.0"
},
"dependencies": {
"@mitodl/mitxonline-api-axios": "2025.8.6",
"@mitodl/mitxonline-api-axios": "2025.8.12",
"@tanstack/react-query": "^5.66.0",
"axios": "^1.6.3"
}
Expand Down
9 changes: 5 additions & 4 deletions frontends/api/src/mitxonline/hooks/courses/queries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { queryOptions } from "@tanstack/react-query"
import type {
CoursesApiApiV2CoursesListRequest,
PaginatedV2CourseWithCourseRunsList,
PaginatedCourseWithCourseRunsSerializerV2List,
} from "@mitodl/mitxonline-api-axios/v2"
import { coursesApi } from "../../clients"

Expand All @@ -18,9 +18,10 @@ const coursesQueries = {
coursesList: (opts?: CoursesApiApiV2CoursesListRequest) =>
queryOptions({
queryKey: coursesKeys.coursesList(opts),
queryFn: async (): Promise<PaginatedV2CourseWithCourseRunsList> => {
return coursesApi.apiV2CoursesList(opts).then((res) => res.data)
},
queryFn:
async (): Promise<PaginatedCourseWithCourseRunsSerializerV2List> => {
return coursesApi.apiV2CoursesList(opts).then((res) => res.data)
},
}),
}

Expand Down
4 changes: 2 additions & 2 deletions frontends/api/src/mitxonline/hooks/organizations/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { organizationQueries } from "./queries"
import { organizationQueries, useB2BAttachMutation } from "./queries"

export { organizationQueries }
export { organizationQueries, useB2BAttachMutation }
27 changes: 23 additions & 4 deletions frontends/api/src/mitxonline/hooks/organizations/queries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { B2bApiB2bOrganizationsRetrieveRequest } from "@mitodl/mitxonline-api-axios/v0"
import { OrganizationPage } from "@mitodl/mitxonline-api-axios/v2"
import { queryOptions } from "@tanstack/react-query"
import {
queryOptions,
useMutation,
useQueryClient,
} from "@tanstack/react-query"
import { b2bApi } from "../../clients"
import {
OrganizationPage,
B2bApiB2bAttachCreateRequest,
B2bApiB2bOrganizationsRetrieveRequest,
} from "@mitodl/mitxonline-api-axios/v2"

const organizationKeys = {
root: ["mitxonline", "organizations"],
Expand All @@ -22,4 +29,16 @@ const organizationQueries = {
}),
}

export { organizationQueries, organizationKeys }
const useB2BAttachMutation = (opts: B2bApiB2bAttachCreateRequest) => {
const queryClient = useQueryClient()
return useMutation({
mutationFn: () => b2bApi.b2bAttachCreate(opts),
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: organizationKeys.organizationsRetrieve(),
})
},
})
}

export { organizationQueries, organizationKeys, useB2BAttachMutation }
10 changes: 6 additions & 4 deletions frontends/api/src/mitxonline/test-utils/factories/courses.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { mergeOverrides, makePaginatedFactory } from "ol-test-utilities"
import type { PartialFactory } from "ol-test-utilities"
import type { V2CourseWithCourseRuns } from "@mitodl/mitxonline-api-axios/v2"
import type { CourseWithCourseRunsSerializerV2 } from "@mitodl/mitxonline-api-axios/v2"
import { faker } from "@faker-js/faker/locale/en"
import { UniqueEnforcer } from "enforce-unique"

const uniqueCourseId = new UniqueEnforcer()
const uniqueCourseRunId = new UniqueEnforcer()

const course: PartialFactory<V2CourseWithCourseRuns> = (overrides = {}) => {
const defaults: V2CourseWithCourseRuns = {
const course: PartialFactory<CourseWithCourseRunsSerializerV2> = (
overrides = {},
) => {
const defaults: CourseWithCourseRunsSerializerV2 = {
id: uniqueCourseId.enforce(() => faker.number.int()),
title: faker.lorem.words(3),
readable_id: faker.lorem.slug(),
Expand Down Expand Up @@ -86,7 +88,7 @@ const course: PartialFactory<V2CourseWithCourseRuns> = (overrides = {}) => {
ingest_content_files_for_ai: faker.datatype.boolean(),
}

return mergeOverrides<V2CourseWithCourseRuns>(defaults, overrides)
return mergeOverrides<CourseWithCourseRunsSerializerV2>(defaults, overrides)
}

const courses = makePaginatedFactory(course)
Expand Down
5 changes: 5 additions & 0 deletions frontends/api/src/mitxonline/test-utils/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ const organization = {
`${API_BASE_URL}/api/v0/b2b/organizations/${organizationSlug}/`,
}

const b2bAttach = {
b2bAttachView: (code: string) => `${API_BASE_URL}/api/v0/b2b/attach/${code}/`,
}

export {
b2b,
b2bAttach,
currentUser,
enrollment,
programs,
Expand Down
2 changes: 1 addition & 1 deletion frontends/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@emotion/cache": "^11.13.1",
"@emotion/styled": "^11.11.0",
"@mitodl/course-search-utils": "3.3.2",
"@mitodl/mitxonline-api-axios": "2025.8.6",
"@mitodl/mitxonline-api-axios": "2025.8.12",
"@mitodl/smoot-design": "^6.10.0",
"@next/bundle-analyzer": "^14.2.15",
"@remixicon/react": "^4.2.0",
Expand Down
50 changes: 50 additions & 0 deletions frontends/main/src/app-pages/B2BAttachPage/B2BAttachPage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from "react"
import { renderWithProviders, setMockResponse, waitFor } from "@/test-utils"
import { urls } from "api/test-utils"
import { urls as b2bUrls } from "api/mitxonline-test-utils"
import * as commonUrls from "@/common/urls"
import { Permission } from "api/hooks/user"
import B2BAttachPage from "./B2BAttachPage"
import { redirect } from "next/navigation"

// Mock Next.js redirect function
jest.mock("next/navigation", () => ({
redirect: jest.fn(),
}))

const mockRedirect = jest.mocked(redirect)

describe("B2BAttachPage", () => {
beforeEach(() => {
jest.clearAllMocks()
})

test("Renders when logged in", async () => {
setMockResponse.get(urls.userMe.get(), {
[Permission.Authenticated]: true,
})

setMockResponse.post(b2bUrls.b2bAttach.b2bAttachView("test-code"), [])

renderWithProviders(<B2BAttachPage code="test-code" />, {
url: commonUrls.B2B_ATTACH_VIEW,
})
})

test("Redirects to dashboard on successful attachment", async () => {
setMockResponse.get(urls.userMe.get(), {
[Permission.Authenticated]: true,
})

setMockResponse.post(b2bUrls.b2bAttach.b2bAttachView("test-code"), [])

renderWithProviders(<B2BAttachPage code="test-code" />, {
url: commonUrls.B2B_ATTACH_VIEW,
})

// Wait for the mutation to complete and verify redirect was called
await waitFor(() => {
expect(mockRedirect).toHaveBeenCalledWith(commonUrls.DASHBOARD_HOME)
})
})
})
50 changes: 50 additions & 0 deletions frontends/main/src/app-pages/B2BAttachPage/B2BAttachPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"use client"
import React from "react"
import { redirect } from "next/navigation"
import { styled, Breadcrumbs, Container, Typography } from "ol-components"
import * as urls from "@/common/urls"
import { useB2BAttachMutation } from "api/mitxonline-hooks/organizations"

type B2BAttachPageProps = {
code: string
}

const InterstitialMessage = styled(Typography)(({ theme }) => ({
...theme.typography.body1,
textAlign: "center",
}))

const B2BAttachPage: React.FC<B2BAttachPageProps> = ({ code }) => {
const {
mutate: attach,
isSuccess,
isPending,
} = useB2BAttachMutation({
enrollment_code: code,
})

React.useEffect(() => {
attach?.()
}, [attach])

React.useEffect(() => {
if (isSuccess) {
redirect(urls.DASHBOARD_HOME)
}
}, [isSuccess])

return (
<Container>
<Breadcrumbs
variant="light"
ancestors={[{ href: urls.HOME, label: "Home" }]}
current="Use Enrollment Code"
/>
{isPending && (
<InterstitialMessage>Validating code "{code}"...</InterstitialMessage>
)}
</Container>
)
}

export default B2BAttachPage
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import {
CourseRunEnrollment,
V2CourseWithCourseRuns,
CourseWithCourseRunsSerializerV2,
V2Program,
V2ProgramCollection,
} from "@mitodl/mitxonline-api-axios/v2"
Expand Down Expand Up @@ -72,7 +72,7 @@ const mitxonlineEnrollments = (data: CourseRunEnrollment[]) =>
data.map((course) => mitxonlineEnrollment(course))

const mitxonlineUnenrolledCourse = (
course: V2CourseWithCourseRuns,
course: CourseWithCourseRunsSerializerV2,
): DashboardCourse => {
const run = course.courseruns.find((run) => run.id === course.next_run_id)
return {
Expand All @@ -98,7 +98,7 @@ const mitxonlineUnenrolledCourse = (
}

const mitxonlineCourses = (raw: {
courses: V2CourseWithCourseRuns[]
courses: CourseWithCourseRunsSerializerV2[]
enrollments: CourseRunEnrollment[]
}) => {
const enrollmentsByCourseId = groupBy(
Expand Down
26 changes: 26 additions & 0 deletions frontends/main/src/app/attach/[code]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react"
import { Metadata } from "next"
import { standardizeMetadata } from "@/common/metadata"
import invariant from "tiny-invariant"
import { Permission } from "api/hooks/user"
import RestrictedRoute from "@/components/RestrictedRoute/RestrictedRoute"
import type { PageParams } from "@/app/types"
import B2BAttachPage from "@/app-pages/B2BAttachPage/B2BAttachPage"

export const metadata: Metadata = standardizeMetadata({
title: "Use Enrollment Code",
})

const Page: React.FC<PageParams<object, { code: string }>> = async ({
params,
}) => {
const resolved = await params
invariant(resolved?.code, "code is required")
return (
<RestrictedRoute requires={Permission.Authenticated}>
<B2BAttachPage code={resolved?.code} />
</RestrictedRoute>
)
}

export default Page
4 changes: 4 additions & 0 deletions frontends/main/src/common/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,7 @@ export const SEARCH_LEARNING_MATERIAL = querifiedSearchUrl({
})

export const ECOMMERCE_CART = "/cart/" as const

export const B2B_ATTACH_VIEW = "/attach/[code]"
export const b2bAttachView = (code: string) =>
generatePath(B2B_ATTACH_VIEW, { code: code })
10 changes: 10 additions & 0 deletions learning_resources/etl/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,16 @@ def load_playlist(video_channel: VideoChannel, playlist_data: dict) -> LearningR

video_resources = load_videos(videos_data)
load_topics(playlist_resource, most_common_topics(video_resources))
unpublished_videos = playlist_resource.resources.filter(
resource_type=LearningResourceType.video.name,
published=True,
).exclude(id__in=[video.id for video in video_resources])
unpublished_videos.update(published=False)
bulk_resources_unpublished_actions(
unpublished_videos.values_list("id", flat=True),
LearningResourceType.video.name,
)

playlist_resource.resources.clear()
for idx, video in enumerate(video_resources):
playlist_resource.resources.add(
Expand Down
22 changes: 18 additions & 4 deletions learning_resources/etl/loaders_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,8 @@ def test_load_videos():
assert Video.objects.count() == len(video_resources)


def test_load_playlist(mocker):
@pytest.mark.parametrize("playlist_exists", [True, False])
def test_load_playlist(mocker, playlist_exists):
"""Test load_playlist"""
expected_topics = [{"name": "Biology"}, {"name": "Physics"}]
[
Expand All @@ -1475,9 +1476,19 @@ def test_load_playlist(mocker):
return_value=expected_topics,
)
channel = VideoChannelFactory.create()
playlist = VideoPlaylistFactory.build().learning_resource
assert VideoPlaylist.objects.count() == 0
assert Video.objects.count() == 0
if playlist_exists:
playlist = VideoPlaylistFactory.create(channel=channel).learning_resource
deleted_video = VideoFactory.create().learning_resource
playlist.resources.add(
deleted_video,
through_defaults={
"relation_type": LearningResourceRelationTypes.PLAYLIST_VIDEOS,
"position": 1,
},
)
else:
playlist = VideoPlaylistFactory.build().learning_resource

video_resources = [video.learning_resource for video in VideoFactory.build_batch(5)]
videos_data = [
{
Expand Down Expand Up @@ -1511,6 +1522,9 @@ def test_load_playlist(mocker):
assert list(result.topics.values_list("name", flat=True).order_by("name")) == [
topic["name"] for topic in expected_topics
]
if playlist_exists:
deleted_video.refresh_from_db()
assert not deleted_video.published


def test_load_playlists_unpublish(mocker):
Expand Down
12 changes: 11 additions & 1 deletion learning_resources/etl/posthog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from learning_resources.exceptions import PostHogAuthenticationError, PostHogQueryError
from learning_resources.models import LearningResource, LearningResourceViewEvent
from learning_resources.utils import resource_upserted_actions

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -275,4 +276,13 @@ def load_posthog_lrd_view_events(
List of LearningResourceViewEvent
"""

return [load_posthog_lrd_view_event(event) for event in events]
events = [load_posthog_lrd_view_event(event) for event in events]
learning_resource_ids = {
event.learning_resource_id for event in events if event is not None
}

for resource_id in learning_resource_ids:
learning_resource = LearningResource.objects.get(id=resource_id)
resource_upserted_actions(learning_resource, percolate=False)

return events
Loading
Loading