Skip to content

Commit

Permalink
Merge pull request #1141 from contentstack/feat/CS-40615-teams
Browse files Browse the repository at this point in the history
Feat/CS-40615- Adding teams support to export-to-csv
  • Loading branch information
abhinav-from-contentstack authored Nov 3, 2023
2 parents dcc4aa8 + df7e97e commit 6d1dfda
Show file tree
Hide file tree
Showing 9 changed files with 967 additions and 249 deletions.
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

0 comments on commit 6d1dfda

Please sign in to comment.