mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 12:44:07 -08:00
fix(Jira Software Node): Get all users in dropdown/RLC (#7322)
Github issue / Community forum post (link here to close automatically): fixes #2670 --------- Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
parent
e7a90c73b3
commit
3704760724
|
@ -6,6 +6,7 @@ import type {
|
||||||
IHookFunctions,
|
IHookFunctions,
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
INodeListSearchItems,
|
INodeListSearchItems,
|
||||||
|
INodePropertyOptions,
|
||||||
JsonObject,
|
JsonObject,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
import { NodeApiError } from 'n8n-workflow';
|
import { NodeApiError } from 'n8n-workflow';
|
||||||
|
@ -228,3 +229,40 @@ export function filterSortSearchListItems(items: INodeListSearchItems[], filter?
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
|
const jiraVersion = this.getCurrentNodeParameter('jiraVersion') as string;
|
||||||
|
const maxResults = 1000;
|
||||||
|
const query: IDataObject = { maxResults };
|
||||||
|
let endpoint = '/api/2/users/search';
|
||||||
|
|
||||||
|
if (jiraVersion === 'server') {
|
||||||
|
endpoint = '/api/2/user/search';
|
||||||
|
query.username = "'";
|
||||||
|
}
|
||||||
|
|
||||||
|
const users = [];
|
||||||
|
let hasNextPage: boolean;
|
||||||
|
|
||||||
|
do {
|
||||||
|
const usersPage = (await jiraSoftwareCloudApiRequest.call(
|
||||||
|
this,
|
||||||
|
endpoint,
|
||||||
|
'GET',
|
||||||
|
{},
|
||||||
|
{ ...query, startAt: users.length },
|
||||||
|
)) as IDataObject[];
|
||||||
|
users.push(...usersPage);
|
||||||
|
hasNextPage = usersPage.length === maxResults;
|
||||||
|
} while (hasNextPage);
|
||||||
|
|
||||||
|
return users
|
||||||
|
.filter((user) => user.active)
|
||||||
|
.map((user) => ({
|
||||||
|
name: user.displayName as string,
|
||||||
|
value: (user.accountId ?? user.name) as string,
|
||||||
|
}))
|
||||||
|
.sort((a: INodePropertyOptions, b: INodePropertyOptions) => {
|
||||||
|
return a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import { BINARY_ENCODING, NodeOperationError } from 'n8n-workflow';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
filterSortSearchListItems,
|
filterSortSearchListItems,
|
||||||
|
getUsers,
|
||||||
jiraSoftwareCloudApiRequest,
|
jiraSoftwareCloudApiRequest,
|
||||||
jiraSoftwareCloudApiRequestAllItems,
|
jiraSoftwareCloudApiRequestAllItems,
|
||||||
simplifyIssueOutput,
|
simplifyIssueOutput,
|
||||||
|
@ -206,30 +207,9 @@ export class Jira implements INodeType {
|
||||||
// Get all the users to display them to user so that they can
|
// Get all the users to display them to user so that they can
|
||||||
// select them easily
|
// select them easily
|
||||||
async getUsers(this: ILoadOptionsFunctions, filter?: string): Promise<INodeListSearchResult> {
|
async getUsers(this: ILoadOptionsFunctions, filter?: string): Promise<INodeListSearchResult> {
|
||||||
const jiraVersion = this.getCurrentNodeParameter('jiraVersion') as string;
|
const users = await getUsers.call(this);
|
||||||
const query: IDataObject = {};
|
|
||||||
let endpoint = '/api/2/users/search';
|
|
||||||
|
|
||||||
if (jiraVersion === 'server') {
|
return { results: filterSortSearchListItems(users, filter) };
|
||||||
endpoint = '/api/2/user/search';
|
|
||||||
query.username = "'";
|
|
||||||
}
|
|
||||||
|
|
||||||
const users = await jiraSoftwareCloudApiRequest.call(this, endpoint, 'GET', {}, query);
|
|
||||||
const returnData: INodeListSearchItems[] = users.reduce(
|
|
||||||
(activeUsers: INodeListSearchItems[], user: IDataObject) => {
|
|
||||||
if (user.active) {
|
|
||||||
activeUsers.push({
|
|
||||||
name: user.displayName as string,
|
|
||||||
value: (user.accountId ?? user.name) as string,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return activeUsers;
|
|
||||||
},
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
return { results: filterSortSearchListItems(returnData, filter) };
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Get all the priorities to display them to user so that they can
|
// Get all the priorities to display them to user so that they can
|
||||||
|
@ -373,30 +353,7 @@ export class Jira implements INodeType {
|
||||||
// Get all the users to display them to user so that they can
|
// Get all the users to display them to user so that they can
|
||||||
// select them easily
|
// select them easily
|
||||||
async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const jiraVersion = this.getCurrentNodeParameter('jiraVersion') as string;
|
return getUsers.call(this);
|
||||||
const query: IDataObject = {};
|
|
||||||
let endpoint = '/api/2/users/search';
|
|
||||||
|
|
||||||
if (jiraVersion === 'server') {
|
|
||||||
endpoint = '/api/2/user/search';
|
|
||||||
query.username = "'";
|
|
||||||
}
|
|
||||||
|
|
||||||
const users = await jiraSoftwareCloudApiRequest.call(this, endpoint, 'GET', {}, query);
|
|
||||||
|
|
||||||
return users
|
|
||||||
.reduce((activeUsers: INodePropertyOptions[], user: IDataObject) => {
|
|
||||||
if (user.active) {
|
|
||||||
activeUsers.push({
|
|
||||||
name: user.displayName as string,
|
|
||||||
value: (user.accountId || user.name) as string,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return activeUsers;
|
|
||||||
}, [])
|
|
||||||
.sort((a: INodePropertyOptions, b: INodePropertyOptions) => {
|
|
||||||
return a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Get all the groups to display them to user so that they can
|
// Get all the groups to display them to user so that they can
|
||||||
|
@ -985,7 +942,7 @@ export class Jira implements INodeType {
|
||||||
);
|
);
|
||||||
|
|
||||||
const executionData = this.helpers.constructExecutionMetaData(
|
const executionData = this.helpers.constructExecutionMetaData(
|
||||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
this.helpers.returnJsonArray({ success: true }), //endpoint returns no content
|
||||||
{ itemData: { item: i } },
|
{ itemData: { item: i } },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue