|
3 | 3 | * SPDX-License-Identifier: Apache-2 |
4 | 4 | * For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0 |
5 | 5 | */ |
6 | | -import {Args, Flags, ux} from '@oclif/core'; |
7 | | -import cliui from 'cliui'; |
| 6 | +import {Args, Flags} from '@oclif/core'; |
8 | 7 | import {AmCommand} from '@salesforce/b2c-tooling-sdk/cli'; |
9 | 8 | import type {AccountManagerUser, UserExpandOption} from '@salesforce/b2c-tooling-sdk'; |
10 | 9 | import {t} from '../../../i18n/index.js'; |
| 10 | +import {printUserDetails} from '../../../utils/am/user-display.js'; |
11 | 11 |
|
12 | 12 | /** |
13 | 13 | * Valid expand values for the users API. |
@@ -107,96 +107,12 @@ export default class UserGet extends AmCommand<typeof UserGet> { |
107 | 107 | return user; |
108 | 108 | } |
109 | 109 |
|
110 | | - this.printUserDetails(user); |
| 110 | + const [roleMapping, orgMapping] = await Promise.all([ |
| 111 | + this.accountManagerClient.getRoleMapping(), |
| 112 | + this.accountManagerClient.getOrgMapping(), |
| 113 | + ]); |
| 114 | + printUserDetails(user, roleMapping, orgMapping); |
111 | 115 |
|
112 | 116 | return user; |
113 | 117 | } |
114 | | - |
115 | | - private printBasicFields(ui: ReturnType<typeof cliui>, user: AccountManagerUser): void { |
116 | | - const isPasswordExpired = user.passwordExpirationTimestamp |
117 | | - ? user.passwordExpirationTimestamp < Date.now() |
118 | | - : undefined; |
119 | | - const twoFAEnabled = user.verifiers && user.verifiers.length > 0 ? 'Yes' : 'No'; |
120 | | - |
121 | | - const fields: [string, string | undefined][] = [ |
122 | | - ['ID', user.id], |
123 | | - ['Email', user.mail], |
124 | | - ['First Name', user.firstName], |
125 | | - ['Last Name', user.lastName], |
126 | | - ['Display Name', user.displayName], |
127 | | - ['State', user.userState], |
128 | | - ['Primary Organization', user.primaryOrganization], |
129 | | - ['Preferred Locale', user.preferredLocale || undefined], |
130 | | - ['Business Phone', user.businessPhone || undefined], |
131 | | - ['Home Phone', user.homePhone || undefined], |
132 | | - ['Mobile Phone', user.mobilePhone || undefined], |
133 | | - ['Linked to SF Identity', user.linkedToSfIdentity?.toString()], |
134 | | - ['2FA Enabled', twoFAEnabled], |
135 | | - ['Password Expired', isPasswordExpired === undefined ? undefined : isPasswordExpired ? 'Yes' : 'No'], |
136 | | - ['Last Login', user.lastLoginDate || undefined], |
137 | | - ['Created At', user.createdAt ? new Date(user.createdAt).toLocaleString() : undefined], |
138 | | - ['Last Modified', user.lastModified ? new Date(user.lastModified).toLocaleString() : undefined], |
139 | | - ]; |
140 | | - |
141 | | - for (const [label, value] of fields) { |
142 | | - if (value !== undefined) { |
143 | | - ui.div({text: `${label}:`, width: 25, padding: [0, 2, 0, 0]}, {text: value, padding: [0, 0, 0, 0]}); |
144 | | - } |
145 | | - } |
146 | | - } |
147 | | - |
148 | | - private printOrganizations(ui: ReturnType<typeof cliui>, user: AccountManagerUser): void { |
149 | | - if (user.organizations === undefined || user.organizations.length === 0) { |
150 | | - return; |
151 | | - } |
152 | | - |
153 | | - ui.div({text: 'Organizations', padding: [2, 0, 0, 0]}); |
154 | | - ui.div({text: '─'.repeat(50), padding: [0, 0, 0, 0]}); |
155 | | - |
156 | | - const orgIds = user.organizations.map((o) => (typeof o === 'string' ? o : o.id || 'Unknown')); |
157 | | - ui.div( |
158 | | - {text: 'Organization IDs:', width: 25, padding: [0, 2, 0, 0]}, |
159 | | - {text: orgIds.join(', '), padding: [0, 0, 0, 0]}, |
160 | | - ); |
161 | | - } |
162 | | - |
163 | | - private printRoles(ui: ReturnType<typeof cliui>, user: AccountManagerUser): void { |
164 | | - if (user.roles === undefined || user.roles.length === 0) { |
165 | | - return; |
166 | | - } |
167 | | - |
168 | | - ui.div({text: 'Roles', padding: [2, 0, 0, 0]}); |
169 | | - ui.div({text: '─'.repeat(50), padding: [0, 0, 0, 0]}); |
170 | | - |
171 | | - const roleNames = user.roles.map((r) => (typeof r === 'string' ? r : r.roleEnumName || r.id || 'Unknown')); |
172 | | - ui.div({text: 'Role IDs:', width: 25, padding: [0, 2, 0, 0]}, {text: roleNames.join(', '), padding: [0, 0, 0, 0]}); |
173 | | - } |
174 | | - |
175 | | - private printRoleTenantFilters(ui: ReturnType<typeof cliui>, user: AccountManagerUser): void { |
176 | | - if (user.roleTenantFilterMap === undefined || Object.keys(user.roleTenantFilterMap).length === 0) { |
177 | | - return; |
178 | | - } |
179 | | - |
180 | | - ui.div({text: 'Role Tenant Filters', padding: [2, 0, 0, 0]}); |
181 | | - ui.div({text: '─'.repeat(50), padding: [0, 0, 0, 0]}); |
182 | | - |
183 | | - for (const [roleId, filter] of Object.entries(user.roleTenantFilterMap)) { |
184 | | - const filterValue = typeof filter === 'string' ? filter : JSON.stringify(filter); |
185 | | - ui.div({text: `${roleId}:`, width: 30, padding: [0, 2, 0, 0]}, {text: filterValue, padding: [0, 0, 0, 0]}); |
186 | | - } |
187 | | - } |
188 | | - |
189 | | - private printUserDetails(user: AccountManagerUser): void { |
190 | | - const ui = cliui({width: process.stdout.columns || 80}); |
191 | | - |
192 | | - ui.div({text: 'User Details', padding: [1, 0, 0, 0]}); |
193 | | - ui.div({text: '─'.repeat(50), padding: [0, 0, 0, 0]}); |
194 | | - |
195 | | - this.printBasicFields(ui, user); |
196 | | - this.printOrganizations(ui, user); |
197 | | - this.printRoles(ui, user); |
198 | | - this.printRoleTenantFilters(ui, user); |
199 | | - |
200 | | - ux.stdout(ui.toString()); |
201 | | - } |
202 | 118 | } |
0 commit comments