Skip to content

Commit 1e7a49d

Browse files
integrate mitxonline api (#2256)
* change local code to hit mitxonline API (currently broken) * partially wire up the dashboard to actual mitxonline api client library * remove remaining mocked data, wire in API * update the api and pull org content based on org id * fix yarn lock after rebase * replace hard coded domain with CSRF_COOKIE_DOMAIN * add CSRF_COOKIE_DOMAIN to docker-compose config for apigateway * fix function call name in enrollmentdisplay * fix test url config issue * fix unit tests * fix issue with nextjs build * fix feature flagging of org dashboard tab * make mitxonline domain configurable * match apisix config for mitxonline on domain instead * set the proper name for the mitx online base url * hide enrollements display if not enrolled in any courses * fix homecontent test * don't show "show all" unless there is something to reveal * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * whoops this copy of the repo doesn't have pre-commit on * add mitx online url to the default frontend env * separate upstream and domain in apisix config for mitxonline * update api client and use org_id in course filtering on org page --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4ff9b31 commit 1e7a49d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+500
-8314
lines changed

config/apisix/apisix.yaml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ upstreams:
33
nodes:
44
"nginx:${{NGINX_PORT}}": 1
55
type: roundrobin
6+
- id: 2
7+
nodes:
8+
"${{MITX_ONLINE_UPSTREAM}}": 1
9+
type: roundrobin
610

711
routes:
812
- id: 1
@@ -22,7 +26,9 @@ routes:
2226
ssl_verify: false
2327
session:
2428
secret: ${{APISIX_SESSION_SECRET_KEY}}
25-
cookie: { lifetime = 1209600 }
29+
cookie:
30+
lifetime: 1209600
31+
domain: ${{CSRF_COOKIE_DOMAIN}}
2632
logout_path: "/logout/oidc"
2733
post_logout_redirect_uri: ${{APISIX_LOGOUT_URL}}
2834
unauth_action: "pass"
@@ -53,7 +59,9 @@ routes:
5359
ssl_verify: false
5460
session:
5561
secret: ${{APISIX_SESSION_SECRET_KEY}}
56-
cookie: { lifetime = 1209600 }
62+
cookie:
63+
lifetime: 1209600
64+
domain: ${{CSRF_COOKIE_DOMAIN}}
5765
logout_path: "/logout/oidc"
5866
post_logout_redirect_uri: ${{APISIX_LOGOUT_URL}}
5967
unauth_action: "auth"
@@ -69,4 +77,30 @@ routes:
6977
uris:
7078
- "/admin/login/*"
7179
- "/login"
80+
- id: 3
81+
name: "mitxonline-wildcard"
82+
desc: "General route for the mitxonline application, includes user data if any."
83+
priority: 10
84+
upstream_id: 2
85+
plugins:
86+
openid-connect:
87+
client_id: ${{KEYCLOAK_CLIENT_ID}}
88+
client_secret: ${{KEYCLOAK_CLIENT_SECRET}}
89+
discovery: ${{KEYCLOAK_DISCOVERY_URL}}
90+
realm: ${{KEYCLOAK_REALM_NAME}}
91+
scope: "openid profile ol-profile"
92+
bearer_only: false
93+
introspection_endpoint_auth_method: "client_secret_post"
94+
ssl_verify: false
95+
session:
96+
secret: ${{APISIX_SESSION_SECRET_KEY}}
97+
cookie:
98+
lifetime: 1209600
99+
domain: ${{CSRF_COOKIE_DOMAIN}}
100+
logout_path: "/logout"
101+
post_logout_redirect_uri: ${{APISIX_LOGOUT_URL}}
102+
unauth_action: "pass"
103+
uri: "*"
104+
hosts:
105+
- ${{MITX_ONLINE_DOMAIN}}
72106
#END

docker-compose.services.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ services:
119119
- apisix
120120
image: apache/apisix:latest
121121
environment:
122+
- CSRF_COOKIE_DOMAIN=${CSRF_COOKIE_DOMAIN:-.odl.local}
122123
- KEYCLOAK_REALM_NAME=${KEYCLOAK_REALM_NAME:-ol-local}
123124
- KEYCLOAK_CLIENT_ID=${KEYCLOAK_CLIENT_ID:-apisix}
124125
- KEYCLOAK_CLIENT_SECRET=${KEYCLOAK_CLIENT_SECRET}
@@ -127,6 +128,8 @@ services:
127128
- APISIX_PORT=${APISIX_PORT:-8065}
128129
- APISIX_SESSION_SECRET_KEY=${APISIX_SESSION_SECRET_KEY:-something_at_least_16_characters}
129130
- APISIX_LOGOUT_URL=${APISIX_LOGOUT_URL:-http://open.odl.local:8065/}
131+
- MITX_ONLINE_UPSTREAM=${MITX_ONLINE_UPSTREAM:-mitxonline.odl.local:8013}
132+
- MITX_ONLINE_DOMAIN=${MITX_ONLINE_DOMAIN:-mitxonline.odl.local}
130133
- NGINX_PORT=${NGINX_PORT:-8062}
131134
ports:
132135
- ${APISIX_PORT}:${APISIX_PORT}

env/frontend.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ NEXT_PUBLIC_DEFAULT_SEARCH_MAX_INCOMPLETENESS_PENALTY=90
2121

2222
NEXT_PUBLIC_LEARN_AI_RECOMMENDATION_ENDPOINT=https://api-learn-ai-qa.ol.mit.edu/http/recommendation_agent/
2323
NEXT_PUBLIC_LEARN_AI_SYLLABUS_ENDPOINT=https://api-learn-ai-qa.ol.mit.edu/http/syllabus_agent/
24+
25+
NEXT_PUBLIC_MITX_ONLINE_BASE_URL=${MITX_ONLINE_BASE_URL}

frontends/api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"ol-test-utilities": "0.0.0"
3131
},
3232
"dependencies": {
33+
"@mitodl/mitxonline-api-axios": "^2025.6.3",
3334
"@tanstack/react-query": "^5.66.0",
3435
"axios": "^1.6.3"
3536
}
Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
1-
import { EnrollmentsApi, ProgramsApi, CoursesApi } from "./generated/v0/api"
1+
import {
2+
B2bApi,
3+
CoursesApi,
4+
EnrollmentsApi,
5+
ProgramsApi,
6+
UsersApi,
7+
} from "@mitodl/mitxonline-api-axios/v1"
28
import axios from "axios"
39

4-
const axiosInstance = axios.create({})
10+
const axiosInstance = axios.create({
11+
baseURL: process.env.NEXT_PUBLIC_MITX_ONLINE_BASE_URL,
12+
xsrfCookieName: process.env.NEXT_PUBLIC_CSRF_COOKIE_NAME,
13+
xsrfHeaderName: "X-CSRFToken",
14+
withXSRFToken: true,
15+
withCredentials:
16+
process.env.NEXT_PUBLIC_MITOL_AXIOS_WITH_CREDENTIALS === "true",
17+
})
518

619
const BASE_PATH =
7-
process.env.NEXT_PUBLIC_MITXONLINE_API_BASE_URL?.replace(/\/+$/, "") ?? ""
20+
process.env.NEXT_PUBLIC_MITX_ONLINE_BASE_URL?.replace(/\/+$/, "") ?? ""
821

22+
const usersApi = new UsersApi(undefined, BASE_PATH, axiosInstance)
23+
const b2bApi = new B2bApi(undefined, BASE_PATH, axiosInstance)
924
const enrollmentsApi = new EnrollmentsApi(undefined, BASE_PATH, axiosInstance)
1025
const programsApi = new ProgramsApi(undefined, BASE_PATH, axiosInstance)
1126
const coursesApi = new CoursesApi(undefined, BASE_PATH, axiosInstance)
1227

13-
export { enrollmentsApi, programsApi, coursesApi, axiosInstance }
28+
export {
29+
usersApi,
30+
b2bApi,
31+
enrollmentsApi,
32+
programsApi,
33+
coursesApi,
34+
axiosInstance,
35+
}

frontends/api/src/mitxonline/generated/v0/.openapi-generator/FILES

Lines changed: 0 additions & 5 deletions
This file was deleted.

frontends/api/src/mitxonline/generated/v0/.openapi-generator/VERSION

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)