From 6e62183b1ea60eaa1fb9051a5cdcdaa5dd88416b Mon Sep 17 00:00:00 2001 From: Dusan Stloukal Date: Mon, 14 Aug 2017 00:27:20 +0200 Subject: Possibility to disable notification when sharing to user or group Added the parameter --no-notification to the action "share" to not send notification e-mails to users or groups. Not allowed for other requests. It must not be disabled for ownership transfers. --- drive/share.go | 15 +++++++++++++-- gdrive.go | 6 ++++++ handlers_drive.go | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drive/share.go b/drive/share.go index e942c17..36ffb47 100644 --- a/drive/share.go +++ b/drive/share.go @@ -2,6 +2,7 @@ package drive import ( "fmt" + "strings" "google.golang.org/api/drive/v3" "io" "text/tabwriter" @@ -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) } diff --git a/gdrive.go b/gdrive.go index c1a817e..87d207a 100644 --- a/gdrive.go +++ b/gdrive.go @@ -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, + }, ), }, }, diff --git a/handlers_drive.go b/handlers_drive.go index 7bda872..fbf5a2f 100644 --- a/handlers_drive.go +++ b/handlers_drive.go @@ -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) } -- cgit v1.2.3