mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -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,
|
||||
ILoadOptionsFunctions,
|
||||
INodeListSearchItems,
|
||||
INodePropertyOptions,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
@ -228,3 +229,40 @@ export function filterSortSearchListItems(items: INodeListSearchItems[], filter?
|
|||
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 {
|
||||
filterSortSearchListItems,
|
||||
getUsers,
|
||||
jiraSoftwareCloudApiRequest,
|
||||
jiraSoftwareCloudApiRequestAllItems,
|
||||
simplifyIssueOutput,
|
||||
|
@ -206,30 +207,9 @@ export class Jira implements INodeType {
|
|||
// Get all the users to display them to user so that they can
|
||||
// select them easily
|
||||
async getUsers(this: ILoadOptionsFunctions, filter?: string): Promise<INodeListSearchResult> {
|
||||
const jiraVersion = this.getCurrentNodeParameter('jiraVersion') as string;
|
||||
const query: IDataObject = {};
|
||||
let endpoint = '/api/2/users/search';
|
||||
const users = await getUsers.call(this);
|
||||
|
||||
if (jiraVersion === 'server') {
|
||||
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) };
|
||||
return { results: filterSortSearchListItems(users, filter) };
|
||||
},
|
||||
|
||||
// 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
|
||||
// select them easily
|
||||
async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const jiraVersion = this.getCurrentNodeParameter('jiraVersion') as string;
|
||||
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;
|
||||
});
|
||||
return getUsers.call(this);
|
||||
},
|
||||
|
||||
// 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(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
this.helpers.returnJsonArray({ success: true }), //endpoint returns no content
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue