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/cs 42021 teams support implementation #91

Merged
merged 23 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dba8f48
feat: :sparkles: teams implementation with unit and api tests
harshithad0703 Oct 27, 2023
393d8c0
docs: added teams documentation
harshithad0703 Nov 1, 2023
c575b4b
test: :white_check_mark: updated api and unit test cases for teams su…
harshithad0703 Nov 1, 2023
797ba45
feat: :sparkles: teams users implementation and api test cases
harshithad0703 Nov 1, 2023
fec3852
test: :white_check_mark: added unit test cases for team users
harshithad0703 Nov 2, 2023
99fc8c1
feat: :sparkles: stackrolemapping implementation and api test cases
harshithad0703 Nov 6, 2023
c8425fb
test: changes made in update implementation and its test case
harshithad0703 Nov 6, 2023
cd9dea7
test: update stackrolemapping implementation and api test cases
harshithad0703 Nov 6, 2023
864db84
added assertions to check the response
harshithad0703 Nov 7, 2023
231711f
added unit test cases for stack role mapping
harshithad0703 Nov 7, 2023
4fcf217
replaced query with fetchAll function
harshithad0703 Nov 7, 2023
95d5f86
changing folder name to be same as class name
harshithad0703 Nov 7, 2023
59827bf
ci: :green_heart: fix unit test github action
nadeem-cs Nov 7, 2023
e79409f
ci: fix unit test github action
nadeem-cs Nov 7, 2023
83c136c
feat: types support for teams
harshithad0703 Nov 7, 2023
e66b74e
chore: :arrow_up: update axios lib
nadeem-cs Nov 7, 2023
9e59400
added valid assertions for the test
harshithad0703 Nov 7, 2023
46c0976
teams test cases for types support
harshithad0703 Nov 7, 2023
e5b0807
types support for team Users and api test cases
harshithad0703 Nov 9, 2023
e85be9f
interface changed from User to TeamUser in types
harshithad0703 Nov 9, 2023
0aa565d
types support for stackRoleMapping and test cases
harshithad0703 Nov 9, 2023
8098385
stackRoleMapping test cases in types support
harshithad0703 Nov 10, 2023
a582e8a
stackRoleMapping update test case on types support
harshithad0703 Nov 10, 2023
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
6 changes: 4 additions & 2 deletions .jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
"lib/stack/roles/index.js",
"lib/stack/webhook/index.js",
"lib/stack/workflow/index.js",
"lib/stack/workflow/publishRules/index.js"

"lib/stack/workflow/publishRules/index.js",
"lib/organization/teams/index.js",
"lib/organization/teams/stackRoleMappings/index.js",
"lib/organization/teams/teamUsers/index.js"
],
"excludePattern": "(node_modules/|jsdocs)"
},
Expand Down
21 changes: 21 additions & 0 deletions lib/organization/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { StackCollection } from '../stack'
import { UserCollection } from '../user'
import { App } from '../app'
import { AppRequest } from '../app/request'
import { Teams } from './teams'
/**
* 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>.
* @namespace Organization
Expand All @@ -18,6 +19,26 @@ export function Organization (http, data) {
Object.assign(this, cloneDeep(data.organization))
this.urlPath = `/organizations/${this.uid}`

/**
* @description The teams call fetches teams details.
* @memberof Organization
* @func teams
* @returns {Promise<Organization.Organization>} Promise for Organization instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.organization('organization_uid').teams('teamsUid').fetch()
* .then((organization) => console.log(organization))
*
*/
this.teams = (teamUid = null) => {
data.organizationUid = this.uid
if (teamUid) {
data.uid = teamUid
}
return new Teams(http, data)
}
/**
* @description The fetch Organization call fetches Organization details.
* @memberof Organization
Expand Down
153 changes: 153 additions & 0 deletions lib/organization/teams/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import cloneDeep from 'lodash/cloneDeep'
import {
create,
fetch,
deleteEntity,
fetchAll
} from '../../entity'
import { TeamUsers } from './teamUsers'
import { StackRoleMappings } from './stackRoleMappings'
import error from '../../core/contentstackError'

export function Teams (http, data) {
this.organizationUid = data.organizationUid
this.urlPath = `/organizations/${this.organizationUid}/teams`
if (data && data.uid) {
Object.assign(this, cloneDeep(data))

this.urlPath = `/organizations/${this.organizationUid}/teams/${this.uid}`

/**
* @description The update call on team will allow to update details of team.
* @memberof Teams
* @func update
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const updateData = {
* name: 'updatedname',
* users: [
* {
* email: '[email protected]'
* }
* ],
* organizationRole: 'blt09e5dfced326aaea',
* stackRoleMapping: []
* }
* client.organization(s'organizationUid').teams('teamUid').update(updateData)
* .then((response) => console.log(response))
*
*/
this.update = async (updateData, params = {}) => {
try {
const response = await http.put(this.urlPath, updateData, { params })
if (response.data) {
return response.data
}
} catch (err) {
throw error(err)
}
}

/**
* @description The delete call on team will delete the existing team.
* @memberof Teams
* @func delete
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* client.organization('organizationUid').teams('teamUid').delete()
* .then((response) => console.log(response))
*
*/
this.delete = deleteEntity(http)

/**
* @description The fetch call on team will delete the existing team.
* @memberof Teams
* @func fetch
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* client.organization('organizationUid').teams('teamUid').fetch()
* .then((response) => console.log(response))
*
*/
this.fetch = fetch(http, 'team')

/**
* @description The users call on team will get users details.
* @memberof Teams
* @func users
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* client.organization('organizationUid').teams('teamUid').users().fetchAll()
* .then((response) => console.log(response))
*
*/
this.users = (userId = null) => {
data.organizationUid = this.organizationUid
data.teamUid = this.uid
if (userId) {
data.userId = userId
}
return new TeamUsers(http, data)
}

this.stackRoleMappings = (stackApiKey = null) => {
data.organizationUid = this.organizationUid
data.teamUid = this.uid
if (stackApiKey) {
data.stackApiKey = stackApiKey
}
return new StackRoleMappings(http, data)
}
} else {
/**
* @description The fetch call on team will delete the existing team.
* @memberof Teams
* @func create
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const team = {
* name: 'name',
* organizationUid: 'organization_uid',
* users: [],
* stackRoleMapping: [],
* organizationRole: 'organizationRole'
* }
* client.organization('organizationUid').teams().create(team)
* .then((response) => console.log(response))
*
*/
this.create = create({ http })

/**
* @description The fetchAll on team will allow to fetch details of all teams.
* @memberof Teams
* @func fetchAll
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.organization('organizationUid').teams().fetchAll()
* .then((response) => console.log(response))
*/
this.fetchAll = fetchAll(http, TeamsCollection)
}
}
export function TeamsCollection (http, teamsData) {
const obj = cloneDeep(teamsData) || []
const teamsCollection = obj.map((team) => {
return new Teams(http, team)
})
return teamsCollection
}
118 changes: 118 additions & 0 deletions lib/organization/teams/stackRoleMappings/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* @namespace StackRoleMappings
*/
import cloneDeep from 'lodash/cloneDeep'
import {
deleteEntity
} from '../../../entity'
import error from '../../../core/contentstackError'

export function StackRoleMappings (http, data) {
const _urlPath = `/organizations/${data.organizationUid}/teams/${data.teamUid}/stack_role_mappings`
if (data && data.stackApiKey) {
Object.assign(this, cloneDeep(data))

if (this.organizationUid) this.urlPath = `${_urlPath}/${this.stackApiKey}`
/**
* @description The update stackRoleMappings call is used to update the roles.
* @memberof StackRoleMappings
* @func update
* @returns {Promise<StackRoleMappings.StackRoleMappings>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const updateRoles = {
* roles: [
* 'roles_uid1',
* 'roles_uid2'
* ]
* }
* client.organization('organizationUid').teams('teamUid').stackRoleMappings('stackApiKey').update(updateRoles)
* .then((response) => console.log(response))
*/
this.update = async (updateData, params = {}) => {
try {
const response = await http.put(this.urlPath, updateData, { params })
if (response.data) {
return response.data
}
} catch (err) {
throw error(err)
}
}

/**
* @description The delete stackRoleMappings call is used to delete the roles.
* @memberof StackRoleMappings
* @func delete
* @returns {Promise<StackRoleMappings.StackRoleMappings>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.organization('organizationUid').teams('teamUid').stackRoleMappings('stackApiKey').delete()
* .then((response) => console.log(response))
*/
this.delete = deleteEntity(http)
} else {
this.urlPath = _urlPath
/**
* @description The add stackRoleMappings call is used to add the roles.
* @memberof StackRoleMappings
* @func add
* @returns {Promise<StackRoleMappings.StackRoleMappings>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* const addRole = {
* 'stackApiKey: 'stackApiKey',
* 'roles': [
* 'role_uid'
* ]
* }
* client.organization('organizationUid').teams('teamUid').stackRoleMappings().add(addRole)
* .then((response) => console.log(response))
*/
this.add = async (updateData, params = {}) => {
try {
const response = await http.post(this.urlPath, updateData, { params })
if (response.data) {
return response.data
}
} catch (err) {
throw error(err)
}
}

/**
* @description The fetchAll stackRoleMappings call is used to fetchAll the roles.
* @memberof StackRoleMappings
* @func fetchAll
* @returns {Promise<StackRoleMappings.StackRoleMappings>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.organization('organizationUid').teams('teamUid').stackRoleMappings().fetchAll
* .then((response) => console.log(response))
*/
this.fetchAll = async () => {
try {
const response = await http.get(this.urlPath)
if (response.data) {
return response.data
}
} catch (err) {
throw error(err)
}
}
}
}
export function stackRoleMappingsCollection (http, data) {
const obj = cloneDeep(data.stackRoleMappings) || []
const stackRoleMappingCollection = obj.map((stackRoleMappings) => {
return stackRoleMappings(http, { stackRoleMappings: stackRoleMappings })
})
return new StackRoleMappings(http, stackRoleMappingCollection)
}
72 changes: 72 additions & 0 deletions lib/organization/teams/teamUsers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import cloneDeep from 'lodash/cloneDeep'
import {
create,
deleteEntity,
fetchAll
} from '../../../entity'

export function TeamUsers (http, data) {
if (data && data.userId) {
Object.assign(this, cloneDeep(data))

const _urlPath = `/organizations/${this.organizationUid}/teams/${this.teamUid}/users/${data.userId}`
if (this.organizationUid) this.urlPath = _urlPath

/**
* @description The Remove teamUser call is used to remove an existing user of that team.
* @memberof TeamUsers
* @func remove
* @returns {Promise<TeamUsers.TeamUsers>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.organization('organizationUid').teams('teamUid').users('userId').remove()
* .then((response) => console.log(response))
*
*/
this.remove = deleteEntity(http)
} else {
this.urlPath = `/organizations/${data.organizationUid}/teams/${data.teamUid}/users`

/**
* @description The Add teamUser call is used to add an user the team.
* @memberof TeamUsers
* @func add
* @returns {Promise<TeamUsers.TeamUsers>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const usersMail = {
* emails: ['emailId1','emailId2' ]
* }
* client.organization('organizationUid').teams('teamUid').users('userId').add(usersMail)
* .then((response) => console.log(response))
*
*/
this.add = create({ http })

/**
* @description The Query on teamUser will allow to fetch details of all teamUsers.
* @memberof TeamUsers
* @func query
* @returns {Promise<TeamUsers.TeamUsers>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const usersMail = {
* emails: ['emailId1','emailId2' ]}
* client.organization('organizationUid').teams('teamUid').users('userId').query().find()
* .then((response) => console.log(response))
*
*/
this.fetchAll = fetchAll(http, UsersCollection)
}
}
export function UsersCollection (http, data) {
const obj = cloneDeep(data.users) || []
const usersCollection = obj.map((user) => {
return new TeamUsers(http, { userId: user })
})
return usersCollection
}
Loading
Loading