Skip to content

Commit 322f9af

Browse files
Merge pull request #91 from contentstack/feat/cs-42021-teams-support-implementation
Feat/cs 42021 teams support implementation
2 parents 85fd19b + a582e8a commit 322f9af

27 files changed

+1079
-19
lines changed

.github/workflows/unit-test.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
name: Unit Test & Reports
22
on:
33
pull_request:
4-
push:
4+
branches:
5+
- master
6+
- main
7+
- next
58
jobs:
69
build-test:
710
name: Build & Test
@@ -23,6 +26,5 @@ jobs:
2326
reporter: mocha-json # Format of test results
2427
- name: Coverage report
2528
uses: lucassabreu/comment-coverage-clover@main
26-
with:
27-
name: Unit test Coverage report
29+
with:
2830
file: coverage/clover.xml

.jsdoc.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
"lib/stack/roles/index.js",
3333
"lib/stack/webhook/index.js",
3434
"lib/stack/workflow/index.js",
35-
"lib/stack/workflow/publishRules/index.js"
36-
35+
"lib/stack/workflow/publishRules/index.js",
36+
"lib/organization/teams/index.js",
37+
"lib/organization/teams/stackRoleMappings/index.js",
38+
"lib/organization/teams/teamUsers/index.js"
3739
],
3840
"excludePattern": "(node_modules/|jsdocs)"
3941
},

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
threshold: medium
22
fileignoreconfig:
33
- filename: package-lock.json
4-
checksum: ef5d374553f431b5a952069f46184ec7e49efd7d72143e1a1642994758db4359
4+
checksum: 9a7bec9513834a0fc7db31b9a312ec35980600415c04f0d404e1370cfce1ef1b
55
version: ""

lib/organization/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { StackCollection } from '../stack'
77
import { UserCollection } from '../user'
88
import { App } from '../app'
99
import { AppRequest } from '../app/request'
10+
import { Teams } from './teams'
1011
/**
1112
* Organization is the top-level entity in the hierarchy of Contentstack, consisting of stacks and stack resources, and users. Organization allows easy management of projects as well as users within the Organization. Read more about <a href='https://www.contentstack.com/docs/guide/organization'>Organizations.</a>.
1213
* @namespace Organization
@@ -18,6 +19,26 @@ export function Organization (http, data) {
1819
Object.assign(this, cloneDeep(data.organization))
1920
this.urlPath = `/organizations/${this.uid}`
2021

22+
/**
23+
* @description The teams call fetches teams details.
24+
* @memberof Organization
25+
* @func teams
26+
* @returns {Promise<Organization.Organization>} Promise for Organization instance
27+
* @example
28+
* import * as contentstack from '@contentstack/management'
29+
* const client = contentstack.client()
30+
*
31+
* client.organization('organization_uid').teams('teamsUid').fetch()
32+
* .then((organization) => console.log(organization))
33+
*
34+
*/
35+
this.teams = (teamUid = null) => {
36+
data.organizationUid = this.uid
37+
if (teamUid) {
38+
data.uid = teamUid
39+
}
40+
return new Teams(http, data)
41+
}
2142
/**
2243
* @description The fetch Organization call fetches Organization details.
2344
* @memberof Organization

lib/organization/teams/index.js

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
import cloneDeep from 'lodash/cloneDeep'
2+
import {
3+
create,
4+
fetch,
5+
deleteEntity,
6+
fetchAll
7+
} from '../../entity'
8+
import { TeamUsers } from './teamUsers'
9+
import { StackRoleMappings } from './stackRoleMappings'
10+
import error from '../../core/contentstackError'
11+
12+
export function Teams (http, data) {
13+
this.organizationUid = data.organizationUid
14+
this.urlPath = `/organizations/${this.organizationUid}/teams`
15+
if (data && data.uid) {
16+
Object.assign(this, cloneDeep(data))
17+
18+
this.urlPath = `/organizations/${this.organizationUid}/teams/${this.uid}`
19+
20+
/**
21+
* @description The update call on team will allow to update details of team.
22+
* @memberof Teams
23+
* @func update
24+
* @returns {Promise<Teams.Teams>} Response Object.
25+
* @example
26+
* import * as contentstack from '@contentstack/management'
27+
* const client = contentstack.client()
28+
* const updateData = {
29+
* name: 'updatedname',
30+
* users: [
31+
* {
32+
* email: 'abc@abc.com'
33+
* }
34+
* ],
35+
* organizationRole: 'blt09e5dfced326aaea',
36+
* stackRoleMapping: []
37+
* }
38+
* client.organization(s'organizationUid').teams('teamUid').update(updateData)
39+
* .then((response) => console.log(response))
40+
*
41+
*/
42+
this.update = async (updateData) => {
43+
try {
44+
const response = await http.put(this.urlPath, updateData)
45+
if (response.data) {
46+
return response.data
47+
}
48+
} catch (err) {
49+
throw error(err)
50+
}
51+
}
52+
53+
/**
54+
* @description The delete call on team will delete the existing team.
55+
* @memberof Teams
56+
* @func delete
57+
* @returns {Promise<Teams.Teams>} Response Object.
58+
* @example
59+
* import * as contentstack from '@contentstack/management'
60+
* const client = contentstack.client()
61+
* client.organization('organizationUid').teams('teamUid').delete()
62+
* .then((response) => console.log(response))
63+
*
64+
*/
65+
this.delete = deleteEntity(http)
66+
67+
/**
68+
* @description The fetch call on team will delete the existing team.
69+
* @memberof Teams
70+
* @func fetch
71+
* @returns {Promise<Teams.Teams>} Response Object.
72+
* @example
73+
* import * as contentstack from '@contentstack/management'
74+
* const client = contentstack.client()
75+
* client.organization('organizationUid').teams('teamUid').fetch()
76+
* .then((response) => console.log(response))
77+
*
78+
*/
79+
this.fetch = fetch(http, 'team')
80+
81+
/**
82+
* @description The users call on team will get users details.
83+
* @memberof Teams
84+
* @func users
85+
* @returns {Promise<Teams.Teams>} Response Object.
86+
* @example
87+
* import * as contentstack from '@contentstack/management'
88+
* const client = contentstack.client()
89+
* client.organization('organizationUid').teams('teamUid').users().fetchAll()
90+
* .then((response) => console.log(response))
91+
*
92+
*/
93+
this.users = (userId = null) => {
94+
data.organizationUid = this.organizationUid
95+
data.teamUid = this.uid
96+
if (userId) {
97+
data.userId = userId
98+
}
99+
return new TeamUsers(http, data)
100+
}
101+
102+
this.stackRoleMappings = (stackApiKey = null) => {
103+
data.organizationUid = this.organizationUid
104+
data.teamUid = this.uid
105+
if (stackApiKey) {
106+
data.stackApiKey = stackApiKey
107+
}
108+
return new StackRoleMappings(http, data)
109+
}
110+
} else {
111+
/**
112+
* @description The fetch call on team will delete the existing team.
113+
* @memberof Teams
114+
* @func create
115+
* @returns {Promise<Teams.Teams>} Response Object.
116+
* @example
117+
* import * as contentstack from '@contentstack/management'
118+
* const client = contentstack.client()
119+
* const team = {
120+
* name: 'name',
121+
* organizationUid: 'organization_uid',
122+
* users: [],
123+
* stackRoleMapping: [],
124+
* organizationRole: 'organizationRole'
125+
* }
126+
* client.organization('organizationUid').teams().create(team)
127+
* .then((response) => console.log(response))
128+
*
129+
*/
130+
this.create = create({ http })
131+
132+
/**
133+
* @description The fetchAll on team will allow to fetch details of all teams.
134+
* @memberof Teams
135+
* @func fetchAll
136+
* @returns {Promise<Teams.Teams>} Response Object.
137+
* @example
138+
* import * as contentstack from '@contentstack/management'
139+
* const client = contentstack.client()
140+
*
141+
* client.organization('organizationUid').teams().fetchAll()
142+
* .then((response) => console.log(response))
143+
*/
144+
this.fetchAll = fetchAll(http, TeamsCollection)
145+
}
146+
}
147+
export function TeamsCollection (http, teamsData) {
148+
const obj = cloneDeep(teamsData) || []
149+
const teamsCollection = obj.map((team) => {
150+
return new Teams(http, team)
151+
})
152+
return teamsCollection
153+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/**
2+
* @namespace StackRoleMappings
3+
*/
4+
import cloneDeep from 'lodash/cloneDeep'
5+
import {
6+
deleteEntity
7+
} from '../../../entity'
8+
import error from '../../../core/contentstackError'
9+
10+
export function StackRoleMappings (http, data) {
11+
const _urlPath = `/organizations/${data.organizationUid}/teams/${data.teamUid}/stack_role_mappings`
12+
if (data && data.stackApiKey) {
13+
Object.assign(this, cloneDeep(data))
14+
15+
if (this.organizationUid) this.urlPath = `${_urlPath}/${this.stackApiKey}`
16+
/**
17+
* @description The update stackRoleMappings call is used to update the roles.
18+
* @memberof StackRoleMappings
19+
* @func update
20+
* @returns {Promise<StackRoleMappings.StackRoleMappings>} Response Object.
21+
* @example
22+
* import * as contentstack from '@contentstack/management'
23+
* const client = contentstack.client()
24+
* const updateRoles = {
25+
* roles: [
26+
* 'roles_uid1',
27+
* 'roles_uid2'
28+
* ]
29+
* }
30+
* client.organization('organizationUid').teams('teamUid').stackRoleMappings('stackApiKey').update(updateRoles)
31+
* .then((response) => console.log(response))
32+
*/
33+
this.update = async (updateData, params = {}) => {
34+
try {
35+
const response = await http.put(this.urlPath, updateData, { params })
36+
if (response.data) {
37+
return response.data
38+
}
39+
} catch (err) {
40+
throw error(err)
41+
}
42+
}
43+
44+
/**
45+
* @description The delete stackRoleMappings call is used to delete the roles.
46+
* @memberof StackRoleMappings
47+
* @func delete
48+
* @returns {Promise<StackRoleMappings.StackRoleMappings>} Response Object.
49+
* @example
50+
* import * as contentstack from '@contentstack/management'
51+
* const client = contentstack.client()
52+
*
53+
* client.organization('organizationUid').teams('teamUid').stackRoleMappings('stackApiKey').delete()
54+
* .then((response) => console.log(response))
55+
*/
56+
this.delete = deleteEntity(http)
57+
} else {
58+
this.urlPath = _urlPath
59+
/**
60+
* @description The add stackRoleMappings call is used to add the roles.
61+
* @memberof StackRoleMappings
62+
* @func add
63+
* @returns {Promise<StackRoleMappings.StackRoleMappings>} Response Object.
64+
* @example
65+
* import * as contentstack from '@contentstack/management'
66+
* const client = contentstack.client()
67+
*
68+
* const addRole = {
69+
* 'stackApiKey: 'stackApiKey',
70+
* 'roles': [
71+
* 'role_uid'
72+
* ]
73+
* }
74+
* client.organization('organizationUid').teams('teamUid').stackRoleMappings().add(addRole)
75+
* .then((response) => console.log(response))
76+
*/
77+
this.add = async (updateData, params = {}) => {
78+
try {
79+
const response = await http.post(this.urlPath, updateData, { params })
80+
if (response.data) {
81+
return response.data
82+
}
83+
} catch (err) {
84+
throw error(err)
85+
}
86+
}
87+
88+
/**
89+
* @description The fetchAll stackRoleMappings call is used to fetchAll the roles.
90+
* @memberof StackRoleMappings
91+
* @func fetchAll
92+
* @returns {Promise<StackRoleMappings.StackRoleMappings>} Response Object.
93+
* @example
94+
* import * as contentstack from '@contentstack/management'
95+
* const client = contentstack.client()
96+
*
97+
* client.organization('organizationUid').teams('teamUid').stackRoleMappings().fetchAll
98+
* .then((response) => console.log(response))
99+
*/
100+
this.fetchAll = async () => {
101+
try {
102+
const response = await http.get(this.urlPath)
103+
if (response.data) {
104+
return response.data
105+
}
106+
} catch (err) {
107+
throw error(err)
108+
}
109+
}
110+
}
111+
}
112+
export function stackRoleMappingsCollection (http, data) {
113+
const obj = cloneDeep(data.stackRoleMappings) || []
114+
const stackRoleMappingCollection = obj.map((stackRoleMappings) => {
115+
return stackRoleMappings(http, { stackRoleMappings: stackRoleMappings })
116+
})
117+
return new StackRoleMappings(http, stackRoleMappingCollection)
118+
}

0 commit comments

Comments
 (0)