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
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/contentstack-export-to-csv/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-export-to-csv",
"description": "Export entities to csv",
"version": "1.4.4",
"version": "1.5.0",
"author": "Abhinav Gupta @abhinav-from-contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class ExportToCsvCommand extends Command {
action: flags.string({
required: false,
multiple: false,
options: ['entries', 'users'],
description: `Option to export data (entries, users)`,
options: ['entries', 'users', 'teams'],
description: `Option to export data (entries, users, teams)`,
}),
alias: flags.string({
char: 'a',
Expand Down Expand Up @@ -59,6 +59,9 @@ class ExportToCsvCommand extends Command {
multiple: false,
required: false,
}),
"team-uid": flags.string({
description: 'Uid of the team whose user data and stack roles are required'
})
};

async run() {
Expand All @@ -75,11 +78,18 @@ class ExportToCsvCommand extends Command {
'content-type': contentTypesFlag,
alias: managementTokenAlias,
branch: branchUid,
"team-uid": teamUid
},
} = await this.parse(ExportToCsvCommand);

if (!managementTokenAlias) {
managementAPIClient = await managementSDKClient({ host: this.cmaHost });
if (!isAuthenticated()) {
this.error(config.CLI_EXPORT_CSV_ENTRIES_ERROR, {
exit: 2,
suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
});
}
}

if (actionFlag) {
Expand Down Expand Up @@ -113,14 +123,6 @@ class ExportToCsvCommand extends Command {
this.error('Provided management token alias not found in your config.!');
} else {
let organization;

if (!isAuthenticated()) {
this.error(config.CLI_EXPORT_CSV_ENTRIES_ERROR, {
exit: 2,
suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
});
}

if (org) {
organization = { uid: org };
} else {
Expand Down Expand Up @@ -227,12 +229,6 @@ class ExportToCsvCommand extends Command {
case config.exportUsers:
case 'users': {
try {
if (!isAuthenticated()) {
this.error(config.CLI_EXPORT_CSV_LOGIN_FAILED, {
exit: 2,
suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
});
}
let organization;

if (org) {
Expand All @@ -258,6 +254,24 @@ class ExportToCsvCommand extends Command {
}
break;
}
case config.exportTeams:
case 'teams': {
try{
let organization;
if (org) {
organization = { uid: org, name: orgName || org };
} else {
organization = await util.chooseOrganization(managementAPIClient, action); // prompt for organization
}

await util.exportTeams(managementAPIClient,organization,teamUid);
} catch (error) {
if (error.message || error.errorMessage) {
cliux.error(util.formatError(error));
}
}
}
break;
}
} catch (error) {
if (error.message || error.errorMessage) {
Expand Down Expand Up @@ -310,6 +324,21 @@ ExportToCsvCommand.examples = [
'',
'Exporting organization users to csv with organization name provided',
'csdx cm:export-to-csv --action <users> --org <org-uid> --org-name <org-name>',
'',
'Exporting Organizations Teams to CSV',
'csdx cm:export-to-csv --action <teams>',
'',
'Exporting Organizations Teams to CSV with org-uid',
'csdx cm:export-to-csv --action <teams> --org <org-uid>',
'',
'Exporting Organizations Teams to CSV with team uid',
'csdx cm:export-to-csv --action <teams> --team-uid <team-uid>',
'',
'Exporting Organizations Teams to CSV with org-uid and team uid',
'csdx cm:export-to-csv --action <teams> --org <org-uid> --team-uid <team-uid>',
'',
'Exporting Organizations Teams to CSV with org-uid and team uid',
'csdx cm:export-to-csv --action <teams> --org <org-uid> --team-uid <team-uid> --org-name <org-name>',
];

module.exports = ExportToCsvCommand;
7 changes: 4 additions & 3 deletions packages/contentstack-export-to-csv/src/util/config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module.exports = {
cancelString: 'Cancel and Exit',
exportEntries: 'Export entries to a .CSV file',
exportUsers: "Export organization users' data to a .CSV file",
exportUsers: "Export organization user's data to a .CSV file",
exportTeams: "Export organization team's data to a .csv file",
adminError: "Unable to export data. Make sure you're an admin or owner of this organization",
organizationNameRegex: /\'/,
CLI_EXPORT_CSV_LOGIN_FAILED: "You need to login to execute this command. See: auth:login --help",
CLI_EXPORT_CSV_ENTRIES_ERROR: "You need to either login or provide a management token to execute this command"

CLI_EXPORT_CSV_ENTRIES_ERROR: "You need to either login or provide a management token to execute this command",
CLI_EXPORT_CSV_API_FAILED: 'Something went wrong. Please try again!'
};
Loading
Loading