Class: Heroku::Command::Sharing

Inherits:
Base
  • Object
show all
Defined in:
lib/heroku/command/sharing.rb

Overview

manage collaborators on an app

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Base

#api, #app, #heroku, #initialize, namespace, #org, #org_api

Methods included from Helpers

#action, #app_owner, #ask, #confirm, #confirm_command, #create_git_remote, #debug, #debugging?, #default_org_host, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #error, #error_log, #error_log_path, error_with_failure, error_with_failure=, extended, extended_into, #fail, #format_bytes, #format_date, #format_error, #format_with_bang, #get_terminal_environment, #git, #has_git?, #has_git_remote?, #has_http_git_entry_in_netrc, #home_directory, #hprint, #hputs, included, included_into, #json_decode, #json_encode, #launchy, #line_formatter, #longest, #org?, #org_host, #output_with_bang, #quantify, #redisplay, #retry_on_exception, #run_command, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #stderr_print, #stderr_puts, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #time_ago, #truncate, #update_git_remote, #warn_if_using_jruby, #with_tty

Constructor Details

This class inherits a constructor from Heroku::Command::Base

Instance Method Details

#addObject

sharing:add EMAIL

add a collaborator to an app

Example:

$ heroku sharing:add [email protected] Adding [email protected] to example collaborators… done


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/heroku/command/sharing.rb', line 40

def add
  unless email = shift_argument
    error("Usage: heroku sharing:add EMAIL\nMust specify EMAIL to add sharing.")
  end
  validate_arguments!
  org_from_app!

  action("Adding #{email} to #{app} as collaborator") do
    if org && org_api.get_members(org).body.map { |m| m['email'] }.include?(email)
      org_api.post_collaborator(org, app, email)
    else
      api.post_collaborator(app, email)
    end
  end
end

#indexObject

sharing

list collaborators on an app

Example:

$ heroku sharing

example Collaborators

[email protected] collaborator [email protected] owner


20
21
22
23
24
25
26
27
28
29
# File 'lib/heroku/command/sharing.rb', line 20

def index
  validate_arguments!

  # this is never empty, as it always includes the owner
  collaborators = api.get_collaborators(app).body
  collaborators = collaborators.delete_if { |collaborator| org? collaborator["email"] }

  styled_header("#{app} Access List")
  styled_array(collaborators.map {|collaborator| [collaborator["email"], collaborator.fetch("role", "collaborator")] })
end

#removeObject

sharing:remove EMAIL

remove a collaborator from an app

Example:

$ heroku sharing:remove [email protected] Removing [email protected] to example collaborators… done


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/heroku/command/sharing.rb', line 65

def remove
  unless email = shift_argument
    error("Usage: heroku sharing:remove EMAIL\nMust specify EMAIL to remove sharing.")
  end
  validate_arguments!
  org_from_app!

  action("Removing #{email} from #{app} collaborators") do
    if org && org_api.get_members(org).body.map { |m| m['email'] }.include?(email)
      org_api.delete_collaborator(org, app, email)
    else
      api.delete_collaborator(app, email)
    end
  end
end

#transferObject

sharing:transfer TARGET

transfers an app to another user or an organization. TARGET is the email of another user or the name of the organization to transfer to.

Example:

$ heroku sharing:transfer [email protected] Transferring example to [email protected]… done

$ heroku sharing:transfer acme-widgets Transferring example to acme-widgets… done

-l, –locked # lock the app upon transfer


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/heroku/command/sharing.rb', line 97

def transfer
  unless target = shift_argument
    error("Usage: heroku sharing:transfer EMAIL\nMust specify EMAIL to transfer an app.")
  end
  validate_arguments!
  org_from_app!

  action("Transferring #{app} to #{target}") do
    if org || !target.include?('@')
      locked = options[:locked]

      org_api.transfer_app(target, app, locked)
      display("App is locked. Organization members must be invited to access.") if locked

    else
      api.put_app(app, "transfer_owner" => target)
    end
  end
end