From 379ac52906d52784476a14466c73a0fb27d4938f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr>
Date: Mon, 27 Sep 2021 17:27:30 +0200
Subject: [PATCH] fix login if no user and reload permissions after logout

---
 src/store/index.js                   | 13 +++++++------
 src/views/project/Project_detail.vue |  2 +-
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/store/index.js b/src/store/index.js
index 225a436b..5035d682 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -162,14 +162,14 @@ export default new Vuex.Store({
     },
 
     USER_INFO({ state, commit }) {
-      if (state.user) {
+      if (!state.user) {
         axios
           .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}user_info/`)
           .then((response) => {
             if (response && response.status === 200) {
               const user = response.data.user;
               commit("SET_USER", user);
-              window.localStorage.setItem("user", JSON.stringify(user)); //? toujours nécessaire ?
+              //window.localStorage.setItem("user", JSON.stringify(user)); // ? nécessaire ?
             }
           })
           .catch(() => {
@@ -178,16 +178,17 @@ export default new Vuex.Store({
       }
     },
 
-    LOGOUT({ commit }) {
-      const pageNoRedirect = ["liste-signalements", "details-type-signalement", "details-signalement", "project_detail", "mentions", "aide", "index"]
+    LOGOUT({ commit, dispatch }) {
+      // const pageNoRedirect = ["liste-signalements", "details-type-signalement", "details-signalement", "project_detail", "mentions", "aide", "index"]
       axios
         .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}logout/`)
         .then((response) => {
           if (response && response.status === 200) {
             commit("SET_USER", false);
             commit("SET_USER_LEVEL_PROJECTS", null);
-            commit("SET_USER_PERMISSIONS", null);
-            if (!pageNoRedirect.includes(router.history.current.name)) router.push("/");
+            dispatch("GET_USER_LEVEL_PERMISSIONS");
+            // if (!pageNoRedirect.includes(router.history.current.name)) router.push("/");
+            router.push("/");
           }
         })
         .catch((error) => {
diff --git a/src/views/project/Project_detail.vue b/src/views/project/Project_detail.vue
index a07d8420..5b1ae27e 100644
--- a/src/views/project/Project_detail.vue
+++ b/src/views/project/Project_detail.vue
@@ -530,7 +530,7 @@ export default {
   },
 
   mounted() {
-    if (this.project) {
+    if (this.project && this.permissions.can_view_project) {
       this.$store.dispatch("map/INITIATE_MAP");
       const url = `${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${this.$route.params.slug}/feature/?output=geojson`;
       let self = this;
-- 
GitLab