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