diff --git a/src/components/TeamAssignment/teamAssign.utils.ts b/src/components/TeamAssignment/teamAssign.utils.ts index 219fb8d..7ef50a6 100644 --- a/src/components/TeamAssignment/teamAssign.utils.ts +++ b/src/components/TeamAssignment/teamAssign.utils.ts @@ -21,7 +21,7 @@ export const useTeamAssign = (): [any, any] => { volunteer: volunteer.id, team: volunteer.team === teamId ? 0 : teamId, }) - refreshVolunteers() + refreshVolunteers(jwtToken) }, [save, refreshVolunteers, jwtToken] ) diff --git a/src/server/gsheets/volunteers.ts b/src/server/gsheets/volunteers.ts index a778d99..596042f 100644 --- a/src/server/gsheets/volunteers.ts +++ b/src/server/gsheets/volunteers.ts @@ -23,7 +23,12 @@ const expressAccessor = new ExpressAccessors( translationVolunteer ) -export const volunteerListGet = expressAccessor.listGet() +export const volunteerListGet = expressAccessor.get(async (list, _body, id) => { + if (id <= 0) { + throw Error(`L'accès est réservé aux utilisateurs identifiés`) + } + return list +}) export const volunteerSet = expressAccessor.set() export const volunteerDiscordId = expressAccessor.get(async (list, body, id) => { @@ -174,8 +179,8 @@ async function sendForgetEmail(email: string, password: string): Promise { to: email, from: "contact@parisestludique.fr", subject: "Nouveau mot de passe pour le site bénévole de Paris est Ludique", - text: `Voici le nouveau mot de passe : ${password}\nL'ancien fonctionne encore, si tu t'en rappelles.`, - html: `Voici le nouveau mot de passe : ${password}
L'ancien fonctionne encore, si tu t'en rappelles.`, + text: `Voici le nouveau mot de passe : ${password}\nPour te connecter à https://fo.parisestludique.fr`, + html: `Voici le nouveau mot de passe : ${password}\nPour te connecter à https://fo.parisestludique.fr`, } await sgMail.send(msg) } diff --git a/src/server/index.ts b/src/server/index.ts index a11786e..c6db8de 100755 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -90,7 +90,7 @@ app.post("/PostulantAdd", postulantAdd) app.post("/VolunteerPartialAdd", volunteerPartialAdd) app.post("/VolunteerLogin", volunteerLogin) app.post("/VolunteerForgot", volunteerForgot) -app.get("/VolunteerListGet", volunteerListGet) +app.get("/VolunteerListGet", secure as RequestHandler, volunteerListGet) // Secured APIs app.get("/AnnouncementListGet", secure as RequestHandler, announcementListGet) diff --git a/src/services/volunteersAccessors.ts b/src/services/volunteersAccessors.ts index 3c1d2f4..bb6efe4 100644 --- a/src/services/volunteersAccessors.ts +++ b/src/services/volunteersAccessors.ts @@ -12,7 +12,7 @@ import { const serviceAccessors = new ServiceAccessors(elementName) -export const volunteerListGet = serviceAccessors.listGet() +export const volunteerListGet = serviceAccessors.securedListGet() export const volunteerDiscordIdGet = serviceAccessors.securedCustomGet<[number]>("DiscordId") export const volunteerPartialAdd = serviceAccessors.customPost<[Partial]>("PartialAdd") export const volunteerSet = serviceAccessors.set() diff --git a/src/store/__tests__/volunteerList.ts b/src/store/__tests__/volunteerList.ts deleted file mode 100644 index fa069f7..0000000 --- a/src/store/__tests__/volunteerList.ts +++ /dev/null @@ -1,79 +0,0 @@ -import axios from "axios" -import _ from "lodash" - -import mockStore from "../../utils/mockStore" -import volunteerList, { - initialState, - getRequesting, - getSuccess, - getFailure, - fetchVolunteerList, -} from "../volunteerList" -import { Volunteer, volunteerExample } from "../../services/volunteers" - -jest.mock("axios") - -const mockData: Volunteer[] = [volunteerExample] -const mockError = "Oops! Something went wrong." - -describe("volunteerList reducer", () => { - it("should handle initial state", () => { - // @ts-expect-error - expect(volunteerList(undefined, {})).toEqual(initialState) - }) - - it("should handle requesting correctly", () => { - expect(volunteerList(undefined, { type: getRequesting.type })).toEqual({ - readyStatus: "request", - ids: [], - entities: {}, - }) - }) - - it("should handle success correctly", () => { - expect(volunteerList(undefined, { type: getSuccess.type, payload: mockData })).toEqual({ - ...initialState, - readyStatus: "success", - ids: _.map(mockData, "id"), - entities: _.keyBy(mockData, "id"), - }) - }) - - it("should handle failure correctly", () => { - expect(volunteerList(undefined, { type: getFailure.type, payload: mockError })).toEqual({ - ...initialState, - readyStatus: "failure", - error: mockError, - }) - }) -}) - -describe("volunteerList action", () => { - it("fetches volunteer list successful", async () => { - const { dispatch, getActions } = mockStore() - const expectedActions = [ - { type: getRequesting.type, payload: undefined }, - { type: getSuccess.type, payload: mockData }, - ] - - // @ts-expect-error - axios.get.mockResolvedValue({ data: mockData }) - - await dispatch(fetchVolunteerList()) - expect(getActions()).toEqual(expectedActions) - }) - - it("fetches volunteer list failed", async () => { - const { dispatch, getActions } = mockStore() - const expectedActions = [ - { type: getRequesting.type }, - { type: getFailure.type, payload: mockError }, - ] - - // @ts-expect-error - axios.get.mockRejectedValue({ message: mockError }) - - await dispatch(fetchVolunteerList()) - expect(getActions()).toEqual(expectedActions) - }) -}) diff --git a/src/store/volunteerList.ts b/src/store/volunteerList.ts index b99633c..d03aa71 100644 --- a/src/store/volunteerList.ts +++ b/src/store/volunteerList.ts @@ -42,13 +42,23 @@ export const fetchVolunteerList = elementListFetch( const shouldFetchVolunteerList = (state: AppState) => state.volunteerList.readyStatus !== "success" -export const fetchVolunteerListIfNeed = (): AppThunk => (dispatch, getState) => { - if (shouldFetchVolunteerList(getState())) return dispatch(fetchVolunteerList()) +export const fetchVolunteerListIfNeed = + (id = 0): AppThunk => + (dispatch, getState) => { + let jwt = "" - return null -} + if (!id) { + ;({ jwt, id } = getState().auth) + } + if (shouldFetchVolunteerList(getState())) return dispatch(fetchVolunteerList(jwt)) -export const refreshVolunteerList = (): AppThunk => (dispatch) => dispatch(fetchVolunteerList()) + return null + } + +export const refreshVolunteerList = + (jwt: string): AppThunk => + (dispatch) => + dispatch(fetchVolunteerList(jwt)) export const selectVolunteerListState = (state: AppState): EntitiesRequest => state.volunteerList