zm-ruby-client 0.14.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +4 -5
  4. data/README.md +6 -0
  5. data/lib/zm/client/account/account.rb +29 -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 +43 -7
  35. data/lib/zm/client/cluster/cluster_config.rb +19 -17
  36. data/lib/zm/client/connector/rest_account.rb +0 -3
  37. data/lib/zm/client/connector/soap_account.rb +76 -177
  38. data/lib/zm/client/connector/soap_admin.rb +82 -51
  39. data/lib/zm/client/connector/soap_base.rb +12 -12
  40. data/lib/zm/client/contact/contact.rb +2 -1
  41. data/lib/zm/client/contact/contacts_builder.rb +3 -13
  42. data/lib/zm/client/contact/contacts_collection.rb +6 -12
  43. data/lib/zm/client/cos/cos.rb +11 -6
  44. data/lib/zm/client/cos/coses_builder.rb +1 -16
  45. data/lib/zm/client/cos/coses_collection.rb +6 -9
  46. data/lib/zm/client/distributionlist/distributionlist.rb +44 -6
  47. data/lib/zm/client/distributionlist/distributionlists_builder.rb +2 -17
  48. data/lib/zm/client/distributionlist/distributionlists_collection.rb +4 -11
  49. data/lib/zm/client/distributionlist/dls_membership_collection.rb +24 -0
  50. data/lib/zm/client/distributionlist.rb +1 -0
  51. data/lib/zm/client/document/document.rb +7 -9
  52. data/lib/zm/client/domain/domain.rb +11 -6
  53. data/lib/zm/client/domain/domain_accounts_collection.rb +13 -0
  54. data/lib/zm/client/domain/domains_builder.rb +1 -19
  55. data/lib/zm/client/domain/domains_collection.rb +7 -10
  56. data/lib/zm/client/domain.rb +1 -0
  57. data/lib/zm/client/folder/folder.rb +50 -124
  58. data/lib/zm/client/folder/folder_grant.rb +44 -22
  59. data/lib/zm/client/folder/folder_grant_jsns_builder.rb +43 -0
  60. data/lib/zm/client/folder/folder_grants_collection.rb +35 -0
  61. data/lib/zm/client/folder/folder_jsns_builder.rb +132 -0
  62. data/lib/zm/client/folder/folder_jsns_initializer.rb +49 -0
  63. data/lib/zm/client/folder/folder_retention_policies_collection.rb +40 -0
  64. data/lib/zm/client/folder/folder_retention_policy.rb +8 -30
  65. data/lib/zm/client/folder/folders_builder.rb +2 -2
  66. data/lib/zm/client/folder/folders_collection.rb +21 -19
  67. data/lib/zm/client/folder/folders_jsns_builder.rb +22 -0
  68. data/lib/zm/client/folder.rb +6 -0
  69. data/lib/zm/client/identity/identities_builder.rb +4 -15
  70. data/lib/zm/client/identity/identities_collection.rb +7 -13
  71. data/lib/zm/client/identity/identity.rb +19 -19
  72. data/lib/zm/client/message/message.rb +111 -21
  73. data/lib/zm/client/message/messages_builder.rb +1 -1
  74. data/lib/zm/client/message/messages_collection.rb +10 -92
  75. data/lib/zm/client/mountpoint/mountpoint.rb +15 -68
  76. data/lib/zm/client/mountpoint/mountpoint_jsns_builder.rb +100 -0
  77. data/lib/zm/client/mountpoint/mountpoint_jsns_initializer.rb +33 -0
  78. data/lib/zm/client/mountpoint/mountpoints_builder.rb +1 -1
  79. data/lib/zm/client/mountpoint/mountpoints_collection.rb +14 -23
  80. data/lib/zm/client/mountpoint.rb +2 -0
  81. data/lib/zm/client/resource/resource.rb +5 -5
  82. data/lib/zm/client/resource/resources_builder.rb +1 -16
  83. data/lib/zm/client/resource/resources_collection.rb +5 -13
  84. data/lib/zm/client/search_folder/search_folder.rb +19 -39
  85. data/lib/zm/client/search_folder/search_folder_jsns_builder.rb +86 -0
  86. data/lib/zm/client/search_folder/search_folder_jsns_initializer.rb +33 -0
  87. data/lib/zm/client/search_folder/search_folders_builder.rb +7 -11
  88. data/lib/zm/client/search_folder/search_folders_collection.rb +7 -15
  89. data/lib/zm/client/search_folder.rb +2 -0
  90. data/lib/zm/client/server/server.rb +7 -14
  91. data/lib/zm/client/server/server_accounts_collection.rb +19 -0
  92. data/lib/zm/client/server/servers_builder.rb +4 -16
  93. data/lib/zm/client/server/servers_collection.rb +5 -10
  94. data/lib/zm/client/server.rb +1 -0
  95. data/lib/zm/client/share/share.rb +2 -9
  96. data/lib/zm/client/share/shares_builder.rb +3 -12
  97. data/lib/zm/client/signature/signature.rb +17 -13
  98. data/lib/zm/client/signature/signature_jsns_builder.rb +5 -1
  99. data/lib/zm/client/signature/signature_jsns_initializer.rb +25 -0
  100. data/lib/zm/client/signature/signatures_builder.rb +7 -11
  101. data/lib/zm/client/signature/signatures_collection.rb +6 -14
  102. data/lib/zm/client/signature.rb +1 -0
  103. data/lib/zm/client/tag/tag.rb +27 -20
  104. data/lib/zm/client/tag/tag_jsns_builder.rb +55 -0
  105. data/lib/zm/client/tag/tag_jsns_initializer.rb +26 -0
  106. data/lib/zm/client/tag/tags_builder.rb +6 -9
  107. data/lib/zm/client/tag/tags_collection.rb +6 -12
  108. data/lib/zm/client/tag.rb +2 -0
  109. data/lib/zm/client/task/tasks_collection.rb +6 -90
  110. data/lib/zm/client/upload/upload.rb +1 -1
  111. data/lib/zm/client/version.rb +1 -1
  112. data/lib/zm/modules/common/dl_common.rb +3 -1
  113. data/lib/zm/modules/common/zimbra-attrs.json.bak +1 -0
  114. data/lib/zm/modules/zm_logger.rb +24 -0
  115. data/lib/zm/modules/zm_model.rb +41 -0
  116. data/test/accounts.rb +15 -1
  117. data/test/ace.rb +50 -0
  118. data/test/cluster.rb +41 -0
  119. data/test/cluster_zimbra_attributes.rb +38 -0
  120. data/test/folder.rb +125 -0
  121. data/test/folder_grant.rb +51 -0
  122. data/test/mountpoint.rb +49 -0
  123. data/test/retention_policies.rb +40 -0
  124. data/test/search_folder.rb +67 -0
  125. data/test/signature.rb +53 -0
  126. data/test/tag.rb +65 -0
  127. data/test/zimbra_attributes.rb +35 -0
  128. data/zm-ruby-client.gemspec +15 -10
  129. metadata +53 -26
  130. data/lib/zm/client/connector/soap_xml_builder.rb +0 -68
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ DlMembership = Struct.new(:name, :id, :via)
6
+
7
+ class DlsMembershipCollection < Base::ObjectsCollection
8
+ def initialize(parent)
9
+ @parent = parent
10
+ end
11
+
12
+ private
13
+
14
+ def make_query
15
+ @parent.sac.get_distribution_list_membership(@parent.id, :id)
16
+ end
17
+
18
+ def build_response
19
+ @all = make_query.dig(:Body, :GetDistributionListMembershipResponse, :dl) || []
20
+ @all.map { |json| DlMembership.new(json[:name], json[:id], json[:via]) }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -3,3 +3,4 @@
3
3
  require 'zm/client/distributionlist/distributionlist'
4
4
  require 'zm/client/distributionlist/distributionlists_builder'
5
5
  require 'zm/client/distributionlist/distributionlists_collection'
6
+ require 'zm/client/distributionlist/dls_membership_collection'
@@ -19,8 +19,8 @@ module Zm
19
19
  yield(self) if block_given?
20
20
  end
21
21
 
22
- def concat
23
- INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
22
+ def all_instance_variable_keys
23
+ INSTANCE_VARIABLE_KEYS
24
24
  end
25
25
 
26
26
  def folder
@@ -31,6 +31,11 @@ module Zm
31
31
  @parent.sacc.item_action(@parent.token, :tag, @id, tn: tag_name)
32
32
  end
33
33
 
34
+ def move!(folder_id)
35
+ @parent.sacc.item_action(@parent.token, 'move', @id, l: folder_id)
36
+ @l = folder_id
37
+ end
38
+
34
39
  def delete!
35
40
  @parent.sacc.item_action(@parent.token, :delete, @id)
36
41
  end
@@ -39,13 +44,6 @@ module Zm
39
44
  uploader = Upload.new(@parent, RestAccountConnector.new)
40
45
  uploader.download_file(folder.absFolderPath, nil, nil, [id], dest_file_path)
41
46
  end
42
-
43
- def init_from_json(json)
44
- INSTANCE_VARIABLE_KEYS.each do |key|
45
- var_name = "@#{key}"
46
- instance_variable_set(var_name, json[key])
47
- end
48
- end
49
47
  end
50
48
  end
51
49
  end
@@ -15,11 +15,11 @@ module Zm
15
15
  @grantee_type = 'dom'.freeze
16
16
  end
17
17
 
18
- def to_h
19
- hashmap = Hash[all_instance_variable_keys.map { |key| [key, instance_variable_get(arrow_name(key))] }]
20
- hashmap.delete_if { |_, v| v.nil? }
21
- hashmap
22
- end
18
+ # def to_h
19
+ # hashmap = Hash[all_instance_variable_keys.map { |key| [key, instance_variable_get(arrow_name(key))] }]
20
+ # hashmap.delete_if { |_, v| v.nil? }
21
+ # hashmap
22
+ # end
23
23
 
24
24
  def all_instance_variable_keys
25
25
  INSTANCE_VARIABLE_KEYS
@@ -51,9 +51,14 @@ module Zm
51
51
  end
52
52
 
53
53
  def accounts
54
- @accounts ||= AccountsCollection.new(self)
54
+ @accounts ||= DomainAccountsCollection.new(self)
55
55
  end
56
56
 
57
+ # def account_quotas(server_id)
58
+ # rep = sac.get_quota_usage(name, nil, nil, nil, nil, nil, nil, server_id)
59
+ # AccountsBuilder.new(@parent, rep).make
60
+ # end
61
+
57
62
  def init_from_json(json)
58
63
  super(json)
59
64
  return unless json[:a].is_a? Array
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # Collection Accounts from domain
6
+ class DomainAccountsCollection < AccountsCollection
7
+ def initialize(parent)
8
+ @domain_name = parent.name
9
+ super(parent)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -7,25 +7,7 @@ module Zm
7
7
  def initialize(parent, json)
8
8
  super(parent, json)
9
9
  @child_class = Domain
10
- end
11
-
12
- # def make
13
- # records = []
14
- # return records if json_items.nil?
15
- #
16
- # json_items.each do |entry|
17
- # domain = Domain.new(@parent)
18
- # domain.init_from_json(entry)
19
- # records << domain
20
- # end
21
- #
22
- # records
23
- # end
24
-
25
- private
26
-
27
- def json_items
28
- @json_items ||= @json[:Body][json_key][:domain]
10
+ @json_item_key = :domain
29
11
  end
30
12
  end
31
13
  end
@@ -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