diff --git a/src/main.js b/src/main.js index 8fa1df523375fa257cd03c49a7ed4de4354f8850..0a98314409ddff6a46a7d4477fe3aed478a39be3 100644 --- a/src/main.js +++ b/src/main.js @@ -13,6 +13,7 @@ store.dispatch("GET_ALL_PROJECTS"), store.dispatch("GET_STATIC_PAGES"), store.dispatch("GET_USER_LEVEL_PROJECTS"), store.dispatch("map/GET_LAYERS"), +store.dispatch("GET_USER_LEVEL_PERMISSIONS"), ]).then(axios.spread(function () { new Vue({ router, diff --git a/src/store/index.js b/src/store/index.js index f1fceb11d381953cef729fbafbb0e1ec3a6a543d..a75f0cab6cabdfd6aa3dc1beb628c6a93c8569f4 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -38,7 +38,8 @@ export default new Vuex.Store({ last_comments: [], staticPages: null, SSO_SETTED: false, - USER_LEVEL_PROJECTS: null + USER_LEVEL_PROJECTS: null, + user_permissions: null, }, mutations: { @@ -75,6 +76,9 @@ export default new Vuex.Store({ SET_PROJECT_COMMENTS(state, last_comments) { state.last_comments = last_comments }, + SET_USER_PERMISSIONS(state, userPermissions) { + state.user_permissions = userPermissions + }, }, getters: { @@ -139,18 +143,18 @@ export default new Vuex.Store({ if (response && response.status === 200) { const user = response.data.user; commit("SET_USER", user); - window.localStorage.setItem("user", JSON.stringify(user)); + window.localStorage.setItem("user", JSON.stringify(user)); //? toujours nécessaire ? } - }) // todo: ajouter au localestorage + }) .catch(() => { router.push({ name: "login" }); }); }, - LOGOUT({ commit }) { // ? logout bien dans django ? + LOGOUT({ commit }) { // ? logout se fait bien dans django ? axios .get(`${DJANGO_API_BASE}logout/`) - .then((response) => { // todo: check status + .then((response) => { if (response && response.status === 200) { commit("SET_USER", false); // ? better false or null commit("SET_USER_LEVEL_PROJECTS", null); @@ -175,6 +179,19 @@ export default new Vuex.Store({ }); }, + GET_USER_LEVEL_PERMISSIONS({ commit }) { + axios + .get(`${DJANGO_API_BASE}user-permissions/`) + .then((response) => { + if (response && response.status === 200) { + commit("SET_USER_PERMISSIONS", response.data) + } + }) + .catch((error) => { + throw error; + }); + }, + GET_PROJECT_INFO({ commit, dispatch }, slug) { commit("SET_PROJECT_SLUG", slug); dispatch("GET_PROJECT_LAST_MESSAGES", slug); diff --git a/src/views/My_account.vue b/src/views/My_account.vue index e679b7d5579a951cc93a294be4ca9ebbcdd82b2a..c05a6d27d60e16d6ba70681c7620b924ecc8ba88 100644 --- a/src/views/My_account.vue +++ b/src/views/My_account.vue @@ -19,7 +19,7 @@ <div class="item"> <div class="right floated content"> <div class="description"> - {{ user.get_full_name }} + {{ userFullname }} </div> </div> <div class="content">Nom complet</div> @@ -56,7 +56,7 @@ :src=" project.thumbnail.includes('default') ? require('@/assets/img/default.png') - : project.thumbnail + : DJANGO_BASE_URL + project.thumbnail + refreshId() " height="200" /> @@ -288,6 +288,18 @@ export default { computed: { // todo : filter projects to user ...mapState(["user", "projects", "USER_LEVEL_PROJECTS"]), + DJANGO_BASE_URL: () => process.env.VUE_APP_DJANGO_BASE, + userFullname: function () { + if (this.user.first_name || this.user.last_name) + return this.user.first_name + " " + this.user.last_name; + return null; + }, + }, + + methods: { + refreshId() { + return "?ver=" + Math.random(); + }, }, }; </script> \ No newline at end of file diff --git a/src/views/project/Project_type_list.vue b/src/views/project/Project_type_list.vue index addbd98901d3597b1a326822d4590bf93967c5fb..3909eab7ac7c1f54d274d63744467eda05df91a0 100644 --- a/src/views/project/Project_type_list.vue +++ b/src/views/project/Project_type_list.vue @@ -7,7 +7,13 @@ <div class="ui divided items"> <div v-for="project in project_types" :key="project.slug" class="item"> <div class="ui tiny image"> - <img :src="project.thumbnail" /> + <img + :src=" + project.thumbnail.includes('default') + ? require('@/assets/img/default.png') + : DJANGO_BASE_URL + project.thumbnail + refreshId() + " + /> </div> <div class="middle aligned content"> <div class="description"> @@ -67,6 +73,13 @@ export default { computed: { ...mapGetters(["project_types"]), + DJANGO_BASE_URL: () => process.env.VUE_APP_DJANGO_BASE, + }, + + methods: { + refreshId() { + return "?ver=" + Math.random(); + }, }, }; </script> \ No newline at end of file