Skip to content

Commit

Permalink
Update share.go
Browse files Browse the repository at this point in the history
add sharing
  • Loading branch information
FrostF0X authored May 19, 2023
1 parent ab27085 commit df166fd
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions drive/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,27 @@ type ShareArgs struct {
Discoverable bool
}

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

_, err := self.service.Permissions.Create(args.FileId, permission).Do()
if err != nil {
return fmt.Errorf("Failed to share file: %s", err)
}

fmt.Fprintf(args.Out, "Granted %s permission to %s\n", args.Role, args.Type)
return nil
}
func (self *Drive) Share(args ShareArgs) error {
permission := &drive.Permission{
AllowFileDiscovery: args.Discoverable,
Role: args.Role,
Type: args.Type,
EmailAddress: args.Email,
}

call := self.service.Permissions.Create(args.FileId, permission)
if permission.Role == "owner" {
call.TransferOwnership(true)
}

_, err := call.Do()
if err != nil {
return fmt.Errorf("Failed to share file: %s", err)
}

fmt.Fprintf(args.Out, "Granted %s permission to %s\n", args.Role, args.Type)
return nil
}

type RevokePermissionArgs struct {
Out io.Writer
Expand Down

0 comments on commit df166fd

Please sign in to comment.