zm-ruby-client 0.10.4 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +1 -0
  4. data/README.md +6 -0
  5. data/lib/zm/client/account/account.rb +39 -17
  6. data/lib/zm/client/account/account_jsns_initializer.rb +44 -0
  7. data/lib/zm/client/account/accounts_builder.rb +6 -3
  8. data/lib/zm/client/account/accounts_collection.rb +11 -20
  9. data/lib/zm/client/account.rb +1 -0
  10. data/lib/zm/client/ace/ace.rb +22 -9
  11. data/lib/zm/client/ace/ace_jsns_builder.rb +38 -0
  12. data/lib/zm/client/ace/ace_jsns_initializer.rb +26 -0
  13. data/lib/zm/client/ace/aces_builder.rb +6 -9
  14. data/lib/zm/client/ace/aces_collection.rb +23 -9
  15. data/lib/zm/client/ace.rb +2 -0
  16. data/lib/zm/client/appointment/appointment.rb +9 -6
  17. data/lib/zm/client/appointment/appointments_collection.rb +6 -90
  18. data/lib/zm/client/backup/backup.rb +8 -4
  19. data/lib/zm/client/base/account_object.rb +34 -0
  20. data/lib/zm/client/base/account_objects_collection.rb +14 -0
  21. data/lib/zm/client/base/account_search_objects_collection.rb +125 -0
  22. data/lib/zm/client/base/admin_object.rb +6 -0
  23. data/lib/zm/client/base/admin_objects_collection.rb +65 -0
  24. data/lib/zm/client/base/base_jsns_builder.rb +19 -0
  25. data/lib/zm/client/base/base_jsns_initializer.rb +29 -0
  26. data/lib/zm/client/base/folder_object.rb +41 -0
  27. data/lib/zm/client/base/ldap_filter.rb +33 -0
  28. data/lib/zm/client/base/object.rb +19 -0
  29. data/lib/zm/client/base/objects_builder.rb +4 -0
  30. data/lib/zm/client/base/objects_collection.rb +11 -32
  31. data/lib/zm/client/base/zimbra_attribute.rb +119 -0
  32. data/lib/zm/client/base/zimbra_attributes_collection.rb +38 -0
  33. data/lib/zm/client/base.rb +15 -0
  34. data/lib/zm/client/cluster/cluster.rb +47 -7
  35. data/lib/zm/client/cluster/cluster_config.rb +19 -17
  36. data/lib/zm/client/common/token_metadata.rb +44 -0
  37. data/lib/zm/client/common.rb +2 -1
  38. data/lib/zm/client/connector/rest_account.rb +0 -3
  39. data/lib/zm/client/connector/soap_account.rb +66 -122
  40. data/lib/zm/client/connector/soap_admin.rb +47 -15
  41. data/lib/zm/client/connector/soap_base.rb +11 -3
  42. data/lib/zm/client/contact/contact.rb +2 -1
  43. data/lib/zm/client/contact/contacts_builder.rb +3 -13
  44. data/lib/zm/client/contact/contacts_collection.rb +6 -12
  45. data/lib/zm/client/cos/cos.rb +9 -5
  46. data/lib/zm/client/cos/coses_builder.rb +1 -16
  47. data/lib/zm/client/cos/coses_collection.rb +6 -9
  48. data/lib/zm/client/distributionlist/distributionlist.rb +44 -6
  49. data/lib/zm/client/distributionlist/distributionlists_builder.rb +2 -17
  50. data/lib/zm/client/distributionlist/distributionlists_collection.rb +4 -11
  51. data/lib/zm/client/distributionlist/dls_membership_collection.rb +24 -0
  52. data/lib/zm/client/distributionlist.rb +1 -0
  53. data/lib/zm/client/document/document.rb +11 -9
  54. data/lib/zm/client/domain/domain.rb +23 -7
  55. data/lib/zm/client/domain/domain_accounts_collection.rb +13 -0
  56. data/lib/zm/client/domain/domains_builder.rb +1 -19
  57. data/lib/zm/client/domain/domains_collection.rb +7 -10
  58. data/lib/zm/client/domain.rb +1 -0
  59. data/lib/zm/client/folder/folder.rb +50 -124
  60. data/lib/zm/client/folder/folder_grant.rb +44 -22
  61. data/lib/zm/client/folder/folder_grant_jsns_builder.rb +43 -0
  62. data/lib/zm/client/folder/folder_grants_collection.rb +35 -0
  63. data/lib/zm/client/folder/folder_jsns_builder.rb +132 -0
  64. data/lib/zm/client/folder/folder_jsns_initializer.rb +49 -0
  65. data/lib/zm/client/folder/folder_retention_policies_collection.rb +40 -0
  66. data/lib/zm/client/folder/folder_retention_policy.rb +8 -30
  67. data/lib/zm/client/folder/folders_builder.rb +2 -2
  68. data/lib/zm/client/folder/folders_collection.rb +46 -19
  69. data/lib/zm/client/folder/folders_jsns_builder.rb +22 -0
  70. data/lib/zm/client/folder.rb +6 -0
  71. data/lib/zm/client/identity/identities_builder.rb +4 -15
  72. data/lib/zm/client/identity/identities_collection.rb +7 -13
  73. data/lib/zm/client/identity/identity.rb +9 -7
  74. data/lib/zm/client/message/message.rb +111 -21
  75. data/lib/zm/client/message/messages_builder.rb +1 -1
  76. data/lib/zm/client/message/messages_collection.rb +10 -92
  77. data/lib/zm/client/mountpoint/mountpoint.rb +15 -68
  78. data/lib/zm/client/mountpoint/mountpoint_jsns_builder.rb +100 -0
  79. data/lib/zm/client/mountpoint/mountpoint_jsns_initializer.rb +33 -0
  80. data/lib/zm/client/mountpoint/mountpoints_builder.rb +1 -1
  81. data/lib/zm/client/mountpoint/mountpoints_collection.rb +14 -23
  82. data/lib/zm/client/mountpoint.rb +2 -0
  83. data/lib/zm/client/resource/resource.rb +5 -5
  84. data/lib/zm/client/resource/resources_builder.rb +1 -16
  85. data/lib/zm/client/resource/resources_collection.rb +5 -13
  86. data/lib/zm/client/search_folder/search_folder.rb +19 -39
  87. data/lib/zm/client/search_folder/search_folder_jsns_builder.rb +86 -0
  88. data/lib/zm/client/search_folder/search_folder_jsns_initializer.rb +33 -0
  89. data/lib/zm/client/search_folder/search_folders_builder.rb +7 -11
  90. data/lib/zm/client/search_folder/search_folders_collection.rb +7 -15
  91. data/lib/zm/client/search_folder.rb +2 -0
  92. data/lib/zm/client/server/server.rb +7 -14
  93. data/lib/zm/client/server/server_accounts_collection.rb +19 -0
  94. data/lib/zm/client/server/servers_builder.rb +4 -16
  95. data/lib/zm/client/server/servers_collection.rb +5 -10
  96. data/lib/zm/client/server.rb +1 -0
  97. data/lib/zm/client/share/share.rb +2 -9
  98. data/lib/zm/client/share/shares_builder.rb +3 -12
  99. data/lib/zm/client/signature/signature.rb +17 -13
  100. data/lib/zm/client/signature/signature_jsns_builder.rb +5 -1
  101. data/lib/zm/client/signature/signature_jsns_initializer.rb +25 -0
  102. data/lib/zm/client/signature/signatures_builder.rb +7 -11
  103. data/lib/zm/client/signature/signatures_collection.rb +6 -14
  104. data/lib/zm/client/signature.rb +1 -0
  105. data/lib/zm/client/tag/tag.rb +27 -20
  106. data/lib/zm/client/tag/tag_jsns_builder.rb +55 -0
  107. data/lib/zm/client/tag/tag_jsns_initializer.rb +26 -0
  108. data/lib/zm/client/tag/tags_builder.rb +6 -9
  109. data/lib/zm/client/tag/tags_collection.rb +6 -12
  110. data/lib/zm/client/tag.rb +2 -0
  111. data/lib/zm/client/task/tasks_collection.rb +6 -90
  112. data/lib/zm/client/upload/upload.rb +1 -1
  113. data/lib/zm/client/version.rb +2 -2
  114. data/lib/zm/modules/common/dl_common.rb +6 -1
  115. data/lib/zm/modules/common/zimbra-attrs.json.bak +1 -0
  116. data/lib/zm/modules/zm_logger.rb +24 -0
  117. data/lib/zm/modules/zm_model.rb +41 -0
  118. data/test/accounts.rb +15 -1
  119. data/test/ace.rb +50 -0
  120. data/test/cluster.rb +41 -0
  121. data/test/cluster_zimbra_attributes.rb +38 -0
  122. data/test/domains.rb +8 -0
  123. data/test/folder.rb +125 -0
  124. data/test/folder_grant.rb +51 -0
  125. data/test/mountpoint.rb +49 -0
  126. data/test/retention_policies.rb +40 -0
  127. data/test/search_folder.rb +67 -0
  128. data/test/signature.rb +53 -0
  129. data/test/tag.rb +65 -0
  130. data/test/zimbra_attributes.rb +35 -0
  131. data/zm-ruby-client.gemspec +1 -0
  132. metadata +60 -3
@@ -3,29 +3,26 @@
3
3
  module Zm
4
4
  module Client
5
5
  # Class Collection [Domain]
6
- class DomainsCollection < Base::ObjectsCollection
6
+ class DomainsCollection < Base::AdminObjectsCollection
7
7
  def initialize(parent)
8
8
  @child_class = Domain
9
- @parent = parent
10
- reset_query_params
9
+ @builder_class = DomainsBuilder
10
+ @search_type = SearchType::DOMAIN
11
+ super(parent)
11
12
  end
12
13
 
13
- def find_by(hash, *attrs)
14
- rep = sac.get_domain(hash.values.first, hash.keys.first, attrs.join(COMMA))
14
+ def find_by(hash)
15
+ rep = sac.get_domain(hash.values.first, hash.keys.first, attrs_comma)
15
16
  entry = rep[:Body][:GetDomainResponse][:domain].first
16
17
 
18
+ reset_query_params
17
19
  build_from_entry(entry)
18
20
  end
19
21
 
20
22
  private
21
23
 
22
- def build_response
23
- DomainsBuilder.new(@parent, make_query).make
24
- end
25
-
26
24
  def reset_query_params
27
25
  super
28
- @search_type = SearchType::DOMAIN
29
26
  @attrs = SearchType::Attributes::DOMAIN.dup
30
27
  @all_servers = 1
31
28
  @refresh = 0
@@ -3,3 +3,4 @@
3
3
  require 'zm/client/domain/domain'
4
4
  require 'zm/client/domain/domains_builder'
5
5
  require 'zm/client/domain/domains_collection'
6
+ require 'zm/client/domain/domain_accounts_collection'
@@ -3,17 +3,22 @@
3
3
  module Zm
4
4
  module Client
5
5
  # class for account folder
6
- class Folder < Base::AccountObject
6
+ class Folder < Base::FolderObject
7
+ include Zm::Model::AttributeChangeObserver
7
8
 
8
9
  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]
10
+ view rev ms webOfflineSyncDays activesyncdisabled n s i4ms i4next zid rid
11
+ ruuid owner reminder acl itemCount broken deletable color rgb fb].freeze
12
+
13
+ attr_reader :type, :id, :uuid, :absFolderPath, :luuid, :rev, :ms, :webOfflineSyncDays, :activesyncdisabled, :n,
14
+ :s, :i4ms, :i4next, :zid, :rid, :ruuid, :owner, :reminder, :acl, :itemCount, :broken, :deletable, :fb
11
15
 
12
- attr_accessor *INSTANCE_VARIABLE_KEYS
13
16
  attr_accessor :folders, :grants, :retention_policies
14
17
 
15
- def concat
16
- INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
18
+ define_changed_attributes :name, :color, :rgb, :l, :url, :f, :view
19
+
20
+ def all_instance_variable_keys
21
+ INSTANCE_VARIABLE_KEYS
17
22
  end
18
23
 
19
24
  alias nb_messages n
@@ -21,14 +26,16 @@ module Zm
21
26
  alias parent_id l
22
27
  alias size s
23
28
 
24
- def initialize(parent, json = nil, key = :folder)
25
- @parent = parent
26
- @type = key
29
+ def initialize(parent)
30
+ super(parent)
31
+
32
+ @type = :folder
27
33
  @folders = []
28
- @grants = []
29
- @retention_policies = []
30
- init_from_json(json) if json.is_a?(Hash)
34
+ @grants = FolderGrantsCollection.new(self)
35
+ @retention_policies = FolderRetentionPoliciesCollection.new(self)
36
+
31
37
  yield(self) if block_given?
38
+
32
39
  extend(DocumentFolder) if view == 'document'
33
40
  end
34
41
 
@@ -40,69 +47,40 @@ module Zm
40
47
  "inid:#{id}"
41
48
  end
42
49
 
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
50
  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)
51
+ rep = @parent.sacc.create_folder(@parent.token, jsns_builder.to_jsns)
52
+ json = rep[:Body][:CreateFolderResponse][:folder].first
53
+ FolderJsnsInitializer.update(self, json)
74
54
  end
75
55
 
76
56
  def update!(options)
77
- @parent.sacc.folder_action(@parent.token, 'update', @id, options)
78
- end
57
+ options.delete_if { |k, v| v.nil? || !respond_to?(k) }
58
+ return false if options.empty?
79
59
 
80
- def rename!(new_name)
81
- @parent.sacc.folder_action(@parent.token, 'rename', @id, name: new_name)
82
- @name = new_name
83
- end
60
+ @parent.sacc.folder_action(@parent.token, jsns_builder.to_patch(options))
84
61
 
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
62
+ options.each do |k, v|
63
+ instance_variable_set("@#{k}", v)
64
+ end
89
65
 
90
- def move!(folder_id)
91
- @parent.sacc.folder_action(@parent.token, 'move', @id, l: folder_id)
92
- @l = folder_id
66
+ true
93
67
  end
94
68
 
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
69
+ # def add_retention_policy!(retention_policies)
70
+ # options = if retention_policies.is_a?(Hash)
71
+ # retention_policies
72
+ # else
73
+ # retention_policies.map(&:to_h).reduce({}, :merge)
74
+ # end
75
+ #
76
+ # @parent.sacc.folder_action(@parent.token, 'retentionPolicy', @id, retentionPolicy: options)
77
+ # end
102
78
 
103
79
  def reload!
104
- rep = @parent.sacc.get_folder(@parent.token, @id)
105
- init_from_json(rep[:Body][:GetFolderResponse][:folder].first)
80
+ rep = @parent.sacc.get_folder(@parent.token, jsns_builder.to_find)
81
+ json = rep[:Body][:GetFolderResponse][:folder].first
82
+ FolderJsnsInitializer.update(self, json)
83
+ true
106
84
  end
107
85
 
108
86
  def empty?
@@ -110,60 +88,19 @@ module Zm
110
88
  end
111
89
 
112
90
  def empty!
113
- @parent.sacc.folder_action(
114
- @parent.token,
115
- :empty,
116
- @id,
117
- recursive: false
118
- )
91
+ @parent.sacc.folder_action(@parent.token, jsns_builder.to_empty) unless @n.zero?
92
+ @n = 0
119
93
  end
120
94
  alias clear empty!
121
95
 
122
96
  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
97
+ return false if is_immutable?
137
98
 
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)
99
+ super
162
100
  end
163
101
 
164
102
  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)
103
+ fmt ||= File.extname(file_path)[1..]
167
104
  uploader = Upload.new(@parent, RestAccountConnector.new)
168
105
  uploader.send_file(absFolderPath, fmt, types, resolve, file_path)
169
106
  end
@@ -194,21 +131,10 @@ module Zm
194
131
  @parent.uploader.download_file_with_url(url_query, dest_file_path)
195
132
  end
196
133
 
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
134
+ private
206
135
 
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
136
+ def jsns_builder
137
+ @jsns_builder ||= FolderJsnsBuilder.new(self)
212
138
  end
213
139
  end
214
140
  end
@@ -3,19 +3,29 @@
3
3
  module Zm
4
4
  module Client
5
5
  # class for account folder
6
- class FolderGrant < Base::AccountObject
7
- attr_accessor :zid, :gt, :perm, :d
6
+ class FolderGrant
7
+ attr_reader :parent, :folder_id
8
+ attr_accessor :zid, :gt, :perm, :d, :expiry, :key
8
9
 
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
10
+ # pour créer un nouveau partage, il faut indiquer zid et/ou d
11
+ # l'attribut gt est obligatoire !
12
+ # l'attribut perm est obligatoire !
13
+
14
+ def initialize(parent, zid, gt, perm, d)
15
+ @parent = parent
16
+ @zid = zid
17
+ @gt = gt
18
+ @perm = perm
19
+ @d = d
20
+ @expiry = nil
21
+ @key = nil
22
+ @folder_id = parent.parent.id
15
23
  end
16
24
 
17
- def concat
18
- [zid, gt, perm, d]
25
+ def to_h
26
+ h = Hash[instance_variables.reject { |iv| iv == :@parent }.map { |iv| [iv, instance_variable_get(iv)] }]
27
+ h.merge!({ :@parent => @parent.class })
28
+ h
19
29
  end
20
30
 
21
31
  def is_account?
@@ -38,20 +48,32 @@ module Zm
38
48
  gt == 'guest'
39
49
  end
40
50
 
41
- def init_from_json(json)
42
- @zid = json[:zid]
43
- @gt = json[:gt]
44
- @perm = json[:perm]
45
- @d = json[:d]
51
+ def is_key?
52
+ gt == 'key'
46
53
  end
47
54
 
48
- def to_h
49
- {
50
- zid: @zid,
51
- gt: @gt,
52
- perm: @perm,
53
- d: @d
54
- }
55
+ def save!
56
+ @parent.sacc.folder_action(get_token, jsns_builder.to_create)
57
+ end
58
+
59
+ def delete!
60
+ @parent.sacc.folder_action(get_token, jsns_builder.to_delete)
61
+ @parent.all.delete(self)
62
+ end
63
+
64
+ private
65
+
66
+ def jsns_builder
67
+ @jsns_builder ||= FolderGrantJsnsBuilder.new(self)
68
+ end
69
+
70
+ def get_token(target = self)
71
+ token = nil
72
+ return target.token if target.respond_to?(:token) && !target.token.nil?
73
+
74
+ token = get_token(target.parent) if target.respond_to?(:parent)
75
+
76
+ token
55
77
  end
56
78
  end
57
79
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for account folder grant jsns builder
6
+ class FolderGrantJsnsBuilder < Base::BaseJsnsBuilder
7
+
8
+ def to_jsns
9
+ grant = {
10
+ zid: @item.zid,
11
+ gt: @item.gt,
12
+ perm: @item.perm,
13
+ d: @item.d,
14
+ expiry: @item.expiry,
15
+ key: @item.key
16
+ }.delete_if { |_, v| v.nil? }
17
+
18
+ {
19
+ action: {
20
+ op: :grant,
21
+ id: @item.folder_id,
22
+ grant: grant
23
+ }
24
+ }
25
+ end
26
+
27
+ alias to_create to_jsns
28
+
29
+ def to_delete
30
+ {
31
+ action: {
32
+ op: '!grant',
33
+ id: @item.folder_id,
34
+ zid: @item.zid,
35
+ gt: @item.gt,
36
+ perm: @item.perm,
37
+ d: @item.d
38
+ }
39
+ }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for folder retention policies collection
6
+ class FolderGrantsCollection
7
+
8
+ attr_reader :parent, :all
9
+
10
+ def initialize(parent)
11
+ @parent = parent
12
+ @all = []
13
+ end
14
+
15
+ def new(zid, gt, perm, d)
16
+ FolderGrant.new(self, zid, gt, perm, d)
17
+ end
18
+
19
+ def create(zid, gt, perm, d)
20
+ fg = new(zid, gt, perm, d)
21
+ add(fg)
22
+ end
23
+
24
+ def add(fg)
25
+ @all << fg
26
+ end
27
+
28
+ def soap_account_connector
29
+ @parent.soap_account_connector
30
+ end
31
+
32
+ alias sacc soap_account_connector
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,132 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for account folder jsns builder
6
+ class FolderJsnsBuilder < Base::BaseJsnsBuilder
7
+
8
+ def to_find
9
+ { folder: { l: @item.id } }
10
+ end
11
+
12
+ def to_jsns
13
+ folder = {
14
+ f: @item.f,
15
+ name: @item.name,
16
+ l: @item.l,
17
+ color: @item.color,
18
+ rgb: @item.rgb,
19
+ url: @item.url,
20
+ fb: @item.fb,
21
+ view: @item.view
22
+ }.delete_if { |_, v| v.nil? }
23
+
24
+ { folder: folder }
25
+ end
26
+
27
+ alias to_create to_jsns
28
+
29
+ def to_update
30
+ action = {
31
+ op: :update,
32
+ id: @item.id,
33
+ f: @item.f,
34
+ name: @item.name,
35
+ l: @item.l,
36
+ color: @item.color,
37
+ rgb: @item.rgb,
38
+ url: @item.url,
39
+ fb: @item.fb,
40
+ view: @item.view
41
+ }.delete_if { |_, v| v.nil? }
42
+
43
+ if @item.is_immutable?
44
+ action.delete(:name)
45
+ action.delete(:l)
46
+ end
47
+
48
+ { action: action }
49
+ end
50
+
51
+ def to_patch(options)
52
+ action = {
53
+ op: :update,
54
+ id: @item.id
55
+ }.merge(options)
56
+
57
+ { action: action }
58
+ end
59
+
60
+ def to_rename
61
+ action = {
62
+ op: :rename,
63
+ id: @item.id,
64
+ name: @item.name
65
+ }
66
+
67
+ { action: action }
68
+ end
69
+
70
+ def to_move
71
+ action = {
72
+ op: :move,
73
+ id: @item.id,
74
+ l: @item.l
75
+ }
76
+
77
+ { action: action }
78
+ end
79
+
80
+ def to_color
81
+ action = {
82
+ op: :color,
83
+ id: @item.id
84
+ }
85
+
86
+ action[:rgb] = @item.rgb if @item.rgb_changed?
87
+ action[:color] = @item.color if @item.color_changed?
88
+
89
+ { action: action }
90
+ end
91
+
92
+ def to_empty
93
+ action = {
94
+ op: :empty,
95
+ id: @item.id,
96
+ recursive: false
97
+ }
98
+
99
+ { action: action }
100
+ end
101
+
102
+ def to_delete
103
+ { action: { op: :delete, id: @item.id } }
104
+ end
105
+
106
+ def to_retentionpolicy
107
+ retentionpolicy = @item.retention_policies.all.map { |rp| retentionpolicy_jsns(rp) }.reduce({}, :merge)
108
+
109
+ {
110
+ action: {
111
+ op: :retentionpolicy,
112
+ id: @item.id,
113
+ retentionPolicy: retentionpolicy
114
+ }
115
+ }
116
+ end
117
+
118
+ private
119
+
120
+ def retentionpolicy_jsns(rp)
121
+ {
122
+ rp.policy => {
123
+ policy: {
124
+ lifetime: rp.lifetime,
125
+ type: rp.type
126
+ }
127
+ }
128
+ }
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for initialize account folder
6
+ class FolderJsnsInitializer
7
+ class << self
8
+ def create(parent, json)
9
+ item = Folder.new(parent)
10
+
11
+ item.instance_variable_set(:@id, json[:id])
12
+ item.instance_variable_set(:@name, json[:name])
13
+
14
+ update(item, json)
15
+ end
16
+
17
+ def update(item, json)
18
+ item.all_instance_variable_keys.reject { |key| json[key].nil? }.each do |key|
19
+ item.instance_variable_set(arrow_name(key), json[key])
20
+ end
21
+
22
+ if !json[:acl].nil? && json[:acl][:grant].is_a?(Array)
23
+ json[:acl][:grant].each do |json|
24
+ item.grants.create(json[:zid], json[:gt], json[:perm], json[:d])
25
+ end
26
+ end
27
+
28
+ if json[:retentionPolicy].is_a?(Array)
29
+ json[:retentionPolicy].first.map do |policy, v|
30
+ next if v.first[:policy].nil?
31
+
32
+ type = v.first[:policy].first[:type]
33
+ lifetime = v.first[:policy].first[:lifetime]
34
+ item.retention_policies.create(policy, lifetime, type)
35
+ end
36
+ end
37
+
38
+ item
39
+ end
40
+
41
+ def arrow_name(name)
42
+ return name if name.to_s.start_with?('@')
43
+
44
+ "@#{name}"
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for folder retention policies collection
6
+ class FolderRetentionPoliciesCollection
7
+
8
+ attr_reader :all
9
+
10
+ def initialize(parent)
11
+ @parent = parent
12
+ @all = []
13
+ end
14
+
15
+ def new(policy, lifetime, type)
16
+ FolderRetentionPolicy.new(self, policy, lifetime, type)
17
+ end
18
+
19
+ def create(policy, lifetime, type)
20
+ frp = new(policy, lifetime, type)
21
+ add(frp)
22
+ end
23
+
24
+ def add(retention_policy)
25
+ @all << retention_policy
26
+ end
27
+
28
+ def save!
29
+ @parent.sacc.folder_action(@parent.parent.token, jsns_builder.to_retentionpolicy)
30
+ true
31
+ end
32
+
33
+ private
34
+
35
+ def jsns_builder
36
+ @jsns_builder ||= FolderJsnsBuilder.new(@parent)
37
+ end
38
+ end
39
+ end
40
+ end