mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
⚡ Add GSuite group resource (#1048)
This commit is contained in:
@@ -21,6 +21,11 @@ import {
|
||||
userOperations,
|
||||
} from './UserDescription';
|
||||
|
||||
import {
|
||||
groupFields,
|
||||
groupOperations,
|
||||
} from './GroupDescripion';
|
||||
|
||||
export class GSuiteAdmin implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'G Suite Admin',
|
||||
@@ -48,6 +53,10 @@ export class GSuiteAdmin implements INodeType {
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Group',
|
||||
value: 'group',
|
||||
},
|
||||
{
|
||||
name: 'User',
|
||||
value: 'user',
|
||||
@@ -56,6 +65,8 @@ export class GSuiteAdmin implements INodeType {
|
||||
default: 'user',
|
||||
description: 'The resource to operate on.',
|
||||
},
|
||||
...groupOperations,
|
||||
...groupFields,
|
||||
...userOperations,
|
||||
...userFields,
|
||||
],
|
||||
@@ -119,12 +130,112 @@ export class GSuiteAdmin implements INodeType {
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (resource === 'group') {
|
||||
//https://developers.google.com/admin-sdk/directory/v1/reference/groups/insert
|
||||
if (operation === 'create') {
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
||||
const body: IDataObject = {
|
||||
email,
|
||||
};
|
||||
|
||||
Object.assign(body, additionalFields);
|
||||
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/directory/v1/groups`,
|
||||
body,
|
||||
);
|
||||
}
|
||||
|
||||
//https://developers.google.com/admin-sdk/directory/v1/reference/groups/delete
|
||||
if (operation === 'delete') {
|
||||
const groupId = this.getNodeParameter('groupId', i) as string;
|
||||
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/directory/v1/groups/${groupId}`,
|
||||
{}
|
||||
);
|
||||
|
||||
responseData = { success: true };
|
||||
}
|
||||
|
||||
//https://developers.google.com/admin-sdk/directory/v1/reference/groups/get
|
||||
if (operation === 'get') {
|
||||
const groupId = this.getNodeParameter('groupId', i) as string;
|
||||
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/directory/v1/groups/${groupId}`,
|
||||
{},
|
||||
);
|
||||
}
|
||||
|
||||
//https://developers.google.com/admin-sdk/directory/v1/reference/groups/list
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
|
||||
Object.assign(qs, options);
|
||||
|
||||
if (qs.customer === undefined) {
|
||||
qs.customer = 'my_customer';
|
||||
}
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await googleApiRequestAllItems.call(
|
||||
this,
|
||||
'groups',
|
||||
'GET',
|
||||
`/directory/v1/groups`,
|
||||
{},
|
||||
qs
|
||||
);
|
||||
|
||||
} else {
|
||||
qs.maxResults = this.getNodeParameter('limit', i) as number;
|
||||
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/directory/v1/groups`,
|
||||
{},
|
||||
qs
|
||||
);
|
||||
|
||||
responseData = responseData.groups;
|
||||
}
|
||||
}
|
||||
|
||||
//https://developers.google.com/admin-sdk/directory/v1/reference/groups/update
|
||||
if (operation === 'update') {
|
||||
const groupId = this.getNodeParameter('groupId', i) as string;
|
||||
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
|
||||
const body: IDataObject = {};
|
||||
|
||||
Object.assign(body, updateFields);
|
||||
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'PUT',
|
||||
`/directory/v1/groups/${groupId}`,
|
||||
body,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (resource === 'user') {
|
||||
|
||||
//https://developers.google.com/admin-sdk/directory/v1/reference/users/insert
|
||||
if (operation === 'create') {
|
||||
|
||||
const domain = this.getNodeParameter('domain', i) as string;
|
||||
|
||||
const firstName = this.getNodeParameter('firstName', i) as string;
|
||||
@@ -151,7 +262,6 @@ export class GSuiteAdmin implements INodeType {
|
||||
Object.assign(body, additionalFields);
|
||||
|
||||
if (additionalFields.phoneUi) {
|
||||
|
||||
const phones = (additionalFields.phoneUi as IDataObject).phoneValues as IDataObject[];
|
||||
|
||||
body.phones = phones;
|
||||
@@ -160,7 +270,6 @@ export class GSuiteAdmin implements INodeType {
|
||||
}
|
||||
|
||||
if (additionalFields.emailUi) {
|
||||
|
||||
const emails = (additionalFields.emailUi as IDataObject).emailValues as IDataObject[];
|
||||
|
||||
body.emails = emails;
|
||||
@@ -177,7 +286,6 @@ export class GSuiteAdmin implements INodeType {
|
||||
);
|
||||
|
||||
if (makeAdmin) {
|
||||
|
||||
await googleApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
@@ -191,7 +299,6 @@ export class GSuiteAdmin implements INodeType {
|
||||
|
||||
//https://developers.google.com/admin-sdk/directory/v1/reference/users/delete
|
||||
if (operation === 'delete') {
|
||||
|
||||
const userId = this.getNodeParameter('userId', i) as string;
|
||||
|
||||
responseData = await googleApiRequest.call(
|
||||
@@ -206,7 +313,6 @@ export class GSuiteAdmin implements INodeType {
|
||||
|
||||
//https://developers.google.com/admin-sdk/directory/v1/reference/users/get
|
||||
if (operation === 'get') {
|
||||
|
||||
const userId = this.getNodeParameter('userId', i) as string;
|
||||
|
||||
const projection = this.getNodeParameter('projection', i) as string;
|
||||
@@ -236,7 +342,6 @@ export class GSuiteAdmin implements INodeType {
|
||||
|
||||
//https://developers.google.com/admin-sdk/directory/v1/reference/users/list
|
||||
if (operation === 'getAll') {
|
||||
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
|
||||
const projection = this.getNodeParameter('projection', i) as string;
|
||||
@@ -260,7 +365,6 @@ export class GSuiteAdmin implements INodeType {
|
||||
}
|
||||
|
||||
if (returnAll) {
|
||||
|
||||
responseData = await googleApiRequestAllItems.call(
|
||||
this,
|
||||
'users',
|
||||
@@ -271,7 +375,6 @@ export class GSuiteAdmin implements INodeType {
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
qs.maxResults = this.getNodeParameter('limit', i) as number;
|
||||
|
||||
responseData = await googleApiRequest.call(
|
||||
@@ -288,7 +391,6 @@ export class GSuiteAdmin implements INodeType {
|
||||
|
||||
//https://developers.google.com/admin-sdk/directory/v1/reference/users/update
|
||||
if (operation === 'update') {
|
||||
|
||||
const userId = this.getNodeParameter('userId', i) as string;
|
||||
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
@@ -315,7 +417,6 @@ export class GSuiteAdmin implements INodeType {
|
||||
}
|
||||
|
||||
if (updateFields.phoneUi) {
|
||||
|
||||
const phones = (updateFields.phoneUi as IDataObject).phoneValues as IDataObject[];
|
||||
|
||||
body.phones = phones;
|
||||
@@ -325,7 +426,6 @@ export class GSuiteAdmin implements INodeType {
|
||||
}
|
||||
|
||||
if (updateFields.emailUi) {
|
||||
|
||||
const emails = (updateFields.emailUi as IDataObject).emailValues as IDataObject[];
|
||||
|
||||
body.emails = emails;
|
||||
@@ -349,11 +449,9 @@ export class GSuiteAdmin implements INodeType {
|
||||
}
|
||||
|
||||
if (Array.isArray(responseData)) {
|
||||
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
|
||||
} else if (responseData !== undefined) {
|
||||
|
||||
returnData.push(responseData as IDataObject);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user