zm-ruby-client 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +58 -0
  3. data/Gemfile +8 -0
  4. data/LICENSE +674 -0
  5. data/README.md +47 -0
  6. data/SECURITY.md +21 -0
  7. data/lib/zm/client/account/account.rb +345 -0
  8. data/lib/zm/client/account/account_dls_membership_collection.rb +22 -0
  9. data/lib/zm/client/account/account_dls_owner_collection.rb +22 -0
  10. data/lib/zm/client/account/accounts_builder.rb +19 -0
  11. data/lib/zm/client/account/accounts_collection.rb +48 -0
  12. data/lib/zm/client/account.rb +7 -0
  13. data/lib/zm/client/ace/ace.rb +32 -0
  14. data/lib/zm/client/ace/aces_builder.rb +25 -0
  15. data/lib/zm/client/ace/aces_collection.rb +36 -0
  16. data/lib/zm/client/ace.rb +5 -0
  17. data/lib/zm/client/appointment/appointment.rb +143 -0
  18. data/lib/zm/client/appointment/appointment_jsns_builder.rb +125 -0
  19. data/lib/zm/client/appointment/appointment_jsns_initializer.rb +129 -0
  20. data/lib/zm/client/appointment/appointments_builder.rb +33 -0
  21. data/lib/zm/client/appointment/appointments_collection.rb +106 -0
  22. data/lib/zm/client/appointment.rb +7 -0
  23. data/lib/zm/client/backup/backup.rb +59 -0
  24. data/lib/zm/client/backup/backups_builder.rb +26 -0
  25. data/lib/zm/client/backup/backups_collection.rb +22 -0
  26. data/lib/zm/client/backup.rb +5 -0
  27. data/lib/zm/client/base/account_object.rb +17 -0
  28. data/lib/zm/client/base/admin_object.rb +45 -0
  29. data/lib/zm/client/base/object.rb +80 -0
  30. data/lib/zm/client/base/objects_builder.rb +31 -0
  31. data/lib/zm/client/base/objects_collection.rb +135 -0
  32. data/lib/zm/client/base.rb +7 -0
  33. data/lib/zm/client/cluster/cluster.rb +121 -0
  34. data/lib/zm/client/cluster/cluster_config.rb +100 -0
  35. data/lib/zm/client/cluster.rb +4 -0
  36. data/lib/zm/client/common/message.rb +10 -0
  37. data/lib/zm/client/common/recipients.rb +67 -0
  38. data/lib/zm/client/common/token_metadata.rb +44 -0
  39. data/lib/zm/client/common.rb +5 -0
  40. data/lib/zm/client/config.rb +12 -0
  41. data/lib/zm/client/connector/rest_account.rb +74 -0
  42. data/lib/zm/client/connector/soap_account.rb +563 -0
  43. data/lib/zm/client/connector/soap_admin.rb +532 -0
  44. data/lib/zm/client/connector/soap_base.rb +65 -0
  45. data/lib/zm/client/connector/soap_error.rb +26 -0
  46. data/lib/zm/client/connector/soap_xml_builder.rb +68 -0
  47. data/lib/zm/client/constant.rb +217 -0
  48. data/lib/zm/client/contact/contact.rb +124 -0
  49. data/lib/zm/client/contact/contact_member.rb +73 -0
  50. data/lib/zm/client/contact/contacts_builder.rb +24 -0
  51. data/lib/zm/client/contact/contacts_collection.rb +26 -0
  52. data/lib/zm/client/contact/mod_group_contact.rb +74 -0
  53. data/lib/zm/client/contact.rb +7 -0
  54. data/lib/zm/client/cos/cos.rb +59 -0
  55. data/lib/zm/client/cos/coses_builder.rb +29 -0
  56. data/lib/zm/client/cos/coses_collection.rb +33 -0
  57. data/lib/zm/client/cos.rb +5 -0
  58. data/lib/zm/client/data_source.rb +5 -0
  59. data/lib/zm/client/distributionlist/distributionlist.rb +125 -0
  60. data/lib/zm/client/distributionlist/distributionlists_builder.rb +29 -0
  61. data/lib/zm/client/distributionlist/distributionlists_collection.rb +41 -0
  62. data/lib/zm/client/distributionlist.rb +5 -0
  63. data/lib/zm/client/document/document.rb +51 -0
  64. data/lib/zm/client/document/documents_builder.rb +31 -0
  65. data/lib/zm/client/document/documents_collection.rb +93 -0
  66. data/lib/zm/client/document.rb +5 -0
  67. data/lib/zm/client/domain/domain.rb +85 -0
  68. data/lib/zm/client/domain/domains_builder.rb +32 -0
  69. data/lib/zm/client/domain/domains_collection.rb +36 -0
  70. data/lib/zm/client/domain.rb +5 -0
  71. data/lib/zm/client/folder/folder.rb +215 -0
  72. data/lib/zm/client/folder/folder_grant.rb +58 -0
  73. data/lib/zm/client/folder/folder_retention_policy.rb +48 -0
  74. data/lib/zm/client/folder/folders_builder.rb +58 -0
  75. data/lib/zm/client/folder/folders_collection.rb +95 -0
  76. data/lib/zm/client/folder/mod_document_folder.rb +17 -0
  77. data/lib/zm/client/folder.rb +8 -0
  78. data/lib/zm/client/identity/identities_builder.rb +25 -0
  79. data/lib/zm/client/identity/identities_collection.rb +26 -0
  80. data/lib/zm/client/identity/identity.rb +75 -0
  81. data/lib/zm/client/identity.rb +5 -0
  82. data/lib/zm/client/license/license.rb +29 -0
  83. data/lib/zm/client/license/licenses_collection.rb +28 -0
  84. data/lib/zm/client/license.rb +4 -0
  85. data/lib/zm/client/message/message.rb +225 -0
  86. data/lib/zm/client/message/messages_builder.rb +31 -0
  87. data/lib/zm/client/message/messages_collection.rb +111 -0
  88. data/lib/zm/client/message.rb +5 -0
  89. data/lib/zm/client/mountpoint/mountpoint.rb +95 -0
  90. data/lib/zm/client/mountpoint/mountpoints_builder.rb +38 -0
  91. data/lib/zm/client/mountpoint/mountpoints_collection.rb +61 -0
  92. data/lib/zm/client/mountpoint.rb +5 -0
  93. data/lib/zm/client/mta_queue/mta_queue.rb +60 -0
  94. data/lib/zm/client/mta_queue/mta_queues_builder.rb +26 -0
  95. data/lib/zm/client/mta_queue/mta_queues_collection.rb +95 -0
  96. data/lib/zm/client/mta_queue.rb +5 -0
  97. data/lib/zm/client/mta_queue_item/mta_queue_item.rb +51 -0
  98. data/lib/zm/client/mta_queue_item/mta_queue_items_builder.rb +27 -0
  99. data/lib/zm/client/mta_queue_item/mta_queue_items_collection.rb +99 -0
  100. data/lib/zm/client/mta_queue_item.rb +5 -0
  101. data/lib/zm/client/resource/resource.rb +149 -0
  102. data/lib/zm/client/resource/resources_builder.rb +29 -0
  103. data/lib/zm/client/resource/resources_collection.rb +41 -0
  104. data/lib/zm/client/resource.rb +5 -0
  105. data/lib/zm/client/search_folder/search_folder.rb +63 -0
  106. data/lib/zm/client/search_folder/search_folders_builder.rb +26 -0
  107. data/lib/zm/client/search_folder/search_folders_collection.rb +28 -0
  108. data/lib/zm/client/search_folder.rb +5 -0
  109. data/lib/zm/client/server/server.rb +516 -0
  110. data/lib/zm/client/server/servers_builder.rb +26 -0
  111. data/lib/zm/client/server/servers_collection.rb +37 -0
  112. data/lib/zm/client/server.rb +5 -0
  113. data/lib/zm/client/share/share.rb +60 -0
  114. data/lib/zm/client/share/shares_builder.rb +23 -0
  115. data/lib/zm/client/share/shares_collection.rb +48 -0
  116. data/lib/zm/client/share.rb +5 -0
  117. data/lib/zm/client/signature/signature.rb +62 -0
  118. data/lib/zm/client/signature/signature_jsns_builder.rb +29 -0
  119. data/lib/zm/client/signature/signatures_builder.rb +26 -0
  120. data/lib/zm/client/signature/signatures_collection.rb +28 -0
  121. data/lib/zm/client/signature.rb +6 -0
  122. data/lib/zm/client/tag/tag.rb +45 -0
  123. data/lib/zm/client/tag/tags_builder.rb +25 -0
  124. data/lib/zm/client/tag/tags_collection.rb +26 -0
  125. data/lib/zm/client/tag.rb +5 -0
  126. data/lib/zm/client/task/task.rb +74 -0
  127. data/lib/zm/client/task/tasks_builder.rb +31 -0
  128. data/lib/zm/client/task/tasks_collection.rb +100 -0
  129. data/lib/zm/client/task.rb +5 -0
  130. data/lib/zm/client/upload/upload.rb +154 -0
  131. data/lib/zm/client/upload.rb +3 -0
  132. data/lib/zm/client/version.rb +18 -0
  133. data/lib/zm/client.rb +5 -0
  134. data/lib/zm/modules/common/account_common.rb +71 -0
  135. data/lib/zm/modules/common/cos_common.rb +463 -0
  136. data/lib/zm/modules/common/dl_common.rb +36 -0
  137. data/lib/zm/modules/common/identity_common.rb +19 -0
  138. data/lib/zm/modules/common/resource_common.rb +59 -0
  139. data/lib/zm/modules/common/signature_common.rb +16 -0
  140. data/lib/zm/modules/common/zimbra-attrs.json +1 -0
  141. data/lib/zm/utils/thread_pool.rb +72 -0
  142. data/lib/zm-ruby-client.rb +1 -0
  143. data/test/accounts.rb +62 -0
  144. data/test/cluster_config.rb +30 -0
  145. data/test/coses.rb +26 -0
  146. data/test/domains.rb +70 -0
  147. data/zm-ruby-client.gemspec +24 -0
  148. metadata +244 -0
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # zm-ruby-client
2
+
3
+ Library to interface with Zimbra simply.
4
+
5
+ ## Examples of uses:
6
+
7
+ ### Connection:
8
+
9
+ ```ruby
10
+ admin = Zm::Client::Cluster.new(Zm::Client::ClusterConfig.new('config.json'))
11
+ admin.login
12
+ ````
13
+ or
14
+ ```ruby
15
+ config = Zm::Client::ClusterConfig.new do |cc|
16
+ cc.zimbra_admin_host = 'mail.domain.tld'
17
+ cc.zimbra_admin_scheme = 'https'
18
+ cc.zimbra_admin_port = 443
19
+ cc.zimbra_admin_login = 'admin@domain.tld'
20
+ cc.zimbra_admin_password = 'secret'
21
+ end
22
+ admin = Zm::Client::Cluster.new(config)
23
+ admin.login
24
+ ````
25
+
26
+ ### List all accounts
27
+
28
+ ```ruby
29
+ filter = '(&(mail=*@domain.tld)(zimbraLastLogonTimestamp<=20190225000000Z))'
30
+ accounts = admin.accounts.where(filter).all
31
+ ```
32
+
33
+ ### Find an account
34
+
35
+ ```ruby
36
+ account = admin.accounts.find_by name: 'maxime@domain.tld'
37
+ ```
38
+
39
+ ### Create an account
40
+
41
+ ```ruby
42
+ account = Zm::Client::Account.new(admin) do |acc|
43
+ acc.name = 'maxime@domain.tld'
44
+ end
45
+ account.zimbraMailQuota = 0
46
+ account.save
47
+ ```
data/SECURITY.md ADDED
@@ -0,0 +1,21 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Use this section to tell people about which versions of your project are
6
+ currently being supported with security updates.
7
+
8
+ | Version | Supported |
9
+ | ------- | ------------------ |
10
+ | 5.1.x | :white_check_mark: |
11
+ | 5.0.x | :x: |
12
+ | 4.0.x | :white_check_mark: |
13
+ | < 4.0 | :x: |
14
+
15
+ ## Reporting a Vulnerability
16
+
17
+ Use this section to tell people how to report a vulnerability.
18
+
19
+ Tell them where to go, how often they can expect to get an update on a
20
+ reported vulnerability, what to expect if the vulnerability is accepted or
21
+ declined, etc.
@@ -0,0 +1,345 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/modules/common/account_common'
4
+ # require_relative '../../modules/common/account_galsync'
5
+ require 'zm/client/common'
6
+ require 'zm/client/connector/rest_account'
7
+ require 'zm/client/signature'
8
+ require 'zm/client/folder'
9
+ require 'zm/client/mountpoint'
10
+ require 'zm/client/search_folder'
11
+ require 'zm/client/share'
12
+ require 'zm/client/tag'
13
+ require 'zm/client/ace'
14
+ require 'zm/client/contact'
15
+ require 'zm/client/appointment'
16
+ require 'zm/client/task'
17
+ require 'zm/client/document'
18
+ # require 'zm/client/data_source'
19
+ require 'zm/client/message'
20
+ require 'zm/client/identity'
21
+ require 'zm/client/upload'
22
+ require 'addressable/uri'
23
+
24
+ module Zm
25
+ module Client
26
+ # objectClass: zimbraAccount
27
+ class Account < Base::AdminObject
28
+ attr_reader :name, :id, :token
29
+ attr_writer :home_url
30
+ attr_accessor :password, :domainkey, :company, :zimbraCOSId, :zimbraMailHost, :zimbraMailTransport, :carLicense
31
+
32
+ def initialize(parent, attrs = {})
33
+ extend(AccountCommon)
34
+ super(parent)
35
+ @grantee_type = 'usr'.freeze
36
+ end
37
+
38
+ def init_by_hash(attrs)
39
+ attrs.each do |k, v|
40
+ self.instance_variable_set(arrow_name(k), v)
41
+ end
42
+ end
43
+
44
+ def to_h
45
+ hashmap = Hash[all_instance_variable_keys.map { |key| [key, instance_variable_get(arrow_name(key))] }]
46
+ hashmap.delete_if { |_, v| v.nil? }
47
+ hashmap
48
+ end
49
+
50
+ def all_instance_variable_keys
51
+ AccountCommon::ZM_ACCOUNT_ATTRS
52
+ end
53
+
54
+ def rest_account_connector
55
+ @rest_account_connector ||= RestAccountConnector.new
56
+ end
57
+
58
+ alias rac rest_account_connector
59
+
60
+ def logged?
61
+ !@token.nil?
62
+ end
63
+
64
+ def login
65
+ if @parent.logged?
66
+ admin_login
67
+ else
68
+ account_login
69
+ end
70
+ end
71
+
72
+ def account_login
73
+ if password
74
+ account_login_password
75
+ else
76
+ account_login_preauth
77
+ end
78
+ end
79
+
80
+ def account_login_preauth
81
+ domain_key
82
+ raise ZmError, 'domain key is required to login !' if @domainkey.nil?
83
+
84
+ @token = sacc.auth_preauth(@name, @domainkey)
85
+ end
86
+
87
+ def account_login_password
88
+ raise ZmError, 'password is required to login !' if password.nil?
89
+
90
+ @token = sacc.auth_password(@name, @password)
91
+ end
92
+
93
+ def admin_login
94
+ @token = sac.delegate_auth(@name)
95
+ end
96
+
97
+ def token_metadata
98
+ @token_metadata ||= TokenMetaData.new(@token)
99
+ end
100
+
101
+ def domain_name
102
+ @name.split('@').last
103
+ end
104
+
105
+ def domain_key
106
+ @domainkey ||= @parent.domain_key(domain_name)
107
+ end
108
+
109
+ def infos
110
+ @infos ||= read_infos
111
+ end
112
+
113
+ def read_infos
114
+ @infos = sacc.get_info(@token)[:Body][:GetInfoResponse]
115
+ @id = @infos[:id]
116
+ @used = @infos[:used]
117
+ @public_url = @infos[:publicURL]
118
+ @zimbraCOSId = @infos[:cos][:id]
119
+ @home_url = @infos[:rest]
120
+ end
121
+
122
+ def cos
123
+ @cos ||= @parent.coses.find_by(id: zimbraCOSId)
124
+ end
125
+
126
+ def used
127
+ @used ||= sac.get_mailbox(id)[:Body][:GetMailboxResponse][:mbox].first[:s]
128
+ end
129
+
130
+ def public_url
131
+ infos if @infos.nil?
132
+ @public_url
133
+ end
134
+
135
+ def home_url
136
+ infos if @infos.nil?
137
+ @home_url
138
+ end
139
+
140
+ def messages
141
+ @messages ||= MessagesCollection.new(self)
142
+ end
143
+
144
+ def folders
145
+ @folders ||= FoldersCollection.new(self)
146
+ end
147
+
148
+ def mountpoints
149
+ @mountpointss ||= MountPointsCollection.new(self)
150
+ end
151
+
152
+ def search_folders
153
+ @search_folders ||= SearchFoldersCollection.new(self)
154
+ end
155
+
156
+ def identities
157
+ @identities ||= IdentitiesCollection.new(self)
158
+ end
159
+
160
+ def shares
161
+ @shares ||= SharesCollection.new(self)
162
+ end
163
+
164
+ def contacts
165
+ @contacts ||= ContactsCollection.new(self)
166
+ end
167
+
168
+ def appointments
169
+ @appointments ||= AppointmentsCollection.new(self)
170
+ end
171
+
172
+ def tags
173
+ @tags ||= TagsCollection.new(self)
174
+ end
175
+
176
+ def tasks
177
+ @tasks ||= TasksCollection.new(self)
178
+ end
179
+
180
+ def aces
181
+ @aces ||= AcesCollection.new(self)
182
+ end
183
+ alias rights aces
184
+
185
+ def signatures
186
+ @signatures ||= SignaturesCollection.new(self)
187
+ end
188
+
189
+ def data_sources
190
+ @data_sources ||= DataSourcesCollection.new sac, self
191
+ end
192
+
193
+ def documents
194
+ @documents ||= DocumentsCollection.new(self)
195
+ end
196
+
197
+ def message_folders
198
+ @message_folders ||= folders.all.select { |f| f.view == Zm::Client::FolderView::MESSAGE.to_s }
199
+ end
200
+
201
+ def contact_folders
202
+ @contact_folders ||= folders.all.select { |f| f.view == Zm::Client::FolderView::CONTACT.to_s }
203
+ end
204
+
205
+ def calendar_folders
206
+ @calendar_folders ||= folders.all.select { |f| f.view == Zm::Client::FolderView::APPOINTMENT.to_s }
207
+ end
208
+
209
+ def task_folders
210
+ @task_folders ||= folders.all.select { |f| f.view == Zm::Client::FolderView::TASK.to_s }
211
+ end
212
+
213
+ def document_folders
214
+ @document_folders ||= folders.all.select { |f| f.view == Zm::Client::FolderView::DOCUMENT.to_s }
215
+ end
216
+
217
+ def delete!
218
+ sac.delete_account(@id)
219
+ end
220
+
221
+ def password!(new_password)
222
+ sac.set_password(@id, new_password)
223
+ @password = new_password
224
+ end
225
+
226
+ def update!(hash)
227
+ sac.modify_account(@id, hash)
228
+
229
+ hash.each do |k, v|
230
+ arrow_attr_sym = "@#{k}".to_sym
231
+
232
+ if v.respond_to?(:empty?) && v.empty?
233
+ self.remove_instance_variable(arrow_attr_sym) if self.instance_variable_get(arrow_attr_sym)
234
+ else
235
+ self.instance_variable_set(arrow_attr_sym, v)
236
+ end
237
+ end
238
+ end
239
+
240
+ def modify!
241
+ attrs_to_modify = instance_variables_array(attrs_write)
242
+ return if attrs_to_modify.empty?
243
+
244
+ sac.modify_account(@id, attrs_to_modify)
245
+ end
246
+
247
+ def create!
248
+ rep = sac.create_account(
249
+ @name,
250
+ @password,
251
+ instance_variables_array(attrs_write)
252
+ )
253
+ @id = rep[:Body][:CreateAccountResponse][:account].first[:id]
254
+ end
255
+
256
+ def aliases
257
+ @aliases ||= set_aliases
258
+ end
259
+
260
+ def set_aliases
261
+ return [] if zimbraMailAlias.nil?
262
+ return [zimbraMailAlias] if zimbraMailAlias.is_a?(String)
263
+ zimbraMailAlias
264
+ end
265
+
266
+ def add_alias!(email)
267
+ sac.add_account_alias(@id, email)
268
+ aliases.push(email)
269
+ end
270
+
271
+ def remove_alias!(email)
272
+ sac.remove_account_alias(@id, email)
273
+ aliases.delete(email)
274
+ end
275
+
276
+ def rename!(email)
277
+ sac.rename_account(@id, email)
278
+ @name = email
279
+ end
280
+
281
+ def local_transport
282
+ raise Zm::Client::SoapError, 'zimbraMailHost is null' if zimbraMailHost.nil?
283
+
284
+ "lmtp:#{zimbraMailHost}:7025"
285
+ end
286
+
287
+ def local_transport!
288
+ update!(zimbraMailTransport: local_transport)
289
+ end
290
+
291
+ def is_local_transport?
292
+ return nil unless zimbraMailTransport
293
+
294
+ zimbraMailTransport.start_with?('lmtp')
295
+ end
296
+
297
+ def is_external_transport?
298
+ return nil unless zimbraMailTransport
299
+
300
+ zimbraMailTransport.start_with?('smtp')
301
+ end
302
+
303
+ def uploader
304
+ @uploader ||= Upload.new(self)
305
+ end
306
+
307
+ def last_logon
308
+ @last_logon ||= Time.parse zimbraLastLogonTimestamp unless zimbraLastLogonTimestamp.nil?
309
+ end
310
+
311
+ def created_at
312
+ @created_at ||= Time.parse zimbraCreateTimestamp unless zimbraCreateTimestamp.nil?
313
+ end
314
+
315
+ def flush_cache!
316
+ sac.flush_cache('account', 1, @id)
317
+ end
318
+
319
+ def move_mailbox(server)
320
+ raise Zm::Client::SoapError, 'zimbraMailHost is null' if zimbraMailHost.nil?
321
+
322
+ sac.move_mailbox(@name, zimbraMailHost, server.name, server.id)
323
+ end
324
+
325
+ def is_on_to_move?(server)
326
+ resp = sac.query_mailbox_move(@name, server.id)
327
+ resp[:Body][:QueryMailboxMoveResponse][:account].nil?
328
+ end
329
+
330
+ def memberships
331
+ @memberships ||= AccountDlsMembershipCollection.new(self)
332
+ end
333
+
334
+ def dls_owner
335
+ @dls_owner ||= AccountDlsOwnerCollection.new(self)
336
+ end
337
+
338
+ def init_from_json(json)
339
+ @used = json[:used] if json[:used]
340
+ @zimbraMailQuota = json[:limit] if json[:limit]
341
+ super(json)
342
+ end
343
+ end
344
+ end
345
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # Collection Account dls membership
6
+ class AccountDlsMembershipCollection < Base::ObjectsCollection
7
+ def initialize(parent)
8
+ @parent = parent
9
+ end
10
+
11
+ private
12
+
13
+ def make_query
14
+ @parent.sac.get_account_membership(@parent.id, :id)
15
+ end
16
+
17
+ def build_response
18
+ DistributionListsBuilder.new(@parent, make_query).make
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # Collection Account dls membership
6
+ class AccountDlsOwnerCollection < Base::ObjectsCollection
7
+ def initialize(parent)
8
+ @parent = parent
9
+ end
10
+
11
+ private
12
+
13
+ def make_query
14
+ @parent.sac.search_directory("(zimbraACE=#{@parent.id} usr ownDistList)", SoapUtils::MAX_RESULT, nil, nil, nil, nil, nil, nil, SearchType::DL)
15
+ end
16
+
17
+ def build_response
18
+ DistributionListsBuilder.new(@parent, make_query).make
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class factory [accounts]
6
+ class AccountsBuilder < Base::ObjectsBuilder
7
+ def initialize(parent, json)
8
+ super(parent, json)
9
+ @child_class = Account
10
+ end
11
+
12
+ private
13
+
14
+ def json_items
15
+ @json_items ||= @json[:Body][json_key][:account]
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # Collection Accounts
6
+ class AccountsCollection < Base::ObjectsCollection
7
+ def initialize(parent)
8
+ @child_class = Account
9
+ @parent = parent
10
+ reset_query_params
11
+ end
12
+
13
+ def ldap
14
+ @apply_cos = 0
15
+ self
16
+ end
17
+
18
+ def find_by(hash)
19
+ rep = sac.get_account(hash.values.first, hash.keys.first, attrs_comma, @apply_cos)
20
+ reset_query_params
21
+ entry = rep[:Body][:GetAccountResponse][:account].first
22
+
23
+ build_from_entry(entry)
24
+ end
25
+
26
+ def find_all_quotas(domain_name = nil, target_server_id = nil)
27
+ json = sac.get_quota_usage(domain_name, @all_servers, @limit, @offset, @sort_by, @sort_ascending, @refresh, target_server_id)
28
+ reset_query_params
29
+ AccountsBuilder.new(@parent, json).make
30
+ end
31
+
32
+ private
33
+
34
+ def build_response
35
+ AccountsBuilder.new(@parent, make_query).make
36
+ end
37
+
38
+ def reset_query_params
39
+ super
40
+ @search_type = SearchType::ACCOUNT
41
+ @attrs = SearchType::Attributes::ACCOUNT.dup
42
+ @all_servers = 1
43
+ @refresh = 0
44
+ @apply_cos = 1
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/account/account'
4
+ require 'zm/client/account/accounts_builder'
5
+ require 'zm/client/account/accounts_collection'
6
+ require 'zm/client/account/account_dls_membership_collection'
7
+ require 'zm/client/account/account_dls_owner_collection'
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class account ace
6
+ class Ace < Base::AccountObject
7
+
8
+ INSTANCE_VARIABLE_KEYS = %i[zid gt right d]
9
+
10
+ attr_accessor *INSTANCE_VARIABLE_KEYS
11
+
12
+ def init_from_json(json)
13
+ INSTANCE_VARIABLE_KEYS.each do |key|
14
+ var_name = "@#{key}"
15
+ instance_variable_set(var_name, json[key])
16
+ end
17
+ end
18
+
19
+ def create!
20
+ # todo
21
+ end
22
+
23
+ def delete!
24
+ # todo
25
+ end
26
+
27
+ def rename!(new_name)
28
+ # todo
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class factory [aces]
6
+ class AcesBuilder < Base::ObjectsBuilder
7
+ def initialize(parent, json)
8
+ @parent = parent
9
+ @json = json
10
+ end
11
+
12
+ def make
13
+ root = @json[:Body][:GetRightsResponse][:ace]
14
+ return [] if root.nil?
15
+
16
+ root = [root] unless root.is_a?(Array)
17
+ root.map do |s|
18
+ ace = Ace.new(@parent)
19
+ ace.init_from_json(s)
20
+ ace
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # collection account aces
6
+ class AcesCollection < Base::ObjectsCollection
7
+ def initialize(parent)
8
+ @parent = parent
9
+ reset_query_params
10
+ end
11
+
12
+ def new
13
+ ace = Ace.new(@parent)
14
+ yield(ace) if block_given?
15
+ ace
16
+ end
17
+
18
+ def rights(*rights)
19
+ @rights = rights
20
+ self
21
+ end
22
+
23
+ private
24
+
25
+ def build_response
26
+ rep = @parent.sacc.get_rights(@parent.token, @rights)
27
+ ab = AcesBuilder.new @parent, rep
28
+ ab.make
29
+ end
30
+
31
+ def reset_query_params
32
+ @rights = %i[sendAs sendOnBehalfOf]
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/ace/ace'
4
+ require 'zm/client/ace/aces_builder'
5
+ require 'zm/client/ace/aces_collection'