Skip to content

Commit 127fe56

Browse files
committed
report generated
1 parent 23f2198 commit 127fe56

2 files changed

Lines changed: 101 additions & 12 deletions

File tree

get-workspace-admins/get-team-workspaces.js

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ async function getTeamWorkspaces() {
8888
}
8989

9090
/**
91-
* Get admin users for a specific workspace
91+
* Get admin users for a specific workspace with detailed user information
9292
* @param {string} workspaceId - The ID of the workspace to get admins for
93-
* @returns {Array<string>} - Array of user IDs with Admin role
93+
* @returns {Array<Object>} - Array of user info objects with user_id, user_name, user_username, and user_email
9494
*/
9595
async function getWorkspaceAdmins(workspaceId) {
9696
try {
@@ -110,7 +110,55 @@ async function getWorkspaceAdmins(workspaceId) {
110110

111111
console.log(`Found ${adminUserIds.length} admin users for workspace ID: ${workspaceId}`);
112112

113-
return adminUserIds;
113+
// Array to store detailed user information
114+
const adminUsers = [];
115+
116+
// Fetch detailed information for each admin user
117+
for (const userId of adminUserIds) {
118+
try {
119+
console.log(`Fetching details for user ID: ${userId}...`);
120+
121+
const userResponse = await axios.get(`${postmanApiUrl}/users/${userId}`, {
122+
headers: {
123+
'X-API-Key': apiKey,
124+
},
125+
});
126+
127+
const userData = userResponse.data;
128+
129+
// Create user info object with required properties
130+
const userInfo = {
131+
user_id: userData.id,
132+
user_name: userData.name,
133+
user_username: userData.username,
134+
user_email: userData.email
135+
};
136+
137+
adminUsers.push(userInfo);
138+
139+
// Small delay to avoid rate limiting
140+
await new Promise(resolve => setTimeout(resolve, 100));
141+
142+
} catch (userError) {
143+
console.error(`Error fetching details for user ID ${userId}:`, userError.message);
144+
if (userError.response) {
145+
console.error('Response status:', userError.response.status);
146+
console.error('Response data:', userError.response.data);
147+
}
148+
149+
// Add partial user info with just the ID if we couldn't get full details
150+
adminUsers.push({
151+
user_id: userId,
152+
user_name: 'Unknown',
153+
user_username: 'Unknown',
154+
user_email: 'Unknown'
155+
});
156+
}
157+
}
158+
159+
console.log(`Retrieved details for ${adminUsers.length} admin users for workspace ID: ${workspaceId}`);
160+
161+
return adminUsers;
114162
} catch (error) {
115163
console.error(`Error fetching admin users for workspace ID ${workspaceId}:`, error.message);
116164
if (error.response) {
@@ -146,21 +194,27 @@ async function main() {
146194
curReportItem.workspace_visibility = workspace.visibility;
147195
curReportItem.admin_user_ids = [];
148196
curReportItem.admin_users = [];
149-
const adminUserIds = await getWorkspaceAdmins(workspace.id);
150-
curReportItem.admin_user_ids = adminUserIds;
151-
152-
/*workspacesWithAdmins.push({
153-
id: workspace.id,
154-
name: workspace.name,
155-
type: workspace.type,
156-
adminUserIds
157-
});*/
197+
198+
// Get detailed admin user information
199+
const adminUsers = await getWorkspaceAdmins(workspace.id);
200+
curReportItem.admin_users = adminUsers;
201+
// Extract just the user IDs for backward compatibility
202+
203+
// Add to the admin report
204+
adminReport.push(curReportItem);
158205

159206
// Small delay to avoid rate limiting
160207
await new Promise(resolve => setTimeout(resolve, 100));
161208
}
162209

210+
// Create final report structure
211+
finalReport.workspaces = adminReport;
212+
finalReport.generated_at = new Date().toISOString();
163213

214+
// Save admin report to file
215+
const adminsFilePath = path.join(outputDir, 'workspace-admins-report.json');
216+
fs.writeFileSync(adminsFilePath, JSON.stringify(finalReport, null, 2));
217+
console.log(`\nSaved workspace admin report to: ${adminsFilePath}`);
164218

165219
} catch (error) {
166220
console.error('Error in main execution:', error);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<style type="text/css">
2+
.tftable {
3+
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
4+
font-size: 14px;
5+
color: #333333;
6+
width: 100%;
7+
border-width: 1px;
8+
border-color: #87ceeb;
9+
border-collapse: collapse;
10+
}
11+
.tftable th {
12+
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
13+
font-size: 18px;
14+
background-color: #87ceeb;
15+
border-width: 1px;
16+
padding: 8px;
17+
border-style: solid;
18+
border-color: #87ceeb;
19+
text-align: left;
20+
}
21+
.tftable tr {
22+
background-color: #ffffff;
23+
}
24+
.tftable td {
25+
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
26+
font-size: 14px;
27+
border-width: 1px;
28+
padding: 8px;
29+
border-style: solid;
30+
border-color: #87ceeb;
31+
}
32+
.tftable tr:hover {
33+
background-color: #e0ffff;
34+
}
35+
</style>

0 commit comments

Comments
 (0)