From 6f2154aaf80d444f731f9fe1675b5fff1ab2990a Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Wed, 4 Dec 2019 15:57:56 -0500 Subject: [PATCH 1/2] :sparkles: extended Mattermost functionality --- .../nodes/Mattermost/Mattermost.node.ts | 161 +++++++++++++++++- 1 file changed, 156 insertions(+), 5 deletions(-) diff --git a/packages/nodes-base/nodes/Mattermost/Mattermost.node.ts b/packages/nodes-base/nodes/Mattermost/Mattermost.node.ts index 064c97c5f1..89bd1534ad 100644 --- a/packages/nodes-base/nodes/Mattermost/Mattermost.node.ts +++ b/packages/nodes-base/nodes/Mattermost/Mattermost.node.ts @@ -49,6 +49,14 @@ export class Mattermost implements INodeType { name: 'Message', value: 'message', }, + { + name: 'User', + value: 'user', + }, + { + name: 'Post', + value: 'post', + }, ], default: 'message', description: 'The resource to operate on.', @@ -81,11 +89,15 @@ export class Mattermost implements INodeType { value: 'create', description: 'Create a new channel', }, + { + name: 'Statistics', + value: 'statistics', + description: 'Get statistics for a channel.', + }, ], default: 'create', description: 'The operation to perform.', }, - { displayName: 'Operation', name: 'operation', @@ -253,8 +265,31 @@ export class Mattermost implements INodeType { }, description: 'The ID of the user to invite into channel.', }, - - + // ---------------------------------- + // channel:statistics + // ---------------------------------- + { + displayName: 'Channel ID', + name: 'channelId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getChannels', + }, + options: [], + default: '', + required: true, + displayOptions: { + show: { + operation: [ + 'statistics' + ], + resource: [ + 'channel', + ], + }, + }, + description: 'The ID of the channel to get the statistics from.', + }, // ---------------------------------- // message @@ -520,7 +555,96 @@ export class Mattermost implements INodeType { }, ], }, - + // ---------------------------------- + // user + // ---------------------------------- + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'user', + ], + }, + }, + options: [ + { + name: 'Desactive', + value: 'desactive', + description: 'Deactivates the user and revokes all its sessions by archiving its user object.', + }, + ], + default: '', + description: 'The operation to perform.', + }, + // ---------------------------------- + // user:desactivate + // ---------------------------------- + { + displayName: 'User ID', + name: 'userId', + type: 'string', + required: true, + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'desactive', + ], + }, + }, + default: '', + description: 'User GUID' + }, + // ---------------------------------- + // post + // ---------------------------------- + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'post', + ], + }, + }, + options: [ + { + name: 'Delete', + value: 'delete', + description: 'Soft deletes a post, by marking the post as deleted in the database. Soft deleted posts will not be returned in post queries.', + }, + ], + default: '', + description: 'The operation to perform.', + }, + // ---------------------------------- + // post:delete + // ---------------------------------- + { + displayName: 'Post ID', + name: 'postId', + type: 'string', + required: true, + displayOptions: { + show: { + resource: [ + 'post', + ], + operation: [ + 'delete', + ], + }, + }, + default: '', + description: 'ID of the post to delete', + }, ], }; @@ -663,6 +787,14 @@ export class Mattermost implements INodeType { endpoint = `channels/${channelId}/members`; + } else if (operation === 'statistics') { + // ---------------------------------- + // channel:statistics + // ---------------------------------- + + requestMethod = 'GET'; + const channelId = this.getNodeParameter('channelId', i) as string; + endpoint = `channels/${channelId}/stats`; } } else if (resource === 'message') { if (operation === 'post') { @@ -701,7 +833,26 @@ export class Mattermost implements INodeType { const otherOptions = this.getNodeParameter('otherOptions', i) as IDataObject; Object.assign(body, otherOptions); } - } else { + } else if (resource === 'user') { + if (operation === 'desactive') { + // ---------------------------------- + // user:desactive + // ---------------------------------- + const userId = this.getNodeParameter('userId', i) as string; + requestMethod = 'DELETE'; + endpoint = `users/${userId}`; + } + } else if (resource === 'post') { + if (operation === 'delete') { + // ---------------------------------- + // post:delete + // ---------------------------------- + const postId = this.getNodeParameter('postId', i) as string; + requestMethod = 'DELETE'; + endpoint = `posts/${postId}`; + } + } + else { throw new Error(`The resource "${resource}" is not known!`); } From 731aeca5c5806d3d199f49e5bf808f24efcb892d Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Fri, 6 Dec 2019 22:33:26 +0100 Subject: [PATCH 2/2] :zap: Move Delete Option from Post to Message --- .../nodes/Mattermost/Mattermost.node.ts | 96 +++++++------------ 1 file changed, 37 insertions(+), 59 deletions(-) diff --git a/packages/nodes-base/nodes/Mattermost/Mattermost.node.ts b/packages/nodes-base/nodes/Mattermost/Mattermost.node.ts index 89bd1534ad..1a8262d8d8 100644 --- a/packages/nodes-base/nodes/Mattermost/Mattermost.node.ts +++ b/packages/nodes-base/nodes/Mattermost/Mattermost.node.ts @@ -53,10 +53,6 @@ export class Mattermost implements INodeType { name: 'User', value: 'user', }, - { - name: 'Post', - value: 'post', - }, ], default: 'message', description: 'The resource to operate on.', @@ -110,6 +106,11 @@ export class Mattermost implements INodeType { }, }, options: [ + { + name: 'Delete', + value: 'delete', + description: 'Soft deletes a post, by marking the post as deleted in the database.', + }, { name: 'Post', value: 'post', @@ -295,6 +296,28 @@ export class Mattermost implements INodeType { // message // ---------------------------------- + // ---------------------------------- + // message:delete + // ---------------------------------- + { + displayName: 'Post ID', + name: 'postId', + type: 'string', + required: true, + displayOptions: { + show: { + resource: [ + 'message', + ], + operation: [ + 'delete', + ], + }, + }, + default: '', + description: 'ID of the post to delete', + }, + // ---------------------------------- // message:post // ---------------------------------- @@ -600,51 +623,7 @@ export class Mattermost implements INodeType { default: '', description: 'User GUID' }, - // ---------------------------------- - // post - // ---------------------------------- - { - displayName: 'Operation', - name: 'operation', - type: 'options', - displayOptions: { - show: { - resource: [ - 'post', - ], - }, - }, - options: [ - { - name: 'Delete', - value: 'delete', - description: 'Soft deletes a post, by marking the post as deleted in the database. Soft deleted posts will not be returned in post queries.', - }, - ], - default: '', - description: 'The operation to perform.', - }, - // ---------------------------------- - // post:delete - // ---------------------------------- - { - displayName: 'Post ID', - name: 'postId', - type: 'string', - required: true, - displayOptions: { - show: { - resource: [ - 'post', - ], - operation: [ - 'delete', - ], - }, - }, - default: '', - description: 'ID of the post to delete', - }, + ], }; @@ -797,7 +776,15 @@ export class Mattermost implements INodeType { endpoint = `channels/${channelId}/stats`; } } else if (resource === 'message') { - if (operation === 'post') { + if (operation === 'delete') { + // ---------------------------------- + // message:delete + // ---------------------------------- + + const postId = this.getNodeParameter('postId', i) as string; + requestMethod = 'DELETE'; + endpoint = `posts/${postId}`; + } else if (operation === 'post') { // ---------------------------------- // message:post // ---------------------------------- @@ -842,15 +829,6 @@ export class Mattermost implements INodeType { requestMethod = 'DELETE'; endpoint = `users/${userId}`; } - } else if (resource === 'post') { - if (operation === 'delete') { - // ---------------------------------- - // post:delete - // ---------------------------------- - const postId = this.getNodeParameter('postId', i) as string; - requestMethod = 'DELETE'; - endpoint = `posts/${postId}`; - } } else { throw new Error(`The resource "${resource}" is not known!`);