zm-ruby-client 0.10.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +58 -0
  3. data/Gemfile +8 -0
  4. data/LICENSE +674 -0
  5. data/README.md +47 -0
  6. data/SECURITY.md +21 -0
  7. data/lib/zm/client/account/account.rb +335 -0
  8. data/lib/zm/client/account/account_dls_membership_collection.rb +22 -0
  9. data/lib/zm/client/account/account_dls_owner_collection.rb +22 -0
  10. data/lib/zm/client/account/accounts_builder.rb +19 -0
  11. data/lib/zm/client/account/accounts_collection.rb +48 -0
  12. data/lib/zm/client/account.rb +7 -0
  13. data/lib/zm/client/ace/ace.rb +32 -0
  14. data/lib/zm/client/ace/aces_builder.rb +25 -0
  15. data/lib/zm/client/ace/aces_collection.rb +36 -0
  16. data/lib/zm/client/ace.rb +5 -0
  17. data/lib/zm/client/appointment/appointment.rb +143 -0
  18. data/lib/zm/client/appointment/appointment_jsns_builder.rb +125 -0
  19. data/lib/zm/client/appointment/appointment_jsns_initializer.rb +129 -0
  20. data/lib/zm/client/appointment/appointments_builder.rb +33 -0
  21. data/lib/zm/client/appointment/appointments_collection.rb +106 -0
  22. data/lib/zm/client/appointment.rb +7 -0
  23. data/lib/zm/client/backup/backup.rb +59 -0
  24. data/lib/zm/client/backup/backups_builder.rb +26 -0
  25. data/lib/zm/client/backup/backups_collection.rb +22 -0
  26. data/lib/zm/client/backup.rb +5 -0
  27. data/lib/zm/client/base/account_object.rb +17 -0
  28. data/lib/zm/client/base/admin_object.rb +45 -0
  29. data/lib/zm/client/base/object.rb +80 -0
  30. data/lib/zm/client/base/objects_builder.rb +31 -0
  31. data/lib/zm/client/base/objects_collection.rb +135 -0
  32. data/lib/zm/client/base.rb +7 -0
  33. data/lib/zm/client/cluster/cluster.rb +117 -0
  34. data/lib/zm/client/cluster/cluster_config.rb +100 -0
  35. data/lib/zm/client/cluster.rb +4 -0
  36. data/lib/zm/client/common/message.rb +10 -0
  37. data/lib/zm/client/common/recipients.rb +67 -0
  38. data/lib/zm/client/common.rb +4 -0
  39. data/lib/zm/client/config.rb +12 -0
  40. data/lib/zm/client/connector/rest_account.rb +74 -0
  41. data/lib/zm/client/connector/soap_account.rb +562 -0
  42. data/lib/zm/client/connector/soap_admin.rb +512 -0
  43. data/lib/zm/client/connector/soap_base.rb +65 -0
  44. data/lib/zm/client/connector/soap_error.rb +26 -0
  45. data/lib/zm/client/connector/soap_xml_builder.rb +68 -0
  46. data/lib/zm/client/constant.rb +217 -0
  47. data/lib/zm/client/contact/contact.rb +124 -0
  48. data/lib/zm/client/contact/contact_member.rb +73 -0
  49. data/lib/zm/client/contact/contacts_builder.rb +24 -0
  50. data/lib/zm/client/contact/contacts_collection.rb +26 -0
  51. data/lib/zm/client/contact/mod_group_contact.rb +74 -0
  52. data/lib/zm/client/contact.rb +7 -0
  53. data/lib/zm/client/cos/cos.rb +59 -0
  54. data/lib/zm/client/cos/coses_builder.rb +29 -0
  55. data/lib/zm/client/cos/coses_collection.rb +33 -0
  56. data/lib/zm/client/cos.rb +5 -0
  57. data/lib/zm/client/data_source.rb +5 -0
  58. data/lib/zm/client/distributionlist/distributionlist.rb +125 -0
  59. data/lib/zm/client/distributionlist/distributionlists_builder.rb +29 -0
  60. data/lib/zm/client/distributionlist/distributionlists_collection.rb +41 -0
  61. data/lib/zm/client/distributionlist.rb +5 -0
  62. data/lib/zm/client/document/document.rb +47 -0
  63. data/lib/zm/client/document/documents_builder.rb +31 -0
  64. data/lib/zm/client/document/documents_collection.rb +93 -0
  65. data/lib/zm/client/document.rb +5 -0
  66. data/lib/zm/client/domain/domain.rb +74 -0
  67. data/lib/zm/client/domain/domains_builder.rb +32 -0
  68. data/lib/zm/client/domain/domains_collection.rb +36 -0
  69. data/lib/zm/client/domain.rb +5 -0
  70. data/lib/zm/client/folder/folder.rb +215 -0
  71. data/lib/zm/client/folder/folder_grant.rb +58 -0
  72. data/lib/zm/client/folder/folder_retention_policy.rb +48 -0
  73. data/lib/zm/client/folder/folders_builder.rb +58 -0
  74. data/lib/zm/client/folder/folders_collection.rb +70 -0
  75. data/lib/zm/client/folder/mod_document_folder.rb +17 -0
  76. data/lib/zm/client/folder.rb +8 -0
  77. data/lib/zm/client/identity/identities_builder.rb +25 -0
  78. data/lib/zm/client/identity/identities_collection.rb +26 -0
  79. data/lib/zm/client/identity/identity.rb +75 -0
  80. data/lib/zm/client/identity.rb +5 -0
  81. data/lib/zm/client/license/license.rb +29 -0
  82. data/lib/zm/client/license/licenses_collection.rb +28 -0
  83. data/lib/zm/client/license.rb +4 -0
  84. data/lib/zm/client/message/message.rb +225 -0
  85. data/lib/zm/client/message/messages_builder.rb +31 -0
  86. data/lib/zm/client/message/messages_collection.rb +111 -0
  87. data/lib/zm/client/message.rb +5 -0
  88. data/lib/zm/client/mountpoint/mountpoint.rb +95 -0
  89. data/lib/zm/client/mountpoint/mountpoints_builder.rb +38 -0
  90. data/lib/zm/client/mountpoint/mountpoints_collection.rb +61 -0
  91. data/lib/zm/client/mountpoint.rb +5 -0
  92. data/lib/zm/client/mta_queue/mta_queue.rb +60 -0
  93. data/lib/zm/client/mta_queue/mta_queues_builder.rb +26 -0
  94. data/lib/zm/client/mta_queue/mta_queues_collection.rb +95 -0
  95. data/lib/zm/client/mta_queue.rb +5 -0
  96. data/lib/zm/client/mta_queue_item/mta_queue_item.rb +51 -0
  97. data/lib/zm/client/mta_queue_item/mta_queue_items_builder.rb +27 -0
  98. data/lib/zm/client/mta_queue_item/mta_queue_items_collection.rb +99 -0
  99. data/lib/zm/client/mta_queue_item.rb +5 -0
  100. data/lib/zm/client/resource/resource.rb +149 -0
  101. data/lib/zm/client/resource/resources_builder.rb +29 -0
  102. data/lib/zm/client/resource/resources_collection.rb +41 -0
  103. data/lib/zm/client/resource.rb +5 -0
  104. data/lib/zm/client/search_folder/search_folder.rb +63 -0
  105. data/lib/zm/client/search_folder/search_folders_builder.rb +26 -0
  106. data/lib/zm/client/search_folder/search_folders_collection.rb +28 -0
  107. data/lib/zm/client/search_folder.rb +5 -0
  108. data/lib/zm/client/server/server.rb +516 -0
  109. data/lib/zm/client/server/servers_builder.rb +26 -0
  110. data/lib/zm/client/server/servers_collection.rb +37 -0
  111. data/lib/zm/client/server.rb +5 -0
  112. data/lib/zm/client/share/share.rb +60 -0
  113. data/lib/zm/client/share/shares_builder.rb +23 -0
  114. data/lib/zm/client/share/shares_collection.rb +48 -0
  115. data/lib/zm/client/share.rb +5 -0
  116. data/lib/zm/client/signature/signature.rb +62 -0
  117. data/lib/zm/client/signature/signature_jsns_builder.rb +29 -0
  118. data/lib/zm/client/signature/signatures_builder.rb +26 -0
  119. data/lib/zm/client/signature/signatures_collection.rb +28 -0
  120. data/lib/zm/client/signature.rb +6 -0
  121. data/lib/zm/client/tag/tag.rb +45 -0
  122. data/lib/zm/client/tag/tags_builder.rb +25 -0
  123. data/lib/zm/client/tag/tags_collection.rb +26 -0
  124. data/lib/zm/client/tag.rb +5 -0
  125. data/lib/zm/client/task/task.rb +74 -0
  126. data/lib/zm/client/task/tasks_builder.rb +31 -0
  127. data/lib/zm/client/task/tasks_collection.rb +100 -0
  128. data/lib/zm/client/task.rb +5 -0
  129. data/lib/zm/client/upload/upload.rb +154 -0
  130. data/lib/zm/client/upload.rb +3 -0
  131. data/lib/zm/client/version.rb +18 -0
  132. data/lib/zm/client.rb +5 -0
  133. data/lib/zm/modules/common/account_common.rb +71 -0
  134. data/lib/zm/modules/common/cos_common.rb +463 -0
  135. data/lib/zm/modules/common/dl_common.rb +33 -0
  136. data/lib/zm/modules/common/identity_common.rb +19 -0
  137. data/lib/zm/modules/common/resource_common.rb +59 -0
  138. data/lib/zm/modules/common/signature_common.rb +16 -0
  139. data/lib/zm/modules/common/zimbra-attrs.json +1 -0
  140. data/lib/zm/utils/thread_pool.rb +72 -0
  141. data/lib/zm-ruby-client.rb +1 -0
  142. data/test/accounts.rb +62 -0
  143. data/test/cluster_config.rb +30 -0
  144. data/test/coses.rb +26 -0
  145. data/test/domains.rb +62 -0
  146. data/zm-ruby-client.gemspec +24 -0
  147. metadata +243 -0
@@ -0,0 +1,217 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ COMMA = ','
6
+ DOUBLEPOINT = ' :: '
7
+
8
+ module Regex
9
+ UUID_REGEX = %r{[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}}
10
+ BASEDN_REGEX = %r{^uid=}
11
+ SHARED_CONTACT = %r{[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}:[0-9]+}
12
+ end
13
+
14
+ module FolderDefault
15
+ ROOT = { id: 1, name: '', path: '/', type: 'unknown' }.freeze
16
+ BRIEFCASE = { id: 16, name: 'Briefcase', path: '/Briefcase', type: 'document' }.freeze
17
+ CALENDAR = { id: 10, name: 'Calendar', path: '/Calendar', type: 'appointment' }.freeze
18
+ CHATS = { id: 14, name: 'Chats', path: '/Chats', type: 'message' }.freeze
19
+ CONTACTS = { id: 7, name: 'Contacts', path: '/Contacts', type: 'contact' }.freeze
20
+ DRAFTS = { id: 6, name: 'Drafts', path: '/Drafts', type: 'message' }.freeze
21
+ EMAILED = { id: 13, name: 'Emailed Contacts', path: '/Emailed Contacts', type: 'contact' }.freeze
22
+ INBOX = { id: 2, name: 'Inbox', path: '/Inbox', type: 'message' }.freeze
23
+ JUNK = { id: 4, name: 'Junk', path: '/Junk', type: 'message' }.freeze
24
+ SENT = { id: 5, name: 'Sent', path: '/Sent', type: 'message' }.freeze
25
+ TASKS = { id: 15, name: 'Tasks', path: '/Tasks', type: 'task' }.freeze
26
+ TRASH = { id: 3, name: 'Trash', path: '/Trash', type: 'unknown' }.freeze
27
+
28
+ ALL = [
29
+ ROOT,
30
+ BRIEFCASE,
31
+ CALENDAR,
32
+ CHATS,
33
+ CONTACTS,
34
+ DRAFTS,
35
+ EMAILED,
36
+ INBOX,
37
+ JUNK,
38
+ SENT,
39
+ TASKS,
40
+ TRASH
41
+ ].freeze
42
+
43
+ IDS = ALL.map { |folder| folder[:id] }.freeze
44
+ end
45
+
46
+ module ShareType
47
+ VIEWER = :r
48
+ MANAGER = :rwidx
49
+ ADMIN = :rwidxa
50
+ end
51
+
52
+ module FolderView
53
+ UNKNOWN = 'unknown'
54
+ MESSAGE = 'message'
55
+ APPOINTMENT = 'appointment'
56
+ TASK = 'task'
57
+ DOCUMENT = 'document'
58
+ CONTACT = 'contact'
59
+ ALL = [MESSAGE, APPOINTMENT, TASK, DOCUMENT, CONTACT].freeze
60
+ end
61
+
62
+ module FolderType
63
+ FOLDER = :folder
64
+ LINK = :link
65
+ SEARCH = :search
66
+ ALL = [FOLDER, LINK, SEARCH].freeze
67
+ end
68
+
69
+ module SoapUtils
70
+ MAX_RESULT = 1_000_000
71
+ ON = 1
72
+ OFF = 0
73
+ OFFSET = 0
74
+ LIMIT_RESULT = 10_000
75
+ end
76
+
77
+ module SearchType
78
+ ACCOUNT = :accounts
79
+ DL = :distributionlists
80
+ ALIAS = :aliases
81
+ RESOURCE = :resources
82
+ DOMAIN = :domains
83
+ COS = :coses
84
+
85
+ module Attributes
86
+ ACCOUNT = %i[
87
+ displayName
88
+ zimbraId
89
+ cn
90
+ sn
91
+ zimbraMailHost
92
+ uid
93
+ zimbraCOSId
94
+ zimbraAccountStatus
95
+ zimbraLastLogonTimestamp
96
+ description
97
+ zimbraIsSystemAccount
98
+ zimbraIsDelegatedAdminAccount
99
+ zimbraAuthTokenValidityValue
100
+ zimbraMailStatus
101
+ zimbraIsAdminAccount
102
+ zimbraIsExternalVirtualAccount
103
+ ].freeze
104
+
105
+ DL = %i[
106
+ displayName
107
+ zimbraId
108
+ zimbraMailHost
109
+ uid
110
+ description
111
+ zimbraMailStatus
112
+ zimbraMailAlias
113
+ ].freeze
114
+
115
+ ALIAS = %i[
116
+ zimbraAliasTargetId
117
+ zimbraId
118
+ targetName
119
+ uid
120
+ type
121
+ description
122
+ zimbraIsDelegatedAdminAccount
123
+ zimbraIsAdminAccount
124
+ zimbraIsSystemResource
125
+ zimbraIsSystemAccount
126
+ zimbraIsExternalVirtualAccount
127
+ ].freeze
128
+
129
+ RESOURCE = %i[
130
+ displayName
131
+ zimbraId
132
+ zimbraMailHost
133
+ uid
134
+ zimbraAccountStatus
135
+ description
136
+ zimbraCalResType
137
+ zimbraIsDelegatedAdminAccount
138
+ zimbraIsAdminAccount
139
+ zimbraIsSystemResource
140
+ zimbraIsSystemAccount
141
+ zimbraIsExternalVirtualAccount
142
+ ].freeze
143
+
144
+ DOMAIN = %i[
145
+ description
146
+ zimbraDomainName
147
+ zimbraDomainStatus
148
+ zimbraId
149
+ zimbraDomainType
150
+ zimbraDomainDefaultCOSId
151
+ ].freeze
152
+
153
+ COS = %i[
154
+ cn
155
+ description
156
+ zimbraMailHostPool
157
+ zimbraMailQuota
158
+ ].freeze
159
+ end
160
+ end
161
+
162
+ module ServerServices
163
+ AMAVIS = 'amavis'
164
+ ANTIVIRUS = 'antivirus'
165
+ ANTISPAM = 'antispam'
166
+ OPENDKIM = 'opendkim'
167
+ DNSCACHE = 'dnscache'
168
+ LOGGER = 'logger'
169
+ LDAP = 'ldap'
170
+ SERVICE = 'service'
171
+ ZIMBRA = 'zimbra'
172
+ ZIMBRA_ADMIN = 'zimbraAdmin'
173
+ ZIMLET = 'zimlet'
174
+ MAILBOX = 'mailbox'
175
+ MEMCACHED = 'memcached'
176
+ SPELL = 'spell'
177
+ MTA = 'mta'
178
+ PROXY = 'proxy'
179
+ STATS = 'stats'
180
+ SNMP = 'snmp'
181
+ end
182
+
183
+ module MtaQueueName
184
+ INCOMING = 'incoming'
185
+ DEFERRED = 'deferred'
186
+ CORRUPT = 'corrupt'
187
+ ACTIVE = 'active'
188
+ HOLD = 'hold'
189
+ ALL = [INCOMING, DEFERRED, CORRUPT, ACTIVE, HOLD]
190
+ end
191
+
192
+ module MtaQueueAction
193
+ HOLD = 'hold'
194
+ RELEASE = 'release'
195
+ DELETE = 'delete'
196
+ REQUEUE = 'requeue'
197
+ end
198
+
199
+ module BackupTypes
200
+ FULL = 'full'
201
+ INCREMENTAL = 'incremental'
202
+ end
203
+
204
+ module CountTypes
205
+ USER_ACCOUNT = 'userAccount'
206
+ ACCOUNT = 'account'
207
+ ALIAS = 'alias'
208
+ DL = 'dl'
209
+ DOMAIN = 'domain'
210
+ COS = 'cos'
211
+ SERVER = 'server'
212
+ RESOURCE = 'calresource'
213
+ INTERNAL_USER_ACCOUNT = 'internalUserAccount'
214
+ ALL = [USER_ACCOUNT, ACCOUNT, ALIAS, DL, DOMAIN, COS, SERVER, RESOURCE, INTERNAL_USER_ACCOUNT]
215
+ end
216
+ end
217
+ end
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class account tag
6
+ class Contact < Base::AccountObject
7
+ GROUP_PATTERN = 'group'
8
+
9
+ INSTANCE_VARIABLE_KEYS = %i[
10
+ anniversary assistantPhone birthday callbackPhone carPhone company companyPhone custom1 department email email2
11
+ email3 email4 email5 email6 email7 firstName fullName homeCity homeCountry homeFax homePhone homePostalCode
12
+ homeState homeStreet homeURL imAddress1 imAddress2 imAddress3 imAddress4 imAddress5 jobTitle lastName maidenName
13
+ middleName mobilePhone namePrefix nameSuffix nickname notes otherCity otherCountry otherFax otherPhone
14
+ otherPostalCode otherState otherStreet otherURL pager workCity workCountry workFax workPhone workPostalCode
15
+ workState workStreet workURL image
16
+ ].freeze
17
+
18
+ attr_accessor *INSTANCE_VARIABLE_KEYS
19
+ attr_accessor :id, :name, :l, :type, :members, :old_members, :tn
20
+
21
+ def initialize(parent, json = nil)
22
+ @parent = parent
23
+ @members = []
24
+ @custom_keys = []
25
+ init_from_json(json) if json.is_a?(Hash)
26
+ yield(self) if block_given?
27
+ @old_members = @members.clone
28
+ end
29
+
30
+ def is_group?
31
+ @type == GROUP_PATTERN
32
+ end
33
+
34
+ def emails
35
+ [email, email2, email3, email4, email5, email6, email7].compact
36
+ end
37
+
38
+ def emails_h
39
+ {
40
+ 'email' => email,
41
+ 'email2' => email2,
42
+ 'email3' => email3,
43
+ 'email4' => email4,
44
+ 'email5' => email5,
45
+ 'email6' => email6,
46
+ 'email7' => email7
47
+ }.compact
48
+ end
49
+
50
+ def concat
51
+ [id, name, l] + all_instance_variable_keys.map { |key| instance_variable_get(arrow_name(key)) }
52
+ end
53
+
54
+ def to_h
55
+ hashmap = Hash[all_instance_variable_keys.map { |key| [key, instance_variable_get(arrow_name(key))] }]
56
+ hashmap.delete_if { |_, v| v.nil? }
57
+ hashmap
58
+ end
59
+
60
+ def init_from_json(json)
61
+ @id = json[:id]
62
+ @name = json[:fileAsStr]
63
+ @l = json[:l]
64
+ @tn = json[:tn]
65
+
66
+ init_instance_variable_from_json(json[:_attrs])
67
+
68
+ return unless is_group?
69
+
70
+ extend(GroupContact)
71
+ init_members_from_json(json[:m])
72
+ end
73
+
74
+ def init_instance_variable_from_json(json_attrs)
75
+ return if json_attrs.nil?
76
+
77
+ @type = json_attrs[:type]
78
+
79
+ make_custom_keys(json_attrs)
80
+
81
+ all_instance_variable_keys.each do |key|
82
+ instance_variable_set(arrow_name(key), json_attrs[key])
83
+ end
84
+ end
85
+
86
+ def make_custom_keys(json_attrs)
87
+ @custom_keys = json_attrs.keys - INSTANCE_VARIABLE_KEYS - %i[type fileAs]
88
+ return if @custom_keys.empty?
89
+
90
+ self.class.attr_accessor(*@custom_keys)
91
+ rescue StandardError => _
92
+ @custom_keys.clear
93
+ nil
94
+ end
95
+
96
+ def all_instance_variable_keys
97
+ INSTANCE_VARIABLE_KEYS + @custom_keys
98
+ end
99
+
100
+ def add_custom_property(key, value)
101
+ instance_variable_set(arrow_name(key), value)
102
+ @custom_keys << key unless all_instance_variable_keys.include?(key)
103
+ end
104
+
105
+ def create!
106
+ rep = @parent.sacc.create_contact(@parent.token, l, instance_variables_array(all_instance_variable_keys))
107
+ init_from_json(rep[:Body][:CreateContactResponse][:cn].first)
108
+ end
109
+
110
+ def delete!
111
+ @parent.sacc.contact_action(@parent.token, :delete, id)
112
+ end
113
+
114
+ def update!(hash)
115
+ @parent.sacc.modify_contact(@parent.token, id, hash)
116
+ hash.each { |k, v| send "#{k}=", v }
117
+ end
118
+
119
+ def modify!
120
+ @parent.sacc.modify_contact(@parent.token, id, instance_variables_array(all_instance_variable_keys))
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ class ConcatMember
6
+ INTERNAL = 'C'
7
+ FREE = 'I'
8
+ LDAP = 'G'
9
+ ADD = '+'
10
+ DEL = '-'
11
+
12
+ class << self
13
+ def find_type_by_value(value)
14
+ return INTERNAL if !value.to_i.zero? || Zm::Client::Regex::SHARED_CONTACT.match(value)
15
+ return LDAP if Zm::Client::Regex::BASEDN_REGEX.match(value)
16
+
17
+ FREE
18
+ end
19
+
20
+ def init_by_value(value)
21
+ type_v = find_type_by_value(value)
22
+ new(type_v, value)
23
+ end
24
+ end
25
+
26
+ attr_reader :type, :value, :op
27
+
28
+ def initialize(type, value, op = nil)
29
+ @op = op
30
+ @type = type
31
+ @value = value
32
+ end
33
+
34
+ def concat
35
+ [@value, @type, @op]
36
+ end
37
+
38
+ def to_s
39
+ concat.join(' :: ')
40
+ end
41
+
42
+ def internal?
43
+ @type == INTERNAL && !Zm::Client::Regex::SHARED_CONTACT.match(value)
44
+ end
45
+
46
+ def shared?
47
+ @type == INTERNAL && Zm::Client::Regex::SHARED_CONTACT.match(value)
48
+ end
49
+
50
+ def free?
51
+ @type == FREE
52
+ end
53
+
54
+ def ldap?
55
+ @type == LDAP
56
+ end
57
+
58
+ def add!
59
+ @op = ADD
60
+ end
61
+
62
+ def remove!
63
+ @op = DEL
64
+ end
65
+
66
+ def construct_soap_node
67
+ node = { type: @type, value: @value }
68
+ node[:op] = @op unless @op.nil?
69
+ node
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class factory [contacts]
6
+ class ContactBuilder < Base::ObjectsBuilder
7
+
8
+ def initialize(parent, json)
9
+ @parent = parent
10
+ @json = json
11
+ end
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
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # collection account contacts
6
+ class ContactsCollection < Base::ObjectsCollection
7
+ def initialize(parent)
8
+ @parent = parent
9
+ end
10
+
11
+ def new
12
+ contact = Contact.new(@parent)
13
+ yield(contact) if block_given?
14
+ contact
15
+ end
16
+
17
+ private
18
+
19
+ def build_response
20
+ rep = @parent.sacc.get_all_contacts(@parent.token)
21
+ cb = ContactBuilder.new @parent, rep
22
+ cb.make
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GroupContact
4
+ def init_members_from_json(m)
5
+ return if m.nil?
6
+
7
+ @members = m.map { |m| Zm::Client::ConcatMember.new(m[:type], m[:value]) }
8
+ end
9
+
10
+ def create!
11
+ rep = @parent.sacc.create_group_contact(@parent.token, l, construct_soap_attrs, construct_soap_node_members)
12
+ init_from_json(rep[:Body][:CreateContactResponse][:cn].first)
13
+ end
14
+
15
+ def modify!
16
+ @parent.sacc.modify_group_contact(@parent.token, id, construct_soap_attrs, construct_soap_node_members)
17
+ end
18
+
19
+ def construct_soap_attrs
20
+ [[:nickname, @name], [:fullname, @name], [:fileAs, "8:#{@name}"], %i[type group]]
21
+ end
22
+
23
+ def add_contacts(contacts)
24
+ contacts = [contacts] unless contacts.is_a?(Array)
25
+ new_members = contacts.map { |c| add_member_by_value(c.id) }
26
+ add_members(new_members)
27
+ end
28
+
29
+ def add_members(new_members)
30
+ new_members = [new_members] unless new_members.is_a?(Array)
31
+ @members += new_members
32
+ end
33
+
34
+ def add_members_by_values(member_values)
35
+ member_values = [member_values] unless member_values.is_a?(Array)
36
+ current_member_values = @members.map(&:value)
37
+ member_values.reject! { |value| current_member_values.include?(value) }
38
+ member_values.each { |value| add_member_by_value(value) }
39
+ end
40
+
41
+ def add_member_by_value(value)
42
+ @members << Zm::Client::ConcatMember.init_by_value(value)
43
+ end
44
+
45
+ def delete_members(del_members)
46
+ del_members = [del_members] unless del_members.is_a?(Array)
47
+ @members -= del_members
48
+ end
49
+
50
+ def del_members_by_values(member_values)
51
+ member_values = [member_values] unless member_values.is_a?(Array)
52
+ @members.delete_if { |m| member_values.include?(m.value) }
53
+ end
54
+
55
+ def ldap_members
56
+ return [] if @members.nil?
57
+
58
+ @members.select(&:ldap?)
59
+ end
60
+
61
+ def has_ldap_members?
62
+ ldap_members.any?
63
+ end
64
+
65
+ def construct_soap_node_members
66
+ if recorded?
67
+ (old_members - @members).each(&:remove!)
68
+ (@members - old_members).each(&:add!)
69
+ (old_members + @members).uniq.reject { |m| m.op.nil? }.map(&:construct_soap_node)
70
+ else
71
+ @members.map(&:construct_soap_node)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/contact/contact'
4
+ require 'zm/client/contact/contact_member'
5
+ require 'zm/client/contact/contacts_builder'
6
+ require 'zm/client/contact/contacts_collection'
7
+ require 'zm/client/contact/mod_group_contact'
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/modules/common/cos_common'
4
+ module Zm
5
+ module Client
6
+ # objectClass: zimbraCos
7
+ class Cos < Base::AdminObject
8
+ def initialize(parent)
9
+ extend(CosCommon)
10
+ super(parent)
11
+ end
12
+
13
+ def init_from_json(json)
14
+ super(json)
15
+ @zimbraMailHostPool = [@zimbraMailHostPool] if @zimbraMailHostPool.is_a?(String)
16
+ @zimbraZimletAvailableZimlets = [@zimbraZimletAvailableZimlets] if @zimbraZimletAvailableZimlets.is_a?(String)
17
+ end
18
+
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
+
25
+ def all_instance_variable_keys
26
+ attrs_write
27
+ end
28
+
29
+ def duplicate(attrs = {})
30
+ # n = clone
31
+ # attrs.each{|k,v| n.instance_variable_set(k, v) }
32
+ # n.id = nil
33
+ # n.zimbraId = nil
34
+ # n
35
+ end
36
+
37
+ def modify!
38
+ # sac.modify_cos(id, instance_variables_array)
39
+ end
40
+
41
+ def create!
42
+ sac.create_cos(name, instance_variables_array(attrs_write))
43
+ end
44
+
45
+ def servers
46
+ @servers ||= read_servers
47
+ end
48
+
49
+ private
50
+
51
+ def read_servers
52
+ sc = ServersCollection.new self
53
+ @zimbraMailHostPool.map do |server_id|
54
+ sc.find_by id: server_id
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class factory [coses]
6
+ class CosesBuilder < Base::ObjectsBuilder
7
+ def initialize(parent, json)
8
+ super(parent, json)
9
+ @child_class = Cos
10
+ end
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]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # Collection coses
6
+ class CosesCollection < Base::ObjectsCollection
7
+ def initialize(parent)
8
+ @child_class = Cos
9
+ @parent = parent
10
+ reset_query_params
11
+ end
12
+
13
+ def find_by(hash, *attrs)
14
+ rep = sac.get_cos(hash.values.first, hash.keys.first, attrs.join(COMMA))
15
+ entry = rep[:Body][:GetCosResponse][:cos].first
16
+
17
+ build_from_entry(entry)
18
+ end
19
+
20
+ private
21
+
22
+ def build_response
23
+ CosesBuilder.new(@parent, make_query).make
24
+ end
25
+
26
+ def reset_query_params
27
+ super
28
+ @search_type = SearchType::COS
29
+ @attrs = SearchType::Attributes::COS.dup
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/cos/cos'
4
+ require 'zm/client/cos/coses_builder'
5
+ require 'zm/client/cos/coses_collection'
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/data_source/data_source'
4
+ require 'zm/client/data_source/data_sources_builder'
5
+ require 'zm/client/data_source/data_sources_collection'