Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions drive/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package drive

import (
"fmt"
"strings"
"google.golang.org/api/drive/v3"
"io"
"text/tabwriter"
Expand All @@ -15,18 +16,28 @@ type ShareArgs struct {
Email string
Domain string
Discoverable bool
DisableNotification bool
}

func (self *Drive) Share(args ShareArgs) error {
permission := &drive.Permission{
AllowFileDiscovery: args.Discoverable,
Role: args.Role,
Type: args.Type,
Type: strings.ToLower(args.Type),
EmailAddress: args.Email,
Domain: args.Domain,
}

_, err := self.service.Permissions.Create(args.FileId, permission).Do()
call := self.service.Permissions.Create(args.FileId, permission)

if permission.Type == "user" || permission.Type == "group" {
if args.DisableNotification {
call = call.SendNotificationEmail(false);
}
}

_, err := call.Do()

if err != nil {
return fmt.Errorf("Failed to share file: %s", err)
}
Expand Down
6 changes: 6 additions & 0 deletions gdrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,12 @@ func main() {
Description: "Delete all sharing permissions (owner roles will be skipped)",
OmitValue: true,
},
cli.BoolFlag{
Name: "disableNotification",
Patterns: []string{"--no-notification"},
Description: "Disable notification e-mail when sharing to user or group. Cannot be disabled for ownership transfer.",
OmitValue: true,
},
),
},
},
Expand Down
1 change: 1 addition & 0 deletions handlers_drive.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ func shareHandler(ctx cli.Context) {
Email: args.String("email"),
Domain: args.String("domain"),
Discoverable: args.Bool("discoverable"),
DisableNotification: args.Bool("disableNotification"),
})
checkErr(err)
}
Expand Down