Class: LMC::AccountManager
- Inherits:
-
Object
- Object
- LMC::AccountManager
- Defined in:
- lib/lmc/account_manager.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#initialize(options, global_options) ⇒ AccountManager
constructor
A new instance of AccountManager.
-
#invite(lmcen, distro, line, type, authority_name) ⇒ Object
returns nil if invite did not work.
Constructor Details
#initialize(options, global_options) ⇒ AccountManager
Returns a new instance of AccountManager.
10 11 12 13 14 |
# File 'lib/lmc/account_manager.rb', line 10 def initialize(, ) @options = @global_options = @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/lmc/account_manager.rb', line 8 def errors @errors end |
Instance Method Details
#invite(lmcen, distro, line, type, authority_name) ⇒ Object
returns nil if invite did not work
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/lmc/account_manager.rb', line 17 def invite(lmcen, distro, line, type, ) lmcen.auth_for_accounts([distro['id']]) line = line.strip.downcase begin account = Account.get(distro['id']) = account. # puts account_authorities.inspect if @global_options[:debug] if @global_options[:debug] .each do |a| puts a['name'] puts a.inspect end end = .find { |auth| auth['name'] == } # puts "account authorities: #{account_authorities}" if @global_options[:debug] puts if @global_options[:debug] if !@options[:dry] # TODO: wenn der default authority nicht gibt geht das ding kaputt invited = lmcen.invite_user_to_account(line, distro['id'], type, [['id']]) puts 'Invite response:' + invited.inspect if @global_options[:debug] puts 'Invited ' + invited['name'].to_s + " to account #{distro['name']}(#{invited.code})." if @global_options[:v] if invited.code != 200 @errors << { :line => line, :result => invited.body } return nil end else invited = { 'name' => line } end invite_url = lmcen.build_url('#', 'register', Base64.encode64(invited['name'])) if @options['show-csv'] puts "\n" + invited['name'] + ', ' + invite_url end if @options['send-mail'] && invited mailbody = <<END Hallo, auf #{lmcen.cloud_host} wurde eine Einladung zu dem Account #{distro['name']} für den Nutzer #{invited['name']} erstellt. Falls der Account noch nicht existiert, kann dieser Link zur Registrierung genutzt werden: END mail = Mail.new do from 'Philipp Erbelding <[email protected]>' to invited['name'] subject 'Einladung auf ' + lmcen.cloud_host body mailbody + invite_url end puts invite_url if !@options[:dry] puts 'sending mail to ' + invited['name'] mail.delivery_method :smtp, address: 'lcs-mail' mail.deliver else puts '[DRY RUN] would send mail to ' + invited['name'] end puts mail.to_s if @global_options[:v] end rescue RestClient::ExceptionWithResponse => e puts e.to_s puts invited.inspect resp = JSON.parse(e.response) puts resp.inspect puts resp['message'] end true end |