Sharing: list, get, create, update and delete permissions on files, folders and shared drives (file-id may be a shared drive id).

A permission has a type (user, group, domain, anyone) and a role (owner, organizer, fileOrganizer, writer, commenter, reader). Drive emails users and groups when they are granted access unless you pass {sendNotificationEmail: false}; emailMessage adds a note. Ownership transfer needs {transferOwnership: true} and role: "owner".

Scopes. drive (or drive.file for files the app created). Listing works with drive.readonly / drive.metadata.readonly.

Values

LIST_FIELDS

LIST_FIELDS: Str "nextPageToken,permissions(id,type,role,emailAddress,domain,displayName,expirationTime,deleted,pendingOwner,allowFileDiscovery,permissionDetails)"

PERMISSION_FIELDS

PERMISSION_FIELDS: Str "id,type,role,emailAddress,domain,displayName,expirationTime,deleted,pendingOwner,allowFileDiscovery,permissionDetails"

ROLES

ROLES: Vec [
  "owner",
  "organizer",
  "fileOrganizer",
  "writer",
  "commenter",
  "reader"
]

TYPES

TYPES: Vec [
  "user",
  "group",
  "domain",
  "anyone"
]

Functions

build-permission

fn (grantee: Str, role: Str, target: Str?): Map
fn (grantee: Str, role: Str, target: Str?, extra: Map): Map

Build a permission body (pure), validating the grantee type and role. target is the email for user/group, the domain for domain, and ignored for anyone. extra adds fields such as expirationTime or allowFileDiscovery.

::google::drive::permissions/build-permission("user", "writer", "ada@example.com")
// {type: "user", role: "writer", emailAddress: "ada@example.com"}

create-permission

fn (file-id: Str, permission: Map): Map
fn (file-id: Str, permission: Map, opts: Map): Map

POST /files/{id}/permissions - grant access. permission is a body (see build-permission). Options: sendNotificationEmail, emailMessage, transferOwnership, moveToNewOwnersRoot, useDomainAdminAccess, fields, credentials.

delete-permission

fn (file-id: Str, permission-id: Str): Bool
fn (file-id: Str, permission-id: Str, opts: Map): Bool

DELETE /files/{id}/permissions/{permissionId} - revoke access. Returns true. Inherited shared-drive permissions must be removed where they are set.

get-permission

fn (file-id: Str, permission-id: Str): Map
fn (file-id: Str, permission-id: Str, opts: Map): Map

GET /files/{id}/permissions/{permissionId}.

list-all-permissions

fn (file-id: Str): Vec
fn (file-id: Str, opts: Map): Vec

Every permission on a file (follows nextPageToken).

list-permissions

fn (file-id: Str): Map
fn (file-id: Str, opts: Map): Map

GET /files/{id}/permissions - one page ({permissions, nextPageToken?}). Options: pageSize (max 100), pageToken, fields, useDomainAdminAccess, credentials.

share

fn (file-id: Str, grantee: Str, role: Str, target: Str?, opts: Map): Map

share-with-anyone

fn (file-id: Str, role: Str): Map
fn (file-id: Str, role: Str, opts: Map): Map

Make a file available to anyone with the link (role usually "reader"). For a publicly searchable file, use create-permission(id, build-permission("anyone", "reader", null, {allowFileDiscovery: true})).

share-with-domain

fn (file-id: Str, domain: Str, role: Str): Map
fn (file-id: Str, domain: Str, role: Str, opts: Map): Map

Share with everyone in a Workspace domain (no notification email is sent for domain grants).

share-with-group

fn (file-id: Str, email: Str, role: Str): Map
fn (file-id: Str, email: Str, role: Str, opts: Map): Map

Share with a Google Group by email.

share-with-user

fn (file-id: Str, email: Str): Map
fn (file-id: Str, email: Str, role: Str): Map
fn (file-id: Str, email: Str, role: Str, opts: Map): Map

Share with one user by email. role defaults to "reader" in the 2-arity form.

::google::drive::permissions/share-with-user(file-id, "ada@example.com", "writer", {sendNotificationEmail: false})

update-permission

fn (file-id: Str, permission-id: Str, changes: Map): Map
fn (file-id: Str, permission-id: Str, changes: Map, opts: Map): Map

PATCH /files/{id}/permissions/{permissionId} - change role or expirationTime. Options: transferOwnership, removeExpiration, useDomainAdminAccess, credentials.