Mercurial > gemma
view client/src/stores/usermanagement.js @ 514:4a1db55a9920
Use auth.RunAs in JSON controller.
It's more symmetric to the rest of the application and
returns the database connection earlier to the pool.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 27 Aug 2018 10:35:55 +0200 |
parents | 5a9dde6951ae |
children | 4bc27eea4f09 |
line wrap: on
line source
import { HTTP } from "../lib/http"; const newUser = () => { return { user: "", email: "", country: null, role: null, isNew: true, password: "" }; }; const UserManagement = { namespaced: true, state: { users: null, currentUser: null, userDetailsVisible: false }, getters: { isUserDetailsVisible: state => { return state.userDetailsVisible; }, currentUser: state => { return state.currentUser; }, users: state => { return state.users; }, getUserByName: state => name => { return state.users.find(user => { return user.user === name; }); } }, mutations: { setUserDetailsInvisible: state => { state.userDetailsVisible = false; }, setUserDetailsVisible: state => { state.userDetailsVisible = true; }, usersLoaded: (state, data) => { state.users = data.users; }, setCurrentUser: (state, data) => { state.currentUser = data; state.userDetailsVisible = true; }, clearCurrentUser: state => { state.currentUser = newUser(); } }, actions: { deleteUser({ commit }, data) { const { name } = data; return new Promise((resolve, reject) => { HTTP.delete("/users/" + name, { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { commit("clearCurrentUser"); commit("setUserDetailsInvisible"); resolve(response); }) .catch(error => { reject(error); }); }); }, saveCurrentUser({ commit }, data) { const { path, user } = data; if (user.isNew) { return new Promise((resolve, reject) => { HTTP.post("/users", user, { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { commit("setUserDetailsInvisible"); commit("clearCurrentUser"); resolve(response); }) .catch(error => { reject(error); }); }); } else { return new Promise((resolve, reject) => { HTTP.put("/users/" + path, user, { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { commit("setUserDetailsInvisible"); commit("clearCurrentUser"); resolve(response); }) .catch(error => { reject(error); }); }); } }, loadUsers({ commit }) { return new Promise((resolve, reject) => { HTTP.get("/users", { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { commit("usersLoaded", response.data); resolve(response); }) .catch(error => { reject(error); }); }); } } }; export default UserManagement;