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