From e6274e5b887c5a89580fd807ad05719d4d9cb819 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Fri, 28 Jun 2024 12:49:20 +0530 Subject: [PATCH] Enh/dx 737 taxonomy permission (#161) * chore: replaced uid and other data * refactor: adds and corrects types of ContentstackCollectin and marketplace functions * fix: credentials in response fix; bulkOperation types fixes; * test: :white_check_mark: improves code coverage * Revert "Feat: NRP support, Audit logs, Type correction for User and CScollection added" * fix: users, collection, other fixes, coverage improvements * build: updates package-lock file * chore: version changes in package file * ci: removed secrets-scan file and app tests changes * fix: type fix for environment param * fix: :bug: handles the error in refreshtoken instead of throwing it * ci: :fire: removed sast-scan yml file * fix: :bug: handles workflow response in object format * feat: :sparkles: allows overwrite flag param in import of contenttype and global field * test: :white_check_mark: adds CT and GF import test for overwrite flag * refactor: :recycle: adds type support for overwrite flag param * chore: :package: version changes and package updates * perf: :package: packages update * docs: :memo: Updates README * feat: :sparkles: Taxonomy Implementation with docs, unit and api test cases * test: :white_check_mark: changes made in taxonomy function in stack class * test: uncommented 'detele' api test case * feat: :sparkles: create, fetch, find, update, delete , ancestors and descendants functions are added * test: :white_check_mark: added api test cases for terms implementation * feat: :sparkles: allows content-type for asset upload * test: :white_check_mark: unit test cases for terms implementation (except search and move) * changes done in passing data to create function in api test case * feat: :sparkles: added move and search functions for terms implementation * test: :white_check_mark: updated and added search and move unit test cases * test: :white_check_mark: updated and added search and move api test cases * docs: :memo: updated api reference docs for search, ancestors, descendants and move * build: :package: updated axios module and version number * chore: :loud_sound: update changelog file * feat: :sparkles: taxonomy and terms implementation for typescript * fix: :bug: taxonomy bug fix * feat: :sparkles: terms implementaion with descendants and move function * fix: :bug: taxonomy bug fix in query unit test case * fix: taxonomy and terms fixes * fix: :bug: error message fix on refresh token error * refactor: uncommented unit test cases * test: :white_check_mark: taxonomy API test cases * test: :white_check_mark: terms api test cases and search implementation * test: :white_check_mark: changes in search unit test in terms * changed default host name * added entry on changelog file and changed version * feat: :sparkles: teams implementation with unit and api tests * docs: added teams documentation * test: :white_check_mark: updated api and unit test cases for teams support * feat: :sparkles: teams users implementation and api test cases * test: :white_check_mark: added unit test cases for team users * feat: :sparkles: stackrolemapping implementation and api test cases * test: changes made in update implementation and its test case * test: update stackrolemapping implementation and api test cases * added assertions to check the response * added unit test cases for stack role mapping * replaced query with fetchAll function * changing folder name to be same as class name * ci: :green_heart: fix unit test github action * ci: fix unit test github action * feat: types support for teams * chore: :arrow_up: update axios lib * added valid assertions for the test * teams test cases for types support * types support for team Users and api test cases * interface changed from User to TeamUser in types * types support for stackRoleMapping and test cases * stackRoleMapping test cases in types support * stackRoleMapping update test case on types support * docs: :memo: updated version and changeLog * test: added test cases to improve coverage report * feat: :sparkles: early access headers implementation * types support for earlyaccess and update changeLog * fix: :bug: early_access made optional * fix: :bug: added api_version param which is to be passed in headers * test: :white_check_mark: updated response fetchAll unit test case * fix: :bug: create function response data update * refactor: :recycle: changes users in teams to teamUsers * fix: fixed issue while updating entries with assets * feat: added api test * fix: updated changelog and package lock file * Implemented Management token support (#99) * Implemented Management token support * Fixed PR Comments * test: added sanity tests for user and contenttype * added a script in package.json * Next (#97) * fix: fixed issue while updating entries with assets * feat: added api test * fix: updated changelog and package lock file * Implemented Management token support (#99) * Implemented Management token support * Fixed PR Comments * test: added sanity tests for user and contenttype * added a script in package.json --------- Co-authored-by: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Co-authored-by: harshithad0703 Co-authored-by: harshithad0703 <104908717+harshithad0703@users.noreply.github.com> * test: added entries, assets, organization and stack tests in sanity * changed the decription for it in testcases * test: added taxonomy and terms tests in sanity folder * removed const stack as the api is read from env * fix: changed the url in transferOwnership * test: removed the skipped test case from organization test suit * test: added branches and aliases test suits to sanity folder * test: commented out the test case instead or removing * test: updated url path in unit test case * test: added 1 more test case to branch test suit * test: added create branch test after stack creation test * fix: :package: updates axios version * chore: update package version in package.json * chore: :hammer: updates prerelease hook script * chore: :package: added a package for slack message integeration and script for same * chore: slack integeration for sending test report summary on the channel * test: added environment test to sanity and changes done in branch test * chore: :package: updated slack/bolt package to devDependencies * Revert "chore: :package: updated slack/bolt package to devDependencies" This reverts commit 0119e049d6ec79641ef1506b56598b414ded722d. * updated slack/bolt package dependency * chore: added alldependencies required for slack/bolt package * chore: updates LICENSE file * test: Added locale test suit and delete test suit to sanity folder * chore: updated package-lock file * Added taxonomy import/export support (#112) Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> * Validating the object when update the entries with assets (#114) Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> * test: added delivery token test sanity folder * test: added extension test suit to sanity * test: updated test msg * Next (#115) * test: Added locale test suit and delete test suit to sanity folder * chore: updated package-lock file * Added taxonomy import/export support (#112) Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> * Validating the object when update the entries with assets (#114) Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> --------- Co-authored-by: harshithad0703 Co-authored-by: harshithad0703 <104908717+harshithad0703@users.noreply.github.com> Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> * cleared assertion error * test: added assertions for failing tests * Feat/cs 43619 taxonomy import export testcases (#118) * Next (#115) * test: Added locale test suit and delete test suit to sanity folder * chore: updated package-lock file * Added taxonomy import/export support (#112) Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> * Validating the object when update the entries with assets (#114) Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> --------- Co-authored-by: harshithad0703 Co-authored-by: harshithad0703 <104908717+harshithad0703@users.noreply.github.com> Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> * Added taxonomy import/export testcases. --------- Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> Co-authored-by: harshithad0703 Co-authored-by: harshithad0703 <104908717+harshithad0703@users.noreply.github.com> * test: added global field test suit to sanity * test: add sanity test for label * Next (#119) * test: Added locale test suit and delete test suit to sanity folder * chore: updated package-lock file * Added taxonomy import/export support (#112) Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> * Validating the object when update the entries with assets (#114) Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> * test: added delivery token test sanity folder * test: added extension test suit to sanity * test: updated test msg * cleared assertion error * test: added assertions for failing tests * Feat/cs 43619 taxonomy import export testcases (#118) * Next (#115) * test: Added locale test suit and delete test suit to sanity folder * chore: updated package-lock file * Added taxonomy import/export support (#112) Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> * Validating the object when update the entries with assets (#114) Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> --------- Co-authored-by: harshithad0703 Co-authored-by: harshithad0703 <104908717+harshithad0703@users.noreply.github.com> Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> * Added taxonomy import/export testcases. --------- Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> Co-authored-by: harshithad0703 Co-authored-by: harshithad0703 <104908717+harshithad0703@users.noreply.github.com> * test: added global field test suit to sanity * test: add sanity test for label --------- Co-authored-by: harshithad0703 Co-authored-by: harshithad0703 <104908717+harshithad0703@users.noreply.github.com> Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> * test: added sanity test for workflow-webhook-release * updated sanity.js file * test: added basic sanity for role * test: added basic sanity for management token test suit * fix: upgrade @slack/bolt from 3.17.0 to 3.17.1 Snyk has created this PR to upgrade @slack/bolt from 3.17.0 to 3.17.1. See this package in npm: https://www.npmjs.com/package/@slack/bolt See this project in Snyk: https://app.snyk.io/org/sunil-lakshman/project/d82509a3-a3c4-432f-b8d9-068ef2579b9b?utm_source=github&utm_medium=referral&page=upgrade-pr * feat: :sparkles: adds params support in taxonomy export function * test: added teams and stack share test suit to sanity * test: changed uids of branches and aliases * fix: fixed teams implementation according to the object received * changes the flow of sanity test * Update sca-scan.yml * fix: upgrade axios from 1.6.5 to 1.6.6 Snyk has created this PR to upgrade axios from 1.6.5 to 1.6.6. See this package in npm: https://www.npmjs.com/package/axios See this project in Snyk: https://app.snyk.io/org/sunil-lakshman/project/d82509a3-a3c4-432f-b8d9-068ef2579b9b?utm_source=github&utm_medium=referral&page=upgrade-pr * fix: :bug: fixed update entry which was failing the function cleanAssets was checking with null value * test: removed organization name in assertion * chore: updated changeLog and version * fix: resolved undefined stack in error issue * test: sanity test for bulk operation * chore: :package: update package version and changeLog * chore: :package: upgraded axios package to 1.6.8 * fix: added delete stack method and test case * chore: updated changeLog and package version * chore: :package: updated internal dependencies * chore: :package: updated sdk version to 1.15.4 and changelog update * feat: :sparkles: get languages of an entry implementation * test: :white_check_mark: added unit and api test cases * docs: :memo: added docs for get locales * chore: updated package version and changeLog * feat: get locales types support * test: changes done in branches deletion error message * fix: added fix for missing fs error * fix: updated package version * fix: updated CHANGELOG.md * assertions corrections for webhooks sanity tests * build: upgraded qs package * test: changed the order of test suites in sanity * reorder test suites * reorder test suites * sca-scan.yml * jira.yml * sast-scan.yml * codeql-analysis.yml * fix: adding delay to check the issue with taxonomy for checking gocd pipeline * Added updateCT method for update an content type without fetch method (#157) * Added updateCT method for update an content type without fetch method * Updated node version * Fixed merge conflits * Added taxonomy permission test cases * Fixed merge conflits * Package publish issue fixed --------- Co-authored-by: Nadeem Patwekar Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> Co-authored-by: Shailesh Mishra Co-authored-by: harshithad0703 Co-authored-by: harshithad0703 <104908717+harshithad0703@users.noreply.github.com> Co-authored-by: Abhinav Gupta Co-authored-by: abhinav <63039365+abhinav-from-contentstack@users.noreply.github.com> Co-authored-by: snyk-bot Co-authored-by: Aravind Kumar Co-authored-by: Vikram Kalta Co-authored-by: Vikram Kalta --- .github/workflows/npm-publish.yml | 2 +- CHANGELOG.md | 5 ++ package-lock.json | 14 ++-- package.json | 6 +- test/api/mock/role.js | 30 ++++++++ test/sanity-check/api/contentType-test.js | 23 +++--- test/sanity-check/api/role-test.js | 46 ++++++++++++ test/sanity-check/mock/role.js | 30 ++++++++ test/unit/mock/objects.js | 86 ++++++++++++++++++++++- test/unit/role-test.js | 18 ++++- 10 files changed, 236 insertions(+), 24 deletions(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 4f827b78..94c94b3b 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -25,7 +25,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: '12.x' + node-version: '20.x' registry-url: 'https://npm.pkg.github.com' scope: '@contentstack' - run: npm ci diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a34cb6a..5207ede5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # Changelog +## [v1.17.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.17.0) (2024-07-02) + - Enhancement + - Fixed package publish issue in github workflow + - Added Taxonomy permission roles test cases + - SNYK issues - Upgraded axios and slack/bolt packages version ## [v1.16.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.16.2) (2024-06-24) - Enhancement diff --git a/package-lock.json b/package-lock.json index f928afad..92afbfb1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "@contentstack/management", - "version": "1.16.2", + "version": "1.17.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/management", - "version": "1.16.2", + "version": "1.17.0", "license": "MIT", "dependencies": { - "axios": "^1.6.8", + "axios": "^1.7.2", "form-data": "^3.0.1", "lodash": "^4.17.21", "qs": "^6.12.1" @@ -21,7 +21,7 @@ "@babel/preset-env": "^7.18.2", "@babel/register": "^7.17.7", "@babel/runtime": "^7.18.3", - "@slack/bolt": "^3.18.0", + "@slack/bolt": "^3.19.0", "@types/chai": "^4.3.11", "@types/jest": "^28.1.0", "@types/lodash": "^4.14.202", @@ -3154,9 +3154,9 @@ "license": "(Unlicense OR Apache-2.0)" }, "node_modules/@slack/bolt": { - "version": "3.18.0", - "resolved": "https://registry.npmjs.org/@slack/bolt/-/bolt-3.18.0.tgz", - "integrity": "sha512-A7bDi5kY50fS6/nsmURkQdO3iMxD8aX/rA+m1UXEM2ue2z4KijeQtx2sOZ4YkJQ/h7BsgTQM0CYh3qqmo+m5sQ==", + "version": "3.19.0", + "resolved": "https://registry.npmjs.org/@slack/bolt/-/bolt-3.19.0.tgz", + "integrity": "sha512-P5Yup/PbO8sE5xsuqkBkpSPkxEkfWZ6yo5ZlmBGxRhhoU1usUSU2w0bgZoiDX4WFm7ZX+3x2Dyf4VMa9kzfmVQ==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 2761f129..3ce9d10f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/management", - "version": "1.16.2", + "version": "1.17.0", "description": "The Content Management API is used to manage the content of your Contentstack account", "main": "./dist/node/contentstack-management.js", "browser": "./dist/web/contentstack-management.js", @@ -52,7 +52,7 @@ "author": "Contentstack", "license": "MIT", "dependencies": { - "axios": "^1.6.8", + "axios": "^1.7.2", "form-data": "^3.0.1", "lodash": "^4.17.21", "qs": "^6.12.1" @@ -69,7 +69,7 @@ "@babel/preset-env": "^7.18.2", "@babel/register": "^7.17.7", "@babel/runtime": "^7.18.3", - "@slack/bolt": "^3.18.0", + "@slack/bolt": "^3.19.0", "@types/chai": "^4.3.11", "@types/jest": "^28.1.0", "@types/lodash": "^4.14.202", diff --git a/test/api/mock/role.js b/test/api/mock/role.js index 6d748215..ce81f195 100644 --- a/test/api/mock/role.js +++ b/test/api/mock/role.js @@ -14,6 +14,36 @@ const role = { module: 'locale', locales: [], acl: { read: true } + }, + { + module: "taxonomy", + taxonomies: ["taxonomy_testing1"], + terms: ["taxonomy_testing1.term_test1"], + content_types: [ + { + uid: "$all", + acl: { + read: true, + sub_acl: { + read: true, + create: true, + update: true, + delete: true, + publish: true + } + } + } + ], + acl: { + read: true, + sub_acl: { + read: true, + create: true, + update: true, + delete: true, + publish: true + } + } } ], uid: 'role_uid' diff --git a/test/sanity-check/api/contentType-test.js b/test/sanity-check/api/contentType-test.js index 27623ba5..12b0b54f 100644 --- a/test/sanity-check/api/contentType-test.js +++ b/test/sanity-check/api/contentType-test.js @@ -7,6 +7,7 @@ import { contentstackClient } from '../utility/ContentstackClient.js' let client = {} let multiPageCTUid = '' +let multiPageUpdateCTUid = 'multi_page' describe('Content Type api Test', () => { setup(() => { @@ -93,17 +94,17 @@ describe('Content Type api Test', () => { }) .catch(done) }) - // it('should update Multi page ContentType Schema without fetch', done => { - // makeContentType() - // .updateCT(multiPageCT) - // .then((contentType) => { - // multiPageCTUid = contentType.uid - // expect(contentType.uid).to.be.equal(multiPageCT.content_type.uid) - // expect(contentType.title).to.be.equal(multiPageCT.content_type.title) - // done() - // }) - // .catch(done) - // }) + + it('should update Multi page ContentType Schema without fetch', done => { + makeContentType(multiPageCT.content_type.uid) + .updateCT(multiPageCT) + .then((contentType) => { + expect(contentType.content_type.schema.length).to.be.equal(2) + done() + }) + .catch(done) + }) + it('should import content type', done => { makeContentType().import({ diff --git a/test/sanity-check/api/role-test.js b/test/sanity-check/api/role-test.js index d1a190c1..855db3c0 100644 --- a/test/sanity-check/api/role-test.js +++ b/test/sanity-check/api/role-test.js @@ -9,6 +9,19 @@ dotenv.config() let client = {} let roleUID = '' +const taxonomy = { + uid: 'taxonomy_testing1', + name: 'taxonomy testing1', + description: 'Description for Taxonomy testing' +} +const term = { + term: { + uid: 'term_test1', + name: 'Term test1', + parent_uid: null + } +} + describe('Role api test', () => { setup(() => { const user = jsonReader('loggedinuser.json') @@ -49,6 +62,19 @@ describe('Role api test', () => { .catch(done) }) + it('should create taxonomy', async () => { + await client.stack({ api_key: process.env.API_KEY }).taxonomy().create({ taxonomy }) + }) + + it('should create term', done => { + makeTerms(taxonomy.uid).create(term) + .then((response) => { + expect(response.uid).to.be.equal(term.term.uid) + done() + }) + .catch(done) + }) + it('should create new role in stack', done => { getRole() .create(role) @@ -141,8 +167,28 @@ describe('Role api test', () => { }) .catch(done) }) + it('should delete of the term uid passed', done => { + makeTerms(taxonomy.uid, term.term.uid).delete({ force: true }) + .then((response) => { + expect(response.status).to.be.equal(204) + done() + }) + .catch(done) + }) + + it('should delete taxonomy', async () => { + const taxonomyResponse = await client.stack({ api_key: process.env.API_KEY }).taxonomy(taxonomy.uid).delete({ force: true }) + expect(taxonomyResponse.status).to.be.equal(204) + }) + }) function getRole (uid = null) { return client.stack({ api_key: process.env.API_KEY }).role(uid) } + + +function makeTerms (taxonomyUid, termUid = null) { + return client.stack({ api_key: process.env.API_KEY }).taxonomy(taxonomyUid).terms(termUid) +} + diff --git a/test/sanity-check/mock/role.js b/test/sanity-check/mock/role.js index 343bec72..260b7d32 100644 --- a/test/sanity-check/mock/role.js +++ b/test/sanity-check/mock/role.js @@ -74,6 +74,36 @@ const role = { acl: { read: true } + }, + { + module: "taxonomy", + taxonomies: ["taxonomy_testing1"], + terms: ["taxonomy_testing1.term_test1"], + content_types: [ + { + uid: "$all", + acl: { + read: true, + sub_acl: { + read: true, + create: true, + update: true, + delete: true, + publish: true + } + } + } + ], + acl: { + read: true, + sub_acl: { + read: true, + create: true, + update: true, + delete: true, + publish: true + } + } } ] } diff --git a/test/unit/mock/objects.js b/test/unit/mock/objects.js index 5c44bad5..3f7a5ff1 100644 --- a/test/unit/mock/objects.js +++ b/test/unit/mock/objects.js @@ -143,6 +143,89 @@ const roleMock = { ...adminRoleMock, admin: false } +const roleMockWithTaxonomy = { + ...systemFieldsMock, + ...systemFieldsUserMock, + name: "Admin", + description: "Admin Role", + rules: [ + { + module: "branch", + branches: [ + "main" + ], + acl: { + read: true + } + }, + { + module: "environment", + environments: ["env_uid1", "env_uid2"], + acl: { + read: true + } + }, + { + module: "locale", + locales: ["locales"], + acl: { + read: true + } + }, + { + module: "taxonomy", + taxonomies: ["taxonomy_1"], + terms: ["taxonomy_1.term_1"], + content_types: [ + { + uid: "$all", + acl: { + read: true, + sub_acl: { + read: true, + create: true, + update: true, + delete: true, + publish: true + } + } + } + ], + acl: { + read: true, + sub_acl: { + read: true, + create: true, + update: true, + delete: true, + publish: true + } + } + }, + { + module: "content_type", + content_types: ["ct_1"], + acl: { + read: true, + sub_acl: { + read: true, + create: true, + update: true, + delete: true, + publish: true + } + } + } + ], + org_uid: "org_uid", + api_key: "api_key", + admin: false, + default: true, + users: [ + 'user_uid' + ] + } + const branchMock = { ...systemFieldsMock, ...systemFieldsUserMock, @@ -897,5 +980,6 @@ export { mockCollection, entryMockCollection, checkSystemFields, - managementTokenMock + managementTokenMock, + roleMockWithTaxonomy } diff --git a/test/unit/role-test.js b/test/unit/role-test.js index 0f11b949..c926650f 100644 --- a/test/unit/role-test.js +++ b/test/unit/role-test.js @@ -3,7 +3,7 @@ import { expect } from 'chai' import { describe, it } from 'mocha' import MockAdapter from 'axios-mock-adapter' import { Role, RoleCollection } from '../../lib/stack/roles' -import { systemUidMock, stackHeadersMock, roleMock, noticeMock } from './mock/objects' +import { systemUidMock, stackHeadersMock, roleMock, noticeMock, roleMockWithTaxonomy} from './mock/objects' describe('Contentstack Role test', () => { it('Role test without uid', done => { @@ -88,6 +88,22 @@ describe('Contentstack Role test', () => { .catch(done) }) + it('Role create test with taxonomy permission', done => { + var mock = new MockAdapter(Axios) + mock.onPost('/roles').reply(200, { + role: { + ...roleMockWithTaxonomy + } + }) + makeRole() + .create() + .then((role) => { + checkRole(role) + done() + }) + .catch(done) + }) + it('Role Fetch all without Stack Headers test', done => { var mock = new MockAdapter(Axios) mock.onGet('/roles').reply(200, {