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.
Example
perm ::google::drive::permissions/build-permission("user", "commenter", "ada@example.com")
::google::drive::permissions/create-permission("1AbCfile", perm, {emailMessage: "Please review."})
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.
Example
::google::drive::permissions/delete-permission("1AbCfile", "1234567890")
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}.
Example
perm ::google::drive::permissions/get-permission("1AbCfile", "1234567890")
perm.role
list-all-permissions
fn (file-id: Str): Vec
fn (file-id: Str, opts: Map): Vec
Every permission on a file (follows nextPageToken).
Example
perms ::google::drive::permissions/list-all-permissions("1AbCfile")
map(perms, %.emailAddress)
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.
Example
page ::google::drive::permissions/list-permissions("1AbCfile", {pageSize: 50})
map(page.permissions, %.role)
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})).
Example
::google::drive::permissions/share-with-anyone("1AbCfile", "reader")
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).
Example
::google::drive::permissions/share-with-domain("1AbCfile", "example.com", "reader")
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.
Example
::google::drive::permissions/share-with-group("1AbCfile", "eng@example.com", "reader", {sendNotificationEmail: false})
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("1AbCfile", "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.
Example
::google::drive::permissions/update-permission("1AbCfile", "1234567890", {role: "reader"})