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: add custom role support in audit plugin #1530

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions package-lock.json

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

28 changes: 15 additions & 13 deletions packages/contentstack-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli-audit/1.6.5 darwin-arm64 node-v22.2.0
@contentstack/cli-audit/1.7.0 darwin-arm64 node-v22.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down Expand Up @@ -52,12 +52,13 @@ Perform audits and find possible errors in the exported Contentstack data

```
USAGE
$ csdx audit [--report-path <value>] [--modules content-types|global-fields|entries|extensions|workflows]
[--columns <value> | ] [--sort <value>] [--filter <value>] [--csv | --no-truncate]
$ csdx audit [--report-path <value>] [--modules
content-types|global-fields|entries|extensions|workflows|custom-roles] [--columns <value> | ] [--sort <value>]
[--filter <value>] [--csv | --no-truncate]

FLAGS
--modules=<option>... Provide the list of modules to be audited
<options: content-types|global-fields|entries|extensions|workflows>
<options: content-types|global-fields|entries|extensions|workflows|custom-roles>
--report-path=<value> Path to store the audit reports

TABLE FLAGS
Expand Down Expand Up @@ -92,8 +93,8 @@ Perform audits and fix possible errors in the exported Contentstack data.

```
USAGE
$ csdx audit:fix [--report-path <value>] [--modules content-types|global-fields|entries|extensions|workflows]
[--copy-path <value> --copy-dir] [--fix-only
$ csdx audit:fix [--report-path <value>] [--modules
content-types|global-fields|entries|extensions|workflows|custom-roles] [--copy-path <value> --copy-dir] [--fix-only
reference|global_field|json:rte|json:extension|blocks|group|content_types] [--columns <value> | ] [--sort <value>]
[--filter <value>] [--csv | --no-truncate]

Expand All @@ -103,7 +104,7 @@ FLAGS
--fix-only=<option>... Provide the list of fix options
<options: reference|global_field|json:rte|json:extension|blocks|group|content_types>
--modules=<option>... Provide the list of modules to be audited
<options: content-types|global-fields|entries|extensions|workflows>
<options: content-types|global-fields|entries|extensions|workflows|custom-roles>
--report-path=<value> Path to store the audit reports

TABLE FLAGS
Expand Down Expand Up @@ -140,12 +141,13 @@ Perform audits and find possible errors in the exported Contentstack data

```
USAGE
$ csdx cm:stacks:audit [--report-path <value>] [--modules content-types|global-fields|entries|extensions|workflows]
[--columns <value> | ] [--sort <value>] [--filter <value>] [--csv | --no-truncate]
$ csdx cm:stacks:audit [--report-path <value>] [--modules
content-types|global-fields|entries|extensions|workflows|custom-roles] [--columns <value> | ] [--sort <value>]
[--filter <value>] [--csv | --no-truncate]

FLAGS
--modules=<option>... Provide the list of modules to be audited
<options: content-types|global-fields|entries|extensions|workflows>
<options: content-types|global-fields|entries|extensions|workflows|custom-roles>
--report-path=<value> Path to store the audit reports

TABLE FLAGS
Expand Down Expand Up @@ -182,8 +184,8 @@ Perform audits and fix possible errors in the exported Contentstack data.

```
USAGE
$ csdx cm:stacks:audit:fix [--report-path <value>] [--modules content-types|global-fields|entries|extensions|workflows]
[--copy-path <value> --copy-dir] [--fix-only
$ csdx cm:stacks:audit:fix [--report-path <value>] [--modules
content-types|global-fields|entries|extensions|workflows|custom-roles] [--copy-path <value> --copy-dir] [--fix-only
reference|global_field|json:rte|json:extension|blocks|group|content_types] [--columns <value> | ] [--sort <value>]
[--filter <value>] [--csv | --no-truncate]

Expand All @@ -193,7 +195,7 @@ FLAGS
--fix-only=<option>... Provide the list of fix options
<options: reference|global_field|json:rte|json:extension|blocks|group|content_types>
--modules=<option>... Provide the list of modules to be audited
<options: content-types|global-fields|entries|extensions|workflows>
<options: content-types|global-fields|entries|extensions|workflows|custom-roles>
--report-path=<value> Path to store the audit reports

TABLE FLAGS
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-audit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-audit",
"version": "1.6.5",
"version": "1.7.0",
"description": "Contentstack audit plugin",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/cli",
Expand Down
17 changes: 14 additions & 3 deletions packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
RefErrorReturnType,
WorkflowExtensionsRefErrorReturnType,
} from './types';
import CustomRoles from './modules/custom-roles';

export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseCommand> {
private currentCommand!: CommandNames;
Expand Down Expand Up @@ -56,6 +57,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingCtRefsInWorkflow,
missingSelectFeild,
missingMandatoryFields,
missingRefInCustomRoles
} = await this.scanAndFix();

this.showOutputOnScreen([
Expand All @@ -69,13 +71,15 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
this.showOutputOnScreenWorkflowsAndExtension([
{ module: 'Entries Mandatory Field', missingRefs: missingMandatoryFields },
]);
this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Custom Roles', missingRefs: missingRefInCustomRoles }]);
if (
!isEmpty(missingCtRefs) ||
!isEmpty(missingGfRefs) ||
!isEmpty(missingEntryRefs) ||
!isEmpty(missingCtRefsInWorkflow) ||
!isEmpty(missingCtRefsInExtensions) ||
!isEmpty(missingSelectFeild)
!isEmpty(missingSelectFeild) ||
!isEmpty(missingRefInCustomRoles)
) {
if (this.currentCommand === 'cm:stacks:audit') {
this.log(this.$t(auditMsg.FINAL_REPORT_PATH, { path: this.sharedConfig.reportPath }), 'warn');
Expand All @@ -102,7 +106,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
!isEmpty(missingEntryRefs) ||
!isEmpty(missingCtRefsInWorkflow) ||
!isEmpty(missingCtRefsInExtensions) ||
!isEmpty(missingSelectFeild)
!isEmpty(missingSelectFeild) ||
!isEmpty(missingRefInCustomRoles)
);
}

Expand All @@ -121,7 +126,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingCtRefsInWorkflow,
missingSelectFeild,
missingEntry,
missingMandatoryFields;
missingMandatoryFields,
missingRefInCustomRoles;

for (const module of this.sharedConfig.flags.modules || this.sharedConfig.modules) {
print([
Expand Down Expand Up @@ -174,6 +180,10 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingCtRefsInExtensions = await new Extensions(cloneDeep(constructorParam)).run();
await this.prepareReport(module, missingCtRefsInExtensions);
break;
case 'custom-roles':
missingRefInCustomRoles = await new CustomRoles(cloneDeep(constructorParam)).run();
await this.prepareReport(module, missingRefInCustomRoles);
break;
}

print([
Expand All @@ -198,6 +208,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingCtRefsInWorkflow,
missingSelectFeild,
missingMandatoryFields,
missingRefInCustomRoles,
};
}

Expand Down
7 changes: 6 additions & 1 deletion packages/contentstack-audit/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const config = {
showTerminalOutput: true,
skipRefs: ['sys_assets'],
skipFieldTypes: ['taxonomy', 'group'],
modules: ['content-types', 'global-fields', 'entries', 'extensions', 'workflows'],
modules: ['content-types', 'global-fields', 'entries', 'extensions', 'workflows', 'custom-roles'],
'fix-fields': ['reference', 'global_field', 'json:rte', 'json:extension', 'blocks', 'group', 'content_types'],
moduleConfig: {
'content-types': {
Expand Down Expand Up @@ -35,6 +35,11 @@ const config = {
dirName: 'extensions',
fileName: 'extensions.json',
},
'custom-roles': {
name: 'custom-roles',
dirName: 'custom-roles',
fileName: 'custom-roles.json',
},
},
entries: {
systemKeys: [
Expand Down
2 changes: 2 additions & 0 deletions packages/contentstack-audit/src/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const commonMsg = {
EXTENSION_FIX_WARN: `The extension associated with UID {uid} and title '{title}' will be removed.`,
EXTENSION_FIX_CONFIRMATION: `Would you like to overwrite existing file?`,
WF_BRANCH_REMOVAL: `Removing the branch '{branch} from workflow with UID {uid} and name {name} will be removed.'`,
CR_BRANCH_REMOVAL: `Removing the branch '{branch} from custom role with UID {uid} and name {name} will be removed.'`,
};

const auditMsg = {
Expand All @@ -35,6 +36,7 @@ const auditMsg = {
SCAN_EXT_SUCCESS_MSG: "Successfully completed scanning the {module} titled '{title}' with UID '{uid}'",
AUDIT_CMD_DESCRIPTION: 'Perform audits and find possible errors in the exported Contentstack data',
SCAN_WF_SUCCESS_MSG: 'Successfully completed the scanning of workflow with UID {uid} and name {name}.',
SCAN_CR_SUCCESS_MSG: 'Successfully completed the scanning of custom role with UID {uid} and name {name}.',
};

const auditFixMsg = {
Expand Down
Loading
Loading