feature/outlook shared mailbox (#1323)

*  Add shared mailbox support

* 🐛 Add filter field to folderMessage:getAll

*  Small changes to descriptions (#1322)

Co-authored-by: Mika Luhta <12100880+mluhta@users.noreply.github.com>
This commit is contained in:
Ricardo Espinoza 2021-01-10 18:09:58 -05:00 committed by GitHub
parent 76cee5577b
commit d78aaa2d64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 4 deletions

View file

@ -16,7 +16,27 @@ export class MicrosoftOutlookOAuth2Api implements ICredentialType {
displayName: 'Scope',
name: 'scope',
type: 'hidden' as NodePropertyTypes,
default: 'openid offline_access Mail.ReadWrite Mail.Send MailboxSettings.Read',
default: 'openid offline_access Mail.ReadWrite Mail.ReadWrite.Shared Mail.Send Mail.Send.Shared MailboxSettings.Read',
},
{
displayName: 'Use Shared Mailbox',
name: 'useShared',
type: 'boolean' as NodePropertyTypes,
default: false,
},
{
displayName: 'User Principal Name',
name: 'userPrincipalName',
description: 'Target user\'s UPN or ID',
type: 'string' as NodePropertyTypes,
default: '',
displayOptions: {
show: {
useShared: [
true,
],
},
},
},
];
}

View file

@ -251,7 +251,7 @@ export const folderFields = [
name: 'filter',
type: 'string',
default: '',
description: 'Microsoft Graph API OData $filter query.',
description: 'Microsoft Graph API OData $filter query. Information about the syntax can be found <a href="https://docs.microsoft.com/en-us/graph/query-parameters#filter-parameter" target="_blank">here</a>.',
},
],
},

View file

@ -115,7 +115,7 @@ export const folderMessageFields = [
name: 'filter',
type: 'string',
default: '',
description: 'Microsoft Graph API OData $filter query.',
description: 'Microsoft Graph API OData $filter query. Information about the syntax can be found <a href="https://docs.microsoft.com/en-us/graph/query-parameters#filter-parameter" target="_blank">here</a>.',
},
],
},

View file

@ -14,6 +14,14 @@ import {
} from 'n8n-workflow';
export async function microsoftApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}, option: IDataObject = { json: true }): Promise<any> { // tslint:disable-line:no-any
const credentials = this.getCredentials('microsoftOutlookOAuth2Api');
let apiUrl = `https://graph.microsoft.com/v1.0/me${resource}`;
// If accessing shared mailbox
if (credentials!.useShared && credentials!.userPrincipalName) {
apiUrl = `https://graph.microsoft.com/v1.0/users/${credentials!.userPrincipalName}${resource}`;
}
const options: OptionsWithUri = {
headers: {
'Content-Type': 'application/json',
@ -21,7 +29,7 @@ export async function microsoftApiRequest(this: IExecuteFunctions | IExecuteSing
method,
body,
qs,
uri: uri || `https://graph.microsoft.com/v1.0/me${resource}`,
uri: uri || apiUrl,
};
try {
Object.assign(options, option);

View file

@ -926,6 +926,10 @@ export class MicrosoftOutlook implements INodeType {
qs['$select'] = additionalFields.fields;
}
if (additionalFields.filter) {
qs['$filter'] = additionalFields.filter;
}
const endpoint = `/mailFolders/${folderId}/messages`;
if (returnAll) {
responseData = await microsoftApiRequestAllItems.call(