Fix some issues with Zulip

This commit is contained in:
Jan Oberhauser 2020-05-23 00:59:40 +02:00
parent 5e4fde6c6a
commit b445eafccd
7 changed files with 506 additions and 495 deletions

View file

@ -62,4 +62,3 @@ export function validateJSON(json: string | undefined): any { // tslint:disable-
}
return result;
}

View file

@ -33,11 +33,11 @@ export const streamOperations = [
value: 'getSubscribed',
description: 'Get subscribed streams.',
},
{
name: 'Update',
value: 'update',
description: 'Update a stream.',
},
// {
// name: 'Update',
// value: 'update',
// description: 'Update a stream.',
// },
],
default: 'create',
description: 'The operation to perform.',
@ -86,9 +86,56 @@ export const streamFields = [
],
},
},
description: `JSON format parameters for stream creation.`,
},
{
displayName: 'Subscriptions',
name: 'subscriptions',
type: 'fixedCollection',
default: {},
displayOptions: {
show: {
resource: [
'stream',
],
operation: [
'create',
],
jsonParameters: [
false,
],
},
},
required: true,
description: 'A list of dictionaries containing the the key name and value specifying the name of the stream to subscribe. If the stream does not exist a new stream is created.',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Subscription Properties',
name: 'properties',
values: [
{
displayName: 'Name',
name: 'name',
type: 'string',
required: true,
default: '',
description: 'Name of Subscription.',
},
{
displayName: 'Description',
name: 'description',
type: 'string',
required: true,
default: '',
description: 'Description of Subscription.',
}
],
},
],
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
@ -141,6 +188,7 @@ export const streamFields = [
displayName: 'Principals',
name: 'principals',
type: 'fixedCollection',
default: {},
description: 'A list of email addresses of the users that will be subscribed/unsubscribed to the streams specified in the subscriptions argument. If not provided, then the requesting user/bot is subscribed.',
typeOptions: {
multipleValues: true,
@ -162,40 +210,6 @@ export const streamFields = [
},
],
},
{
displayName: 'Subscriptions',
name: 'subscriptions',
type: 'fixedCollection',
required: true,
description: '"A list of dictionaries containing the the key name and value specifying the name of the stream to subscribe. If the stream does not exist a new stream is created.',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Subscription Properties',
name: 'properties',
values: [
{
displayName: 'Name',
name: 'name',
type: 'string',
required: true,
default: '',
description: 'Name of Subscription.',
},
{
displayName: 'Description',
name: 'description',
type: 'string',
required: true,
default: '',
description: 'Description of Subscription.',
}
],
},
],
},
{
displayName: 'Stream Post Policy',
name: 'streamPostPolicy',
@ -222,6 +236,7 @@ export const streamFields = [
}
]
},
/* -------------------------------------------------------------------------- */
/* stream:get all */
/* -------------------------------------------------------------------------- */
@ -279,6 +294,7 @@ export const streamFields = [
},
]
},
/* -------------------------------------------------------------------------- */
/* stream:get subscribed */
/* -------------------------------------------------------------------------- */
@ -308,6 +324,7 @@ export const streamFields = [
}
]
},
/* -------------------------------------------------------------------------- */
/* stream:update */
/* -------------------------------------------------------------------------- */

View file

@ -33,11 +33,11 @@ export const userOperations = [
value: 'getAll',
description: 'Get all users.',
},
{
name: 'Update',
value: 'update',
description: 'Update a user.',
},
// {
// name: 'Update',
// value: 'update',
// description: 'Update a user.',
// },
],
default: 'create',
description: 'The operation to perform.',
@ -120,6 +120,7 @@ export const userFields = [
default: '',
description: 'The short name of the new user. Not user-visible.',
},
/* -------------------------------------------------------------------------- */
/* user:get / getAll */
/* -------------------------------------------------------------------------- */
@ -174,6 +175,7 @@ export const userFields = [
},
]
},
/* -------------------------------------------------------------------------- */
/* user:update */
/* -------------------------------------------------------------------------- */
@ -237,6 +239,7 @@ export const userFields = [
displayName: 'Profile Data',
name: 'profileData',
type: 'fixedCollection',
default: {},
description: 'A dictionary containing the to be updated custom profile field data for the user.',
typeOptions: {
multipleValues: true,
@ -267,6 +270,7 @@ export const userFields = [
},
]
},
/* -------------------------------------------------------------------------- */
/* user:deactivate */
/* -------------------------------------------------------------------------- */

View file

@ -247,6 +247,7 @@ export class Zulip implements INodeType {
}
responseData = await zulipApiRequest.call(this, 'GET', `/streams`, body);
responseData = responseData.streams;
}
if (operation === 'getSubscribed') {
@ -257,10 +258,10 @@ export class Zulip implements INodeType {
}
responseData = await zulipApiRequest.call(this, 'GET', `/users/me/subscriptions`, body);
responseData = responseData.subscriptions;
}
if (operation === 'create') {
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
if (jsonParameters) {
@ -278,13 +279,11 @@ export class Zulip implements INodeType {
}
} else {
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (additionalFields.subscriptions) {
//@ts-ignore
body.subscriptions = JSON.stringify(additionalFields.subscriptions.properties);
}
const subscriptions = this.getNodeParameter('subscriptions', i) as IDataObject;
body.subscriptions = JSON.stringify(subscriptions.properties);
if (additionalFields.inviteOnly) {
body.invite_only = additionalFields.inviteOnly as boolean;
}
@ -396,6 +395,7 @@ export class Zulip implements INodeType {
}
responseData = await zulipApiRequest.call(this, 'GET', `/users`, body);
responseData = responseData.members;
}
if (operation === 'create') {
@ -434,19 +434,10 @@ export class Zulip implements INodeType {
responseData = await zulipApiRequest.call(this, 'DELETE', `/users/${userId}`, body);
}
}
// Specific checks because API returns multiple objects within 1 object with each key name
if (responseData.members) {
returnData.push.apply(returnData, responseData.members as IDataObject[]);
}
if (responseData.streams) {
returnData.push.apply(returnData, responseData.streams as IDataObject[]);
}
if (responseData.subscriptions) {
returnData.push.apply(returnData, responseData.subscriptions as IDataObject[]);
}
else {
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else {
returnData.push(responseData as IDataObject);
}
}