Class: Zm::Client::Account

Inherits:
Base::AdminObject show all
Defined in:
lib/zm/client/account/account.rb

Overview

objectClass: zimbraAccount

Instance Attribute Summary collapse

Attributes inherited from Base::Object

#grantee_type, #parent

Instance Method Summary collapse

Methods inherited from Base::AdminObject

#soap_account_connector, #soap_admin_connector, #to_h

Methods inherited from Base::Object

#arrow_name, #clone, #concat, #convert_json_string_value, #disable_builder, #enable_builder, #instance_variables_array, #instance_variables_hash, #logger, #recorded?, #save!, #to_s, #use_builder?

Constructor Details

#initialize(parent) ⇒ Account

Returns a new instance of Account.



33
34
35
36
37
# File 'lib/zm/client/account/account.rb', line 33

def initialize(parent)
  extend(AccountCommon)
  super(parent)
  @grantee_type = 'usr'.freeze
end

Instance Attribute Details

#carLicenseObject

attr_reader :name, :id, :token attr_writer :home_url attr_accessor :password, :domainkey, :company, :zimbraCOSId, :zimbraMailHost, :zimbraMailTransport, :carLicense



31
32
33
# File 'lib/zm/client/account/account.rb', line 31

def carLicense
  @carLicense
end

#domainkeyObject

attr_reader :name, :id, :token attr_writer :home_url attr_accessor :password, :domainkey, :company, :zimbraCOSId, :zimbraMailHost, :zimbraMailTransport, :carLicense



31
32
33
# File 'lib/zm/client/account/account.rb', line 31

def domainkey
  @domainkey
end

#home_urlObject

attr_reader :name, :id, :token attr_writer :home_url attr_accessor :password, :domainkey, :company, :zimbraCOSId, :zimbraMailHost, :zimbraMailTransport, :carLicense



31
32
33
# File 'lib/zm/client/account/account.rb', line 31

def home_url
  @home_url
end

#idObject

attr_reader :name, :id, :token attr_writer :home_url attr_accessor :password, :domainkey, :company, :zimbraCOSId, :zimbraMailHost, :zimbraMailTransport, :carLicense



31
32
33
# File 'lib/zm/client/account/account.rb', line 31

def id
  @id
end

#nameObject

attr_reader :name, :id, :token attr_writer :home_url attr_accessor :password, :domainkey, :company, :zimbraCOSId, :zimbraMailHost, :zimbraMailTransport, :carLicense



31
32
33
# File 'lib/zm/client/account/account.rb', line 31

def name
  @name
end

#passwordObject

attr_reader :name, :id, :token attr_writer :home_url attr_accessor :password, :domainkey, :company, :zimbraCOSId, :zimbraMailHost, :zimbraMailTransport, :carLicense



31
32
33
# File 'lib/zm/client/account/account.rb', line 31

def password
  @password
end

#tokenObject

attr_reader :name, :id, :token attr_writer :home_url attr_accessor :password, :domainkey, :company, :zimbraCOSId, :zimbraMailHost, :zimbraMailTransport, :carLicense



31
32
33
# File 'lib/zm/client/account/account.rb', line 31

def token
  @token
end

Instance Method Details

#account_loginObject



73
74
75
76
77
78
79
# File 'lib/zm/client/account/account.rb', line 73

def 
  if password
    
  else
    
  end
end

#account_login_passwordObject

Raises:



88
89
90
91
92
# File 'lib/zm/client/account/account.rb', line 88

def 
  raise ZmError, 'password is required to login !' if password.nil?

  @token = sacc.auth_password(@name, @password)
end

#account_login_preauthObject

Raises:



81
82
83
84
85
86
# File 'lib/zm/client/account/account.rb', line 81

def 
  domain_key
  raise ZmError, 'domain key is required to login !' if @domainkey.nil?

  @token = sacc.auth_preauth(@name, @domainkey)
end

#acesObject Also known as: rights



182
183
184
# File 'lib/zm/client/account/account.rb', line 182

def aces
  @aces ||= AcesCollection.new(self)
end

#add_alias!(email) ⇒ Object



274
275
276
277
# File 'lib/zm/client/account/account.rb', line 274

def add_alias!(email)
  sac.(@id, email)
  aliases.push(email)
end

#admin_loginObject



94
95
96
# File 'lib/zm/client/account/account.rb', line 94

def 
  @token = sac.delegate_auth(@name)
end

#aliasesObject



264
265
266
# File 'lib/zm/client/account/account.rb', line 264

def aliases
  @aliases ||= set_aliases
end

#all_instance_variable_keysObject

def to_h

hashmap = Hash[all_instance_variable_keys.map { |key| [key, instance_variable_get(arrow_name(key))] }]
hashmap.delete_if { |_, v| v.nil? }
hashmap

end



51
52
53
# File 'lib/zm/client/account/account.rb', line 51

def all_instance_variable_keys
  AccountCommon::
end

#appointmentsObject



170
171
172
# File 'lib/zm/client/account/account.rb', line 170

def appointments
  @appointments ||= AppointmentsCollection.new(self)
end

#calendar_foldersObject



207
208
209
# File 'lib/zm/client/account/account.rb', line 207

def calendar_folders
  @calendar_folders ||= folders.all.select { |f| f.view == Zm::Client::FolderView::APPOINTMENT.to_s }
end

#contact_foldersObject



203
204
205
# File 'lib/zm/client/account/account.rb', line 203

def contact_folders
  @contact_folders ||= folders.all.select { |f| f.view == Zm::Client::FolderView::CONTACT.to_s }
end

#contactsObject



166
167
168
# File 'lib/zm/client/account/account.rb', line 166

def contacts
  @contacts ||= ContactsCollection.new(self)
end

#cosObject



124
125
126
# File 'lib/zm/client/account/account.rb', line 124

def cos
  @cos ||= @parent.coses.find_by(id: zimbraCOSId)
end

#create!Object



249
250
251
252
253
254
255
256
# File 'lib/zm/client/account/account.rb', line 249

def create!
  rep = sac.(
    @name,
    @password,
    instance_variables_array(attrs_write)
  )
  @id = rep[:Body][:CreateAccountResponse][:account].first[:id]
end

#created_atObject



319
320
321
# File 'lib/zm/client/account/account.rb', line 319

def created_at
  @created_at ||= Time.parse zimbraCreateTimestamp unless zimbraCreateTimestamp.nil?
end

#data_sourcesObject



191
192
193
# File 'lib/zm/client/account/account.rb', line 191

def data_sources
  @data_sources ||= DataSourcesCollection.new sac, self
end

#delete!Object



219
220
221
# File 'lib/zm/client/account/account.rb', line 219

def delete!
  sac.(@id)
end

#dls_ownerObject



342
343
344
# File 'lib/zm/client/account/account.rb', line 342

def dls_owner
  @dls_owner ||= AccountDlsOwnerCollection.new(self)
end

#document_foldersObject



215
216
217
# File 'lib/zm/client/account/account.rb', line 215

def document_folders
  @document_folders ||= folders.all.select { |f| f.view == Zm::Client::FolderView::DOCUMENT.to_s }
end

#documentsObject



195
196
197
# File 'lib/zm/client/account/account.rb', line 195

def documents
  @documents ||= DocumentsCollection.new(self)
end

#domain_keyObject



106
107
108
# File 'lib/zm/client/account/account.rb', line 106

def domain_key
  @domainkey ||= @parent.domain_key(domain_name)
end

#domain_nameObject



102
103
104
# File 'lib/zm/client/account/account.rb', line 102

def domain_name
  @domain_name ||= @name.split('@').last
end

#flush_cache!Object



323
324
325
# File 'lib/zm/client/account/account.rb', line 323

def flush_cache!
  sac.flush_cache('account', 1, @id)
end

#foldersObject



146
147
148
# File 'lib/zm/client/account/account.rb', line 146

def folders
  @folders ||= FoldersCollection.new(self)
end

#identitiesObject



158
159
160
# File 'lib/zm/client/account/account.rb', line 158

def identities
  @identities ||= IdentitiesCollection.new(self)
end

#infosObject



110
111
112
# File 'lib/zm/client/account/account.rb', line 110

def infos
  @infos || read_infos
end

#init_from_json(json) ⇒ Object



350
351
352
353
354
# File 'lib/zm/client/account/account.rb', line 350

def init_from_json(json)
  @used = json[:used] if json[:used]
  @zimbraMailQuota = json[:limit] if json[:limit]
  super(json)
end

#is_external_transport?Boolean

Returns:

  • (Boolean)


305
306
307
308
309
# File 'lib/zm/client/account/account.rb', line 305

def is_external_transport?
  return nil unless zimbraMailTransport

  zimbraMailTransport.start_with?('smtp')
end

#is_local_transport?Boolean

Returns:

  • (Boolean)


299
300
301
302
303
# File 'lib/zm/client/account/account.rb', line 299

def is_local_transport?
  return nil unless zimbraMailTransport

  zimbraMailTransport.start_with?('lmtp')
end

#is_on_to_move?(server) ⇒ Boolean

Returns:

  • (Boolean)


333
334
335
336
# File 'lib/zm/client/account/account.rb', line 333

def is_on_to_move?(server)
  resp = sac.query_mailbox_move(@name, server.id)
  resp[:Body][:QueryMailboxMoveResponse][:account].nil?
end

#last_logonObject



315
316
317
# File 'lib/zm/client/account/account.rb', line 315

def last_logon
  @last_logon ||= Time.parse zimbraLastLogonTimestamp unless zimbraLastLogonTimestamp.nil?
end

#local_transportObject



289
290
291
292
293
# File 'lib/zm/client/account/account.rb', line 289

def local_transport
  raise Zm::Client::SoapError, 'zimbraMailHost is null' if zimbraMailHost.nil?

  "lmtp:#{zimbraMailHost}:7025"
end

#local_transport!Object



295
296
297
# File 'lib/zm/client/account/account.rb', line 295

def local_transport!
  update!(zimbraMailTransport: local_transport)
end

#logged?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/zm/client/account/account.rb', line 61

def logged?
  !@token.nil?
end

#loginObject



65
66
67
68
69
70
71
# File 'lib/zm/client/account/account.rb', line 65

def 
  if @parent.logged?
    
  else
    
  end
end

#membershipsObject



338
339
340
# File 'lib/zm/client/account/account.rb', line 338

def memberships
  @memberships ||= AccountDlsMembershipCollection.new(self)
end

#message_foldersObject



199
200
201
# File 'lib/zm/client/account/account.rb', line 199

def message_folders
  @message_folders ||= folders.all.select { |f| f.view == Zm::Client::FolderView::MESSAGE.to_s }
end

#messagesObject



142
143
144
# File 'lib/zm/client/account/account.rb', line 142

def messages
  @messages ||= MessagesCollection.new(self)
end

#modify!Object



242
243
244
245
246
247
# File 'lib/zm/client/account/account.rb', line 242

def modify!
  attrs_to_modify = instance_variables_array(attrs_write)
  return if attrs_to_modify.empty?

  sac.(@id, attrs_to_modify)
end

#mountpointsObject



150
151
152
# File 'lib/zm/client/account/account.rb', line 150

def mountpoints
  @mountpointss ||= MountPointsCollection.new(self)
end

#move_mailbox(server) ⇒ Object



327
328
329
330
331
# File 'lib/zm/client/account/account.rb', line 327

def move_mailbox(server)
  raise Zm::Client::SoapError, 'zimbraMailHost is null' if zimbraMailHost.nil?

  sac.move_mailbox(@name, zimbraMailHost, server.name, server.id)
end

#password!(new_password) ⇒ Object



223
224
225
226
# File 'lib/zm/client/account/account.rb', line 223

def password!(new_password)
  sac.set_password(@id, new_password)
  @password = new_password
end

#public_urlObject



132
133
134
135
# File 'lib/zm/client/account/account.rb', line 132

def public_url
  infos if @infos.nil?
  @public_url
end

#ranking(op, email = nil) ⇒ Object



346
347
348
# File 'lib/zm/client/account/account.rb', line 346

def ranking(op, email = nil)
  sacc.ranking_action(@token, op, email)
end

#read_infosObject



114
115
116
117
118
119
120
121
122
# File 'lib/zm/client/account/account.rb', line 114

def read_infos
  @infos = sacc.get_info(@token)[:Body][:GetInfoResponse]
  @id = @infos[:id]
  @used = @infos[:used]
  @public_url = @infos[:publicURL]
  @zimbraCOSId = @infos[:cos][:id]
  @home_url = @infos[:rest]
  @infos
end

#remove_alias!(email) ⇒ Object



279
280
281
282
# File 'lib/zm/client/account/account.rb', line 279

def remove_alias!(email)
  sac.(@id, email)
  aliases.delete(email)
end

#rename!(email) ⇒ Object



284
285
286
287
# File 'lib/zm/client/account/account.rb', line 284

def rename!(email)
  sac.(@id, email)
  @name = email
end

#rest_account_connectorObject Also known as: rac



55
56
57
# File 'lib/zm/client/account/account.rb', line 55

def 
   ||= RestAccountConnector.new
end

#search_foldersObject



154
155
156
# File 'lib/zm/client/account/account.rb', line 154

def search_folders
  @search_folders ||= SearchFoldersCollection.new(self)
end

#set_aliasesObject



268
269
270
271
272
# File 'lib/zm/client/account/account.rb', line 268

def set_aliases
  return [] if zimbraMailAlias.nil?
  return [zimbraMailAlias] if zimbraMailAlias.is_a?(String)
  zimbraMailAlias
end

#set_password(new_password = nil) ⇒ Object



258
259
260
261
262
# File 'lib/zm/client/account/account.rb', line 258

def set_password(new_password = nil)
  new_password ||= @password
  sac.set_password(@id, new_password)
  @password = new_password
end

#sharesObject



162
163
164
# File 'lib/zm/client/account/account.rb', line 162

def shares
  @shares ||= SharesCollection.new(self)
end

#signaturesObject



187
188
189
# File 'lib/zm/client/account/account.rb', line 187

def signatures
  @signatures ||= SignaturesCollection.new(self)
end

#tagsObject



174
175
176
# File 'lib/zm/client/account/account.rb', line 174

def tags
  @tags ||= TagsCollection.new(self)
end

#task_foldersObject



211
212
213
# File 'lib/zm/client/account/account.rb', line 211

def task_folders
  @task_folders ||= folders.all.select { |f| f.view == Zm::Client::FolderView::TASK.to_s }
end

#tasksObject



178
179
180
# File 'lib/zm/client/account/account.rb', line 178

def tasks
  @tasks ||= TasksCollection.new(self)
end

#token_metadataObject



98
99
100
# File 'lib/zm/client/account/account.rb', line 98

def 
   ||= .new(@token)
end

#update!(hash) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/zm/client/account/account.rb', line 228

def update!(hash)
  sac.(@id, hash)

  hash.each do |k, v|
    arrow_attr_sym = "@#{k}".to_sym

    if v.respond_to?(:empty?) && v.empty?
      self.remove_instance_variable(arrow_attr_sym) if self.instance_variable_get(arrow_attr_sym)
    else
      self.instance_variable_set(arrow_attr_sym, v)
    end
  end
end

#uploaderObject



311
312
313
# File 'lib/zm/client/account/account.rb', line 311

def uploader
  @uploader ||= Upload.new(self)
end

#usedObject



128
129
130
# File 'lib/zm/client/account/account.rb', line 128

def used
  @used ||= sac.get_mailbox(id)[:Body][:GetMailboxResponse][:mbox].first[:s]
end