Skip to content
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

hotfix(tp+oidc): fixed the wrong keys in optimistic mutations and added leeway to OIDC token validation #1206

Merged
Merged
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
1 change: 1 addition & 0 deletions backend/server/routers/utility/oidc/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def validate_id_token(token: str, access_token: str) -> DecodedIDToken:
audience=CLIENT_ID,
issuer=config["issuer"],
options={ "verify_signature": True },
leeway=5,
)
except jwt.exceptions.InvalidTokenError as e:
raise OIDCValidationError(
Expand Down
68 changes: 40 additions & 28 deletions frontend/src/pages/TermPlanner/TermPlanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import openNotification from 'utils/openNotification';
import PageTemplate from 'components/PageTemplate';
import Spinner from 'components/Spinner';
import { LIVE_YEAR } from 'config/constants';
import useIdentity from 'hooks/useIdentity';
import useSettings from 'hooks/useSettings';
import { GridItem } from './common/styles';
import HideYearTooltip from './HideYearTooltip';
Expand Down Expand Up @@ -70,6 +71,8 @@ const TermPlanner = () => {
const [draggingCourse, setDraggingCourse] = useState('');
const { hiddenYears } = useSettings();

const { userId } = useIdentity();

const queryClient = useQueryClient();
const plannerPicRef = useRef<HTMLDivElement>(null);

Expand Down Expand Up @@ -120,17 +123,20 @@ const TermPlanner = () => {
const setPlannedCourseToTermMutation = useSetPlannedCourseToTermMutation({
mutationOptions: {
onMutate: (data) => {
// TODO-olli
queryClient.setQueryData(['planner'], (prev: PlannerResponse | undefined) => {
if (!prev) return badPlanner;
const curr: PlannerResponse = structuredClone(prev);
curr.years[data.srcRow][data.srcTerm].splice(
curr.years[data.srcRow][data.srcTerm].indexOf(data.courseCode),
1
);
curr.years[data.destRow][data.destTerm].splice(data.destIndex, 0, data.courseCode);
return curr;
});
// TODO: match these keys with queries.ts
queryClient.setQueryData(
['user', userId, 'planner'],
(prev: PlannerResponse | undefined) => {
if (!prev) return badPlanner;
const curr: PlannerResponse = structuredClone(prev);
curr.years[data.srcRow][data.srcTerm].splice(
curr.years[data.srcRow][data.srcTerm].indexOf(data.courseCode),
1
);
curr.years[data.destRow][data.destTerm].splice(data.destIndex, 0, data.courseCode);
return curr;
}
);
}
}
});
Expand All @@ -143,13 +149,16 @@ const TermPlanner = () => {
mutationOptions: {
onMutate: (data) => {
// TODO-olli
queryClient.setQueryData(['planner'], (prev: PlannerResponse | undefined) => {
if (!prev) return badPlanner;
const curr: PlannerResponse = structuredClone(prev);
curr.unplanned.splice(curr.unplanned.indexOf(data.courseCode), 1);
curr.years[data.destRow][data.destTerm].splice(data.destIndex, 0, data.courseCode);
return curr;
});
queryClient.setQueryData(
['user', userId, 'planner'],
(prev: PlannerResponse | undefined) => {
if (!prev) return badPlanner;
const curr: PlannerResponse = structuredClone(prev);
curr.unplanned.splice(curr.unplanned.indexOf(data.courseCode), 1);
curr.years[data.destRow][data.destTerm].splice(data.destIndex, 0, data.courseCode);
return curr;
}
);
}
}
});
Expand All @@ -162,16 +171,19 @@ const TermPlanner = () => {
mutationOptions: {
onMutate: (data) => {
// TODO-olli: remove from here...
queryClient.setQueryData(['planner'], (prev: PlannerResponse | undefined) => {
if (!prev) return badPlanner;
const curr: PlannerResponse = structuredClone(prev);
curr.years[data.srcRow as number][data.srcTerm as string].splice(
curr.years[data.srcRow as number][data.srcTerm as string].indexOf(data.courseCode),
1
);
curr.unplanned.push(data.courseCode);
return curr;
});
queryClient.setQueryData(
['user', userId, 'planner'],
(prev: PlannerResponse | undefined) => {
if (!prev) return badPlanner;
const curr: PlannerResponse = structuredClone(prev);
curr.years[data.srcRow as number][data.srcTerm as string].splice(
curr.years[data.srcRow as number][data.srcTerm as string].indexOf(data.courseCode),
1
);
curr.unplanned.push(data.courseCode);
return curr;
}
);
}
}
});
Expand Down