Skip to content

Commit b8538ef

Browse files
committed
new components
1 parent 03e4f0f commit b8538ef

File tree

6 files changed

+274
-2
lines changed

6 files changed

+274
-2
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import googleDrive from "../../google_drive.app.mjs";
2+
3+
export default {
4+
key: "google_drive-list-access-proposals",
5+
name: "List Access Proposals",
6+
description: "List access proposals for a file or folder. [See the documentation](https://developers.google.com/workspace/drive/api/reference/rest/v3/accessproposals/list)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
googleDrive,
11+
drive: {
12+
propDefinition: [
13+
googleDrive,
14+
"watchedDrive",
15+
],
16+
},
17+
fileOrFolderId: {
18+
propDefinition: [
19+
googleDrive,
20+
"fileOrFolderId",
21+
(c) => ({
22+
drive: c.drive,
23+
}),
24+
],
25+
},
26+
maxResults: {
27+
type: "integer",
28+
label: "Max Results",
29+
description: "The maximum number of results to return",
30+
default: 100,
31+
optional: true,
32+
},
33+
},
34+
async run({ $ }) {
35+
const results = [];
36+
let pageToken;
37+
38+
do {
39+
const {
40+
accessProposals, nextPageToken,
41+
} = await this.googleDrive.listAccessProposals({
42+
fileId: this.fileOrFolderId,
43+
pageToken,
44+
});
45+
if (!accessProposals) {
46+
break;
47+
}
48+
results.push(...accessProposals);
49+
if (this.maxResults && results.length >= this.maxResults) {
50+
results.length = this.maxResults;
51+
break;
52+
}
53+
pageToken = nextPageToken;
54+
} while (pageToken);
55+
56+
$.export("$summary", `Successfully retrieved ${results.length} access proposal${results.length === 1
57+
? ""
58+
: "s"}.`);
59+
return results;
60+
},
61+
};
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import googleDrive from "../../google_drive.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
4+
export default {
5+
key: "google_drive-resolve-access-proposal",
6+
name: "Resolve Access Proposals",
7+
description: "Accept or deny a request for access to a file or folder in Google Drive. [See the documentation](https://developers.google.com/workspace/drive/api/reference/rest/v3/accessproposals/resolve)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
googleDrive,
12+
drive: {
13+
propDefinition: [
14+
googleDrive,
15+
"watchedDrive",
16+
],
17+
},
18+
fileOrFolderId: {
19+
propDefinition: [
20+
googleDrive,
21+
"fileOrFolderId",
22+
(c) => ({
23+
drive: c.drive,
24+
}),
25+
],
26+
},
27+
accessProposalId: {
28+
propDefinition: [
29+
googleDrive,
30+
"accessProposalId",
31+
(c) => ({
32+
fileId: c.fileOrFolderId,
33+
}),
34+
],
35+
},
36+
action: {
37+
type: "string",
38+
label: "Action",
39+
description: "The action to take on the AccessProposal",
40+
options: [
41+
"ACCEPT",
42+
"DENY",
43+
],
44+
},
45+
roles: {
46+
type: "string[]",
47+
label: "Roles",
48+
description: "The roles to allow. Note: This field is required for the `ACCEPT` action.",
49+
options: [
50+
"writer",
51+
"commenter",
52+
"reader",
53+
],
54+
optional: true,
55+
},
56+
sendNotification: {
57+
type: "boolean",
58+
label: "Send Notification",
59+
description: "Whether to send an email to the requester when the AccessProposal is denied or accepted",
60+
optional: true,
61+
},
62+
},
63+
async run({ $ }) {
64+
if (this.action === "ACCEPT" && !this.roles?.length) {
65+
throw new ConfigurationError("A Role is required for the `ACCEPT` action");
66+
}
67+
68+
const response = await this.googleDrive.resolveAccessProposal({
69+
fileId: this.fileOrFolderId,
70+
proposalId: this.accessProposalId,
71+
action: this.action,
72+
role: this.roles,
73+
sendNotification: this.sendNotification,
74+
});
75+
76+
$.export("$summary", `Successfully resolved proposal with ID: ${this.accessProposalId}`);
77+
return response;
78+
},
79+
};

components/google_drive/google_drive.app.mjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,36 @@ export default {
255255
`),
256256
optional: true,
257257
},
258+
accessProposalId: {
259+
type: "string",
260+
label: "Access Proposal ID",
261+
description: "The identifier of an access proposal (when a user requests access to a file/folder)",
262+
async options({
263+
fileId, prevContext,
264+
}) {
265+
if (!fileId) {
266+
return [];
267+
}
268+
const { pageToken } = prevContext;
269+
const {
270+
accessProposals, nextPageToken,
271+
} = await this.listAccessProposals({
272+
fileId,
273+
pageToken,
274+
});
275+
return {
276+
options: accessProposals?.map(({
277+
proposalId: value, requesterEmailAddress: label,
278+
}) => ({
279+
label,
280+
value,
281+
})) || [],
282+
context: {
283+
pageToken: nextPageToken,
284+
},
285+
};
286+
},
287+
},
258288
},
259289
methods: {
260290
// Static methods
@@ -1437,5 +1467,13 @@ export default {
14371467
async getExportFormats() {
14381468
return (await this.getAbout("exportFormats")).exportFormats;
14391469
},
1470+
async listAccessProposals(opts = {}) {
1471+
const drive = this.drive();
1472+
return (await drive.accessproposals.list(opts)).data;
1473+
},
1474+
async resolveAccessProposal(opts = {}) {
1475+
const drive = this.drive();
1476+
return (await drive.accessproposals.resolve(opts)).data;
1477+
},
14401478
},
14411479
};

components/google_drive/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/google_drive",
3-
"version": "0.8.11",
3+
"version": "0.9.0",
44
"description": "Pipedream Google_drive Components",
55
"main": "google_drive.app.mjs",
66
"keywords": [
@@ -11,7 +11,7 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"dependencies": {
1313
"@googleapis/drive": "^2.3.0",
14-
"@pipedream/platform": "^1.4.0",
14+
"@pipedream/platform": "^3.0.3",
1515
"cron-parser": "^4.9.0",
1616
"google-docs-mustaches": "^1.2.2",
1717
"got": "13.0.0",
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import googleDrive from "../../google_drive.app.mjs";
2+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3+
import sampleEmit from "./test-event.mjs";
4+
5+
export default {
6+
key: "google_drive-new-access-proposal",
7+
name: "New Access Proposal",
8+
description: "Emit new event when a new access proposal is requested in Google Drive",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
props: {
13+
googleDrive,
14+
db: "$.service.db",
15+
timer: {
16+
type: "$.interface.timer",
17+
default: {
18+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
19+
},
20+
},
21+
drive: {
22+
propDefinition: [
23+
googleDrive,
24+
"watchedDrive",
25+
],
26+
},
27+
fileOrFolderId: {
28+
propDefinition: [
29+
googleDrive,
30+
"fileOrFolderId",
31+
(c) => ({
32+
drive: c.drive,
33+
}),
34+
],
35+
},
36+
},
37+
methods: {
38+
_getLastTs() {
39+
return this.db.get("lastTs") || 0;
40+
},
41+
_setLastTs(lastTs) {
42+
this.db.set("lastTs", lastTs);
43+
},
44+
generateMeta(item) {
45+
return {
46+
id: item.proposalId,
47+
summary: `New Request From: ${item.requesterEmailAddress}`,
48+
ts: Date.parse(item.createTime),
49+
};
50+
},
51+
},
52+
async run() {
53+
const lastTs = this._getLastTs();
54+
let maxTs = lastTs;
55+
let pageToken;
56+
57+
do {
58+
const {
59+
accessProposals, nextPageToken,
60+
} = await this.googleDrive.listAccessProposals({
61+
fileId: this.fileOrFolderId,
62+
pageToken,
63+
});
64+
if (!accessProposals) {
65+
break;
66+
}
67+
for (const proposal of accessProposals) {
68+
const ts = Date.parse(proposal.createTime);
69+
if (ts > lastTs) {
70+
const meta = this.generateMeta(proposal);
71+
this.$emit(proposal, meta);
72+
maxTs = Math.max(ts, maxTs);
73+
}
74+
}
75+
pageToken = nextPageToken;
76+
} while (pageToken);
77+
78+
this._setLastTs(maxTs);
79+
},
80+
sampleEmit,
81+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export default {
2+
"fileId": "",
3+
"proposalId": "",
4+
"requesterEmailAddress": "",
5+
"recipientEmailAddress": "",
6+
"rolesAndViews": [
7+
{
8+
"role": "writer"
9+
}
10+
],
11+
"requestMessage": "",
12+
"createTime": "2025-04-11T18:36:28.979859Z"
13+
}

0 commit comments

Comments
 (0)