Class: Cli::AccountCli
Instance Method Summary collapse
- #add ⇒ Object
- #associate(uuid) ⇒ Object
- #del(uuid) ⇒ Object
- #disable(uuid) ⇒ Object
- #dissociate(uuid) ⇒ Object
- #enable(uuid) ⇒ Object
- #modify(uuid) ⇒ Object
- #oauth(uuid) ⇒ Object
- #show(uuid = nil) ⇒ Object
Instance Method Details
#add ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cli/account.rb', line 15 def add #Check if the data we got is valid if [:name] != nil && [:name].length > 255 raise "Account name can not be longer than 255 characters." end if [:description] != nil && [:description].length > 100 raise "Account description can not be longer than 100 chracters." end fields = {:name => [:name],:description => [:description], :enable => Account::ENABLED} fields.merge!({:uuid => [:uuid]}) unless [:uuid].nil? puts super(Account,fields) end |
#associate(uuid) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/cli/account.rb', line 139 def associate(uuid) account = Account[uuid] || UnknownUUIDError.raise(uuid) [:users].each { |u| if User[u].nil? puts "Unknown user UUID: #{u}" if [:verbose] elsif !account.users.index(User[u]).nil? puts "Account #{uuid} is already associated with user #{u}." if [:verbose] else user = User[u] account.add_user(user) if user.primary_account_id.nil? user.primary_account_id = account.uuid user.save end puts "Account #{uuid} successfully associated with user #{u}." if [:verbose] end } end |
#del(uuid) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/cli/account.rb', line 93 def del(uuid) to_do = Account[uuid] Error.raise("Unknown frontend account UUID: #{uuid}", 100) if to_do == nil or to_do.is_deleted super(Account,uuid) puts "Account #{uuid} has been deleted." if [:verbose] end |
#disable(uuid) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/cli/account.rb', line 121 def disable(uuid) to_disable = Account[uuid] UnknownUUIDError.raise(uuid) if to_disable == nil or to_disable.is_deleted if to_disable.disable? puts "Account #{id} is already disabled." if [:verbose] else to_disable.enable = Account::DISABLED to_disable.updated_at = Time.now.utc.iso8601 to_disable.save puts "Account #{uuid} has been disabled." if [:verbose] end end |
#dissociate(uuid) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/cli/account.rb', line 163 def dissociate(uuid) account = Account[uuid] || UnknownUUIDError.raise(uuid) [:users].each { |u| user = User[u] if user.nil? puts "Unknown user UUID: #{u}" if [:verbose] elsif account.users.index(User[u]).nil? puts "Account #{uuid} is not associated with user #{u}." if [:verbose] else account.remove_user(user) puts "Account #{uuid} successfully dissociated from user #{u}." if [:verbose] if account.uuid == user.primary_account_id user.primary_account_id = nil user.save puts "This was user #{u}'s primary account. Has been set to Null now." if [:verbose] end end } end |
#enable(uuid) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cli/account.rb', line 104 def enable(uuid) to_enable = Account[uuid] Error.raise("Unknown frontend account UUID: #{uuid}", 100) if to_enable == nil or to_enable.is_deleted if to_enable.enable? puts "Account #{uuid} is already enabled." if [:verbose] else to_enable.enable = Account::ENABLED to_enable.updated_at = Time.now.utc.iso8601 to_enable.save puts "Account #{uuid} has been enabled." if [:verbose] end end |
#modify(uuid) ⇒ Object
84 85 86 87 88 |
# File 'lib/cli/account.rb', line 84 def modify(uuid) raise "Account name can not be longer than 255 characters." if [:name] != nil && [:name].length > 255 raise "Description can not be longer than 100 characters." if [:description] != nil && [:description].length > 100 super(Account,uuid,{:name => [:name],:description => [:description]}) end |
#oauth(uuid) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/cli/account.rb', line 188 def oauth(uuid) require 'oauth' acc = Account[uuid] Error.raise("Unknown frontend account UUID: #{uuid}", 100) if acc == nil or acc.is_deleted oauth_token = OauthToken.new oauth_token.generate_keys oauth_consumer = OauthConsumer.find(:account_id => acc.id) if oauth_consumer.nil? oauth_consumer = OauthConsumer.create( :key => oauth_token.token, :secret => oauth_token.secret, :account_id => acc.id ) end puts ERB.new("Account UUID:\n<%- if acc.class == Account -%>\n <%= acc.canonical_uuid %>\n<%- else -%>\n <%= Account.uuid_prefix%>-<%= acc.uuid %>\n<%- end -%>\n\nConsumer Key:\n <%= oauth_consumer.key %>\nConsumer Secret:\n <%= oauth_consumer.secret %>\n", nil, '-').result(binding) end |
#show(uuid = nil) ⇒ Object
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 |
# File 'lib/cli/account.rb', line 31 def show(uuid = nil) if uuid acc = Account[uuid] || UnknownUUIDError.raise(uuid) puts ERB.new("Account UUID:\n<%- if acc.class == Account -%>\n <%= acc.canonical_uuid %>\n<%- else -%>\n <%= Account.uuid_prefix%>-<%= acc.uuid %>\n<%- end -%>\nEnabled:\n<%- if acc.enable? -%>\n Yes\n<%- else -%>\n No\n<%- end -%>\n<%- if acc.name -%>\nName:\n <%= acc.name %>\n<%- end -%>\n<%- if acc.description -%>\nDescription:\n <%= acc.description %>\n<%- end -%>\n<%- if acc.is_deleted -%>\nDeleted at:\n <%= acc.deleted_at %>\n<%- end -%>\n<%- unless acc.users.empty? -%>\nAssociated users:\n<%- acc.users.each { |row| -%>\n <%= row.canonical_uuid %>\\t<%= row.name %>\n<%- } -%>\n<%- end -%>\n", nil, '-').result(binding) else #This needs an "|| false" because options[:deleted] is usually nil which isn't the same as false acc = Account.filter(:is_deleted => ([:deleted] || false )).all puts ERB.new("<%- acc.each { |row| -%>\n<%- if row.class == Account -%>\n<%= row.canonical_uuid %>\\t<%= row.name %>\n<%- else -%>\n<%= Account.uuid_prefix%>-<%= row.uuid %>\\t<%= row.name %>\n<%- end -%>\n<%- } -%>\n", nil, '-').result(binding) end end |