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

Methods inherited from Base::Object

#arrow_name, #clone, #concat, #convert_json_string_value, #instance_variables_array, #instance_variables_hash, #recorded?, #save!, #to_s

Constructor Details

#initialize(parent, attrs = {}) ⇒ Account

Returns a new instance of Account.



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

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

Instance Attribute Details

#carLicenseObject

Returns the value of attribute carLicense.



29
30
31
# File 'lib/zm/client/account/account.rb', line 29

def carLicense
  @carLicense
end

#companyObject

Returns the value of attribute company.



29
30
31
# File 'lib/zm/client/account/account.rb', line 29

def company
  @company
end

#domainkeyObject

Returns the value of attribute domainkey.



29
30
31
# File 'lib/zm/client/account/account.rb', line 29

def domainkey
  @domainkey
end

#home_urlObject



130
131
132
133
# File 'lib/zm/client/account/account.rb', line 130

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

#idObject (readonly)

Returns the value of attribute id.



27
28
29
# File 'lib/zm/client/account/account.rb', line 27

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/zm/client/account/account.rb', line 27

def name
  @name
end

#passwordObject

Returns the value of attribute password.



29
30
31
# File 'lib/zm/client/account/account.rb', line 29

def password
  @password
end

#tokenObject (readonly)

Returns the value of attribute token.



27
28
29
# File 'lib/zm/client/account/account.rb', line 27

def token
  @token
end

#zimbraCOSIdObject

Returns the value of attribute zimbraCOSId.



29
30
31
# File 'lib/zm/client/account/account.rb', line 29

def zimbraCOSId
  @zimbraCOSId
end

#zimbraMailHostObject

Returns the value of attribute zimbraMailHost.



29
30
31
# File 'lib/zm/client/account/account.rb', line 29

def zimbraMailHost
  @zimbraMailHost
end

#zimbraMailTransportObject

Returns the value of attribute zimbraMailTransport.



29
30
31
# File 'lib/zm/client/account/account.rb', line 29

def zimbraMailTransport
  @zimbraMailTransport
end

Instance Method Details

#account_loginObject



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

def 
  if password
    
  else
    
  end
end

#account_login_passwordObject

Raises:



86
87
88
89
90
# File 'lib/zm/client/account/account.rb', line 86

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

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

#account_login_preauthObject

Raises:



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

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



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

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

#add_alias!(email) ⇒ Object



256
257
258
259
# File 'lib/zm/client/account/account.rb', line 256

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

#admin_loginObject



92
93
94
# File 'lib/zm/client/account/account.rb', line 92

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

#aliasesObject



246
247
248
# File 'lib/zm/client/account/account.rb', line 246

def aliases
  @aliases ||= set_aliases
end

#all_instance_variable_keysObject



49
50
51
# File 'lib/zm/client/account/account.rb', line 49

def all_instance_variable_keys
  AccountCommon::
end

#appointmentsObject



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

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

#calendar_foldersObject



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

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

#contact_foldersObject



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

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

#contactsObject



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

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

#cosObject



117
118
119
# File 'lib/zm/client/account/account.rb', line 117

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

#create!Object



237
238
239
240
241
242
243
244
# File 'lib/zm/client/account/account.rb', line 237

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

#created_atObject



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

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

#data_sourcesObject



184
185
186
# File 'lib/zm/client/account/account.rb', line 184

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

#delete!Object



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

def delete!
  sac.(@id)
end

#dls_ownerObject



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

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

#document_foldersObject



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

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

#documentsObject



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

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

#domain_keyObject



100
101
102
# File 'lib/zm/client/account/account.rb', line 100

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

#domain_nameObject



96
97
98
# File 'lib/zm/client/account/account.rb', line 96

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

#flush_cache!Object



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

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

#foldersObject



139
140
141
# File 'lib/zm/client/account/account.rb', line 139

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

#identitiesObject



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

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

#infosObject



104
105
106
# File 'lib/zm/client/account/account.rb', line 104

def infos
  @infos ||= read_infos
end

#init_by_hash(attrs) ⇒ Object



37
38
39
40
41
# File 'lib/zm/client/account/account.rb', line 37

def init_by_hash(attrs)
  attrs.each do |k, v|
    self.instance_variable_set(arrow_name(k), v)
  end
end

#init_from_json(json) ⇒ Object



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

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)


287
288
289
290
291
# File 'lib/zm/client/account/account.rb', line 287

def is_external_transport?
  return nil unless zimbraMailTransport

  zimbraMailTransport.start_with?('smtp')
end

#is_local_transport?Boolean

Returns:

  • (Boolean)


281
282
283
284
285
# File 'lib/zm/client/account/account.rb', line 281

def is_local_transport?
  return nil unless zimbraMailTransport

  zimbraMailTransport.start_with?('lmtp')
end

#is_on_to_move?(server) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#last_logonObject



297
298
299
# File 'lib/zm/client/account/account.rb', line 297

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

#local_transportObject



271
272
273
274
275
# File 'lib/zm/client/account/account.rb', line 271

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

  "lmtp:#{zimbraMailHost}:7025"
end

#local_transport!Object



277
278
279
# File 'lib/zm/client/account/account.rb', line 277

def local_transport!
  update!(zimbraMailTransport: local_transport)
end

#logged?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/zm/client/account/account.rb', line 59

def logged?
  !@token.nil?
end

#loginObject



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

def 
  if @parent.logged?
    
  else
    
  end
end

#membershipsObject



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

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

#message_foldersObject



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

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

#messagesObject



135
136
137
# File 'lib/zm/client/account/account.rb', line 135

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

#modify!Object



230
231
232
233
234
235
# File 'lib/zm/client/account/account.rb', line 230

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

  sac.(@id, attrs_to_modify)
end

#mountpointsObject



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

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

#move_mailbox(server) ⇒ Object



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

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

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

#public_urlObject



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

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

#read_infosObject



108
109
110
111
112
113
114
115
# File 'lib/zm/client/account/account.rb', line 108

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]
end

#remove_alias!(email) ⇒ Object



261
262
263
264
# File 'lib/zm/client/account/account.rb', line 261

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

#rename!(email) ⇒ Object



266
267
268
269
# File 'lib/zm/client/account/account.rb', line 266

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

#rest_account_connectorObject Also known as: rac



53
54
55
# File 'lib/zm/client/account/account.rb', line 53

def 
   ||= RestAccountConnector.new
end

#search_foldersObject



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

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

#set_aliasesObject



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

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

#sharesObject



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

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

#signaturesObject



180
181
182
# File 'lib/zm/client/account/account.rb', line 180

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

#tagsObject



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

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

#task_foldersObject



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

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

#tasksObject



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

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

#to_hObject



43
44
45
46
47
# File 'lib/zm/client/account/account.rb', line 43

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

#update!(hash) ⇒ Object



216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/zm/client/account/account.rb', line 216

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



293
294
295
# File 'lib/zm/client/account/account.rb', line 293

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

#usedObject



121
122
123
# File 'lib/zm/client/account/account.rb', line 121

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