Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/CS-40615- Adding teams support to export-to-csv #1141

Merged
merged 42 commits into from
Nov 3, 2023
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
791a1e8
Added function to get all the teams
cs-raj Oct 17, 2023
2be572b
added pagination to get only 100 teams as the limit on get API call w…
cs-raj Oct 17, 2023
3c8f049
Getting the teams from api calls to
cs-raj Oct 17, 2023
0993759
added api-version to header and includeUserDetails so that a single a…
cs-raj Oct 18, 2023
e1a79cc
Exporting all the teams into csv
cs-raj Oct 18, 2023
d920578
Merge branch 'development' into feat/CS-41971
cs-raj Oct 18, 2023
b212d65
Refactoring
cs-raj Oct 18, 2023
b53f88f
Used loadash deep clone, added catch block in sdk call added team-uid…
cs-raj Oct 19, 2023
cb76049
refactoring
cs-raj Oct 19, 2023
0d9d04b
change api response handler
cs-raj Oct 19, 2023
622e24c
Merge branch 'development' into feat/CS-41971
cs-raj Oct 19, 2023
a0a2d66
Merge branch 'feat/CS-40615-teams' into feat/CS-41971
cs-raj Oct 20, 2023
ac08fb2
Exporting Teams stack role
cs-raj Oct 23, 2023
411bb4a
PR changes
cs-raj Oct 23, 2023
9a01f39
PR changes
cs-raj Oct 23, 2023
28ce263
PR changes
cs-raj Oct 23, 2023
79b97f4
added examples
cs-raj Oct 23, 2023
c5a3f9e
Modified the handle error message. Added common auth check and remove…
cs-raj Oct 23, 2023
d58616a
Merge branch 'feat/CS-41971' into feat/CS-41983
cs-raj Oct 24, 2023
39bb23e
added optional chaining and comments
cs-raj Oct 24, 2023
bc06695
added text message before exporting the teams
cs-raj Oct 25, 2023
ab58e73
used map in exporting the role mapping, changed the color of message …
cs-raj Oct 25, 2023
0b23fad
corrected the error message
cs-raj Oct 25, 2023
88c98f8
used loadash find method and handled iteration over empty array
cs-raj Oct 25, 2023
d4d64d3
used Nullish coalescing operator
cs-raj Oct 25, 2023
b295e85
Replaced getStack SDK call with getRole SDK call
cs-raj Oct 26, 2023
33fc0a4
added prompt
cs-raj Oct 26, 2023
16440ae
pr changes
cs-raj Oct 26, 2023
3b21cba
Merge pull request #1121 from contentstack/feat/CS-41983
cs-raj Oct 26, 2023
c74227e
Merge pull request #1108 from contentstack/feat/CS-41971
cs-raj Oct 26, 2023
72d8f67
Merge branch 'development' into feat/CS-40615-teams
cs-raj Oct 30, 2023
d1719b4
added unit test case for teams in export-to-csv
cs-raj Oct 30, 2023
605312b
fixed case when the teams is selected through the prompt
cs-raj Nov 1, 2023
902e9c8
handling case where the user is not admin in the stack and exporting …
cs-raj Nov 1, 2023
cf938b8
added prompt to ask user about whether to export the stack role mappi…
cs-raj Nov 1, 2023
bd94de0
Merge branch 'feat/CS-40615-teams' into feat/CS-42000
cs-raj Nov 1, 2023
b6ac9cc
Merge pull request #1134 from contentstack/feat/CS-42000
cs-raj Nov 1, 2023
947ad50
modified the test cases
cs-raj Nov 1, 2023
549ef47
modified the warning message, and handled condition when org role is …
cs-raj Nov 2, 2023
2a48b94
Ui text changes
cs-raj Nov 2, 2023
faaf1af
error
cs-raj Nov 2, 2023
df7e97e
Merge branch 'development' into feat/CS-40615-teams
abhinav-from-contentstack Nov 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added optional chaining and comments
  • Loading branch information
cs-raj committed Oct 24, 2023
commit 39bb23e76f38e0e9b753bdd871b4913b9ecaf6f2
17 changes: 9 additions & 8 deletions packages/contentstack-export-to-csv/src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,13 +699,13 @@ async function apiRequestHandler(org, queryParam = {}) {
return await new HttpClient()
.headers(headers)
.queryParams(queryParam)
.get(`${configHandler.get('region')?.cma}/organizations/${org.uid}/teams`)
.get(`${configHandler.get('region')?.cma}/organizations/${org?.uid}/teams`)
.then((res) => {
const { status, data } = res;
if (status === 200) {
return data;
} else {
cliux.print(`${data.error_message || data.message || data.errorMessage}`, { color: 'red' });
cliux.print(`${data?.error_message || data?.message || data?.errorMessage}`, { color: 'red' });
process.exit(1);
}
})
Expand All @@ -717,7 +717,7 @@ async function apiRequestHandler(org, queryParam = {}) {
async function exportOrgTeams(managementAPIClient, org) {
let teamsObjectArray = [];
let skip = 0;
let limit = config.limit || 100;
let limit = config?.limit || 100;
do {
const data = await apiRequestHandler(org, { skip: skip, limit: limit, includeUserDetails: true });
skip += limit;
Expand Down Expand Up @@ -796,6 +796,7 @@ async function exportTeams(managementAPIClient, organization, teamUid) {
write(this, modifiedTeam, fileName, ' organization Team details');
// exporting teams user data or a single team user data
await getTeamsDetail(allTeamsData,organization,teamUid);
// Exporting the stack Role data for all the teams or exporting stack role data for a single team
await exportRoleMappings(managementAPIClient, allTeamsData, teamUid);
}
}
Expand Down Expand Up @@ -843,8 +844,8 @@ async function exportRoleMappings(managementAPIClient, allTeamsData, teamUid) {
}
}
const fileName = `${kebabize(
"All_Teams_Role_Mapping".replace(config.organizationNameRegex, ''),
)}.csv`;
"Stack_Role_Mapping".replace(config.organizationNameRegex, ''),
)}${teamUid?teamUid:""}.csv`;

write(this, stackRoleWithTeamData, fileName, 'Team Stack Role details');
}
Expand All @@ -853,7 +854,7 @@ async function mapRoleWithTeams(managementAPIClient, stackRoleMapping, teamName,
const Stack = await getStackData(managementAPIClient, stackRoleMapping.stackApiKey);
const stackRole = {};
const roles = await Stack.role().fetchAll()
roles?.items?.forEach((role) => {
roles?.items.forEach((role) => {
if(!stackRole.hasOwnProperty(role?.uid)){
stackRole[role?.uid] = role?.name;
}
Expand All @@ -868,15 +869,15 @@ async function mapRoleWithTeams(managementAPIClient, stackRoleMapping, teamName,
stackRoleMap['Role Name'] = stackRole[role]
stackRoleMap['Role Uid'] = role;
stackRoleMapOfTeam.push(stackRoleMap);
})
});

// console.log(stackRole);
return stackRoleMapOfTeam;
}

async function getStackData(managementAPIClient, stackApiKey) {
return await managementAPIClient.stack({ api_key: stackApiKey }).fetch();
}

async function getTeamsUserDetails(teamsObject) {
const allTeamUsers = [];
teamsObject.forEach((team) => {
Expand Down