Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #703 from SELab-2/url-fix
Browse files Browse the repository at this point in the history
fix: remove logs and double / error
  • Loading branch information
BramDevlaminck authored May 22, 2022
2 parents e9c1097 + 0483c02 commit 7422ec3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 13 deletions.
5 changes: 3 additions & 2 deletions backend/routes/followup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as ormJA from "../orm_functions/job_application";
import * as rq from "../request";
import { Responses } from "../types";
import * as util from "../utility";
import { checkYearPermissionStudent, errors } from "../utility";
import { checkYearPermissionsFollowup, errors } from "../utility";
import { getOsocYearsForLoginUser } from "../orm_functions/login_user";
import { getLatestOsoc, getOsocById } from "../orm_functions/osoc";
import { getJobApplication } from "../orm_functions/job_application";
Expand All @@ -21,6 +21,7 @@ export async function getFollowup(
return rq
.parseGetFollowupStudentRequest(req)
.then((parsed) => util.checkSessionKey(parsed))
.then(checkYearPermissionsFollowup)
.then((checked) =>
ormJA
.getJobApplication(checked.data.id)
Expand Down Expand Up @@ -59,7 +60,7 @@ export async function updateFollowup(
return rq
.parseSetFollowupStudentRequest(req)
.then((parsed) => util.checkSessionKey(parsed))
.then(checkYearPermissionStudent)
.then(checkYearPermissionsFollowup)
.then(async (checked) => {
// modifications to a job application is only allowed if the job application is of the most recent osoc year
const [jobApplication, latestOsoc] = await Promise.all([
Expand Down
7 changes: 6 additions & 1 deletion backend/tests/routes_unit/followup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ jest.mock("../../utility", () => {
checkSessionKey: jest.fn(),
isAdmin: jest.fn(),
checkYearPermissionStudent: jest.fn(),
}; // we want to only mock checkSessionKey, isAdmin and checkYearPermissionStudent
checkYearPermissionsFollowup: jest.fn(),
}; // we want to only mock checkSessionKey, isAdmin, checkYearPermissionStudent and checkYearPermissionsFollowup
});
export const utilMock = util as jest.Mocked<typeof util>;

Expand Down Expand Up @@ -179,6 +180,9 @@ beforeEach(() => {
utilMock.checkYearPermissionStudent.mockImplementation((v) =>
Promise.resolve(v)
);
utilMock.checkYearPermissionsFollowup.mockImplementation((v) =>
Promise.resolve(v)
);

osocMock.getLatestOsoc.mockResolvedValue(osocdat);
osocMock.getOsocById.mockResolvedValue(osocdat);
Expand Down Expand Up @@ -210,6 +214,7 @@ afterEach(() => {
utilMock.checkSessionKey.mockReset();
utilMock.isAdmin.mockReset();
utilMock.checkYearPermissionStudent.mockReset();
utilMock.checkYearPermissionsFollowup.mockReset();

osocMock.getLatestOsoc.mockReset();
osocMock.getOsocById.mockReset();
Expand Down
24 changes: 24 additions & 0 deletions backend/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { getAppliedYearsForStudent } from "./orm_functions/student";
import IdRequest = Requests.IdRequest;
import { getProjectYear } from "./orm_functions/project";
import { getOsocById } from "./orm_functions/osoc";
import { getJobApplication } from "./orm_functions/job_application";

/**
* The API error cooking functions. HTTP error codes are loaded from
Expand Down Expand Up @@ -416,6 +417,29 @@ export async function checkYearPermissionOsoc<T extends IdRequest>(
return Promise.reject(errors.cookInsufficientRights());
}

/**
* returns the userData object if the user is allowed to see the followup
* Otherwise it returns an insufficient rights error.
* @param userData: object with the userId and osocID
*/
export async function checkYearPermissionsFollowup<T extends IdRequest>(
userData: WithUserID<T>
): Promise<WithUserID<T>> {
// get the years that are visible for the loginUser
const visibleYears = await getOsocYearsForLoginUser(userData.userId);
// get the year that the application belongs to
const job_application = await getJobApplication(userData.data.id);

// check if the project year is inside the visible years for the user
if (
job_application !== null &&
visibleYears.includes(job_application.osoc.year)
) {
return userData;
}
return Promise.reject(errors.cookInsufficientRights());
}

/**
* Generates a new session key.
* @returns The newly generated session key.
Expand Down
8 changes: 1 addition & 7 deletions frontend/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,7 @@ export const Header: React.FC = () => {
Accept: "application/json",
Authorization: `auth/osoc2 ${sessionKey}`,
},
})
.then((response) => {
if (!response.ok) {
console.log(response);
}
})
.catch((error) => console.log(error));
}).catch((error) => console.log(error));
});
};

Expand Down
1 change: 0 additions & 1 deletion frontend/components/ProjectCard/ProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const ProjectCard: React.FC<{
const { sessionKey } = getSession
? await getSession()
: { sessionKey: "" };
console.log("test");
const response = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/project/${project.id}/assignee`,
{
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Students/Students.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export const Students: React.FC<{
paramsQuery.delete("id");
// push the url
router
.push(`/${window.location.pathname}?${paramsQuery.toString()}`)
.push(`${window.location.pathname}?${paramsQuery.toString()}`)
.then();

if (params !== undefined) {
Expand Down
1 change: 0 additions & 1 deletion frontend/pages/osocs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ const Osocs: NextPage = () => {
*/
const search = useCallback(
async (params: OsocFilterParams, page: number) => {
console.log("callback");
if (loading) return;
isLoading(true);
const filters = [];
Expand Down

0 comments on commit 7422ec3

Please sign in to comment.