Yoshie Muranaka | 224d6ad | 2020-05-21 09:10:52 -0700 | [diff] [blame] | 1 | import api, { getResponseCount } from '@/store/api'; |
| 2 | import i18n from '@/i18n'; |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 3 | |
MichalX Szopinski | 5905f96 | 2021-06-07 15:46:59 +0200 | [diff] [blame^] | 4 | const getServerErrorMessages = function (error) { |
| 5 | let errorData = error.response.data.error |
| 6 | ? error.response.data.error |
| 7 | : error.response.data; |
| 8 | if (typeof errorData == 'string') { |
| 9 | return []; |
| 10 | } |
| 11 | return Object.values(errorData) |
| 12 | .reduce((a, b) => a.concat(b)) |
| 13 | .filter((info) => info.Message) |
| 14 | .map((info) => info.Message); |
| 15 | }; |
| 16 | |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 17 | const UserManagementStore = { |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 18 | namespaced: true, |
| 19 | state: { |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 20 | allUsers: [], |
Yoshie Muranaka | 038a9da | 2020-04-17 11:22:56 -0700 | [diff] [blame] | 21 | accountRoles: [], |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 22 | accountLockoutDuration: null, |
| 23 | accountLockoutThreshold: null, |
| 24 | accountMinPasswordLength: null, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 25 | accountMaxPasswordLength: null, |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 26 | }, |
| 27 | getters: { |
| 28 | allUsers(state) { |
| 29 | return state.allUsers; |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 30 | }, |
Yoshie Muranaka | 038a9da | 2020-04-17 11:22:56 -0700 | [diff] [blame] | 31 | accountRoles(state) { |
| 32 | return state.accountRoles; |
| 33 | }, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 34 | accountSettings(state) { |
| 35 | return { |
| 36 | lockoutDuration: state.accountLockoutDuration, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 37 | lockoutThreshold: state.accountLockoutThreshold, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 38 | }; |
| 39 | }, |
| 40 | accountPasswordRequirements(state) { |
| 41 | return { |
| 42 | minLength: state.accountMinPasswordLength, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 43 | maxLength: state.accountMaxPasswordLength, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 44 | }; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 45 | }, |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 46 | }, |
| 47 | mutations: { |
| 48 | setUsers(state, allUsers) { |
| 49 | state.allUsers = allUsers; |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 50 | }, |
Yoshie Muranaka | 038a9da | 2020-04-17 11:22:56 -0700 | [diff] [blame] | 51 | setAccountRoles(state, accountRoles) { |
| 52 | state.accountRoles = accountRoles; |
| 53 | }, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 54 | setLockoutDuration(state, lockoutDuration) { |
| 55 | state.accountLockoutDuration = lockoutDuration; |
| 56 | }, |
| 57 | setLockoutThreshold(state, lockoutThreshold) { |
| 58 | state.accountLockoutThreshold = lockoutThreshold; |
| 59 | }, |
| 60 | setAccountMinPasswordLength(state, minPasswordLength) { |
| 61 | state.accountMinPasswordLength = minPasswordLength; |
| 62 | }, |
| 63 | setAccountMaxPasswordLength(state, maxPasswordLength) { |
| 64 | state.accountMaxPasswordLength = maxPasswordLength; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 65 | }, |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 66 | }, |
| 67 | actions: { |
Yoshie Muranaka | 346be2a | 2020-04-28 11:12:14 -0700 | [diff] [blame] | 68 | async getUsers({ commit }) { |
| 69 | return await api |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 70 | .get('/redfish/v1/AccountService/Accounts') |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 71 | .then((response) => |
| 72 | response.data.Members.map((user) => user['@odata.id']) |
| 73 | ) |
| 74 | .then((userIds) => api.all(userIds.map((user) => api.get(user)))) |
| 75 | .then((users) => { |
| 76 | const userData = users.map((user) => user.data); |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 77 | commit('setUsers', userData); |
Yoshie Muranaka | 74c24f1 | 2019-12-03 10:45:46 -0800 | [diff] [blame] | 78 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 79 | .catch((error) => { |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 80 | console.log(error); |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 81 | const message = i18n.t('pageUserManagement.toast.errorLoadUsers'); |
Yoshie Muranaka | 8fc53ad | 2020-05-04 10:40:41 -0700 | [diff] [blame] | 82 | throw new Error(message); |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 83 | }); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 84 | }, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 85 | getAccountSettings({ commit }) { |
| 86 | api |
| 87 | .get('/redfish/v1/AccountService') |
| 88 | .then(({ data }) => { |
| 89 | commit('setLockoutDuration', data.AccountLockoutDuration); |
| 90 | commit('setLockoutThreshold', data.AccountLockoutThreshold); |
| 91 | commit('setAccountMinPasswordLength', data.MinPasswordLength); |
| 92 | commit('setAccountMaxPasswordLength', data.MaxPasswordLength); |
| 93 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 94 | .catch((error) => { |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 95 | console.log(error); |
Yoshie Muranaka | 8fc53ad | 2020-05-04 10:40:41 -0700 | [diff] [blame] | 96 | const message = i18n.t( |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 97 | 'pageUserManagement.toast.errorLoadAccountSettings' |
Yoshie Muranaka | 8fc53ad | 2020-05-04 10:40:41 -0700 | [diff] [blame] | 98 | ); |
| 99 | throw new Error(message); |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 100 | }); |
| 101 | }, |
Yoshie Muranaka | 038a9da | 2020-04-17 11:22:56 -0700 | [diff] [blame] | 102 | getAccountRoles({ commit }) { |
| 103 | api |
| 104 | .get('/redfish/v1/AccountService/Roles') |
| 105 | .then(({ data: { Members = [] } = {} }) => { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 106 | const roles = Members.map((role) => { |
Yoshie Muranaka | 038a9da | 2020-04-17 11:22:56 -0700 | [diff] [blame] | 107 | return role['@odata.id'].split('/').pop(); |
| 108 | }); |
| 109 | commit('setAccountRoles', roles); |
| 110 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 111 | .catch((error) => console.log(error)); |
Yoshie Muranaka | 038a9da | 2020-04-17 11:22:56 -0700 | [diff] [blame] | 112 | }, |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 113 | async createUser({ dispatch }, { username, password, privilege, status }) { |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 114 | const data = { |
| 115 | UserName: username, |
| 116 | Password: password, |
| 117 | RoleId: privilege, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 118 | Enabled: status, |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 119 | }; |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 120 | return await api |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 121 | .post('/redfish/v1/AccountService/Accounts', data) |
| 122 | .then(() => dispatch('getUsers')) |
Yoshie Muranaka | 8fc53ad | 2020-05-04 10:40:41 -0700 | [diff] [blame] | 123 | .then(() => |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 124 | i18n.t('pageUserManagement.toast.successCreateUser', { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 125 | username, |
Yoshie Muranaka | 8fc53ad | 2020-05-04 10:40:41 -0700 | [diff] [blame] | 126 | }) |
| 127 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 128 | .catch((error) => { |
MichalX Szopinski | 5905f96 | 2021-06-07 15:46:59 +0200 | [diff] [blame^] | 129 | let serverMessages = getServerErrorMessages(error); |
| 130 | let message = |
| 131 | serverMessages.length > 0 |
| 132 | ? serverMessages.join(' ') |
| 133 | : i18n.t('pageUserManagement.toast.errorCreateUser', { |
| 134 | username: username, |
| 135 | }); |
Yoshie Muranaka | 8fc53ad | 2020-05-04 10:40:41 -0700 | [diff] [blame] | 136 | throw new Error(message); |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 137 | }); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 138 | }, |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 139 | async updateUser( |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 140 | { dispatch }, |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 141 | { originalUsername, username, password, privilege, status, locked } |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 142 | ) { |
| 143 | const data = {}; |
| 144 | if (username) data.UserName = username; |
| 145 | if (password) data.Password = password; |
| 146 | if (privilege) data.RoleId = privilege; |
| 147 | if (status !== undefined) data.Enabled = status; |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 148 | if (locked !== undefined) data.Locked = locked; |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 149 | return await api |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 150 | .patch(`/redfish/v1/AccountService/Accounts/${originalUsername}`, data) |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 151 | .then(() => dispatch('getUsers')) |
Yoshie Muranaka | 8fc53ad | 2020-05-04 10:40:41 -0700 | [diff] [blame] | 152 | .then(() => |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 153 | i18n.t('pageUserManagement.toast.successUpdateUser', { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 154 | username: originalUsername, |
Yoshie Muranaka | 8fc53ad | 2020-05-04 10:40:41 -0700 | [diff] [blame] | 155 | }) |
| 156 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 157 | .catch((error) => { |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 158 | console.log(error); |
MichalX Szopinski | 5905f96 | 2021-06-07 15:46:59 +0200 | [diff] [blame^] | 159 | const serverMessages = getServerErrorMessages(error); |
| 160 | const message = |
| 161 | serverMessages.length > 0 |
| 162 | ? serverMessages.join(' ') |
| 163 | : i18n.t('pageUserManagement.toast.errorUpdateUser', { |
| 164 | username: originalUsername, |
| 165 | }); |
Yoshie Muranaka | 8fc53ad | 2020-05-04 10:40:41 -0700 | [diff] [blame] | 166 | throw new Error(message); |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 167 | }); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 168 | }, |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 169 | async deleteUser({ dispatch }, username) { |
| 170 | return await api |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 171 | .delete(`/redfish/v1/AccountService/Accounts/${username}`) |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 172 | .then(() => dispatch('getUsers')) |
Yoshie Muranaka | 8fc53ad | 2020-05-04 10:40:41 -0700 | [diff] [blame] | 173 | .then(() => |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 174 | i18n.t('pageUserManagement.toast.successDeleteUser', { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 175 | username, |
Yoshie Muranaka | 8fc53ad | 2020-05-04 10:40:41 -0700 | [diff] [blame] | 176 | }) |
| 177 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 178 | .catch((error) => { |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 179 | console.log(error); |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 180 | const message = i18n.t('pageUserManagement.toast.errorDeleteUser', { |
| 181 | username, |
| 182 | }); |
Yoshie Muranaka | 8fc53ad | 2020-05-04 10:40:41 -0700 | [diff] [blame] | 183 | throw new Error(message); |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 184 | }); |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 185 | }, |
| 186 | async deleteUsers({ dispatch }, users) { |
| 187 | const promises = users.map(({ username }) => { |
| 188 | return api |
| 189 | .delete(`/redfish/v1/AccountService/Accounts/${username}`) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 190 | .catch((error) => { |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 191 | console.log(error); |
| 192 | return error; |
| 193 | }); |
| 194 | }); |
| 195 | return await api |
| 196 | .all(promises) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 197 | .then((response) => { |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 198 | dispatch('getUsers'); |
| 199 | return response; |
| 200 | }) |
| 201 | .then( |
| 202 | api.spread((...responses) => { |
| 203 | const { successCount, errorCount } = getResponseCount(responses); |
| 204 | let toastMessages = []; |
| 205 | |
| 206 | if (successCount) { |
| 207 | const message = i18n.tc( |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 208 | 'pageUserManagement.toast.successBatchDelete', |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 209 | successCount |
| 210 | ); |
| 211 | toastMessages.push({ type: 'success', message }); |
| 212 | } |
| 213 | |
| 214 | if (errorCount) { |
| 215 | const message = i18n.tc( |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 216 | 'pageUserManagement.toast.errorBatchDelete', |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 217 | errorCount |
| 218 | ); |
| 219 | toastMessages.push({ type: 'error', message }); |
| 220 | } |
| 221 | |
| 222 | return toastMessages; |
| 223 | }) |
| 224 | ); |
| 225 | }, |
| 226 | async enableUsers({ dispatch }, users) { |
| 227 | const data = { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 228 | Enabled: true, |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 229 | }; |
| 230 | const promises = users.map(({ username }) => { |
| 231 | return api |
| 232 | .patch(`/redfish/v1/AccountService/Accounts/${username}`, data) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 233 | .catch((error) => { |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 234 | console.log(error); |
| 235 | return error; |
| 236 | }); |
| 237 | }); |
| 238 | return await api |
| 239 | .all(promises) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 240 | .then((response) => { |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 241 | dispatch('getUsers'); |
| 242 | return response; |
| 243 | }) |
| 244 | .then( |
| 245 | api.spread((...responses) => { |
| 246 | const { successCount, errorCount } = getResponseCount(responses); |
| 247 | let toastMessages = []; |
| 248 | |
| 249 | if (successCount) { |
| 250 | const message = i18n.tc( |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 251 | 'pageUserManagement.toast.successBatchEnable', |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 252 | successCount |
| 253 | ); |
| 254 | toastMessages.push({ type: 'success', message }); |
| 255 | } |
| 256 | |
| 257 | if (errorCount) { |
| 258 | const message = i18n.tc( |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 259 | 'pageUserManagement.toast.errorBatchEnable', |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 260 | errorCount |
| 261 | ); |
| 262 | toastMessages.push({ type: 'error', message }); |
| 263 | } |
| 264 | |
| 265 | return toastMessages; |
| 266 | }) |
| 267 | ); |
| 268 | }, |
| 269 | async disableUsers({ dispatch }, users) { |
| 270 | const data = { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 271 | Enabled: false, |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 272 | }; |
| 273 | const promises = users.map(({ username }) => { |
| 274 | return api |
| 275 | .patch(`/redfish/v1/AccountService/Accounts/${username}`, data) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 276 | .catch((error) => { |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 277 | console.log(error); |
| 278 | return error; |
| 279 | }); |
| 280 | }); |
| 281 | return await api |
| 282 | .all(promises) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 283 | .then((response) => { |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 284 | dispatch('getUsers'); |
| 285 | return response; |
| 286 | }) |
| 287 | .then( |
| 288 | api.spread((...responses) => { |
| 289 | const { successCount, errorCount } = getResponseCount(responses); |
| 290 | let toastMessages = []; |
| 291 | |
| 292 | if (successCount) { |
| 293 | const message = i18n.tc( |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 294 | 'pageUserManagement.toast.successBatchDisable', |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 295 | successCount |
| 296 | ); |
| 297 | toastMessages.push({ type: 'success', message }); |
| 298 | } |
| 299 | |
| 300 | if (errorCount) { |
| 301 | const message = i18n.tc( |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 302 | 'pageUserManagement.toast.errorBatchDisable', |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 303 | errorCount |
| 304 | ); |
| 305 | toastMessages.push({ type: 'error', message }); |
| 306 | } |
| 307 | |
| 308 | return toastMessages; |
| 309 | }) |
| 310 | ); |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 311 | }, |
| 312 | async saveAccountSettings( |
| 313 | { dispatch }, |
| 314 | { lockoutThreshold, lockoutDuration } |
| 315 | ) { |
| 316 | const data = {}; |
| 317 | if (lockoutThreshold !== undefined) { |
| 318 | data.AccountLockoutThreshold = lockoutThreshold; |
| 319 | } |
| 320 | if (lockoutDuration !== undefined) { |
| 321 | data.AccountLockoutDuration = lockoutDuration; |
| 322 | } |
| 323 | |
| 324 | return await api |
| 325 | .patch('/redfish/v1/AccountService', data) |
| 326 | //GET new settings to update view |
| 327 | .then(() => dispatch('getAccountSettings')) |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 328 | .then(() => i18n.t('pageUserManagement.toast.successSaveSettings')) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 329 | .catch((error) => { |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 330 | console.log(error); |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 331 | const message = i18n.t('pageUserManagement.toast.errorSaveSettings'); |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 332 | throw new Error(message); |
| 333 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 334 | }, |
| 335 | }, |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 336 | }; |
| 337 | |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 338 | export default UserManagementStore; |