Skip to content

Commit

Permalink
unshare: use by default accountType User
Browse files Browse the repository at this point in the history
Fixes #747.

By default use accountType User, as is done with share,
so that users can easily do things like
```shell
$ drive unshare -emails somebody@gmail.com -id some_id
```
instead of getting back a cryptic error
```shell
no matches found!
```

and the common assumptions will work without them
having to know the entire setup of share and unshare.
I too found this confusing and had to step back a little
to figure out that previously the accountTypes were
never set hence the loop that runs through each file
never runs.

This change also ensures that if errors were encountered entirely
errors, without any successful shares/unshares, we won't give back
the previously cryptic and not useful error of
```shell
no matches found!
```
  • Loading branch information
odeke-em committed Oct 16, 2016
1 parent dcc59f1 commit 88d72e5
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ func (c *Commands) playShareChanges(change *shareChange) (err error) {
withLink: change.withLink,
}

if err := fn(&perm); err != nil {
err = reComposeError(err, fmt.Sprintf("%s err %s: %v\n", fnName, file.Name, err))
if ferr := fn(&perm); ferr != nil {
err = reComposeError(err, fmt.Sprintf("%s err %s: %v\n", fnName, file.Name, ferr))
} else {
successes += 1
if c.opts.Verbose {
Expand All @@ -323,11 +323,15 @@ func (c *Commands) playShareChanges(change *shareChange) (err error) {
}
}

if err != nil {
return err
}

if successes < 1 {
return noMatchesFoundErr(fmt.Errorf("no matches found!"))
}

return err
return nil
}

func (c *Commands) share(revoke, byId bool) (err error) {
Expand All @@ -337,15 +341,18 @@ func (c *Commands) share(revoke, byId bool) (err error) {
var emailMessage string

roles := []Role{}
accountTypes := []AccountType{}

// By default, if they don't specify any
// account types to invoke, let's assume User.
// See Issue https://github.com/odeke-em/drive/issues/747.
accountTypes := []AccountType{User}

if revoke {
// In case of unsharing, when a user doesn't specify the
// roles, the addressee should be removed from all roles
roles = append(roles, Reader, Writer, Commenter)
} else {
roles = append(roles, Reader)
accountTypes = append(accountTypes, User)
}

meta := *c.opts.Meta
Expand Down

0 comments on commit 88d72e5

Please sign in to comment.