zm-ruby-client 0.14.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +4 -5
- data/README.md +6 -0
- data/lib/zm/client/account/account.rb +29 -17
- data/lib/zm/client/account/account_jsns_initializer.rb +44 -0
- data/lib/zm/client/account/accounts_builder.rb +6 -3
- data/lib/zm/client/account/accounts_collection.rb +11 -20
- data/lib/zm/client/account.rb +1 -0
- data/lib/zm/client/ace/ace.rb +22 -9
- data/lib/zm/client/ace/ace_jsns_builder.rb +38 -0
- data/lib/zm/client/ace/ace_jsns_initializer.rb +26 -0
- data/lib/zm/client/ace/aces_builder.rb +6 -9
- data/lib/zm/client/ace/aces_collection.rb +23 -9
- data/lib/zm/client/ace.rb +2 -0
- data/lib/zm/client/appointment/appointment.rb +9 -6
- data/lib/zm/client/appointment/appointments_collection.rb +6 -90
- data/lib/zm/client/backup/backup.rb +8 -4
- data/lib/zm/client/base/account_object.rb +34 -0
- data/lib/zm/client/base/account_objects_collection.rb +14 -0
- data/lib/zm/client/base/account_search_objects_collection.rb +125 -0
- data/lib/zm/client/base/admin_object.rb +6 -0
- data/lib/zm/client/base/admin_objects_collection.rb +65 -0
- data/lib/zm/client/base/base_jsns_builder.rb +19 -0
- data/lib/zm/client/base/base_jsns_initializer.rb +29 -0
- data/lib/zm/client/base/folder_object.rb +41 -0
- data/lib/zm/client/base/ldap_filter.rb +33 -0
- data/lib/zm/client/base/object.rb +19 -0
- data/lib/zm/client/base/objects_builder.rb +4 -0
- data/lib/zm/client/base/objects_collection.rb +11 -32
- data/lib/zm/client/base/zimbra_attribute.rb +119 -0
- data/lib/zm/client/base/zimbra_attributes_collection.rb +38 -0
- data/lib/zm/client/base.rb +15 -0
- data/lib/zm/client/cluster/cluster.rb +43 -7
- data/lib/zm/client/cluster/cluster_config.rb +19 -17
- data/lib/zm/client/connector/rest_account.rb +0 -3
- data/lib/zm/client/connector/soap_account.rb +76 -177
- data/lib/zm/client/connector/soap_admin.rb +82 -51
- data/lib/zm/client/connector/soap_base.rb +12 -12
- data/lib/zm/client/contact/contact.rb +2 -1
- data/lib/zm/client/contact/contacts_builder.rb +3 -13
- data/lib/zm/client/contact/contacts_collection.rb +6 -12
- data/lib/zm/client/cos/cos.rb +11 -6
- data/lib/zm/client/cos/coses_builder.rb +1 -16
- data/lib/zm/client/cos/coses_collection.rb +6 -9
- data/lib/zm/client/distributionlist/distributionlist.rb +44 -6
- data/lib/zm/client/distributionlist/distributionlists_builder.rb +2 -17
- data/lib/zm/client/distributionlist/distributionlists_collection.rb +4 -11
- data/lib/zm/client/distributionlist/dls_membership_collection.rb +24 -0
- data/lib/zm/client/distributionlist.rb +1 -0
- data/lib/zm/client/document/document.rb +7 -9
- data/lib/zm/client/domain/domain.rb +11 -6
- data/lib/zm/client/domain/domain_accounts_collection.rb +13 -0
- data/lib/zm/client/domain/domains_builder.rb +1 -19
- data/lib/zm/client/domain/domains_collection.rb +7 -10
- data/lib/zm/client/domain.rb +1 -0
- data/lib/zm/client/folder/folder.rb +50 -124
- data/lib/zm/client/folder/folder_grant.rb +44 -22
- data/lib/zm/client/folder/folder_grant_jsns_builder.rb +43 -0
- data/lib/zm/client/folder/folder_grants_collection.rb +35 -0
- data/lib/zm/client/folder/folder_jsns_builder.rb +132 -0
- data/lib/zm/client/folder/folder_jsns_initializer.rb +49 -0
- data/lib/zm/client/folder/folder_retention_policies_collection.rb +40 -0
- data/lib/zm/client/folder/folder_retention_policy.rb +8 -30
- data/lib/zm/client/folder/folders_builder.rb +2 -2
- data/lib/zm/client/folder/folders_collection.rb +21 -19
- data/lib/zm/client/folder/folders_jsns_builder.rb +22 -0
- data/lib/zm/client/folder.rb +6 -0
- data/lib/zm/client/identity/identities_builder.rb +4 -15
- data/lib/zm/client/identity/identities_collection.rb +7 -13
- data/lib/zm/client/identity/identity.rb +19 -19
- data/lib/zm/client/message/message.rb +111 -21
- data/lib/zm/client/message/messages_builder.rb +1 -1
- data/lib/zm/client/message/messages_collection.rb +10 -92
- data/lib/zm/client/mountpoint/mountpoint.rb +15 -68
- data/lib/zm/client/mountpoint/mountpoint_jsns_builder.rb +100 -0
- data/lib/zm/client/mountpoint/mountpoint_jsns_initializer.rb +33 -0
- data/lib/zm/client/mountpoint/mountpoints_builder.rb +1 -1
- data/lib/zm/client/mountpoint/mountpoints_collection.rb +14 -23
- data/lib/zm/client/mountpoint.rb +2 -0
- data/lib/zm/client/resource/resource.rb +5 -5
- data/lib/zm/client/resource/resources_builder.rb +1 -16
- data/lib/zm/client/resource/resources_collection.rb +5 -13
- data/lib/zm/client/search_folder/search_folder.rb +19 -39
- data/lib/zm/client/search_folder/search_folder_jsns_builder.rb +86 -0
- data/lib/zm/client/search_folder/search_folder_jsns_initializer.rb +33 -0
- data/lib/zm/client/search_folder/search_folders_builder.rb +7 -11
- data/lib/zm/client/search_folder/search_folders_collection.rb +7 -15
- data/lib/zm/client/search_folder.rb +2 -0
- data/lib/zm/client/server/server.rb +7 -14
- data/lib/zm/client/server/server_accounts_collection.rb +19 -0
- data/lib/zm/client/server/servers_builder.rb +4 -16
- data/lib/zm/client/server/servers_collection.rb +5 -10
- data/lib/zm/client/server.rb +1 -0
- data/lib/zm/client/share/share.rb +2 -9
- data/lib/zm/client/share/shares_builder.rb +3 -12
- data/lib/zm/client/signature/signature.rb +17 -13
- data/lib/zm/client/signature/signature_jsns_builder.rb +5 -1
- data/lib/zm/client/signature/signature_jsns_initializer.rb +25 -0
- data/lib/zm/client/signature/signatures_builder.rb +7 -11
- data/lib/zm/client/signature/signatures_collection.rb +6 -14
- data/lib/zm/client/signature.rb +1 -0
- data/lib/zm/client/tag/tag.rb +27 -20
- data/lib/zm/client/tag/tag_jsns_builder.rb +55 -0
- data/lib/zm/client/tag/tag_jsns_initializer.rb +26 -0
- data/lib/zm/client/tag/tags_builder.rb +6 -9
- data/lib/zm/client/tag/tags_collection.rb +6 -12
- data/lib/zm/client/tag.rb +2 -0
- data/lib/zm/client/task/tasks_collection.rb +6 -90
- data/lib/zm/client/upload/upload.rb +1 -1
- data/lib/zm/client/version.rb +1 -1
- data/lib/zm/modules/common/dl_common.rb +3 -1
- data/lib/zm/modules/common/zimbra-attrs.json.bak +1 -0
- data/lib/zm/modules/zm_logger.rb +24 -0
- data/lib/zm/modules/zm_model.rb +41 -0
- data/test/accounts.rb +15 -1
- data/test/ace.rb +50 -0
- data/test/cluster.rb +41 -0
- data/test/cluster_zimbra_attributes.rb +38 -0
- data/test/folder.rb +125 -0
- data/test/folder_grant.rb +51 -0
- data/test/mountpoint.rb +49 -0
- data/test/retention_policies.rb +40 -0
- data/test/search_folder.rb +67 -0
- data/test/signature.rb +53 -0
- data/test/tag.rb +65 -0
- data/test/zimbra_attributes.rb +35 -0
- data/zm-ruby-client.gemspec +15 -10
- metadata +53 -26
- data/lib/zm/client/connector/soap_xml_builder.rb +0 -68
|
@@ -2,22 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative 'soap_base'
|
|
4
4
|
require_relative 'soap_error'
|
|
5
|
-
require_relative 'soap_xml_builder'
|
|
6
5
|
|
|
7
6
|
module Zm
|
|
8
7
|
module Client
|
|
9
8
|
class SoapAdminConnector < SoapBaseConnector
|
|
10
|
-
|
|
11
|
-
SOAP_PATH = '/service/admin/soap/'
|
|
12
9
|
ADMINSPACE = 'urn:zimbraAdmin'
|
|
13
|
-
A_NODE_PROC =
|
|
10
|
+
A_NODE_PROC = ->(n) { { n: n.first, _content: n.last } }
|
|
14
11
|
|
|
15
12
|
attr_accessor :token
|
|
16
13
|
|
|
17
14
|
def initialize(scheme, host, port)
|
|
18
|
-
|
|
19
|
-
@uri = URI::HTTP.new(scheme, nil, host, port, nil, SOAP_PATH, nil, nil, nil)
|
|
20
|
-
init_curl_client
|
|
15
|
+
super(scheme, host, port, '/service/admin/soap/')
|
|
21
16
|
end
|
|
22
17
|
|
|
23
18
|
def auth(mail, password)
|
|
@@ -47,7 +42,7 @@ module Zm
|
|
|
47
42
|
def count_object(type)
|
|
48
43
|
soap_name = :CountObjectsRequest
|
|
49
44
|
body = init_hash_request(soap_name)
|
|
50
|
-
req = { type: type}
|
|
45
|
+
req = { type: type }
|
|
51
46
|
body[:Body][soap_name].merge!(req)
|
|
52
47
|
curl_request(body)
|
|
53
48
|
end
|
|
@@ -90,7 +85,7 @@ module Zm
|
|
|
90
85
|
curl_request(body)
|
|
91
86
|
end
|
|
92
87
|
|
|
93
|
-
def create_data_source(name, account_id, type, attrs = {
|
|
88
|
+
def create_data_source(name, account_id, type, attrs = {})
|
|
94
89
|
req = {
|
|
95
90
|
id: account_id,
|
|
96
91
|
dataSource: {
|
|
@@ -141,23 +136,28 @@ module Zm
|
|
|
141
136
|
curl_request(body)
|
|
142
137
|
end
|
|
143
138
|
|
|
144
|
-
def create_cos(name, attrs =
|
|
145
|
-
req = { name: name }
|
|
139
|
+
def create_cos(name, attrs = [])
|
|
140
|
+
req = { name: { _content: name } }
|
|
141
|
+
req[:a] = attrs.map do |i|
|
|
142
|
+
if i.last.is_a?(Array)
|
|
143
|
+
i.last.map do |j|
|
|
144
|
+
[i.first, j]
|
|
145
|
+
end
|
|
146
|
+
else
|
|
147
|
+
[i]
|
|
148
|
+
end
|
|
149
|
+
end.flatten(1).map(&A_NODE_PROC)
|
|
150
|
+
|
|
146
151
|
body = init_hash_request(:CreateCosRequest)
|
|
147
152
|
body[:Body][:CreateCosRequest].merge!(req)
|
|
148
|
-
|
|
149
|
-
# a: attrs.to_a.map { |n| { n: n.first, _content: n.last } }
|
|
150
|
-
# puts SoapXmlBuilder.new(body).to_xml
|
|
151
|
-
# todo ne fonctionne pas !
|
|
152
|
-
curl_xml(SoapXmlBuilder.new(body).to_xml)
|
|
153
|
+
curl_request(body)
|
|
153
154
|
end
|
|
154
155
|
|
|
155
|
-
def modify_cos(id,
|
|
156
|
+
def modify_cos(id, _attrs = nil)
|
|
156
157
|
# req = { _jsns: ADMINSPACE, id: id, a: attrs.to_a.map{ |n| { n: n.first, _content: n.last } } }
|
|
157
158
|
req = { _jsns: ADMINSPACE, id: id }
|
|
158
159
|
body = { Body: { ModifyCosRequest: req } }.merge(hash_header(@token))
|
|
159
|
-
#
|
|
160
|
-
# todo ne fonctionne pas !
|
|
160
|
+
# TODO: ne fonctionne pas !
|
|
161
161
|
# peut-être seul la version xml fonctionne. Il faudrait créer une fonction qui converti le json en xml
|
|
162
162
|
curl_request(body)
|
|
163
163
|
end
|
|
@@ -165,11 +165,18 @@ module Zm
|
|
|
165
165
|
def create_account(name, password = nil, attrs = [])
|
|
166
166
|
soap_name = :CreateAccountRequest
|
|
167
167
|
req = { name: name, password: password }.reject { |_, v| v.nil? }
|
|
168
|
-
req[:a] = attrs.map
|
|
168
|
+
req[:a] = attrs.map do |i|
|
|
169
|
+
if i.last.is_a?(Array)
|
|
170
|
+
i.last.map do |j|
|
|
171
|
+
[i.first, j]
|
|
172
|
+
end
|
|
173
|
+
else
|
|
174
|
+
[i]
|
|
175
|
+
end
|
|
176
|
+
end.flatten(1).map(&A_NODE_PROC)
|
|
169
177
|
# req[:a] = attrs.map{|i|i.last.is_a?(Array) ? i.last.map{|j|[i.first, j]} : [i]}.flatten(1).map { |n| { n: n.first, _content: n.last } }
|
|
170
178
|
body = init_hash_request(soap_name)
|
|
171
179
|
body[:Body][soap_name].merge!(req)
|
|
172
|
-
# puts body
|
|
173
180
|
curl_request(body)
|
|
174
181
|
end
|
|
175
182
|
|
|
@@ -177,7 +184,15 @@ module Zm
|
|
|
177
184
|
soap_name = :CreateCalendarResourceRequest
|
|
178
185
|
req = { name: name, password: password }
|
|
179
186
|
req.reject! { |_, v| v.nil? }
|
|
180
|
-
req[:a] = attrs.map
|
|
187
|
+
req[:a] = attrs.map do |i|
|
|
188
|
+
if i.last.is_a?(Array)
|
|
189
|
+
i.last.map do |j|
|
|
190
|
+
[i.first, j]
|
|
191
|
+
end
|
|
192
|
+
else
|
|
193
|
+
[i]
|
|
194
|
+
end
|
|
195
|
+
end.flatten(1).map(&A_NODE_PROC)
|
|
181
196
|
body = init_hash_request(soap_name)
|
|
182
197
|
body[:Body][soap_name].merge!(req)
|
|
183
198
|
curl_request(body)
|
|
@@ -186,10 +201,17 @@ module Zm
|
|
|
186
201
|
def create_distribution_list(name, attrs = [])
|
|
187
202
|
soap_name = :CreateDistributionListRequest
|
|
188
203
|
req = { name: name }
|
|
189
|
-
req[:a] = attrs.map
|
|
204
|
+
req[:a] = attrs.map do |i|
|
|
205
|
+
if i.last.is_a?(Array)
|
|
206
|
+
i.last.map do |j|
|
|
207
|
+
[i.first, j]
|
|
208
|
+
end
|
|
209
|
+
else
|
|
210
|
+
[i]
|
|
211
|
+
end
|
|
212
|
+
end.flatten(1).map(&A_NODE_PROC)
|
|
190
213
|
body = init_hash_request(soap_name)
|
|
191
214
|
body[:Body][soap_name].merge!(req)
|
|
192
|
-
# puts body
|
|
193
215
|
curl_request(body)
|
|
194
216
|
end
|
|
195
217
|
|
|
@@ -215,14 +237,6 @@ module Zm
|
|
|
215
237
|
curl_request(body)
|
|
216
238
|
end
|
|
217
239
|
|
|
218
|
-
def set_password(id, new_password)
|
|
219
|
-
soap_name = :SetPasswordRequest
|
|
220
|
-
req = { id: id, newPassword: new_password }
|
|
221
|
-
body = init_hash_request(soap_name)
|
|
222
|
-
body[:Body][soap_name].merge!(req)
|
|
223
|
-
curl_request(body)
|
|
224
|
-
end
|
|
225
|
-
|
|
226
240
|
def add_account_alias(id, email)
|
|
227
241
|
generic_alias(:AddAccountAliasRequest, id, email)
|
|
228
242
|
end
|
|
@@ -231,7 +245,6 @@ module Zm
|
|
|
231
245
|
generic_alias(:RemoveAccountAliasRequest, id, email)
|
|
232
246
|
end
|
|
233
247
|
|
|
234
|
-
|
|
235
248
|
def rename_account(id, email)
|
|
236
249
|
generic_rename(:RenameAccountRequest, id, email)
|
|
237
250
|
end
|
|
@@ -245,7 +258,7 @@ module Zm
|
|
|
245
258
|
end
|
|
246
259
|
|
|
247
260
|
def generic_members(soap_name, id, emails)
|
|
248
|
-
req = { id: id, dlm: emails.map { |email| {_content: email} } }
|
|
261
|
+
req = { id: id, dlm: emails.map { |email| { _content: email } } }
|
|
249
262
|
body = init_hash_request(soap_name)
|
|
250
263
|
body[:Body][soap_name].merge!(req)
|
|
251
264
|
curl_request(body)
|
|
@@ -263,7 +276,6 @@ module Zm
|
|
|
263
276
|
req = { id: id, alias: email }
|
|
264
277
|
body = init_hash_request(soap_name)
|
|
265
278
|
body[:Body][soap_name].merge!(req)
|
|
266
|
-
# puts body
|
|
267
279
|
curl_request(body)
|
|
268
280
|
end
|
|
269
281
|
|
|
@@ -284,7 +296,6 @@ module Zm
|
|
|
284
296
|
body = init_hash_request(:GetDomainRequest)
|
|
285
297
|
body[:Body][:GetDomainRequest].merge!(req)
|
|
286
298
|
# TODO: tester param attrs
|
|
287
|
-
# puts body
|
|
288
299
|
curl_request(body)
|
|
289
300
|
end
|
|
290
301
|
|
|
@@ -309,7 +320,6 @@ module Zm
|
|
|
309
320
|
req[:attrs] = attrs unless attrs.nil? || attrs.empty?
|
|
310
321
|
body = init_hash_request(soap_name)
|
|
311
322
|
body[:Body][soap_name].merge!(req)
|
|
312
|
-
# puts body
|
|
313
323
|
curl_request(body)
|
|
314
324
|
end
|
|
315
325
|
|
|
@@ -341,6 +351,16 @@ module Zm
|
|
|
341
351
|
curl_request(body)
|
|
342
352
|
end
|
|
343
353
|
|
|
354
|
+
def get_distribution_list_membership(by_key, by = 'name', limit = nil, offset = nil)
|
|
355
|
+
soap_name = :GetDistributionListMembershipRequest
|
|
356
|
+
req = { dl: { by: by, _content: by_key }, limit: limit, offset: offset }
|
|
357
|
+
req.reject! { |_, v| v.nil? }
|
|
358
|
+
body = init_hash_request(soap_name)
|
|
359
|
+
body[:Body][soap_name].merge!(req)
|
|
360
|
+
|
|
361
|
+
curl_request(body)
|
|
362
|
+
end
|
|
363
|
+
|
|
344
364
|
def delete_account(id)
|
|
345
365
|
generic_delete(:DeleteAccountRequest, id)
|
|
346
366
|
end
|
|
@@ -369,8 +389,8 @@ module Zm
|
|
|
369
389
|
curl_request(body)
|
|
370
390
|
end
|
|
371
391
|
|
|
372
|
-
def search_directory(query = nil, maxResults = nil, limit = nil, offset = nil, domain = nil, applyCos = nil,
|
|
373
|
-
|
|
392
|
+
def search_directory(query = nil, maxResults = nil, limit = nil, offset = nil, domain = nil, applyCos = nil,
|
|
393
|
+
applyConfig = nil, sortBy = nil, types = nil, sortAscending = nil, countOnly = nil, attrs = nil)
|
|
374
394
|
# Désactivé car moins performant !
|
|
375
395
|
# req = Hash[method(__method__).parameters.map{ |p|[p.last, (eval p.last.to_s)] }].select!{ |k,v|!v.nil? }
|
|
376
396
|
|
|
@@ -394,12 +414,12 @@ module Zm
|
|
|
394
414
|
# body = { Body: { SearchDirectoryRequest: { _jsns: ADMINSPACE } } }.merge(hash_header(@token))
|
|
395
415
|
body = init_hash_request(soap_name)
|
|
396
416
|
body[:Body][soap_name].merge!(req)
|
|
397
|
-
# puts body
|
|
398
417
|
|
|
399
418
|
curl_request(body)
|
|
400
419
|
end
|
|
401
420
|
|
|
402
|
-
def get_quota_usage(domain = nil, allServers = nil, limit = nil, offset = nil, sortBy = nil, sortAscending = nil,
|
|
421
|
+
def get_quota_usage(domain = nil, allServers = nil, limit = nil, offset = nil, sortBy = nil, sortAscending = nil,
|
|
422
|
+
refresh = nil, target_server_id = nil)
|
|
403
423
|
soap_name = :GetQuotaUsageRequest
|
|
404
424
|
req = {
|
|
405
425
|
domain: domain,
|
|
@@ -420,20 +440,20 @@ module Zm
|
|
|
420
440
|
def get_mailbox(id)
|
|
421
441
|
soap_name = :GetMailboxRequest
|
|
422
442
|
req = {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
443
|
+
mbox: {
|
|
444
|
+
id: id
|
|
445
|
+
}
|
|
426
446
|
}
|
|
427
447
|
body = init_hash_request(soap_name)
|
|
428
448
|
body[:Body][soap_name].merge!(req)
|
|
429
449
|
curl_request(body)
|
|
430
450
|
end
|
|
431
451
|
|
|
432
|
-
def flush_cache(type, all_servers, id = nil)
|
|
452
|
+
def flush_cache(type, all_servers, id = nil, target_server_id = nil)
|
|
433
453
|
soap_name = :FlushCacheRequest
|
|
434
454
|
req = { cache: { type: type, allServers: all_servers } }
|
|
435
455
|
req[:cache].merge!({ entry: { by: :id, _content: id } }) unless id.nil?
|
|
436
|
-
body = init_hash_request(soap_name)
|
|
456
|
+
body = init_hash_request(soap_name, target_server_id)
|
|
437
457
|
body[:Body][soap_name].merge!(req)
|
|
438
458
|
curl_request(body)
|
|
439
459
|
end
|
|
@@ -467,7 +487,6 @@ module Zm
|
|
|
467
487
|
body = init_hash_request(soap_name)
|
|
468
488
|
req = { server: { name: server_name } }
|
|
469
489
|
body[:Body][soap_name].merge!(req)
|
|
470
|
-
# puts body.to_json
|
|
471
490
|
curl_request(body)
|
|
472
491
|
end
|
|
473
492
|
|
|
@@ -495,7 +514,6 @@ module Zm
|
|
|
495
514
|
}
|
|
496
515
|
}
|
|
497
516
|
body[:Body][soap_name].merge!(req)
|
|
498
|
-
# puts body.to_json
|
|
499
517
|
curl_request(body)
|
|
500
518
|
end
|
|
501
519
|
|
|
@@ -505,7 +523,8 @@ module Zm
|
|
|
505
523
|
soap_name = :MailQueueActionRequest
|
|
506
524
|
value = [value] unless value.is_a?(Array)
|
|
507
525
|
body = init_hash_request(soap_name)
|
|
508
|
-
req = { server: { name: server_name,
|
|
526
|
+
req = { server: { name: server_name,
|
|
527
|
+
queue: { name: queue_name, action: { op: op, by: by, _content: value.join(',') } } } }
|
|
509
528
|
body[:Body][soap_name].merge!(req)
|
|
510
529
|
curl_request(body)
|
|
511
530
|
end
|
|
@@ -515,9 +534,21 @@ module Zm
|
|
|
515
534
|
body = init_hash_request(soap_name, dest_id)
|
|
516
535
|
req = { query: {} }
|
|
517
536
|
body[:Body][soap_name].merge!(req)
|
|
518
|
-
# puts body
|
|
519
537
|
curl_request(body)
|
|
520
|
-
|
|
538
|
+
end
|
|
539
|
+
|
|
540
|
+
def set_password(id, new_password)
|
|
541
|
+
soap_name = :SetPasswordRequest
|
|
542
|
+
body = init_hash_request(soap_name)
|
|
543
|
+
req = { id: id, newPassword: new_password }
|
|
544
|
+
body[:Body][soap_name].merge!(req)
|
|
545
|
+
curl_request(body)
|
|
546
|
+
end
|
|
547
|
+
|
|
548
|
+
def get_version_info
|
|
549
|
+
soap_name = :GetVersionInfoRequest
|
|
550
|
+
body = init_hash_request(soap_name)
|
|
551
|
+
curl_request(body)
|
|
521
552
|
end
|
|
522
553
|
|
|
523
554
|
def init_hash_request(soap_name, target_server = nil)
|
|
@@ -16,6 +16,13 @@ module Zm
|
|
|
16
16
|
}.freeze
|
|
17
17
|
BODY = :Body
|
|
18
18
|
|
|
19
|
+
def initialize(scheme, host, port, soap_path)
|
|
20
|
+
extend(ZmLogger)
|
|
21
|
+
@verbose = false
|
|
22
|
+
@uri = URI::HTTP.new(scheme, nil, host, port, nil, soap_path, nil, nil, nil)
|
|
23
|
+
init_curl_client
|
|
24
|
+
end
|
|
25
|
+
|
|
19
26
|
def verbose!
|
|
20
27
|
@verbose = true
|
|
21
28
|
@curl.verbose = @verbose
|
|
@@ -36,19 +43,10 @@ module Zm
|
|
|
36
43
|
end
|
|
37
44
|
|
|
38
45
|
def curl_request(body, error_handler = SoapError)
|
|
39
|
-
|
|
46
|
+
logger.debug body.to_json
|
|
40
47
|
@curl.http_post(body.to_json)
|
|
41
48
|
|
|
42
|
-
|
|
43
|
-
soapbody = JSON.parse(@curl.body_str, symbolize_names: true)
|
|
44
|
-
raise(error_handler, soapbody) if @curl.status.to_i >= 400
|
|
45
|
-
|
|
46
|
-
soapbody
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def curl_xml(xml, error_handler = SoapError)
|
|
50
|
-
# puts xml
|
|
51
|
-
@curl.http_post(xml)
|
|
49
|
+
logger.debug @curl.body_str
|
|
52
50
|
|
|
53
51
|
soapbody = JSON.parse(@curl.body_str, symbolize_names: true)
|
|
54
52
|
raise(error_handler, soapbody) if @curl.status.to_i >= 400
|
|
@@ -57,7 +55,9 @@ module Zm
|
|
|
57
55
|
end
|
|
58
56
|
|
|
59
57
|
def hash_header(token, target_server = nil)
|
|
60
|
-
context = { authToken: token, userAgent: { name: :zmsoap }, targetServer: target_server }.delete_if
|
|
58
|
+
context = { authToken: token, userAgent: { name: :zmsoap }, targetServer: target_server }.delete_if do |_, v|
|
|
59
|
+
v.nil?
|
|
60
|
+
end
|
|
61
61
|
{ Header: { context: context, _jsns: BASESPACE } }
|
|
62
62
|
end
|
|
63
63
|
end
|
|
@@ -4,20 +4,10 @@ module Zm
|
|
|
4
4
|
module Client
|
|
5
5
|
# class factory [contacts]
|
|
6
6
|
class ContactBuilder < Base::ObjectsBuilder
|
|
7
|
-
|
|
8
7
|
def initialize(parent, json)
|
|
9
|
-
|
|
10
|
-
@
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def make
|
|
14
|
-
root = @json[:Body][:GetContactsResponse][:cn]
|
|
15
|
-
return [] if root.nil?
|
|
16
|
-
|
|
17
|
-
root = [root] unless root.is_a?(Array)
|
|
18
|
-
root.map do |s|
|
|
19
|
-
Contact.new(@parent, s)
|
|
20
|
-
end
|
|
8
|
+
super(parent, json)
|
|
9
|
+
@child_class = Contact
|
|
10
|
+
@json_item_key = :cn
|
|
21
11
|
end
|
|
22
12
|
end
|
|
23
13
|
end
|
|
@@ -3,23 +3,17 @@
|
|
|
3
3
|
module Zm
|
|
4
4
|
module Client
|
|
5
5
|
# collection account contacts
|
|
6
|
-
class ContactsCollection < Base::
|
|
6
|
+
class ContactsCollection < Base::AccountObjectsCollection
|
|
7
7
|
def initialize(parent)
|
|
8
|
-
@
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def new
|
|
12
|
-
contact = Contact.new(@parent)
|
|
13
|
-
yield(contact) if block_given?
|
|
14
|
-
contact
|
|
8
|
+
@child_class = Contact
|
|
9
|
+
@builder_class = ContactBuilder
|
|
10
|
+
super(parent)
|
|
15
11
|
end
|
|
16
12
|
|
|
17
13
|
private
|
|
18
14
|
|
|
19
|
-
def
|
|
20
|
-
|
|
21
|
-
cb = ContactBuilder.new @parent, rep
|
|
22
|
-
cb.make
|
|
15
|
+
def make_query
|
|
16
|
+
@parent.sacc.get_all_contacts(@parent.token)
|
|
23
17
|
end
|
|
24
18
|
end
|
|
25
19
|
end
|
data/lib/zm/client/cos/cos.rb
CHANGED
|
@@ -16,11 +16,11 @@ module Zm
|
|
|
16
16
|
@zimbraZimletAvailableZimlets = [@zimbraZimletAvailableZimlets] if @zimbraZimletAvailableZimlets.is_a?(String)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
def to_h
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
end
|
|
19
|
+
# def to_h
|
|
20
|
+
# hashmap = Hash[all_instance_variable_keys.map { |key| [key, instance_variable_get(arrow_name(key))] }]
|
|
21
|
+
# hashmap.delete_if { |_, v| v.nil? }
|
|
22
|
+
# hashmap
|
|
23
|
+
# end
|
|
24
24
|
|
|
25
25
|
def all_instance_variable_keys
|
|
26
26
|
attrs_write
|
|
@@ -39,13 +39,18 @@ module Zm
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def create!
|
|
42
|
-
sac.create_cos(name, instance_variables_array(attrs_write))
|
|
42
|
+
rep = sac.create_cos(name, instance_variables_array(attrs_write))
|
|
43
|
+
@id = rep[:Body][:CreateCosResponse][:cos].first[:id]
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
def servers
|
|
46
47
|
@servers ||= read_servers
|
|
47
48
|
end
|
|
48
49
|
|
|
50
|
+
def accounts
|
|
51
|
+
# TODO: sélectionner tous les comptes qui ont zimbraCOSID=self.id
|
|
52
|
+
end
|
|
53
|
+
|
|
49
54
|
private
|
|
50
55
|
|
|
51
56
|
def read_servers
|
|
@@ -7,22 +7,7 @@ module Zm
|
|
|
7
7
|
def initialize(parent, json)
|
|
8
8
|
super(parent, json)
|
|
9
9
|
@child_class = Cos
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
# def make
|
|
13
|
-
# return [] if json_items.nil?
|
|
14
|
-
#
|
|
15
|
-
# json_items.map do |entry|
|
|
16
|
-
# cos = Cos.new(@parent)
|
|
17
|
-
# cos.init_from_json(entry)
|
|
18
|
-
# cos
|
|
19
|
-
# end
|
|
20
|
-
# end
|
|
21
|
-
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
def json_items
|
|
25
|
-
@json_items ||= @json[:Body][json_key][:cos]
|
|
10
|
+
@json_item_key = :cos
|
|
26
11
|
end
|
|
27
12
|
end
|
|
28
13
|
end
|
|
@@ -3,29 +3,26 @@
|
|
|
3
3
|
module Zm
|
|
4
4
|
module Client
|
|
5
5
|
# Collection coses
|
|
6
|
-
class CosesCollection < Base::
|
|
6
|
+
class CosesCollection < Base::AdminObjectsCollection
|
|
7
7
|
def initialize(parent)
|
|
8
8
|
@child_class = Cos
|
|
9
|
+
@builder_class = CosesBuilder
|
|
10
|
+
@search_type = SearchType::COS
|
|
9
11
|
@parent = parent
|
|
10
|
-
reset_query_params
|
|
11
12
|
end
|
|
12
13
|
|
|
13
|
-
def find_by(hash
|
|
14
|
-
rep = sac.get_cos(hash.values.first, hash.keys.first,
|
|
14
|
+
def find_by(hash)
|
|
15
|
+
rep = sac.get_cos(hash.values.first, hash.keys.first, attrs_comma)
|
|
15
16
|
entry = rep[:Body][:GetCosResponse][:cos].first
|
|
16
17
|
|
|
18
|
+
reset_query_params
|
|
17
19
|
build_from_entry(entry)
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
private
|
|
21
23
|
|
|
22
|
-
def build_response
|
|
23
|
-
CosesBuilder.new(@parent, make_query).make
|
|
24
|
-
end
|
|
25
|
-
|
|
26
24
|
def reset_query_params
|
|
27
25
|
super
|
|
28
|
-
@search_type = SearchType::COS
|
|
29
26
|
@attrs = SearchType::Attributes::COS.dup
|
|
30
27
|
end
|
|
31
28
|
end
|
|
@@ -6,21 +6,22 @@ module Zm
|
|
|
6
6
|
# objectClass: zimbraDistributionList
|
|
7
7
|
class DistributionList < Base::AdminObject
|
|
8
8
|
attr_accessor :members
|
|
9
|
-
attr_reader :owners
|
|
9
|
+
attr_reader :owners, :aces
|
|
10
10
|
|
|
11
11
|
def initialize(parent)
|
|
12
12
|
extend(DistributionListCommon)
|
|
13
13
|
super(parent)
|
|
14
14
|
@members = []
|
|
15
15
|
@owners = []
|
|
16
|
+
@aces = []
|
|
16
17
|
@grantee_type = 'grp'.freeze
|
|
17
18
|
end
|
|
18
19
|
|
|
19
|
-
def to_h
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
end
|
|
20
|
+
# def to_h
|
|
21
|
+
# hashmap = Hash[all_instance_variable_keys.map { |key| [key, instance_variable_get(arrow_name(key))] }]
|
|
22
|
+
# hashmap.delete_if { |_, v| v.nil? }
|
|
23
|
+
# hashmap
|
|
24
|
+
# end
|
|
24
25
|
|
|
25
26
|
def all_instance_variable_keys
|
|
26
27
|
DistributionListCommon::ALL_ATTRS
|
|
@@ -35,6 +36,7 @@ module Zm
|
|
|
35
36
|
@zimbraMailAlias = [@zimbraMailAlias].compact unless @zimbraMailAlias.is_a?(Array)
|
|
36
37
|
@zimbraMailAlias.delete(@name)
|
|
37
38
|
@aliases = @zimbraMailAlias
|
|
39
|
+
set_aces_from_json
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
def create!
|
|
@@ -99,6 +101,16 @@ module Zm
|
|
|
99
101
|
@members -= emails
|
|
100
102
|
end
|
|
101
103
|
|
|
104
|
+
def add_owners!(*emails)
|
|
105
|
+
# todo à tester
|
|
106
|
+
sac.distribution_list_action(@id, :id, { op: 'addOwners', owner: { by: :name, type: :usr, _content: emails } })
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def remove_owners!(*emails)
|
|
110
|
+
# todo à tester
|
|
111
|
+
sac.distribution_list_action(@id, :id, { op: 'removeOwners', owner: { by: :name, type: :usr, _content: emails } })
|
|
112
|
+
end
|
|
113
|
+
|
|
102
114
|
def local_transport
|
|
103
115
|
raise Zm::Client::SoapError, 'zimbraMailHost is null' if zimbraMailHost.nil?
|
|
104
116
|
|
|
@@ -120,6 +132,32 @@ module Zm
|
|
|
120
132
|
|
|
121
133
|
zimbraMailTransport.start_with?('smtp')
|
|
122
134
|
end
|
|
135
|
+
|
|
136
|
+
def memberships
|
|
137
|
+
@memberships ||= DlsMembershipCollection.new(self)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def hide_in_gal?
|
|
141
|
+
zimbraHideInGal == 'TRUE'
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def group?
|
|
145
|
+
zimbraMailStatus == 'disabled'
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def mailing_list?
|
|
149
|
+
zimbraMailStatus == 'enabled'
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def set_aces_from_json
|
|
153
|
+
return if @zimbraACE.nil?
|
|
154
|
+
|
|
155
|
+
zimbra_aces = @zimbraACE.is_a?(Array) ? @zimbraACE : [@zimbraACE]
|
|
156
|
+
@aces = zimbra_aces.map do |str|
|
|
157
|
+
parts = str.split(/\s+/)
|
|
158
|
+
{ zimbra_id: parts[0], type: parts[1], right: parts[2] }
|
|
159
|
+
end
|
|
160
|
+
end
|
|
123
161
|
end
|
|
124
162
|
end
|
|
125
163
|
end
|
|
@@ -2,27 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
module Zm
|
|
4
4
|
module Client
|
|
5
|
-
# class factory [
|
|
5
|
+
# class factory [dls]
|
|
6
6
|
class DistributionListsBuilder < Base::ObjectsBuilder
|
|
7
7
|
def initialize(parent, json)
|
|
8
8
|
super(parent, json)
|
|
9
9
|
@child_class = DistributionList
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
# def make
|
|
13
|
-
# return [] if json_items.nil?
|
|
14
|
-
#
|
|
15
|
-
# json_items.map do |entry|
|
|
16
|
-
# dl = DistributionList.new(@parent)
|
|
17
|
-
# dl.init_from_json(entry)
|
|
18
|
-
# dl
|
|
19
|
-
# end
|
|
20
|
-
# end
|
|
21
|
-
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
def json_items
|
|
25
|
-
@json_items ||= @json[:Body][json_key][:dl]
|
|
10
|
+
@json_item_key = :dl
|
|
26
11
|
end
|
|
27
12
|
end
|
|
28
13
|
end
|
|
@@ -3,34 +3,27 @@
|
|
|
3
3
|
module Zm
|
|
4
4
|
module Client
|
|
5
5
|
# Collection Resources
|
|
6
|
-
class DistributionListsCollection < Base::
|
|
6
|
+
class DistributionListsCollection < Base::AdminObjectsCollection
|
|
7
7
|
def initialize(parent)
|
|
8
8
|
@child_class = DistributionList
|
|
9
|
+
@builder_class = DistributionListsBuilder
|
|
10
|
+
@search_type = SearchType::DL
|
|
9
11
|
@parent = parent
|
|
10
12
|
reset_query_params
|
|
11
13
|
end
|
|
12
14
|
|
|
13
|
-
def ldap
|
|
14
|
-
@apply_cos = 0
|
|
15
|
-
self
|
|
16
|
-
end
|
|
17
|
-
|
|
18
15
|
def find_by(hash)
|
|
19
16
|
rep = sac.get_distribution_list(hash.values.first, hash.keys.first, attrs_comma)
|
|
20
17
|
entry = rep[:Body][:GetDistributionListResponse][:dl].first
|
|
21
18
|
|
|
19
|
+
reset_query_params
|
|
22
20
|
build_from_entry(entry)
|
|
23
21
|
end
|
|
24
22
|
|
|
25
23
|
private
|
|
26
24
|
|
|
27
|
-
def build_response
|
|
28
|
-
DistributionListsBuilder.new(@parent, make_query).make
|
|
29
|
-
end
|
|
30
|
-
|
|
31
25
|
def reset_query_params
|
|
32
26
|
super
|
|
33
|
-
@search_type = SearchType::DL
|
|
34
27
|
@attrs = SearchType::Attributes::DL.dup
|
|
35
28
|
@all_servers = 1
|
|
36
29
|
@refresh = 0
|