Skip to content

Commit

Permalink
share: anyone with link, not publicly published
Browse files Browse the repository at this point in the history
Allow sharing of file with `anyone with link` without
having to publish it to the internet. Publishing is different
because after a file is published, it is indexed
(See #568 (comment)).
We don't want the file to be indexed, but just accessible by anyone with
a link to it.

```shell
$ drive share --type user,anyone,anyone,user --role reader,anyone --emails "emm.odeke@gmail.com" outf.gif
Provide access for accountType(s)
  user
  anyone

For roles(s)
  reader

Addressees:
  + emm.odeke@gmail.com
  + Anyone with the link

File(s) to share:
  + outf.gif

Proceed with the changes? [Y/n]:y
successful share for outf.gif with email "emm.odeke@gmail.com", role "reader" accountType "user"
successful share for outf.gif with email "", role "reader" accountType "anyone"
```

Fixes #568.
  • Loading branch information
odeke-em committed May 19, 2016
1 parent 859a511 commit 0086aa9
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,13 @@ var reverseRoleResolve = stringToRole()
var reverseAccountTypeResolve = stringToAccountType()

func reverseRolesResolver(roleArgv ...string) (roles []Role) {
alreadySeen := map[Role]bool{}
for _, roleStr := range roleArgv {
roles = append(roles, reverseRoleResolve(roleStr))
role := reverseRoleResolve(roleStr)
if _, seen := alreadySeen[role]; !seen {
roles = append(roles, role)
alreadySeen[role] = true
}
}

return roles
Expand Down Expand Up @@ -238,6 +243,9 @@ func showPromptShareChanges(logy *log.Logger, change *shareChange) Agreement {
if len(change.emails) >= 1 {
logy.Logf("\nAddressees:\n")
for _, email := range change.emails {
if email == "" {
email = "Anyone with the link"
}
logy.Logf("\t\033[92m+\033[00m %s\n", email)
}
}
Expand Down Expand Up @@ -275,9 +283,15 @@ func (c *Commands) playShareChanges(change *shareChange) (err error) {
successes := 0

for _, file := range change.files {
for _, email := range change.emails {
for _, role := range change.roles {
for _, accountType := range change.accountTypes {
for _, accountType := range change.accountTypes {
for _, email := range change.emails {
if accountType == Anyone && email != "" {
// It doesn't make sense to share a file with
// permission "anyone" yet provide an email
continue
}

for _, role := range change.roles {
perm := permission{
fileId: file.Id,
value: email,
Expand Down Expand Up @@ -363,6 +377,15 @@ func (c *Commands) share(revoke, byId bool) (err error) {

notify := (c.opts.TypeMask & Notify) != 0

// Now here we have to match up emails with roles
// See Issue #568. If we've requested say `anyone`, this role needs no email
// address, so we should add an empty "" to the list of emails
for _, accountType := range accountTypes {
if accountType == Anyone {
emails = append(emails, "")
}
}

change := shareChange{
accountTypes: accountTypes,
emailMessage: emailMessage,
Expand Down

0 comments on commit 0086aa9

Please sign in to comment.