Skip to content

Commit

Permalink
fix(dashboard): reset all atoms on organisation change (#1717)
Browse files Browse the repository at this point in the history
* fix(dashboard): reset all atoms on organisation change

* add new test
  • Loading branch information
arnaudambro authored Oct 10, 2023
1 parent 2cb3513 commit 6b0c9f8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
14 changes: 14 additions & 0 deletions dashboard/src/components/DataLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,20 @@ export function useDataLoader(options = { refreshOnMount: false }) {
async function resetCache() {
await clearCache();
setLastLoad(0);
setPersons([]);
setGroups([]);
setReports([]);
setPassages([]);
setRencontres([]);
setActions([]);
setTerritories([]);
setPlaces([]);
setRelsPersonPlace([]);
setTerritoryObservations([]);
setComments([]);
setConsultations([]);
setTreatments([]);
setMedicalFiles([]);
}

return {
Expand Down
6 changes: 3 additions & 3 deletions dashboard/src/scenes/auth/signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ const SignIn = () => {
const { user, token, ok } = authViaCookie ? await API.get({ path: '/user/signin-token' }) : await API.post({ path: '/user/signin', body });
if (!ok) return setIsSubmitting(false);
const { organisation } = user;
if (organisation._id !== window.localStorage.getItem('mano-organisationId')) {
await resetCache();
}
if (!!organisation.encryptionEnabled && !showEncryption && !['superadmin'].includes(user.role)) {
setShowEncryption(true);
return setIsSubmitting(false);
}
if (token) setToken(token);
setSessionInitialTimestamp(Date.now());
if (organisation._id !== window.localStorage.getItem('mano-organisationId')) {
await resetCache();
}
window.localStorage.setItem('mano-organisationId', organisation._id);
setOrganisation(organisation);
if (!['superadmin'].includes(user.role) && !!signinForm.orgEncryptionKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,21 @@ test("Person creation", async ({ page }) => {
await expect(page).toHaveURL("http://localhost:8090/person");

await expect(page.getByRole("cell", { name: person1Name })).toBeVisible();

await test.step("Login with user from other organisation should clear the cache", async () => {
await page.getByRole("button", { name: "User Admin Test - 5" }).click();
await page.getByRole("menuitem", { name: "Se déconnecter et vider le cache" }).click();
await expect(page).toHaveURL("http://localhost:8090/auth");

await page.getByLabel("Email").fill("[email protected]");
await page.getByLabel("Mot de passe").fill("secret");
await page.getByRole("button", { name: "Se connecter" }).click();
await page.getByLabel("Clé de chiffrement d'organisation").fill("plouf");
await page.getByRole("button", { name: "Se connecter" }).click();
await expect(page).toHaveURL("http://localhost:8090/reception?calendarTab=2");
await page.getByRole("link", { name: "Personnes suivies" }).click();
await expect(page).toHaveURL("http://localhost:8090/person");

await expect(page.getByRole("cell", { name: person1Name })).not.toBeVisible();
});
});

0 comments on commit 6b0c9f8

Please sign in to comment.