🐛 Fix update:group in Bitwarden node (#1580)

*  Fix default args for update:group

*  Add external IDs to resource loader
This commit is contained in:
Iván Ovejero 2021-03-29 10:06:07 +02:00 committed by GitHub
parent 33c70153c8
commit 2ee5853bd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 15 deletions

View file

@ -303,7 +303,7 @@ export class Bitwarden implements INodeType {
// group: update
// ----------------------------------
const body = {} as IDataObject;
const groupId = this.getNodeParameter('groupId', i);
const updateFields = this.getNodeParameter('updateFields', i) as GroupUpdateFields;
@ -311,7 +311,25 @@ export class Bitwarden implements INodeType {
throw new Error(`Please enter at least one field to update for the ${resource}.`);
}
const { name, collections, externalId, accessAll } = updateFields;
// set defaults for `name` and `accessAll`, required by Bitwarden but optional in n8n
let { name, accessAll } = updateFields;
if (name === undefined) {
responseData = await bitwardenApiRequest.call(this, 'GET', `/public/groups/${groupId}`, {}, {}) as { name: string };
name = responseData.name;
}
if (accessAll === undefined) {
accessAll = false;
}
const body = {
name,
AccessAll: accessAll,
} as IDataObject;
const { collections, externalId } = updateFields;
if (collections) {
body.collections = collections.map((collectionId) => ({
@ -320,20 +338,11 @@ export class Bitwarden implements INodeType {
}));
}
if (name) {
body.name = name;
}
if (externalId) {
body.externalId = externalId;
}
if (accessAll !== undefined) {
body.AccessAll = accessAll;
}
const id = this.getNodeParameter('groupId', i);
const endpoint = `/public/groups/${id}`;
const endpoint = `/public/groups/${groupId}`;
responseData = await bitwardenApiRequest.call(this, 'PUT', endpoint, {}, body);
} else if (operation === 'updateMembers') {

View file

@ -157,9 +157,9 @@ export async function loadResource(
const { data } = await bitwardenApiRequest.call(this, 'GET', endpoint, {}, {}, token);
data.forEach(({ id, name }: { id: string, name: string }) => {
data.forEach(({ id, name, externalId }: { id: string, name: string, externalId?: string }) => {
returnData.push({
name: name || id,
name: externalId || name || id,
value: id,
});
});

View file

@ -203,12 +203,12 @@ export const groupFields = [
placeholder: 'Add Field',
default: {},
options: [
{
displayName: 'Access All',
name: 'accessAll',
type: 'boolean',
default: false,
description: 'Allow this group to access all collections within the organization, instead of only its associated collections.<br>If set to true, this option overrides any collection assignments.',
},
{
displayName: 'Collections',