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,215 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for account folder
6
+ class Folder < Base::AccountObject
7
+
8
+ INSTANCE_VARIABLE_KEYS = %i[type id uuid name absFolderPath l url luuid f
9
+ view rev ms webOfflineSyncDays activesyncdisabled n s i4ms i4next zid rid
10
+ ruuid owner reminder acl itemCount broken deletable color rgb fb]
11
+
12
+ attr_accessor *INSTANCE_VARIABLE_KEYS
13
+ attr_accessor :folders, :grants, :retention_policies
14
+
15
+ def concat
16
+ INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
17
+ end
18
+
19
+ alias nb_messages n
20
+ alias nb_items n
21
+ alias parent_id l
22
+ alias size s
23
+
24
+ def initialize(parent, json = nil, key = :folder)
25
+ @parent = parent
26
+ @type = key
27
+ @folders = []
28
+ @grants = []
29
+ @retention_policies = []
30
+ init_from_json(json) if json.is_a?(Hash)
31
+ yield(self) if block_given?
32
+ extend(DocumentFolder) if view == 'document'
33
+ end
34
+
35
+ def is_immutable?
36
+ @is_immutable ||= Zm::Client::FolderDefault::IDS.include?(@id.to_i)
37
+ end
38
+
39
+ def to_query
40
+ "inid:#{id}"
41
+ end
42
+
43
+ def to_h
44
+ {
45
+ f: f,
46
+ name: name,
47
+ l: l,
48
+ color: color,
49
+ rgb: rgb,
50
+ url: url,
51
+ fb: fb,
52
+ view: view
53
+ }
54
+ end
55
+
56
+ def create!
57
+ options = to_h
58
+ options.delete_if { |_, v| v.nil? }
59
+ rep = @parent.sacc.create_folder(@parent.token, options)
60
+ # rep = @parent.sacc.create_folder(@parent.token, @l, @name, @view, @color)
61
+ init_from_json(rep[:Body][:CreateFolderResponse][:folder].first)
62
+ end
63
+
64
+ def modify!
65
+ options = to_h
66
+ options.delete_if { |_, v| v.nil? }
67
+
68
+ if is_immutable?
69
+ options.delete(:name)
70
+ options.delete(:l)
71
+ end
72
+
73
+ update!(options)
74
+ end
75
+
76
+ def update!(options)
77
+ @parent.sacc.folder_action(@parent.token, 'update', @id, options)
78
+ end
79
+
80
+ def rename!(new_name)
81
+ @parent.sacc.folder_action(@parent.token, 'rename', @id, name: new_name)
82
+ @name = new_name
83
+ end
84
+
85
+ def add_retention_policy!(retention_policies)
86
+ options = retention_policies.is_a?(Hash) ? retention_policies : retention_policies.map(&:to_h).reduce({}, :merge)
87
+ @parent.sacc.folder_action(@parent.token, 'retentionPolicy', @id, retentionPolicy: options)
88
+ end
89
+
90
+ def move!(folder_id)
91
+ @parent.sacc.folder_action(@parent.token, 'move', @id, l: folder_id)
92
+ @l = folder_id
93
+ end
94
+
95
+ def color!(new_color)
96
+ key = new_color.to_i.zero? ? :rgb : :color
97
+ options = {}
98
+ options[key] = new_color
99
+ @parent.sacc.folder_action(@parent.token, 'color', @id, options)
100
+ instance_variable_set("@#{key}", new_color)
101
+ end
102
+
103
+ def reload!
104
+ rep = @parent.sacc.get_folder(@parent.token, @id)
105
+ init_from_json(rep[:Body][:GetFolderResponse][:folder].first)
106
+ end
107
+
108
+ def empty?
109
+ @n.zero?
110
+ end
111
+
112
+ def empty!
113
+ @parent.sacc.folder_action(
114
+ @parent.token,
115
+ :empty,
116
+ @id,
117
+ recursive: false
118
+ )
119
+ end
120
+ alias clear empty!
121
+
122
+ def delete!
123
+ @parent.sacc.folder_action(@parent.token, :delete, @id)
124
+ end
125
+
126
+ #
127
+ # folder_grant: Zm::Client::FolderGrant
128
+ #
129
+ def grant!(folder_grant)
130
+ @parent.sacc.folder_action(
131
+ @parent.token,
132
+ 'grant',
133
+ @id,
134
+ grant: folder_grant.to_h
135
+ )
136
+ end
137
+
138
+ # def grant!(parent, right)
139
+ # @parent.sacc.folder_action(
140
+ # @parent.token,
141
+ # 'grant',
142
+ # @id,
143
+ # grant: {
144
+ # zid: parent.id,
145
+ # gt: parent.grantee_type,
146
+ # perm: right
147
+ # }
148
+ # )
149
+ # end
150
+
151
+ def remove_grant!(zid)
152
+ @parent.sacc.folder_action(
153
+ @parent.token,
154
+ '!grant',
155
+ @id,
156
+ zid: zid
157
+ )
158
+ end
159
+
160
+ def retention_policies_h
161
+ @retention_policies.map(&:to_h).reduce({}, :merge)
162
+ end
163
+
164
+ def upload(file_path, fmt = nil, types = nil, resolve = 'replace')
165
+ fmt ||= File.extname(file_path)[1..-1]
166
+ # @parent.uploader.send_file(absFolderPath, fmt, types, resolve, file_path)
167
+ uploader = Upload.new(@parent, RestAccountConnector.new)
168
+ uploader.send_file(absFolderPath, fmt, types, resolve, file_path)
169
+ end
170
+
171
+ def import(file_path)
172
+ uploader = Upload.new(@parent, RestAccountConnector.new)
173
+ uploader.send_file(absFolderPath, 'tgz', nil, 'skip', file_path)
174
+ end
175
+
176
+ def download(dest_file_path, fmt = 'tgz')
177
+ uploader = Upload.new(@parent, RestAccountConnector.new)
178
+ # uploader.download_file(absFolderPath, fmt, [view], nil, dest_file_path)
179
+ uploader.download_folder(@id, fmt, dest_file_path)
180
+ end
181
+
182
+ def export(dest_file_path)
183
+ h = {
184
+ fmt: 'tgz',
185
+ emptyname: 'Vide',
186
+ charset: 'UTF-8',
187
+ auth: 'qp',
188
+ zauthtoken: @parent.token,
189
+ query: to_query
190
+ }
191
+
192
+ url_query = absFolderPath + '?' + h.map { |k, v| [k, v].join('=') }.join('&')
193
+
194
+ @parent.uploader.download_file_with_url(url_query, dest_file_path)
195
+ end
196
+
197
+ def init_from_json(json)
198
+ INSTANCE_VARIABLE_KEYS.each do |key|
199
+ var_name = "@#{key}"
200
+ instance_variable_set(var_name, json[key])
201
+ end
202
+
203
+ if !json[:acl].nil? && json[:acl][:grant].is_a?(Array)
204
+ @grants = json[:acl][:grant].map { |grant| FolderGrant.create_by_json(self, grant) }
205
+ end
206
+
207
+ if json[:retentionPolicy].is_a?(Array)
208
+ @retention_policies = json[:retentionPolicy].first.map do |k, v|
209
+ FolderRetentionPolicy.create_by_json(self, k, v.first)
210
+ end
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for account folder
6
+ class FolderGrant < Base::AccountObject
7
+ attr_accessor :zid, :gt, :perm, :d
8
+
9
+ class << self
10
+ def create_by_json(parent, json)
11
+ fg = self.new(parent)
12
+ fg.init_from_json(json)
13
+ fg
14
+ end
15
+ end
16
+
17
+ def concat
18
+ [zid, gt, perm, d]
19
+ end
20
+
21
+ def is_account?
22
+ gt == 'usr'
23
+ end
24
+
25
+ def is_dom?
26
+ gt == 'dom'
27
+ end
28
+
29
+ def is_dl?
30
+ gt == 'grp'
31
+ end
32
+
33
+ def is_public?
34
+ gt == 'pub'
35
+ end
36
+
37
+ def is_external?
38
+ gt == 'guest'
39
+ end
40
+
41
+ def init_from_json(json)
42
+ @zid = json[:zid]
43
+ @gt = json[:gt]
44
+ @perm = json[:perm]
45
+ @d = json[:d]
46
+ end
47
+
48
+ def to_h
49
+ {
50
+ zid: @zid,
51
+ gt: @gt,
52
+ perm: @perm,
53
+ d: @d
54
+ }
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for account folder retention policy
6
+ class FolderRetentionPolicy < Base::AccountObject
7
+
8
+ class << self
9
+ def create_by_json(parent, policy, json)
10
+ frp = self.new(parent)
11
+ frp.init_from_json(policy, json)
12
+ frp
13
+ end
14
+ end
15
+
16
+ attr_accessor :type, :policy, :lifetime
17
+
18
+ def keep?
19
+ @policy == :keep
20
+ end
21
+
22
+ def purge?
23
+ @policy == :purge
24
+ end
25
+
26
+ def init_from_json(policy, json)
27
+ return if json.empty? || json[:policy].nil?
28
+
29
+ @policy = policy
30
+ @type = json[:policy].first[:type]
31
+ @lifetime = json[:policy].first[:lifetime]
32
+ end
33
+
34
+ def to_h
35
+ # :purge=>[{:policy=>[{:lifetime=>"366d", :type=>"user"}]}]
36
+ {
37
+ @policy => {
38
+ policy: {
39
+ lifetime: @lifetime,
40
+ type: @type
41
+ }
42
+ }
43
+ }
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class factory [folders]
6
+ class FoldersBuilder < Base::ObjectsBuilder
7
+ def initialize(account, json)
8
+ @account = account
9
+ @json = json
10
+ @key = :folder
11
+ @root_folder = nil
12
+ @list = []
13
+ end
14
+
15
+ def ids
16
+ root = @json[:Body][:GetFolderResponse][@key]
17
+ construct_tree_ids(root.first[@key])
18
+ @list
19
+ end
20
+
21
+ def construct_tree_ids(json_folders)
22
+ json_folders.each do |json_folder|
23
+ @list << json_folder[:id]
24
+ construct_tree_ids(json_folder[@key]) if !json_folder[@key].nil? && json_folder[@key].any?
25
+ end
26
+ end
27
+
28
+ def make
29
+ root = @json[:Body][:GetFolderResponse][@key]
30
+
31
+ @root_folder = Folder.new(@account, root.first)
32
+
33
+ if !root.first[@key].nil? && root.first[@key].any?
34
+ construct_tree(@root_folder, root.first[@key])
35
+ end
36
+
37
+ @root_folder
38
+ end
39
+
40
+ def construct_tree(parent_folder, json_folders)
41
+ json_folders.each do |json_folder|
42
+ folder = Folder.new(@account, json_folder)
43
+ parent_folder.folders << folder
44
+
45
+ construct_tree(folder, json_folder[@key]) if !json_folder[@key].nil? && json_folder[@key].any?
46
+ end
47
+ end
48
+
49
+ def flatten(folder = @root_folder, collector = [])
50
+ collector.push(folder)
51
+ folder.folders.each do |child|
52
+ flatten(child, collector)
53
+ end
54
+ collector
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # collection of folders
6
+ class FoldersCollection < Base::ObjectsCollection
7
+ METHODS_MISSING_LIST = %i[select each map length].to_set.freeze
8
+
9
+ attr_reader :root
10
+
11
+ def initialize(parent)
12
+ @parent = parent
13
+ @root = nil
14
+ reset_query_params
15
+ end
16
+
17
+ def new
18
+ folder = Folder.new(@parent)
19
+ yield(folder) if block_given?
20
+ folder
21
+ end
22
+
23
+ def where(view: nil, tr: nil)
24
+ @view = view
25
+ @tr = tr
26
+ @all = nil
27
+ self
28
+ end
29
+
30
+ def ids
31
+ fb = FoldersBuilder.new @parent, make_query
32
+ fb.ids
33
+ end
34
+
35
+ def all
36
+ @all || all!
37
+ end
38
+
39
+ def all!
40
+ build_response
41
+ end
42
+
43
+ def clear
44
+ @all = nil
45
+ @root = nil
46
+ reset_query_params
47
+ end
48
+
49
+ private
50
+
51
+ def build_response
52
+ rep = make_query
53
+ fb = FoldersBuilder.new @parent, rep
54
+ @root = fb.make
55
+ @all = fb.flatten
56
+ @all.select! { |folder| folder.view == @view } unless @view.nil?
57
+ @all
58
+ end
59
+
60
+ def make_query
61
+ @parent.sacc.get_all_folders(@parent.token, @view, @tr)
62
+ end
63
+
64
+ def reset_query_params
65
+ @view = nil
66
+ @tr = nil
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,17 @@
1
+ module DocumentFolder
2
+ 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}:[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}}
3
+
4
+ def upload(file_path)
5
+ uploader = Zm::Client::Upload.new(@parent, Zm::Client::RestAccountConnector.new)
6
+ str = uploader.upload_attachment(file_path)
7
+
8
+ uuid = str.scan(UUID_REGEX).first
9
+
10
+ raise Zm::Client::RestError, "failed to extract uuid" if uuid.nil?
11
+
12
+ upload_options = { upload: { id: uuid } }
13
+ rep = @parent.sacc.save_document(@parent.token, id, upload_options)
14
+
15
+ Zm::Client::Document.new(@parent, rep[:Body][:SaveDocumentResponse][:doc].first)
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/folder/folder'
4
+ require 'zm/client/folder/folder_grant'
5
+ require 'zm/client/folder/folder_retention_policy'
6
+ require 'zm/client/folder/folders_builder'
7
+ require 'zm/client/folder/folders_collection'
8
+ require 'zm/client/folder/mod_document_folder'
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class factory [identitys]
6
+ class IdentitiesBuilder < Base::ObjectsBuilder
7
+ def initialize(parent, json)
8
+ @parent = parent
9
+ @json = json
10
+ end
11
+
12
+ def make
13
+ root = @json[:Body][:GetIdentitiesResponse][:identity]
14
+ return [] if root.nil?
15
+
16
+ root = [root] unless root.is_a?(Array)
17
+ root.map do |s|
18
+ identity = Identity.new(@parent)
19
+ identity.init_from_json(s)
20
+ identity
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # collection account identitys
6
+ class IdentitiesCollection < Base::ObjectsCollection
7
+ def initialize(parent)
8
+ @parent = parent
9
+ end
10
+
11
+ def new
12
+ identity = Identity.new(@parent)
13
+ yield(identity) if block_given?
14
+ identity
15
+ end
16
+
17
+ private
18
+
19
+ def build_response
20
+ rep = @parent.sacc.get_all_identities(@parent.token)
21
+ ib = IdentitiesBuilder.new @parent, rep
22
+ ib.make
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class account identity
6
+ class Identity < Base::AccountObject
7
+
8
+ INSTANCE_VARIABLE_KEYS = %i[id name zimbraPrefIdentityName zimbraPrefFromDisplay zimbraPrefFromAddress
9
+ zimbraPrefFromAddressType zimbraPrefReplyToEnabled zimbraPrefReplyToDisplay zimbraPrefReplyToAddress
10
+ zimbraPrefDefaultSignatureId zimbraPrefForwardReplySignatureId zimbraPrefWhenSentToEnabled
11
+ zimbraPrefWhenInFoldersEnabled]
12
+
13
+ ATTRS_WRITE = %i[zimbraPrefIdentityName zimbraPrefFromDisplay zimbraPrefFromAddress
14
+ zimbraPrefFromAddressType zimbraPrefReplyToEnabled zimbraPrefReplyToDisplay zimbraPrefReplyToAddress
15
+ zimbraPrefDefaultSignatureId zimbraPrefForwardReplySignatureId zimbraPrefWhenSentToEnabled
16
+ zimbraPrefWhenInFoldersEnabled]
17
+
18
+ attr_accessor *INSTANCE_VARIABLE_KEYS
19
+
20
+ def concat
21
+ INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
22
+ end
23
+
24
+ def init_from_json(json)
25
+ super(json)
26
+ INSTANCE_VARIABLE_KEYS.each do |key|
27
+ value = json[:_attrs][key]
28
+ next if value.nil?
29
+
30
+ instance_variable_set(arrow_name(key), value)
31
+ end
32
+ end
33
+
34
+ def create!
35
+ rep = @parent.sacc.create_identity(@parent.token, name, instance_variables_array(ATTRS_WRITE))
36
+ init_from_json(rep[:Body][:CreateIdentityResponse][:identity].first)
37
+ end
38
+
39
+ def update!(hash)
40
+ @parent.sacc.modify_identity(@parent.token, id, hash)
41
+
42
+ hash.each do |k, v|
43
+ arrow_attr_sym = "@#{k}".to_sym
44
+
45
+ if v.respond_to?(:empty?) && v.empty?
46
+ self.remove_instance_variable(arrow_attr_sym) if self.instance_variable_get(arrow_attr_sym)
47
+ else
48
+ self.instance_variable_set(arrow_attr_sym, v)
49
+ end
50
+ end
51
+ end
52
+
53
+ def modify!
54
+ @parent.sacc.modify_identity(@parent.token, id, instance_variables_array(ATTRS_WRITE))
55
+ end
56
+
57
+ def delete!
58
+ @parent.sacc.delete_identity(@parent.token, id)
59
+ end
60
+
61
+ def rename!(new_name)
62
+ end
63
+
64
+ def clone
65
+ new_identity = super do |obj|
66
+ [:@zimbraPrefDefaultSignatureId, :@zimbraPrefForwardReplySignatureId].each do |arrow_key|
67
+ obj.remove_instance_variable(arrow_key) if obj.instance_variable_get(arrow_key)
68
+ end
69
+ end
70
+ yield(new_identity) if block_given?
71
+ new_identity
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/identity/identity'
4
+ require 'zm/client/identity/identities_builder'
5
+ require 'zm/client/identity/identities_collection'
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # objectClass: zimbraDomain
6
+ class License < Base::AdminObject
7
+
8
+ INSTANCE_VARIABLE_KEYS = %i[
9
+ AccountsLimit ArchivingAccountsLimit AttachmentConversionEnabled AttachmentIndexingAccountsLimit BackupEnabled
10
+ CrossMailboxSearchEnabled EwsAccountsLimit HierarchicalStorageManagementEnabled ISyncAccountsLimit InstallType
11
+ IssuedOn IssuedToEmail IssuedToName LicenseId MAPIConnectorAccountsLimit MobileSyncAccountsLimit
12
+ MobileSyncEnabled ResellerName SMIMEAccountsLimit TouchClientsAccountsLimit TwoFactorAuthAccountsLimit
13
+ ValidFrom ValidUntil VoiceAccountsLimit ZSSAccountsLimit ZTalkAccountsLimit
14
+ ]
15
+
16
+ attr_accessor *INSTANCE_VARIABLE_KEYS
17
+
18
+ def init_from_json(json)
19
+ json[:attr].each do |a|
20
+ instance_variable_set(arrow_name(a[:name]), a[:_content])
21
+ end
22
+ end
23
+
24
+ def to_s
25
+ INSTANCE_VARIABLE_KEYS.map { |v| [v, instance_variable_get(arrow_name(v))].join(' : ') }.join("\n")
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # Class Collection [Domain]
6
+ class LicensesCollection
7
+ def initialize(parent)
8
+ @parent = parent
9
+ end
10
+
11
+ def find
12
+ req = sac.get_license
13
+ entry = req[:Body][:GetLicenseResponse][:license].first
14
+ license = License.new(@parent)
15
+ license.init_from_json(entry)
16
+ license
17
+ end
18
+
19
+ private
20
+
21
+ def soap_admin_connector
22
+ @parent.soap_admin_connector
23
+ end
24
+
25
+ alias sac soap_admin_connector
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/license/license'
4
+ require 'zm/client/license/licenses_collection'