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