Skip to content

Commit

Permalink
Enh/dx 737 taxonomy permission (#161)
Browse files Browse the repository at this point in the history
* 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: ✅ 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: 🐛 handles the error in refreshtoken instead of throwing it

* ci: 🔥 removed sast-scan yml file

* fix: 🐛 handles workflow response in object format

* feat: ✨ allows overwrite flag param in import of contenttype and global field

* test: ✅ adds CT and GF import test for overwrite flag

* refactor: ♻️ adds type support for overwrite flag param

* chore: 📦 version changes and package updates

* perf: 📦 packages update

* docs: 📝 Updates README

* feat: ✨ Taxonomy Implementation with docs, unit and api test cases

* test: ✅ changes made in taxonomy function in stack class

* test: uncommented 'detele' api test case

* feat: ✨ create, fetch, find, update, delete , ancestors and descendants functions are added

* test: ✅ added api test cases for terms implementation

* feat: ✨ allows content-type for asset upload

* test: ✅ unit test cases for terms implementation (except search and move)

* changes done in passing data to create function in api test case

* feat: ✨ added move and search functions for terms implementation

* test: ✅ updated and added search and move unit test cases

* test: ✅ updated and added search and move api test cases

* docs: 📝 updated api reference docs for search, ancestors, descendants and move

* build: 📦 updated axios module and version number

* chore: 🔊 update changelog file

* feat: ✨ taxonomy and terms implementation for typescript

* fix: 🐛 taxonomy bug fix

* feat: ✨ terms implementaion with descendants and move function

* fix: 🐛 taxonomy bug fix in query unit test case

* fix: taxonomy and terms fixes

* fix: 🐛 error message fix on refresh token error

* refactor: uncommented unit test cases

* test: ✅ taxonomy API test cases

* test: ✅ terms api test cases and search implementation

* test: ✅ changes in search unit test in terms

* changed default host name

* added entry on changelog file and changed version

* feat: ✨ teams implementation with unit and api tests

* docs: added teams documentation

* test: ✅ updated api and unit test cases for teams support

* feat: ✨ teams users implementation and api test cases

* test: ✅ added unit test cases for team users

* feat: ✨ 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: 💚 fix unit test github action

* ci: fix unit test github action

* feat: types support for teams

* chore: ⬆️ 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: 📝 updated version and changeLog

* test: added test cases to improve coverage report

* feat: ✨ early access headers implementation

* types support for earlyaccess and update changeLog

* fix: 🐛 early_access made optional

* fix: 🐛 added api_version param which is to be passed in headers

* test: ✅ updated response fetchAll unit test case

* fix: 🐛 create function response data update

* refactor: ♻️ 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 <[email protected]>
Co-authored-by: harshithad0703 <[email protected]>
Co-authored-by: harshithad0703 <[email protected]>

* 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: 📦 updates axios version

* chore: update package version in package.json

* chore: 🔨 updates prerelease hook script

* chore: 📦 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: 📦 updated slack/bolt package to devDependencies

* Revert "chore: 📦 updated slack/bolt package to devDependencies"

This reverts commit 7ca1911.

* 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 <[email protected]>

* Validating the object  when update the entries with assets (#114)

Co-authored-by: Nadeem <[email protected]>

* 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 <[email protected]>

* Validating the object  when update the entries with assets (#114)

Co-authored-by: Nadeem <[email protected]>

---------

Co-authored-by: harshithad0703 <[email protected]>
Co-authored-by: harshithad0703 <[email protected]>
Co-authored-by: Nadeem <[email protected]>

* 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 <[email protected]>

* Validating the object  when update the entries with assets (#114)

Co-authored-by: Nadeem <[email protected]>

---------

Co-authored-by: harshithad0703 <[email protected]>
Co-authored-by: harshithad0703 <[email protected]>
Co-authored-by: Nadeem <[email protected]>

* Added taxonomy import/export testcases.

---------

Co-authored-by: Nadeem <[email protected]>
Co-authored-by: harshithad0703 <[email protected]>
Co-authored-by: harshithad0703 <[email protected]>

* 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 <[email protected]>

* Validating the object  when update the entries with assets (#114)

Co-authored-by: Nadeem <[email protected]>

* 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 <[email protected]>

* Validating the object  when update the entries with assets (#114)

Co-authored-by: Nadeem <[email protected]>

---------

Co-authored-by: harshithad0703 <[email protected]>
Co-authored-by: harshithad0703 <[email protected]>
Co-authored-by: Nadeem <[email protected]>

* Added taxonomy import/export testcases.

---------

Co-authored-by: Nadeem <[email protected]>
Co-authored-by: harshithad0703 <[email protected]>
Co-authored-by: harshithad0703 <[email protected]>

* test: added global field test suit to sanity

* test: add sanity test for label

---------

Co-authored-by: harshithad0703 <[email protected]>
Co-authored-by: harshithad0703 <[email protected]>
Co-authored-by: Nadeem <[email protected]>

* 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: ✨ 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: 🐛 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: 📦 update package version and changeLog

* chore: 📦 upgraded axios package to 1.6.8

* fix: added delete stack method

and test case

* chore: updated changeLog and package version

* chore: 📦 updated internal dependencies

* chore: 📦 updated sdk version to 1.15.4 and changelog update

* feat: ✨ get languages of an entry implementation

* test: ✅ added unit and api test cases

* docs: 📝 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 <[email protected]>
Co-authored-by: Nadeem <[email protected]>
Co-authored-by: Shailesh Mishra <[email protected]>
Co-authored-by: harshithad0703 <[email protected]>
Co-authored-by: harshithad0703 <[email protected]>
Co-authored-by: Abhinav Gupta <[email protected]>
Co-authored-by: abhinav <[email protected]>
Co-authored-by: snyk-bot <[email protected]>
Co-authored-by: Aravind Kumar <[email protected]>
Co-authored-by: Vikram Kalta <[email protected]>
Co-authored-by: Vikram Kalta <[email protected]>
  • Loading branch information
12 people authored Jun 28, 2024
1 parent 265808a commit 7308ecc
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
Expand All @@ -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",
Expand Down
30 changes: 30 additions & 0 deletions test/api/mock/role.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
23 changes: 12 additions & 11 deletions test/sanity-check/api/contentType-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { contentstackClient } from '../utility/ContentstackClient.js'

let client = {}
let multiPageCTUid = ''
let multiPageUpdateCTUid = 'multi_page'

describe('Content Type api Test', () => {
setup(() => {
Expand Down Expand Up @@ -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({
Expand Down
46 changes: 46 additions & 0 deletions test/sanity-check/api/role-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

30 changes: 30 additions & 0 deletions test/sanity-check/mock/role.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
]
}
Expand Down
86 changes: 85 additions & 1 deletion test/unit/mock/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -897,5 +980,6 @@ export {
mockCollection,
entryMockCollection,
checkSystemFields,
managementTokenMock
managementTokenMock,
roleMockWithTaxonomy
}
18 changes: 17 additions & 1 deletion test/unit/role-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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, {
Expand Down

0 comments on commit 7308ecc

Please sign in to comment.