zm-ruby-client 3.0.1 → 3.1.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.
Files changed (229) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +96 -0
  3. data/README.md +128 -27
  4. data/VERSION +1 -1
  5. data/lib/zm/client/account/account.rb +12 -19
  6. data/lib/zm/client/account/account_aliases_collection.rb +6 -4
  7. data/lib/zm/client/account/account_dls_membership_collection.rb +4 -3
  8. data/lib/zm/client/account/account_dls_owner_collection.rb +3 -2
  9. data/lib/zm/client/account/account_jsns_builder.rb +10 -10
  10. data/lib/zm/client/account/accounts_collection.rb +27 -16
  11. data/lib/zm/client/ace/ace.rb +3 -6
  12. data/lib/zm/client/ace/ace_jsns_builder.rb +6 -6
  13. data/lib/zm/client/appointment/appointment.rb +32 -14
  14. data/lib/zm/client/appointment/appointment_jsns_builder.rb +5 -5
  15. data/lib/zm/client/appointment/appointment_jsns_initializer.rb +6 -1
  16. data/lib/zm/client/appointment/appointments_collection.rb +12 -9
  17. data/lib/zm/client/backup/backup.rb +5 -2
  18. data/lib/zm/client/backup/backups_collection.rb +3 -2
  19. data/lib/zm/client/base/account_objects_collection.rb +1 -0
  20. data/lib/zm/client/base/account_search_objects_collection.rb +6 -6
  21. data/lib/zm/client/base/admin_objects_collection.rb +60 -7
  22. data/lib/zm/client/base/base_account_jsns_builder.rb +89 -87
  23. data/lib/zm/client/base/base_jsns_builder.rb +3 -3
  24. data/lib/zm/client/base/base_jsns_initializer.rb +20 -15
  25. data/lib/zm/client/base/mailbox_infos_collection.rb +92 -90
  26. data/lib/zm/client/base/mailbox_object.rb +49 -160
  27. data/lib/zm/client/base/mailbox_prefs_collection.rb +54 -52
  28. data/lib/zm/client/base/object.rb +19 -2
  29. data/lib/zm/client/base/objects_collection.rb +10 -10
  30. data/lib/zm/client/base/zimbra_attribute.rb +28 -42
  31. data/lib/zm/client/base/zimbra_attributes_collection.rb +38 -24
  32. data/lib/zm/client/{cluster/batch_request.rb → batch_request.rb} +1 -1
  33. data/lib/zm/client/cluster/cluster.rb +24 -61
  34. data/lib/zm/client/cluster/cluster_config.rb +35 -15
  35. data/lib/zm/client/contact/contact.rb +15 -13
  36. data/lib/zm/client/contact/contact_jsns_builder.rb +9 -6
  37. data/lib/zm/client/contact/contact_jsns_initializer.rb +2 -2
  38. data/lib/zm/client/contact/contact_member.rb +3 -3
  39. data/lib/zm/client/contact/contact_members_collection.rb +3 -3
  40. data/lib/zm/client/contact/contacts_builder.rb +1 -1
  41. data/lib/zm/client/contact/contacts_collection.rb +2 -2
  42. data/lib/zm/client/contact/group_contact_jsns_builder.rb +18 -14
  43. data/lib/zm/client/contact/mod_group_contact.rb +12 -8
  44. data/lib/zm/client/cos/cos.rb +15 -31
  45. data/lib/zm/client/cos/cos_jsns_builder.rb +21 -21
  46. data/lib/zm/client/cos/coses_collection.rb +11 -6
  47. data/lib/zm/client/datasource/datasource.rb +3 -9
  48. data/lib/zm/client/datasource/datasource_jsns_builder.rb +4 -4
  49. data/lib/zm/client/datasource/datasources_builder.rb +1 -1
  50. data/lib/zm/client/datasource/datasources_collection.rb +2 -2
  51. data/lib/zm/client/deprecated_constants.rb +36 -0
  52. data/lib/zm/client/distributionlist/distributionlist.rb +15 -47
  53. data/lib/zm/client/distributionlist/distributionlist_aces_collection.rb +4 -4
  54. data/lib/zm/client/distributionlist/distributionlist_aliases_collection.rb +7 -5
  55. data/lib/zm/client/distributionlist/distributionlist_jsns_builder.rb +29 -41
  56. data/lib/zm/client/distributionlist/distributionlist_jsns_initializer.rb +14 -3
  57. data/lib/zm/client/distributionlist/distributionlist_members_collection.rb +14 -10
  58. data/lib/zm/client/distributionlist/distributionlist_owners_collection.rb +13 -13
  59. data/lib/zm/client/distributionlist/distributionlists_collection.rb +15 -7
  60. data/lib/zm/client/distributionlist/dls_membership_collection.rb +8 -6
  61. data/lib/zm/client/document/document.rb +5 -11
  62. data/lib/zm/client/document/document_jsns_builder.rb +2 -2
  63. data/lib/zm/client/document/documents_collection.rb +4 -4
  64. data/lib/zm/client/domain/domain.rb +8 -25
  65. data/lib/zm/client/domain/domain_jsns_builder.rb +13 -13
  66. data/lib/zm/client/domain/domains_collection.rb +13 -6
  67. data/lib/zm/client/filter_rules/filter_rules_collection.rb +1 -1
  68. data/lib/zm/client/filter_rules/outgoing_filter_rules_collection.rb +1 -1
  69. data/lib/zm/client/folder/folder.rb +34 -21
  70. data/lib/zm/client/folder/folder_default.rb +39 -0
  71. data/lib/zm/client/folder/folder_grant_jsns_builder.rb +3 -3
  72. data/lib/zm/client/folder/folder_grants_collection.rb +1 -1
  73. data/lib/zm/client/folder/folder_jsns_builder.rb +12 -12
  74. data/lib/zm/client/folder/folder_jsns_initializer.rb +1 -1
  75. data/lib/zm/client/folder/folder_retention_policies_collection.rb +6 -2
  76. data/lib/zm/client/folder/folder_view.rb +15 -0
  77. data/lib/zm/client/folder/folders_jsns_builder.rb +1 -1
  78. data/lib/zm/client/folder/mod_document_folder.rb +16 -12
  79. data/lib/zm/client/identity/identities_collection.rb +1 -1
  80. data/lib/zm/client/identity/identity.rb +3 -9
  81. data/lib/zm/client/identity/identity_jsns_builder.rb +8 -8
  82. data/lib/zm/client/{base/ldap_filter.rb → ldap_filter.rb} +1 -1
  83. data/lib/zm/client/license/licenses_collection.rb +1 -1
  84. data/lib/zm/client/mailbox/mailbox_item_concern.rb +0 -2
  85. data/lib/zm/client/message/message.rb +14 -19
  86. data/lib/zm/client/message/message_attachments_collection.rb +39 -0
  87. data/lib/zm/client/message/message_flags_collection.rb +130 -0
  88. data/lib/zm/client/message/message_jsns_builder.rb +4 -8
  89. data/lib/zm/client/message/message_jsns_initializer.rb +4 -4
  90. data/lib/zm/client/message/message_recipients.rb +19 -43
  91. data/lib/zm/client/message/messages_collection.rb +20 -4
  92. data/lib/zm/client/mountpoint/{mountpoint.rb → mount_point.rb} +4 -10
  93. data/lib/zm/client/mountpoint/{mountpoint_jsns_builder.rb → mount_point_jsns_builder.rb} +3 -3
  94. data/lib/zm/client/mountpoint/{mountpoint_jsns_initializer.rb → mount_point_jsns_initializer.rb} +1 -1
  95. data/lib/zm/client/mountpoint/{mountpoints_builder.rb → mount_points_builder.rb} +1 -1
  96. data/lib/zm/client/mta_queue/mta_queue.rb +4 -16
  97. data/lib/zm/client/mta_queue/mta_queue_action.rb +12 -0
  98. data/lib/zm/client/mta_queue/mta_queue_jsns_builder.rb +7 -7
  99. data/lib/zm/client/mta_queue/mta_queue_name.rb +14 -0
  100. data/lib/zm/client/mta_queue/mta_queues_collection.rb +4 -3
  101. data/lib/zm/client/mta_queue_item/mta_queue_items_collection.rb +1 -0
  102. data/lib/zm/client/recipient.rb +21 -0
  103. data/lib/zm/client/{common/recipients.rb → recipients.rb} +0 -16
  104. data/lib/zm/client/resource/resource.rb +3 -7
  105. data/lib/zm/client/resource/resource_jsns_builder.rb +13 -13
  106. data/lib/zm/client/resource/resources_collection.rb +20 -7
  107. data/lib/zm/client/search_folder/search_folder.rb +4 -11
  108. data/lib/zm/client/search_folder/search_folder_jsns_builder.rb +6 -6
  109. data/lib/zm/client/search_folder/search_folders_collection.rb +1 -1
  110. data/lib/zm/client/server/server.rb +16 -22
  111. data/lib/zm/client/server/server_services.rb +26 -0
  112. data/lib/zm/client/server/servers_collection.rb +6 -6
  113. data/lib/zm/client/share/share.rb +2 -5
  114. data/lib/zm/client/share/shares_builder.rb +1 -1
  115. data/lib/zm/client/share/shares_collection.rb +5 -4
  116. data/lib/zm/client/signature/signature.rb +7 -13
  117. data/lib/zm/client/signature/signature_jsns_builder.rb +13 -13
  118. data/lib/zm/client/signature/signature_jsns_initializer.rb +2 -2
  119. data/lib/zm/client/signature/signatures_collection.rb +1 -1
  120. data/lib/zm/client/tag/account_object_tags_collection.rb +45 -47
  121. data/lib/zm/client/tag/tag.rb +3 -9
  122. data/lib/zm/client/tag/tag_jsns_builder.rb +3 -3
  123. data/lib/zm/client/tag/tags_builder.rb +1 -1
  124. data/lib/zm/client/tag/tags_collection.rb +2 -2
  125. data/lib/zm/client/task/task.rb +2 -2
  126. data/lib/zm/client/task/tasks_collection.rb +2 -2
  127. data/lib/zm/client/token.rb +4 -1
  128. data/lib/zm/client/upload.rb +179 -1
  129. data/lib/zm/client/{common/utils.rb → utils.rb} +6 -3
  130. data/lib/zm/client/zm_logger.rb +1 -1
  131. data/lib/zm/client.rb +227 -10
  132. data/lib/zm/connector/network_error_handler.rb +18 -0
  133. data/lib/zm/{client/connector → connector}/rest_connector.rb +46 -40
  134. data/lib/zm/{client/connector/soap_account.rb → connector/soap_account_connector.rb} +15 -17
  135. data/lib/zm/{client/connector/soap_admin.rb → connector/soap_admin_connector.rb} +3 -5
  136. data/lib/zm/connector/soap_base_connector.rb +115 -0
  137. data/lib/zm/connector.rb +13 -0
  138. data/lib/zm/error/auth_error.rb +8 -0
  139. data/lib/zm/error/connection_error.rb +8 -0
  140. data/lib/zm/error/rest_error.rb +8 -0
  141. data/lib/zm/{client/connector → error}/soap_error.rb +1 -10
  142. data/lib/zm/error/zm_error.rb +8 -0
  143. data/lib/zm/error.rb +11 -0
  144. data/lib/zm/relationship/has_many.rb +22 -0
  145. data/lib/zm/relationship/jsns_builder.rb +21 -0
  146. data/lib/zm/relationship/relationship.rb +113 -0
  147. data/lib/zm/relationship/schema.rb +32 -0
  148. data/lib/zm/relationship.rb +5 -0
  149. data/lib/zm/{client/soap_request → soap_request}/request_methods_admin.rb +11 -5
  150. data/lib/zm/{client/soap_request → soap_request}/request_methods_mailbox.rb +1 -1
  151. data/lib/zm/{client/soap_request/account_soap_constants.rb → soap_request/soap_account_constants.rb} +1 -1
  152. data/lib/zm/{client/soap_request/admin_soap_constants.rb → soap_request/soap_admin_constants.rb} +1 -1
  153. data/lib/zm/{client/soap_request → soap_request}/soap_constants.rb +1 -1
  154. data/lib/zm/{client/soap_request → soap_request}/soap_context.rb +13 -5
  155. data/lib/zm/{client/soap_request → soap_request}/soap_element.rb +1 -1
  156. data/lib/zm/{client/soap_request/mail_soap_constants.rb → soap_request/soap_mail_constants.rb} +1 -1
  157. data/lib/zm/soap_request.rb +14 -0
  158. data/lib/zm/support/cache/entry.rb +3 -3
  159. data/lib/zm/support/cache/file_store.rb +4 -6
  160. data/lib/zm/support/cache/null_store.rb +2 -4
  161. data/lib/zm/support/cache/store.rb +17 -9
  162. data/lib/zm/support/cache.rb +13 -8
  163. data/lib/zm/support.rb +7 -0
  164. data/lib/zm/{modules → utils}/belongs_to_folder.rb +1 -1
  165. data/lib/zm/{modules → utils}/belongs_to_tag.rb +2 -2
  166. data/lib/zm/utils/content_part.rb +9 -0
  167. data/lib/zm/utils/content_type.rb +11 -0
  168. data/lib/zm/{modules → utils}/has_soap_admin_connector.rb +1 -1
  169. data/lib/zm/utils/inspector.rb +26 -0
  170. data/lib/zm/utils/log_filter.rb +30 -0
  171. data/lib/zm/utils/missing_method_static_collection.rb +17 -0
  172. data/lib/zm/utils/regex.rb +11 -0
  173. data/lib/zm/utils/search_utils.rb +13 -0
  174. data/lib/zm/utils.rb +16 -0
  175. data/lib/zm-ruby-client.rb +12 -0
  176. data/sig/zm/client/admin_objects.rbs +261 -0
  177. data/sig/zm/client/base.rbs +191 -0
  178. data/sig/zm/client/cluster.rbs +152 -0
  179. data/sig/zm/client/mailbox.rbs +766 -0
  180. data/sig/zm/error.rbs +23 -0
  181. metadata +99 -91
  182. data/.gitignore +0 -59
  183. data/.rubocop.yml +0 -6
  184. data/.ruby-version +0 -1
  185. data/Gemfile +0 -11
  186. data/SECURITY.md +0 -21
  187. data/bin/console +0 -11
  188. data/lib/zm/client/account.rb +0 -9
  189. data/lib/zm/client/ace.rb +0 -7
  190. data/lib/zm/client/appointment.rb +0 -7
  191. data/lib/zm/client/backup.rb +0 -6
  192. data/lib/zm/client/base.rb +0 -21
  193. data/lib/zm/client/cluster.rb +0 -4
  194. data/lib/zm/client/common/message.rb +0 -10
  195. data/lib/zm/client/common.rb +0 -5
  196. data/lib/zm/client/connector/soap_base.rb +0 -104
  197. data/lib/zm/client/constant.rb +0 -229
  198. data/lib/zm/client/contact.rb +0 -11
  199. data/lib/zm/client/cos.rb +0 -10
  200. data/lib/zm/client/datasource.rb +0 -7
  201. data/lib/zm/client/distributionlist.rb +0 -8
  202. data/lib/zm/client/document.rb +0 -7
  203. data/lib/zm/client/domain.rb +0 -10
  204. data/lib/zm/client/filter_rule.rb +0 -7
  205. data/lib/zm/client/folder.rb +0 -14
  206. data/lib/zm/client/identity.rb +0 -7
  207. data/lib/zm/client/license.rb +0 -5
  208. data/lib/zm/client/message/attachments_collection.rb +0 -55
  209. data/lib/zm/client/message/message_flags.rb +0 -115
  210. data/lib/zm/client/message.rb +0 -10
  211. data/lib/zm/client/mountpoint.rb +0 -7
  212. data/lib/zm/client/mta_queue.rb +0 -7
  213. data/lib/zm/client/mta_queue_item.rb +0 -6
  214. data/lib/zm/client/resource.rb +0 -7
  215. data/lib/zm/client/search_folder.rb +0 -7
  216. data/lib/zm/client/server.rb +0 -7
  217. data/lib/zm/client/share.rb +0 -7
  218. data/lib/zm/client/signature.rb +0 -7
  219. data/lib/zm/client/soap_request.rb +0 -11
  220. data/lib/zm/client/tag.rb +0 -8
  221. data/lib/zm/client/task.rb +0 -6
  222. data/lib/zm/client/upload/upload.rb +0 -160
  223. data/lib/zm/modules/base.rb +0 -9
  224. data/lib/zm/modules/common/zimbra-attrs.json +0 -58
  225. data/lib/zm/modules/inspector.rb +0 -24
  226. data/lib/zm/modules/missing_method_static_collection.rb +0 -13
  227. data/lib/zm/modules/zm_model.rb +0 -43
  228. data/zm-ruby-client.gemspec +0 -27
  229. /data/lib/zm/client/mountpoint/{mountpoints_collection.rb → mount_points_collection.rb} +0 -0
@@ -2,70 +2,72 @@
2
2
 
3
3
  module Zm
4
4
  module Client
5
- class MailboxPrefsCollection
6
- def initialize(parent)
7
- @parent = parent
8
- @preferences = []
9
- end
5
+ module Base
6
+ class MailboxPrefsCollection
7
+ def initialize(parent)
8
+ @parent = parent
9
+ @preferences = []
10
+ end
10
11
 
11
- def all
12
- build_response
13
- end
14
- alias all! all
12
+ def all
13
+ build_response
14
+ end
15
+ alias all! all
15
16
 
16
- def clear
17
- reset_query_params
18
- end
17
+ def clear
18
+ reset_query_params
19
+ end
19
20
 
20
- def preferences(*entries)
21
- entries.flatten!
22
- @preferences += entries
23
- self
24
- end
21
+ def preferences(*entries)
22
+ entries.flatten!
23
+ @preferences += entries
24
+ self
25
+ end
25
26
 
26
- def update!(hash)
27
- # The JSON version is different:
28
- # {
29
- # ModifyPrefsRequest: {
30
- # "_attrs": {
31
- # "prefName1": "prefValue1",
32
- # "prefName2": "prefValue2"
33
- # "+nameOfMulitValuedPref3": "addedPrefValue3",
34
- # "-nameOfMulitValuedPref4": "removedPrefValue4",
35
- # "nameOfMulitValuedPref5": ["prefValue5one","prefValue5two"],
36
- # ...
37
- # },
38
- # _jsns: "urn:zimbraAccount"
39
- # }
40
- # }
27
+ def update!(hash)
28
+ # The JSON version is different:
29
+ # {
30
+ # ModifyPrefsRequest: {
31
+ # "_attrs": {
32
+ # "prefName1": "prefValue1",
33
+ # "prefName2": "prefValue2"
34
+ # "+nameOfMulitValuedPref3": "addedPrefValue3",
35
+ # "-nameOfMulitValuedPref4": "removedPrefValue4",
36
+ # "nameOfMulitValuedPref5": ["prefValue5one","prefValue5two"],
37
+ # ...
38
+ # },
39
+ # _jsns: "urn:zimbraAccount"
40
+ # }
41
+ # }
41
42
 
42
- req = {
43
- _attrs: hash
44
- }
43
+ req = {
44
+ _attrs: hash
45
+ }
45
46
 
46
- soap_request = SoapElement.account(SoapAccountConstants::MODIFY_PREFS_REQUEST).add_attributes(req)
47
- @parent.soap_connector.invoke(soap_request)
48
- end
47
+ soap_request = SoapRequest::SoapElement.account(Zm::SoapRequest::SoapAccountConstants::MODIFY_PREFS_REQUEST).add_attributes(req)
48
+ @parent.soap_connector.invoke(soap_request)
49
+ end
49
50
 
50
- private
51
+ private
51
52
 
52
- def build_response
53
- make_query.dig(:GetPrefsResponse, :_attrs)
54
- end
53
+ def build_response
54
+ make_query.dig(:GetPrefsResponse, :_attrs)
55
+ end
55
56
 
56
- def make_query
57
- soap_request = SoapElement.account(SoapAccountConstants::GET_PREFS_REQUEST).add_attributes(jsns)
58
- @parent.soap_connector.invoke(soap_request)
59
- end
57
+ def make_query
58
+ soap_request = SoapRequest::SoapElement.account(Zm::SoapRequest::SoapAccountConstants::GET_PREFS_REQUEST).add_attributes(jsns)
59
+ @parent.soap_connector.invoke(soap_request)
60
+ end
60
61
 
61
- def jsns
62
- return nil if @preferences.empty?
62
+ def jsns
63
+ return nil if @preferences.empty?
63
64
 
64
- { prefs: @preferences.map { |name| { name: name } } }
65
- end
65
+ { prefs: @preferences.map { |name| { name: } } }
66
+ end
66
67
 
67
- def reset_query_params
68
- @preferences.clear
68
+ def reset_query_params
69
+ @preferences.clear
70
+ end
69
71
  end
70
72
  end
71
73
  end
@@ -5,10 +5,11 @@ module Zm
5
5
  module Base
6
6
  # Abstract Class Provisionning Object
7
7
  class Object
8
- attr_accessor :parent, :token, :name, :id
8
+ attr_accessor :parent, :token, :name, :id, :updated
9
9
 
10
10
  def initialize(parent)
11
11
  @parent = parent
12
+ @updated = false
12
13
  yield(self) if block_given?
13
14
  end
14
15
 
@@ -16,13 +17,19 @@ module Zm
16
17
  !@id.nil?
17
18
  end
18
19
 
20
+ def updated?
21
+ @updated
22
+ end
23
+
19
24
  def save!
20
25
  recorded? ? modify! : create!
21
26
  end
22
27
 
23
28
  def clone
24
29
  obj = super
25
- obj.remove_instance_variable(:@id)
30
+ obj.remove_instance_variable(:@id) if obj.instance_variable_defined?(:@id)
31
+ obj.remove_instance_variable(:@jsns_builder) if obj.instance_variable_defined?(:@jsns_builder)
32
+ obj.remove_dependents_of(self)
26
33
  yield(obj) if block_given?
27
34
  obj
28
35
  end
@@ -59,6 +66,16 @@ module Zm
59
66
  keys.delete(:@parent)
60
67
  keys.map { |key| [key, instance_variable_get(key)] }
61
68
  end
69
+
70
+ protected
71
+
72
+ def remove_dependents_of(item)
73
+ instance_variables.each do |key|
74
+ next if key == :@parent
75
+
76
+ remove_instance_variable(key) if instance_variable_get(key).instance_variable_get(:@parent).equal?(item)
77
+ end
78
+ end
62
79
  end
63
80
  end
64
81
  end
@@ -5,7 +5,7 @@ module Zm
5
5
  module Base
6
6
  # Abstract Class Collection
7
7
  class ObjectsCollection
8
- include Zm::Inspector
8
+ include Zm::Utils::Inspector
9
9
 
10
10
  METHODS_MISSING_LIST = %i[select each map length].to_set.freeze
11
11
  attr_reader :parent
@@ -17,7 +17,7 @@ module Zm
17
17
  end
18
18
 
19
19
  def find(id)
20
- find_by(id: id)
20
+ find_by(id:)
21
21
  end
22
22
 
23
23
  def first
@@ -46,7 +46,7 @@ module Zm
46
46
  end
47
47
  alias offset page
48
48
 
49
- def order(sort_by, sort_ascending = SoapUtils::ON)
49
+ def order(sort_by, sort_ascending = Zm::Utils::SearchUtils::ON)
50
50
  return self if @sort_by == sort_by && @sort_ascending == sort_ascending
51
51
 
52
52
  @sort_by = sort_by
@@ -88,19 +88,19 @@ module Zm
88
88
  # @attrs.compact!
89
89
  return nil if @attrs.empty?
90
90
 
91
- @attrs.join(COMMA)
91
+ @attrs.join(',')
92
92
  end
93
93
 
94
94
  def reset_query_params
95
- @max_result = SoapUtils::MAX_RESULT
95
+ @max_result = Zm::Utils::SearchUtils::MAX_RESULT
96
96
  @limit = nil
97
97
  @offset = nil
98
98
  @sort_by = nil
99
- @sort_ascending = SoapUtils::ON
100
- @count_only = SoapUtils::OFF
101
- @all_servers = SoapUtils::OFF
102
- @refresh = SoapUtils::OFF
103
- @apply_cos = SoapUtils::ON
99
+ @sort_ascending = Zm::Utils::SearchUtils::ON
100
+ @count_only = Zm::Utils::SearchUtils::OFF
101
+ @all_servers = Zm::Utils::SearchUtils::OFF
102
+ @refresh = Zm::Utils::SearchUtils::OFF
103
+ @apply_cos = Zm::Utils::SearchUtils::ON
104
104
  end
105
105
  end
106
106
  end
@@ -4,119 +4,105 @@ module Zm
4
4
  module Client
5
5
  module Base
6
6
  class ZimbraAttribute
7
- attr_reader :name, :optionalIn, :flags, :requiredIn, :cardinality, :callback, :immutable, :type, :value, :max,
8
- :min, :since
7
+ attr_reader :name, :type, :objects_scope
9
8
 
10
- def initialize(name: nil, optionalIn: nil, flags: nil, requiredIn: nil, cardinality: nil, callback: nil,
11
- immutable: nil, type: nil, value: nil, max: nil, min: nil, since: nil)
9
+ def initialize(name: nil, optionalIn: nil, requiredIn: nil, immutable: nil, type: nil, **)
12
10
  @name = name
13
- @optionalIn = optionalIn.to_s.split(',')
14
- @flags = flags
15
- @requiredIn = requiredIn.to_s.split(',')
16
- @cardinality = cardinality
17
- @callback = callback
18
- @immutable = immutable
19
- @type = type
20
- @value = value
21
- @max = max
22
- @min = min
23
- @since = since
11
+ @type = type && -type
12
+ @immutable = immutable == '1'
13
+ @objects_scope = (optionalIn.to_s.split(',') + requiredIn.to_s.split(',')).map!(&:-@).freeze
24
14
  end
25
15
 
26
16
  def immutable?
27
- immutable == '1'
28
- end
29
-
30
- def objects_scope
31
- @objects_scope ||= (optionalIn + requiredIn).freeze
17
+ @immutable
32
18
  end
33
19
 
34
20
  def is_account_scoped?
35
- @is_account_scoped ||= objects_scope.include?('account')
21
+ objects_scope.include?('account')
36
22
  end
37
23
 
38
24
  def is_aclTarget_scoped?
39
- @is_aclTarget_scoped ||= objects_scope.include?('aclTarget')
25
+ objects_scope.include?('aclTarget')
40
26
  end
41
27
 
42
28
  def is_alias_scoped?
43
- @is_alias_scoped ||= objects_scope.include?('alias')
29
+ objects_scope.include?('alias')
44
30
  end
45
31
 
46
32
  def is_alwaysOnCluster_scoped?
47
- @is_alwaysOnCluster_scoped ||= objects_scope.include?('alwaysOnCluster')
33
+ objects_scope.include?('alwaysOnCluster')
48
34
  end
49
35
 
50
36
  def is_calendarResource_scoped?
51
- @is_calendarResource_scoped ||= objects_scope.include?('calendarResource') || objects_scope.include?('account')
37
+ objects_scope.include?('calendarResource') || objects_scope.include?('account')
52
38
  end
53
39
 
54
40
  def is_cos_scoped?
55
- @is_cos_scoped ||= objects_scope.include?('cos')
41
+ objects_scope.include?('cos')
56
42
  end
57
43
 
58
44
  def is_dataSource_scoped?
59
- @is_dataSource_scoped ||= objects_scope.include?('dataSource')
45
+ objects_scope.include?('dataSource')
60
46
  end
61
47
 
62
48
  def is_distributionList_scoped?
63
- @is_distributionList_scoped ||= objects_scope.include?('distributionList')
49
+ objects_scope.include?('distributionList')
64
50
  end
65
51
 
66
52
  def is_domain_scoped?
67
- @is_domain_scoped ||= objects_scope.include?('domain')
53
+ objects_scope.include?('domain')
68
54
  end
69
55
 
70
56
  def is_globalConfig_scoped?
71
- @is_globalConfig_scoped ||= objects_scope.include?('globalConfig')
57
+ objects_scope.include?('globalConfig')
72
58
  end
73
59
 
74
60
  def is_group_scoped?
75
- @is_group_scoped ||= objects_scope.include?('group')
61
+ objects_scope.include?('group')
76
62
  end
77
63
 
78
64
  def is_groupDynamicUnit_scoped?
79
- @is_groupDynamicUnit_scoped ||= objects_scope.include?('groupDynamicUnit')
65
+ objects_scope.include?('groupDynamicUnit')
80
66
  end
81
67
 
82
68
  def is_groupStaticUnit_scoped?
83
- @is_groupStaticUnit_scoped ||= objects_scope.include?('groupStaticUnit')
69
+ objects_scope.include?('groupStaticUnit')
84
70
  end
85
71
 
86
72
  def is_identity_scoped?
87
- @is_identity_scoped ||= objects_scope.include?('identity')
73
+ objects_scope.include?('identity')
88
74
  end
89
75
 
90
76
  def is_mailRecipient_scoped?
91
- @is_mailRecipient_scoped ||= objects_scope.include?('mailRecipient')
77
+ objects_scope.include?('mailRecipient')
92
78
  end
93
79
 
94
80
  def is_mimeEntry_scoped?
95
- @is_mimeEntry_scoped ||= objects_scope.include?('mimeEntry')
81
+ objects_scope.include?('mimeEntry')
96
82
  end
97
83
 
98
84
  def is_objectEntry_scoped?
99
- @is_objectEntry_scoped ||= objects_scope.include?('objectEntry')
85
+ objects_scope.include?('objectEntry')
100
86
  end
101
87
 
102
88
  def is_server_scoped?
103
- @is_server_scoped ||= objects_scope.include?('server')
89
+ objects_scope.include?('server')
104
90
  end
105
91
 
106
92
  def is_signature_scoped?
107
- @is_signature_scoped ||= objects_scope.include?('signature')
93
+ objects_scope.include?('signature')
108
94
  end
109
95
 
110
96
  def is_ucService_scoped?
111
- @is_ucService_scoped ||= objects_scope.include?('ucService')
97
+ objects_scope.include?('ucService')
112
98
  end
113
99
 
114
100
  def is_xmppComponent_scoped?
115
- @is_xmppComponent_scoped ||= objects_scope.include?('xmppComponent')
101
+ objects_scope.include?('xmppComponent')
116
102
  end
117
103
 
118
104
  def is_zimletEntry_scoped?
119
- @is_zimletEntry_scoped ||= objects_scope.include?('zimletEntry')
105
+ objects_scope.include?('zimletEntry')
120
106
  end
121
107
  end
122
108
  end
@@ -1,30 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'zm/client/base/zimbra_attribute'
4
3
  require 'csv'
5
4
 
6
5
  module Zm
7
6
  module Client
8
7
  module Base
9
8
  class ZimbraAttributesCollection
10
- include MissingMethodStaticCollection
9
+ include Zm::Utils::MissingMethodStaticCollection
11
10
 
12
- attr_reader :all_versioned
11
+ MUTEX = Mutex.new
12
+ CSV_OPTIONS = {
13
+ headers: true, skip_blanks: true, strip: true, header_converters: ->(header) { header.to_sym }
14
+ }.freeze
15
+
16
+ class << self
17
+ def shared(parent)
18
+ path = File.expand_path(parent.config.zimbra_attributes_path)
19
+ MUTEX.synchronize { shared_instances[path] ||= new(parent).tap(&:set_methods) }
20
+ end
21
+
22
+ def load_attributes(path)
23
+ CSV.open(path, **CSV_OPTIONS).map do |attr|
24
+ attr_h = attr.to_h
25
+ attr_h.compact!
26
+ ZimbraAttribute.new(**attr_h)
27
+ end.freeze
28
+ end
29
+
30
+ private
31
+
32
+ def shared_instances
33
+ @shared_instances ||= {}
34
+ end
35
+ end
36
+
37
+ attr_reader :path
13
38
 
14
39
  def initialize(parent)
15
- @parent = parent
16
-
17
- @all = CSV.open(
18
- File.expand_path(@parent.config.zimbra_attributes_path),
19
- headers: true,
20
- skip_blanks: true,
21
- strip: true,
22
- header_converters: lambda { |header| header.to_sym }
23
- ).map do |attr|
24
- attr_h = attr.to_h
25
- attr_h.compact!
26
- ZimbraAttribute.new(**attr_h)
27
- end.freeze
40
+ @path = File.expand_path(parent.config.zimbra_attributes_path)
41
+ @all = self.class.load_attributes(@path)
28
42
  end
29
43
 
30
44
  def set_methods
@@ -53,7 +67,7 @@ module Zm
53
67
  end
54
68
 
55
69
  def all_cos_attr_types_h
56
- @all_cos_attr_types_h ||= all_cos_attrs.map { |attr| [attr.name, attr.type] }.to_h.freeze
70
+ @all_cos_attr_types_h ||= all_cos_attrs.to_h { |attr| [attr.name, attr.type] }.freeze
57
71
  end
58
72
 
59
73
  def set_cos_methods
@@ -77,7 +91,7 @@ module Zm
77
91
  end
78
92
 
79
93
  def all_server_attr_types_h
80
- @all_server_attr_types_h ||= all_server_attrs.map { |attr| [attr.name, attr.type] }.to_h.freeze
94
+ @all_server_attr_types_h ||= all_server_attrs.to_h { |attr| [attr.name, attr.type] }.freeze
81
95
  end
82
96
 
83
97
  def set_server_methods
@@ -101,7 +115,7 @@ module Zm
101
115
  end
102
116
 
103
117
  def all_domain_attr_types_h
104
- @all_domain_attr_types_h ||= all_domain_attrs.map { |attr| [attr.name, attr.type] }.to_h.freeze
118
+ @all_domain_attr_types_h ||= all_domain_attrs.to_h { |attr| [attr.name, attr.type] }.freeze
105
119
  end
106
120
 
107
121
  def set_domain_methods
@@ -125,7 +139,7 @@ module Zm
125
139
  end
126
140
 
127
141
  def all_account_attr_types_h
128
- @all_account_attr_types_h ||= all_account_attrs.map { |attr| [attr.name, attr.type] }.to_h.freeze
142
+ @all_account_attr_types_h ||= all_account_attrs.to_h { |attr| [attr.name, attr.type] }.freeze
129
143
  end
130
144
 
131
145
  def set_account_methods
@@ -151,9 +165,9 @@ module Zm
151
165
  end
152
166
 
153
167
  def all_distributionlist_attrs_types_h
154
- @all_distributionlist_attrs_types_h ||= all_distributionlist_attrs.map do |attr|
155
- [attr.name, attr.type]
156
- end.to_h.freeze
168
+ @all_distributionlist_attrs_types_h ||= all_distributionlist_attrs.to_h do |attr|
169
+ [attr.name, attr.type]
170
+ end.freeze
157
171
  end
158
172
 
159
173
  def set_distributionlist_methods
@@ -177,7 +191,7 @@ module Zm
177
191
  end
178
192
 
179
193
  def all_resource_attrs_types_h
180
- @all_resource_attrs_types_h ||= all_resource_attrs.map { |attr| [attr.name, attr.type] }.to_h.freeze
194
+ @all_resource_attrs_types_h ||= all_resource_attrs.to_h { |attr| [attr.name, attr.type] }.freeze
181
195
  end
182
196
 
183
197
  def set_resource_methods
@@ -25,7 +25,7 @@ module Zm
25
25
  private
26
26
 
27
27
  def build(onerror)
28
- soap_request = SoapElement.new(SoapConstants::BATCH_REQUEST, SoapConstants::NAMESPACE_STR)
28
+ soap_request = SoapRequest::SoapElement.new(SoapRequest::SoapConstants::BATCH_REQUEST, SoapRequest::SoapConstants::NAMESPACE_STR)
29
29
  soap_request.add_attribute(:onerror, onerror)
30
30
 
31
31
  @requests.each_with_index do |request, index|
@@ -1,21 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'zm/client/connector/soap_admin'
4
- require 'zm/client/connector/soap_account'
5
- require 'zm/client/common'
6
- require 'zm/client/account'
7
- require 'zm/client/resource'
8
- require 'zm/client/distributionlist'
9
- require 'zm/client/domain'
10
- require 'zm/client/server'
11
- require 'zm/client/cos'
12
- require 'zm/client/license'
13
- require 'zm/client/cluster/batch_request'
14
-
15
3
  module Zm
16
4
  module Client
17
5
  # class admin connection
18
6
  class Cluster
7
+ extend Zm::Relationship
8
+
9
+ COUNT_OBJECT_TYPES = %i[userAccount account alias dl domain cos server calresource internalUserAccount].freeze
10
+
19
11
  attr_reader :soap_admin_connector, :config, :zimbra_attributes, :type, :version, :release, :buildDate, :host,
20
12
  :majorversion, :minorversion, :microversion
21
13
 
@@ -23,10 +15,9 @@ module Zm
23
15
  @config = config
24
16
  @version = config.zimbra_version
25
17
 
26
- @zimbra_attributes = Base::ZimbraAttributesCollection.new(self)
27
- @zimbra_attributes.set_methods
18
+ @zimbra_attributes = Base::ZimbraAttributesCollection.shared(self)
28
19
 
29
- @soap_admin_connector = SoapAdminConnector.create(@config)
20
+ @soap_admin_connector = Zm::Connector::SoapAdminConnector.create(@config)
30
21
  end
31
22
 
32
23
  def has_admin_credentials?
@@ -50,9 +41,9 @@ module Zm
50
41
 
51
42
  @soap_admin_connector.token = nil if logged?
52
43
 
53
- soap_request = SoapElement.admin(SoapAdminConstants::AUTH_REQUEST)
44
+ soap_request = SoapRequest::SoapElement.admin(Zm::SoapRequest::SoapAdminConstants::AUTH_REQUEST)
54
45
  soap_request.add_attributes(name: @config.zimbra_admin_login, password: @config.zimbra_admin_password)
55
- soap_resp = @soap_admin_connector.invoke(soap_request, Zm::Client::AuthError)
46
+ soap_resp = @soap_admin_connector.invoke(soap_request, Zm::Error::AuthError)
56
47
  soap_resp_token = soap_resp[:AuthResponse][:authToken].first[:_content]
57
48
  self.token = soap_resp_token
58
49
  end
@@ -62,10 +53,10 @@ module Zm
62
53
  end
63
54
 
64
55
  def alive?
65
- soap_request = SoapElement.admin(SoapAdminConstants::NO_OP_REQUEST)
56
+ soap_request = SoapRequest::SoapElement.admin(Zm::SoapRequest::SoapAdminConstants::NO_OP_REQUEST)
66
57
  @soap_admin_connector.invoke(soap_request)
67
58
  true
68
- rescue Zm::Client::SoapError => e
59
+ rescue Zm::Error::SoapError => e
69
60
  logger.error "Admin session token alive ? #{e.message}"
70
61
  false
71
62
  end
@@ -78,48 +69,19 @@ module Zm
78
69
  return @license if defined? @license
79
70
 
80
71
  @license = LicensesCollection.new(self).find
81
- rescue Zm::Client::SoapError => e
72
+ rescue Zm::Error::SoapError => e
82
73
  logger.error "Get License info #{e.message}"
83
74
  nil
84
75
  end
85
76
 
86
- def domains
87
- return @domains if defined? @domains
88
-
89
- @domains = DomainsCollection.new self
90
- end
91
-
92
- def accounts
93
- return @accounts if defined? @accounts
94
-
95
- @accounts = AccountsCollection.new self
96
- end
97
-
98
- def resources
99
- return @resources if defined? @resources
100
-
101
- @resources = ResourcesCollection.new self
102
- end
103
-
104
- def servers
105
- return @servers if defined? @servers
106
-
107
- @servers = ServersCollection.new self
108
- end
109
-
110
- def coses
111
- return @coses if defined? @coses
112
-
113
- @coses = CosesCollection.new self
114
- end
115
-
116
- def distributionlists
117
- return @distributionlists if defined? @distributionlists
118
-
119
- @distributionlists = DistributionListsCollection.new self
120
- end
77
+ has_many :domains
78
+ has_many :accounts
79
+ has_many :resources
80
+ has_many :servers
81
+ has_many :coses
82
+ has_many :distribution_lists
121
83
 
122
- alias distribution_lists distributionlists
84
+ alias distributionlists distribution_lists
123
85
 
124
86
  def domain_key(domain_name)
125
87
  if logged?
@@ -130,9 +92,10 @@ module Zm
130
92
  end
131
93
 
132
94
  def count_object(type)
133
- raise ZmError, 'Unknown object type' unless Zm::Client::CountTypes::ALL.include?(type)
95
+ type = type.to_sym if type.is_a?(String)
96
+ raise Zm::Error::ZmError, 'Unknown object type' unless COUNT_OBJECT_TYPES.include?(type)
134
97
 
135
- soap_request = SoapElement.admin(SoapAdminConstants::COUNT_OBJECTS_REQUEST)
98
+ soap_request = SoapRequest::SoapElement.admin(Zm::SoapRequest::SoapAdminConstants::COUNT_OBJECTS_REQUEST)
136
99
  soap_request.add_attribute('type', type)
137
100
  soap_resp = @soap_admin_connector.invoke(soap_request)
138
101
  soap_resp[:CountObjectsResponse][:num]
@@ -142,17 +105,17 @@ module Zm
142
105
  jsns = {
143
106
  query: "(mail=#{email})",
144
107
  types: 'accounts,distributionlists,aliases,resources',
145
- countOnly: SoapUtils::ON
108
+ countOnly: Zm::Utils::SearchUtils::ON
146
109
  }
147
110
 
148
- soap_request = SoapElement.admin(SoapAdminConstants::SEARCH_DIRECTORY_REQUEST)
111
+ soap_request = SoapRequest::SoapElement.admin(Zm::SoapRequest::SoapAdminConstants::SEARCH_DIRECTORY_REQUEST)
149
112
  soap_request.add_attributes(jsns)
150
113
  soap_resp = @soap_admin_connector.invoke(soap_request)
151
114
  !soap_resp[:SearchDirectoryResponse][:num].zero?
152
115
  end
153
116
 
154
117
  def infos!
155
- soap_request = SoapElement.admin(SoapAdminConstants::GET_VERSION_INFO_REQUEST)
118
+ soap_request = SoapRequest::SoapElement.admin(Zm::SoapRequest::SoapAdminConstants::GET_VERSION_INFO_REQUEST)
156
119
  soap_response = @soap_admin_connector.invoke(soap_request)
157
120
 
158
121
  json = soap_response[:GetVersionInfoResponse][:info].first