Skip to content

Commit

Permalink
Forward public_id filter from query param to config and to the backend
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Jul 31, 2024
1 parent 5c0dac3 commit 215bb5b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lms/js_config_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,13 @@ class User(TypedDict):

class DashboardConfig(TypedDict):
user: User

organization_public_id: str
"""
Filtering by organization is not like other filters:
- It's only available to staff members
- It doesn't only filter but also authorized access to that orgnaiztion's data
For those resason we include it on the config instead of handling it like other query string parameters.
"""

routes: DashboardRoutes
1 change: 1 addition & 0 deletions lms/resources/_js_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def enable_dashboard_mode(self) -> None:
"mode": JSConfig.Mode.DASHBOARD,
"dashboard": DashboardConfig(
user=self._get_user_info(),
organization_public_id=self._request.params.get("public_id"),
routes=DashboardRoutes(
assignment=self._to_frontend_template(
"api.dashboard.assignment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function AssignmentActivity() {
);
const students = useAPIFetch<StudentsResponse>(routes.students_metrics, {
assignment_id: assignmentId,
public_id: dashboard.organization_public_id || [],
});

const title = `Assignment: ${assignment.data?.title}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function CourseActivity() {
replaceURLParams(routes.course_assignments_metrics, {
course_id: courseId,
}),
{ public_id: dashboard.organization_public_id || [] },
);

const rows: AssignmentsTableRow[] = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ export default function DashboardActivityFilters({
const { dashboard } = useConfig(['dashboard']);
const { routes } = dashboard;

const courses = useAPIFetch<{ courses: Course[] }>(routes.courses);
const courses = useAPIFetch<{ courses: Course[] }>(routes.courses, {
public_id: dashboard.organization_public_id || [],
});
const assignments = useAPIFetch<{ assignments: Assignment[] }>(
routes.assignments,
{ public_id: dashboard.organization_public_id || [] },
);
const students = useAPIFetch<{ students: Student[] }>(routes.students);
const students = useAPIFetch<{ students: Student[] }>(routes.students, {
public_id: dashboard.organization_public_id || [],
});
const studentsWithName = useMemo(
() => students.data?.students.filter(s => !!s.display_name),
[students.data?.students],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default function OrganizationActivity() {
h_userid: studentIds,
assignment_id: assignmentIds,
course_id: courseIds,
public_id: dashboard.organization_public_id || [],
});
const rows: CoursesTableRow[] = useMemo(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,23 @@ describe('OrganizationActivity', () => {
h_userid: ['123', '456'],
assignment_id: [],
course_id: [],
public_id: [],
});

updateFilter('onAssignmentsChange', ['1', '2']);
assertCoursesFetched({
h_userid: [],
assignment_id: ['1', '2'],
course_id: [],
public_id: [],
});

updateFilter('onCoursesChange', ['3', '8', '9']);
assertCoursesFetched({
h_userid: [],
assignment_id: [],
course_id: ['3', '8', '9'],
public_id: [],
});
});

Expand Down
1 change: 1 addition & 0 deletions lms/static/scripts/frontend_apps/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export type DashboardUser = {

export type DashboardConfig = {
routes: DashboardRoutes;
organization_public_id?: string;
user: DashboardUser;
};

Expand Down

0 comments on commit 215bb5b

Please sign in to comment.