zm-ruby-client 0.10.4 → 0.17.1
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 +1 -0
- data/README.md +6 -0
- data/lib/zm/client/account/account.rb +39 -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 +47 -7
- data/lib/zm/client/cluster/cluster_config.rb +19 -17
- data/lib/zm/client/common/token_metadata.rb +44 -0
- data/lib/zm/client/common.rb +2 -1
- data/lib/zm/client/connector/rest_account.rb +0 -3
- data/lib/zm/client/connector/soap_account.rb +66 -122
- data/lib/zm/client/connector/soap_admin.rb +47 -15
- data/lib/zm/client/connector/soap_base.rb +11 -3
- 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 +9 -5
- 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 +11 -9
- data/lib/zm/client/domain/domain.rb +23 -7
- 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 +46 -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 +9 -7
- 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 +2 -2
- data/lib/zm/modules/common/dl_common.rb +6 -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/domains.rb +8 -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 +1 -0
- metadata +60 -3
|
@@ -8,15 +8,14 @@ module Zm
|
|
|
8
8
|
module Client
|
|
9
9
|
class SoapAdminConnector < SoapBaseConnector
|
|
10
10
|
|
|
11
|
+
# SOAP_PATH = '/service/admin/soap/'
|
|
11
12
|
ADMINSPACE = 'urn:zimbraAdmin'
|
|
12
13
|
A_NODE_PROC = lambda { |n| { n: n.first, _content: n.last } }
|
|
13
14
|
|
|
14
15
|
attr_accessor :token
|
|
15
16
|
|
|
16
17
|
def initialize(scheme, host, port)
|
|
17
|
-
|
|
18
|
-
@uri = URI::HTTP.new(scheme, nil, host, port, nil, '/service/admin/soap/', nil, nil, nil)
|
|
19
|
-
init_curl_client
|
|
18
|
+
super(scheme, host, port, '/service/admin/soap/')
|
|
20
19
|
end
|
|
21
20
|
|
|
22
21
|
def auth(mail, password)
|
|
@@ -155,7 +154,6 @@ module Zm
|
|
|
155
154
|
# req = { _jsns: ADMINSPACE, id: id, a: attrs.to_a.map{ |n| { n: n.first, _content: n.last } } }
|
|
156
155
|
req = { _jsns: ADMINSPACE, id: id }
|
|
157
156
|
body = { Body: { ModifyCosRequest: req } }.merge(hash_header(@token))
|
|
158
|
-
# puts body
|
|
159
157
|
# todo ne fonctionne pas !
|
|
160
158
|
# peut-être seul la version xml fonctionne. Il faudrait créer une fonction qui converti le json en xml
|
|
161
159
|
curl_request(body)
|
|
@@ -168,7 +166,6 @@ module Zm
|
|
|
168
166
|
# 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 } }
|
|
169
167
|
body = init_hash_request(soap_name)
|
|
170
168
|
body[:Body][soap_name].merge!(req)
|
|
171
|
-
# puts body
|
|
172
169
|
curl_request(body)
|
|
173
170
|
end
|
|
174
171
|
|
|
@@ -188,7 +185,6 @@ module Zm
|
|
|
188
185
|
req[:a] = attrs.map { |i| i.last.is_a?(Array) ? i.last.map{|j|[i.first, j]} : [i] }.flatten(1).map(&A_NODE_PROC)
|
|
189
186
|
body = init_hash_request(soap_name)
|
|
190
187
|
body[:Body][soap_name].merge!(req)
|
|
191
|
-
# puts body
|
|
192
188
|
curl_request(body)
|
|
193
189
|
end
|
|
194
190
|
|
|
@@ -214,6 +210,14 @@ module Zm
|
|
|
214
210
|
curl_request(body)
|
|
215
211
|
end
|
|
216
212
|
|
|
213
|
+
def set_password(id, new_password)
|
|
214
|
+
soap_name = :SetPasswordRequest
|
|
215
|
+
req = { id: id, newPassword: new_password }
|
|
216
|
+
body = init_hash_request(soap_name)
|
|
217
|
+
body[:Body][soap_name].merge!(req)
|
|
218
|
+
curl_request(body)
|
|
219
|
+
end
|
|
220
|
+
|
|
217
221
|
def add_account_alias(id, email)
|
|
218
222
|
generic_alias(:AddAccountAliasRequest, id, email)
|
|
219
223
|
end
|
|
@@ -254,7 +258,6 @@ module Zm
|
|
|
254
258
|
req = { id: id, alias: email }
|
|
255
259
|
body = init_hash_request(soap_name)
|
|
256
260
|
body[:Body][soap_name].merge!(req)
|
|
257
|
-
# puts body
|
|
258
261
|
curl_request(body)
|
|
259
262
|
end
|
|
260
263
|
|
|
@@ -275,7 +278,17 @@ module Zm
|
|
|
275
278
|
body = init_hash_request(:GetDomainRequest)
|
|
276
279
|
body[:Body][:GetDomainRequest].merge!(req)
|
|
277
280
|
# TODO: tester param attrs
|
|
278
|
-
|
|
281
|
+
curl_request(body)
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def create_domain(name, attrs = [])
|
|
285
|
+
soap_name = :CreateDomainRequest
|
|
286
|
+
req = {
|
|
287
|
+
name: name,
|
|
288
|
+
a: attrs.map(&A_NODE_PROC)
|
|
289
|
+
}
|
|
290
|
+
body = init_hash_request(soap_name)
|
|
291
|
+
body[:Body][soap_name].merge!(req)
|
|
279
292
|
curl_request(body)
|
|
280
293
|
end
|
|
281
294
|
|
|
@@ -289,7 +302,6 @@ module Zm
|
|
|
289
302
|
req[:attrs] = attrs unless attrs.nil? || attrs.empty?
|
|
290
303
|
body = init_hash_request(soap_name)
|
|
291
304
|
body[:Body][soap_name].merge!(req)
|
|
292
|
-
# puts body
|
|
293
305
|
curl_request(body)
|
|
294
306
|
end
|
|
295
307
|
|
|
@@ -321,6 +333,16 @@ module Zm
|
|
|
321
333
|
curl_request(body)
|
|
322
334
|
end
|
|
323
335
|
|
|
336
|
+
def get_distribution_list_membership(by_key, by = 'name', limit = nil, offset = nil)
|
|
337
|
+
soap_name = :GetDistributionListMembershipRequest
|
|
338
|
+
req = { dl: { by: by, _content: by_key }, limit: limit, offset: offset }
|
|
339
|
+
req.reject! { |_, v| v.nil? }
|
|
340
|
+
body = init_hash_request(soap_name)
|
|
341
|
+
body[:Body][soap_name].merge!(req)
|
|
342
|
+
|
|
343
|
+
curl_request(body)
|
|
344
|
+
end
|
|
345
|
+
|
|
324
346
|
def delete_account(id)
|
|
325
347
|
generic_delete(:DeleteAccountRequest, id)
|
|
326
348
|
end
|
|
@@ -374,7 +396,6 @@ module Zm
|
|
|
374
396
|
# body = { Body: { SearchDirectoryRequest: { _jsns: ADMINSPACE } } }.merge(hash_header(@token))
|
|
375
397
|
body = init_hash_request(soap_name)
|
|
376
398
|
body[:Body][soap_name].merge!(req)
|
|
377
|
-
# puts body
|
|
378
399
|
|
|
379
400
|
curl_request(body)
|
|
380
401
|
end
|
|
@@ -409,11 +430,11 @@ module Zm
|
|
|
409
430
|
curl_request(body)
|
|
410
431
|
end
|
|
411
432
|
|
|
412
|
-
def flush_cache(type, all_servers, id = nil)
|
|
433
|
+
def flush_cache(type, all_servers, id = nil, target_server_id = nil)
|
|
413
434
|
soap_name = :FlushCacheRequest
|
|
414
435
|
req = { cache: { type: type, allServers: all_servers } }
|
|
415
436
|
req[:cache].merge!({ entry: { by: :id, _content: id } }) unless id.nil?
|
|
416
|
-
body = init_hash_request(soap_name)
|
|
437
|
+
body = init_hash_request(soap_name, target_server_id)
|
|
417
438
|
body[:Body][soap_name].merge!(req)
|
|
418
439
|
curl_request(body)
|
|
419
440
|
end
|
|
@@ -447,7 +468,6 @@ module Zm
|
|
|
447
468
|
body = init_hash_request(soap_name)
|
|
448
469
|
req = { server: { name: server_name } }
|
|
449
470
|
body[:Body][soap_name].merge!(req)
|
|
450
|
-
# puts body.to_json
|
|
451
471
|
curl_request(body)
|
|
452
472
|
end
|
|
453
473
|
|
|
@@ -475,7 +495,6 @@ module Zm
|
|
|
475
495
|
}
|
|
476
496
|
}
|
|
477
497
|
body[:Body][soap_name].merge!(req)
|
|
478
|
-
# puts body.to_json
|
|
479
498
|
curl_request(body)
|
|
480
499
|
end
|
|
481
500
|
|
|
@@ -495,11 +514,24 @@ module Zm
|
|
|
495
514
|
body = init_hash_request(soap_name, dest_id)
|
|
496
515
|
req = { query: {} }
|
|
497
516
|
body[:Body][soap_name].merge!(req)
|
|
498
|
-
# puts body
|
|
499
517
|
curl_request(body)
|
|
500
518
|
# curl_xml(SoapXmlBuilder.new(body).to_xml)
|
|
501
519
|
end
|
|
502
520
|
|
|
521
|
+
def set_password(id, new_password)
|
|
522
|
+
soap_name = :SetPasswordRequest
|
|
523
|
+
body = init_hash_request(soap_name)
|
|
524
|
+
req = { id: id, newPassword: new_password }
|
|
525
|
+
body[:Body][soap_name].merge!(req)
|
|
526
|
+
curl_request(body)
|
|
527
|
+
end
|
|
528
|
+
|
|
529
|
+
def get_version_info
|
|
530
|
+
soap_name = :GetVersionInfoRequest
|
|
531
|
+
body = init_hash_request(soap_name)
|
|
532
|
+
curl_request(body)
|
|
533
|
+
end
|
|
534
|
+
|
|
503
535
|
def init_hash_request(soap_name, target_server = nil)
|
|
504
536
|
{
|
|
505
537
|
Body: {
|
|
@@ -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,10 +43,11 @@ 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
|
-
|
|
49
|
+
logger.debug @curl.body_str
|
|
50
|
+
|
|
43
51
|
soapbody = JSON.parse(@curl.body_str, symbolize_names: true)
|
|
44
52
|
raise(error_handler, soapbody) if @curl.status.to_i >= 400
|
|
45
53
|
|
|
@@ -47,7 +55,7 @@ module Zm
|
|
|
47
55
|
end
|
|
48
56
|
|
|
49
57
|
def curl_xml(xml, error_handler = SoapError)
|
|
50
|
-
|
|
58
|
+
logger.debug xml
|
|
51
59
|
@curl.http_post(xml)
|
|
52
60
|
|
|
53
61
|
soapbody = JSON.parse(@curl.body_str, symbolize_names: true)
|
|
@@ -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
|
|
@@ -46,6 +46,10 @@ module Zm
|
|
|
46
46
|
@servers ||= read_servers
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
def accounts
|
|
50
|
+
# todo sélectionner tous les comptes qui ont zimbraCOSID=self.id
|
|
51
|
+
end
|
|
52
|
+
|
|
49
53
|
private
|
|
50
54
|
|
|
51
55
|
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
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Zm
|
|
4
|
+
module Client
|
|
5
|
+
DlMembership = Struct.new(:name, :id, :via)
|
|
6
|
+
|
|
7
|
+
class DlsMembershipCollection < Base::ObjectsCollection
|
|
8
|
+
def initialize(parent)
|
|
9
|
+
@parent = parent
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def make_query
|
|
15
|
+
@parent.sac.get_distribution_list_membership(@parent.id, :id)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def build_response
|
|
19
|
+
@all = make_query.dig(:Body, :GetDistributionListMembershipResponse, :dl) || []
|
|
20
|
+
@all.map { |json| DlMembership.new(json[:name], json[:id], json[:via]) }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -19,8 +19,8 @@ module Zm
|
|
|
19
19
|
yield(self) if block_given?
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
def
|
|
23
|
-
INSTANCE_VARIABLE_KEYS
|
|
22
|
+
def all_instance_variable_keys
|
|
23
|
+
INSTANCE_VARIABLE_KEYS
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def folder
|
|
@@ -31,17 +31,19 @@ module Zm
|
|
|
31
31
|
@parent.sacc.item_action(@parent.token, :tag, @id, tn: tag_name)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
def move!(folder_id)
|
|
35
|
+
@parent.sacc.item_action(@parent.token, 'move', @id, l: folder_id)
|
|
36
|
+
@l = folder_id
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def delete!
|
|
40
|
+
@parent.sacc.item_action(@parent.token, :delete, @id)
|
|
41
|
+
end
|
|
42
|
+
|
|
34
43
|
def download(dest_file_path)
|
|
35
44
|
uploader = Upload.new(@parent, RestAccountConnector.new)
|
|
36
45
|
uploader.download_file(folder.absFolderPath, nil, nil, [id], dest_file_path)
|
|
37
46
|
end
|
|
38
|
-
|
|
39
|
-
def init_from_json(json)
|
|
40
|
-
INSTANCE_VARIABLE_KEYS.each do |key|
|
|
41
|
-
var_name = "@#{key}"
|
|
42
|
-
instance_variable_set(var_name, json[key])
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
47
|
end
|
|
46
48
|
end
|
|
47
49
|
end
|
|
@@ -6,7 +6,7 @@ module Zm
|
|
|
6
6
|
class Domain < Base::AdminObject
|
|
7
7
|
INSTANCE_VARIABLE_KEYS = %i[name description zimbraDomainName zimbraDomainStatus zimbraId zimbraDomainType
|
|
8
8
|
zimbraDomainDefaultCOSId zimbraGalAccountId zimbraPreAuthKey zimbraGalLdapBindDn zimbraGalLdapBindPassword
|
|
9
|
-
zimbraGalLdapFilter zimbraGalLdapSearchBase zimbraGalLdapURL zimbraGalMode]
|
|
9
|
+
zimbraGalLdapFilter zimbraGalLdapSearchBase zimbraGalLdapURL zimbraGalMode zimbraMailTransport]
|
|
10
10
|
|
|
11
11
|
attr_accessor *INSTANCE_VARIABLE_KEYS
|
|
12
12
|
|
|
@@ -15,16 +15,27 @@ module Zm
|
|
|
15
15
|
@grantee_type = 'dom'.freeze
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def to_h
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
end
|
|
18
|
+
# def to_h
|
|
19
|
+
# hashmap = Hash[all_instance_variable_keys.map { |key| [key, instance_variable_get(arrow_name(key))] }]
|
|
20
|
+
# hashmap.delete_if { |_, v| v.nil? }
|
|
21
|
+
# hashmap
|
|
22
|
+
# end
|
|
23
23
|
|
|
24
24
|
def all_instance_variable_keys
|
|
25
25
|
INSTANCE_VARIABLE_KEYS
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
def create!
|
|
29
|
+
attrs_write = INSTANCE_VARIABLE_KEYS.dup
|
|
30
|
+
attrs_write.delete(:name)
|
|
31
|
+
|
|
32
|
+
rep = sac.create_domain(
|
|
33
|
+
@name,
|
|
34
|
+
instance_variables_array(attrs_write)
|
|
35
|
+
)
|
|
36
|
+
@id = rep[:Body][:CreateDomainResponse][:domain].first[:id]
|
|
37
|
+
end
|
|
38
|
+
|
|
28
39
|
def update!(hash)
|
|
29
40
|
sac.modify_domain(@id, hash)
|
|
30
41
|
|
|
@@ -40,9 +51,14 @@ module Zm
|
|
|
40
51
|
end
|
|
41
52
|
|
|
42
53
|
def accounts
|
|
43
|
-
@accounts ||=
|
|
54
|
+
@accounts ||= DomainAccountsCollection.new(self)
|
|
44
55
|
end
|
|
45
56
|
|
|
57
|
+
# def account_quotas(server_id)
|
|
58
|
+
# rep = sac.get_quota_usage(name, nil, nil, nil, nil, nil, nil, server_id)
|
|
59
|
+
# AccountsBuilder.new(@parent, rep).make
|
|
60
|
+
# end
|
|
61
|
+
|
|
46
62
|
def init_from_json(json)
|
|
47
63
|
super(json)
|
|
48
64
|
return unless json[:a].is_a? Array
|
|
@@ -7,25 +7,7 @@ module Zm
|
|
|
7
7
|
def initialize(parent, json)
|
|
8
8
|
super(parent, json)
|
|
9
9
|
@child_class = Domain
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
# def make
|
|
13
|
-
# records = []
|
|
14
|
-
# return records if json_items.nil?
|
|
15
|
-
#
|
|
16
|
-
# json_items.each do |entry|
|
|
17
|
-
# domain = Domain.new(@parent)
|
|
18
|
-
# domain.init_from_json(entry)
|
|
19
|
-
# records << domain
|
|
20
|
-
# end
|
|
21
|
-
#
|
|
22
|
-
# records
|
|
23
|
-
# end
|
|
24
|
-
|
|
25
|
-
private
|
|
26
|
-
|
|
27
|
-
def json_items
|
|
28
|
-
@json_items ||= @json[:Body][json_key][:domain]
|
|
10
|
+
@json_item_key = :domain
|
|
29
11
|
end
|
|
30
12
|
end
|
|
31
13
|
end
|