Add user resource and operations to Jira (#1448)

* Add user resource and operations

* Update user resource description

*  Small improvements

Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
This commit is contained in:
Iván Ovejero 2021-02-21 07:00:27 -03:00 committed by GitHub
parent 13e76e33e8
commit b655153431
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 261 additions and 1 deletions

View file

@ -43,6 +43,11 @@ import {
NotificationRecipientsRestrictions,
} from './IssueInterface';
import {
userFields,
userOperations,
} from './UserDescription';
export class Jira implements INodeType {
description: INodeTypeDescription = {
displayName: 'Jira Software',
@ -119,6 +124,11 @@ export class Jira implements INodeType {
value: 'issueComment',
description: 'Get, create, update, and delete a comment from an issue.',
},
{
name: 'User',
value: 'user',
description: 'Get, create and delete a user.',
},
],
default: 'issue',
description: 'Resource to consume.',
@ -129,6 +139,8 @@ export class Jira implements INodeType {
...issueAttachmentFields,
...issueCommentOperations,
...issueCommentFields,
...userOperations,
...userFields,
],
};
@ -952,10 +964,51 @@ export class Jira implements INodeType {
}
}
if (resource === 'user') {
if (operation === 'create') {
// https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-users/#api-rest-api-3-user-post
for (let i = 0; i < length; i++) {
const body = {
name: this.getNodeParameter('username', i),
emailAddress: this.getNodeParameter('emailAddress', i),
displayName: this.getNodeParameter('displayName', i),
};
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
Object.assign(body, additionalFields);
responseData = await jiraSoftwareCloudApiRequest.call(this, '/api/3/user', 'POST', body, {});
returnData.push(responseData);
}
} else if (operation === 'delete') {
// https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-users/#api-rest-api-3-user-delete
for (let i = 0; i < length; i++) {
qs.accountId = this.getNodeParameter('accountId', i);
responseData = await jiraSoftwareCloudApiRequest.call(this, '/api/3/user', 'DELETE', {}, qs);
returnData.push({ success: true });
}
} else if (operation === 'get') {
// https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-users/#api-rest-api-3-user-get
for (let i = 0; i < length; i++) {
qs.accountId = this.getNodeParameter('accountId', i);
const { expand } = this.getNodeParameter('additionalFields', i) as { expand: string[] };
if (expand) {
qs.expand = expand.join(',');
}
responseData = await jiraSoftwareCloudApiRequest.call(this, '/api/3/user', 'GET', {}, qs);
returnData.push(responseData);
}
}
}
if (resource === 'issueAttachment' && (operation === 'getAll' || operation === 'get')) {
return this.prepareOutputData(returnData as unknown as INodeExecutionData[]);
} else {
return [this.helpers.returnJsonArray(returnData)];
}
}
}
}

View file

@ -0,0 +1,207 @@
import {
INodeProperties,
} from 'n8n-workflow';
export const userOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'user',
],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a new user.',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a user.',
},
{
name: 'Get',
value: 'get',
description: 'Retrieve a user.',
},
],
default: 'create',
description: 'The operation to perform.',
},
] as INodeProperties[];
export const userFields = [
/* -------------------------------------------------------------------------- */
/* user:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'Username',
name: 'username',
type: 'string',
required: true,
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'create',
],
},
},
},
{
displayName: 'Email Address',
name: 'emailAddress',
type: 'string',
required: true,
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'create',
],
},
},
},
{
displayName: 'Display Name',
name: 'displayName',
type: 'string',
required: true,
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'create',
],
},
},
default: '',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'create',
],
},
},
options: [
{
displayName: 'Password',
name: 'password',
type: 'string',
default: '',
description: 'Password for the user. If a password is not set, a random password is generated.',
typeOptions: {
password: true,
},
},
{
displayName: 'Notification',
name: 'notification',
type: 'boolean',
default: false,
description: 'Send the user an email confirmation that they have been added to Jira.',
},
],
},
/* -------------------------------------------------------------------------- */
/* user:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Account ID',
name: 'accountId',
type: 'string',
default: '',
description: 'Account ID of the user to delete.',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'delete',
],
},
},
},
/* -------------------------------------------------------------------------- */
/* user:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Account ID',
name: 'accountId',
type: 'string',
default: '',
description: 'Account ID of the user to retrieve.',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'get',
],
},
},
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'get',
],
},
},
options: [
{
displayName: 'Expand',
name: 'expand',
type: 'multiOptions',
default: [],
description: 'Include more information about the user.',
options: [
{
name: 'Groups',
value: 'groups',
description: 'Include all groups to which the user belongs.',
},
{
name: 'Application Roles',
value: 'applicationRoles',
description: 'Include details of all the applications the user can access.',
},
],
},
],
},
] as INodeProperties[];