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

Add support for ServiceDesk api and method for getting organization and adding users to organization #231

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package-lock.json

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

236 changes: 236 additions & 0 deletions src/jira.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,25 @@ export default class JiraApi {
return decodeURIComponent(uri);
}

/**
* @name makeServiceDeskUri
* @function
* Creates a URI object for a given pathname
* @param {UriOptions} object
*/
makeServiceDeskUri(object) {
const intermediateToUse = this.intermediatePath || object.intermediatePath;
const tempPath = intermediateToUse || '/rest/servicedeskapi';
const uri = url.format({
protocol: this.protocol,
hostname: this.host,
port: this.port,
pathname: `${this.base}${tempPath}${object.pathname}`,
query: object.query,
});
return decodeURIComponent(uri);
}

/**
* @name doRequest
* @function
Expand Down Expand Up @@ -693,6 +712,41 @@ export default class JiraApi {
}));
}

/** Update a Jira user
* [Jira Doc](https://docs.atlassian.com/software/jira/docs/api/REST/latest/#user-updateUser)
* @name updateUser
* @function
* @param {object} user - Properly Formatted User object
*/
updateUser(user, key) {
return this.doRequest(this.makeRequestHeader(this.makeUri({
pathname: '/user',
query: {
key,
},
}), {
method: 'PUT',
followAllRedirects: true,
body: user,
}));
}

/** Delete a Jira user
* [Jira Doc](https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-api-2-user-delete)
* @name deleteUser
* @function
* @param {object} user - an object containing user reference : accou
*/
deleteUser(accountId) {
return this.doRequest(this.makeRequestHeader(this.makeUri({
pathname: '/user',
}), {
method: 'DELETE',
followAllRedirects: true,
query: { accountId },
}));
}

/** Search user on Jira
* [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#d2e3756)
* @name searchUsers
Expand Down Expand Up @@ -2018,6 +2072,144 @@ export default class JiraApi {
})));
}

/** Add an organization.
* [Jira Doc](https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-createOrganization)
* @name createOrganization
*/
createOrganization(name) {
return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({
pathname: '/organization',
}), {
method: 'POST',
followAllRedirects: true,
body: { name },
headers: {
'X-ExperimentalApi': 'opt-in',
},
}));
}

/** Rename an organization.
* [Jira Doc](https://youtu.be/dQw4w9WgXcQ?si=RWwWdNwZ2xBfY9dI)
* @name renameOrganization
* @function
* @param {string} organizationId - The organization identifier.
* @param {string} name - The new organization name.
*/
renameOrganization(organizationId, name) {
return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({
intermediatePath: 'rest/servicedesk/1',
pathname: `/organisations/${organizationId}/update`,
}), {
method: 'PUT',
followAllRedirects: true,
body: { newName: name },
headers: {
'X-ExperimentalApi': 'opt-in',
},
}));
}

/** Get Organizations
* [Jira Doc](https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-getOrganizations)
* @name getOrganizations
* @function
* @param {number} [start=0] - The starting index of the returned versions. Base index: 0.
* @param {number} [limit=50] - The maximum number of versions to return per page.
* Default: 50.
*/
getOrganizations(start = 0, limit = 50) {
return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({
pathname: '/organization',
query: {
start,
limit,
},
}), {
headers: {
'X-ExperimentalApi': 'opt-in',
},
}));
}

/** Get Organization
* [Jira Doc](https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-getOrganization)
* @name getOrganization
* @function
* @param {string} organizationId - The organization indentifier.
*/
getOrganization(organizationId) {
return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({
pathname: `/organization/${organizationId}`,
}), {
headers: {
'X-ExperimentalApi': 'opt-in',
},
}));
}

/** Delete Organization
* [Jira Doc](https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-deleteOrganization)
* @name deleteOrganization
* @function
* @param {string} organizationId - The organization indentifier.
*/
deleteOrganization(organizationId) {
return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({
pathname: `/organization/${organizationId}`,
}), {
method: 'DELETE',
headers: {
'X-ExperimentalApi': 'opt-in',
},
}));
}

/** Get Users in an Organization
* [Jira Doc](https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-getUsersInOrganization)
* @name getUsersInOrganization
* @function
* @param {string} organizationId - The organization indentifier.
* @param {number} [start=0] - The starting index of the returned versions. Base index: 0.
* @param {number} [limit=50] - The maximum number of versions to return per page.
* Default: 50.
*/
getUsersInOrganization(organizationId, start = 0, limit = 50) {
return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({
pathname: `/organization/${organizationId}/user`,
query: {
start,
limit,
},
}), {
headers: {
'X-ExperimentalApi': 'opt-in',
},
}));
}

/** Add users to an Organization
* [Jira Doc] (https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-addUsersToOrganization)
* @name addUsersToOrganization
* @function
* @param {string} usernames - the list of usernames of users to add
* @param {string} organizationId - the id of the organization to add them to
*/
addUsersToOrganization(usernames, organizationId) {
return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({
pathname: `/organization/${organizationId}/user`,
}), {
method: 'POST',
followAllRedirects: true,
body: {
usernames,
},
headers: {
'X-ExperimentalApi': 'opt-in',
},
}));
}

/** Get Filter
* [Jira Doc](https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/filter)
* @name getFilter
Expand Down Expand Up @@ -2111,6 +2303,50 @@ export default class JiraApi {
}));
}

/** Remove users from an Organization
* [Jira Doc] (https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-removeUsersFromOrganization)
* @name removeUsersFromOrganization
* @function
* @param {string} usernames - the list of usernames of users to remove
* @param {string} organizationId - the id of the organization to remove them from
*/
removeUsersFromOrganization(usernames, organizationId) {
return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({
pathname: `/organization/${organizationId}/user`,
}), {
method: 'DELETE',
followAllRedirects: true,
body: {
usernames,
},
headers: {
'X-ExperimentalApi': 'opt-in',
},
}));
}

/** Adds an organization to a servicedesk for a given servicedesk id and organization id
* [Jira Doc] (https://docs.atlassian.com/jira-servicedesk/REST/3.15.0/#servicedeskapi/servicedesk/{serviceDeskId}/organization-addOrganization)
* @name addOrganization
* @function
* @param {string} serviceDeskId - the servicedesk in which to add the organization
* @param {string} organizationId - the id of the organization to remove them from
*/
addOrganization(serviceDeskId, organizationId) {
return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({
pathname: `/servicedesk/${serviceDeskId}/organization`,
}), {
method: 'POST',
followAllRedirects: true,
body: {
organizationId,
},
headers: {
'X-ExperimentalApi': 'opt-in',
},
}));
}

/** Rank Epics
* [Jira Doc](https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/epic-rankEpics)
* @name rankEpics
Expand Down