infopark_reactor 1.9.0.beta2 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b96463ad2562d6b77d097a3704b5abcd1f51439d
4
- data.tar.gz: 0ab12aa9b56d9f5e181f19acc58d5fbc12f904f0
3
+ metadata.gz: 432173125e16982290bf5e7eb40370e0f37585d5
4
+ data.tar.gz: 2d7268785b33578ddee8890d8a2ac92deb3b1b91
5
5
  SHA512:
6
- metadata.gz: 44c4dae0ba20c0c8f321c23257a20379030a50b73c4a613abfdcc13871783a0d2116fd9d0af87dfba873af6bc799b1d0ade407dc9254d18b65f162bb2aa5d7b0
7
- data.tar.gz: bd94b0c7b9fdb84c32b559865549e922c7b0e3423246a1d41faae065e59c11b4f7a69d6daa3eef1f3b07a902eefd616b335dbdc4e158efe0481aeaf59d3be20c
6
+ metadata.gz: 00ffdd16e4a53f1246861515d148ccf7031e4aa1a2b6cbf2f5e809ed806269357db74c467d031e7c1abcd80bcb00f80a5df5bcfde862035eb1acf2d3a1681bbe
7
+ data.tar.gz: 7b1bfb1775ed0df349f555d0971beee2e323520c27a5c022ce490a50d7f86b29ea10ed32c97d518c5192504f2b71ea8ab91d88b9dfa8e07323ce8c6d6b6ecb11
@@ -20,22 +20,40 @@ module Reactor
20
20
  Array.instance_methods(false).each do |meth|
21
21
  old = instance_method(meth)
22
22
  define_method(meth) do |*args, &block|
23
- old_size = size
24
- ret = old.bind(self).call(*args, &block)
25
- size_changed(old_size, size) if old_size != size
26
- ret
27
- end if meth.to_sym != :size
23
+ detect_modification do
24
+ old.bind(self).call(*args, &block)
25
+ end
26
+ end if meth.to_sym != :map
28
27
  end
29
28
 
30
29
  def changed?
31
- @changed == true
30
+ @changed == true || temporary_links_present?
32
31
  end
33
32
 
34
- protected
35
- def size_changed(old_size, size)
33
+ def change!
36
34
  @changed = true
37
35
  end
38
36
 
37
+ def original_link_ids
38
+ @original_link_ids ||= link_ids
39
+ end
40
+
41
+ protected
42
+ def link_ids
43
+ self.map(&:id).compact
44
+ end
45
+
46
+ def temporary_links_present?
47
+ self.any? {|l| l.kind_of? Reactor::Link::TemporaryLink }
48
+ end
49
+
50
+ def detect_modification(&block)
51
+ original_link_ids
52
+ yield.tap do
53
+ @changed = @changed || original_link_ids != link_ids
54
+ end
55
+ end
56
+
39
57
  def transform_into_link(link_data)
40
58
  if (link_data.respond_to?(:external?) && link_data.respond_to?(:internal?))
41
59
  link_data
@@ -15,6 +15,7 @@ module Reactor
15
15
  enumerate(@value).each do |link_data|
16
16
  linklist << link_data
17
17
  end
18
+ linklist.change!
18
19
  linklist
19
20
  end
20
21
 
@@ -125,12 +125,12 @@ module Reactor
125
125
 
126
126
  # Returns true if given user (or current user, if none given) has 'read' permission
127
127
  def read?(user = nil)
128
- granted?(user, :read)
128
+ granted?(user, :root) || granted?(user, :read)
129
129
  end
130
130
 
131
131
  # Returns true if given user (or current user, if none given) has 'write' permission
132
132
  def write?(user = nil)
133
- granted?(user, :write)
133
+ granted?(user, :root) || granted?(user, :write)
134
134
  end
135
135
 
136
136
  # Returns true if given user (or current user, if none given) has 'root' permission
@@ -140,7 +140,7 @@ module Reactor
140
140
 
141
141
  # Returns true if given user (or current user, if none given) has 'create_children' permission
142
142
  def create_children?(user = nil)
143
- granted?(user, :create_children)
143
+ granted?(user, :root) || granted?(user, :create_children)
144
144
  end
145
145
 
146
146
  # @see #root?
@@ -167,6 +167,7 @@ module Reactor
167
167
  # permissions depend on the state of the object)
168
168
  def release?(user = nil)
169
169
  (has_workflow? && root?(user)) || (!has_workflow? && write?(user))
170
+ write?(user) || root?(user)
170
171
  end
171
172
 
172
173
  # Setter to overwrite the current groups for the given +permission+ with the
@@ -177,23 +177,25 @@ module Reactor
177
177
  # any other reload methods (neither from RailsConnector nor from ActiveRecord)
178
178
  # but tries to mimmic their behaviour.
179
179
  def reload(options = nil)
180
- #super # Throws RecordNotFound when changing obj_class
181
- # AR reload
182
- clear_aggregation_cache
183
- clear_association_cache
184
- fresh_object = Obj.find(self.id, options)
185
- @attributes = fresh_object.instance_variable_get('@attributes')
186
- @attributes_cache = {}
187
- # RC reload
188
- @attr_values = nil
189
- @attr_defs = nil
190
- @attr_dict = nil
191
- @obj_class_definition = nil
192
- @object_with_meta_data = nil
193
- # meta reload
194
- @editor = nil
195
- @object_with_meta_data = nil
196
- self
180
+ Obj.uncached do
181
+ #super # Throws RecordNotFound when changing obj_class
182
+ # AR reload
183
+ clear_aggregation_cache
184
+ clear_association_cache
185
+ fresh_object = Obj.find(self.id, options)
186
+ @attributes = fresh_object.instance_variable_get('@attributes')
187
+ @attributes_cache = {}
188
+ # RC reload
189
+ @attr_values = nil
190
+ @attr_defs = nil
191
+ @attr_dict = nil
192
+ @obj_class_definition = nil
193
+ @object_with_meta_data = nil
194
+ # meta reload
195
+ @editor = nil
196
+ @object_with_meta_data = nil
197
+ self
198
+ end
197
199
  end
198
200
 
199
201
  # Resolves references in any of the html fields. Returns true on success,
@@ -248,6 +250,7 @@ module Reactor
248
250
  end
249
251
 
250
252
 
253
+ =begin
251
254
  # @see [ActiveRecord::Persistence#update_attributes]
252
255
  def update_attributes(attributes, options={})
253
256
  attributes.each do |attr, value|
@@ -263,6 +266,7 @@ module Reactor
263
266
  end
264
267
  self.save!
265
268
  end
269
+ =end
266
270
 
267
271
  # Equivalent to Obj#edited?
268
272
  def really_edited?
@@ -275,14 +279,6 @@ module Reactor
275
279
  end
276
280
 
277
281
  protected
278
- def requires_resolve_refs?(field)
279
- force_resolve_refs?|| field == :blob || attribute_type(field.to_s) == :html
280
- end
281
-
282
- def force_resolve_refs
283
- @force_resolve_refs = true
284
- end
285
-
286
282
  def prevent_resolve_refs
287
283
  @prevent_resolve_refs = true
288
284
  end
@@ -291,10 +287,6 @@ module Reactor
291
287
  @prevent_resolve_refs == true
292
288
  end
293
289
 
294
- def force_resolve_refs?
295
- @force_resolve_refs == true
296
- end
297
-
298
290
  def sanitize_name
299
291
  self.name = self.class.send(:sanitize_name, self.name)
300
292
  end
@@ -313,28 +305,11 @@ module Reactor
313
305
  end
314
306
  end
315
307
 
316
- # Returns all values that will be set for crul interface
317
308
  def crul_attributes
318
309
  @__crul_attributes || {}
319
310
  end
320
311
 
321
- # Takes cached values and sets the values for crul interface.
322
- # Does not store them, only forwards them to underlying class.
323
- def forward_crul_attributes
324
- crul_attributes.each do |field, (value, options)|
325
- options ||= {}
326
- crul_obj.set(field, value, options) unless self.send(:attribute_type, field) == :linklist
327
- end
328
- end
329
-
330
- def prepare_crul_links
331
- changed_linklists.each do |link|
332
- crul_set(link, self.send(:[], link.to_sym), {})
333
- end
334
- end
335
-
336
312
  def crul_obj
337
- #@crul_obj ||= Reactor::Cm::Obj.get(obj_id)
338
313
  @crul_obj ||= Reactor::Cm::Obj.load(obj_id)
339
314
  end
340
315
 
@@ -343,30 +318,63 @@ module Reactor
343
318
  end
344
319
 
345
320
  def crul_obj_save
346
- prepare_crul_links
347
- if persisted?
348
- take
349
- edit
321
+ attrs, _ = crul_attributes.partition do |field, (value, options)|
322
+ self.send(:attribute_type, field) != :linklist
350
323
  end
324
+ linklists = changed_linklists
351
325
 
352
- forward_crul_attributes
326
+ new_links = {}.tap do |result|
327
+ linklists.map do |field|
328
+ result[field] = self.__read_link(field).map do |l|
329
+ {:link_id => l.id, :title => l.title, :destination_url => (l.internal? ? l.destination_object.path : l.url)}
330
+ end
331
+ end
332
+ end
353
333
 
354
- crul_obj.save!
355
- self.id = crul_obj.obj_id
334
+ links_modified = !linklists.empty?
356
335
 
357
- crul_store_links
336
+ crul_obj.composite_save(attrs, [], [], [], links_modified) do |attrs, links_to_add, links_to_remove, links_to_set|
358
337
 
359
- # TODO: REFACTOR!!!
360
- possible_fields = ((self.obj_class_def.custom_attributes.keys) + [:blob, :body])
361
- crul_obj.resolve_refs! if possible_fields.map {|field| requires_resolve_refs?(field) }.include?(true) && !prevent_resolve_refs?
362
- #crul_obj.resolve_refs! if @force_resolve_refs == true || possible_fields.include?(:blob) || possible_fields.detect do |field|
363
- # attr = cms_attributes[field.to_s]
364
- # attr && attr.attribute_type == 'html'
365
- #end
338
+ links_to_add.clear
339
+ links_to_remove.clear
340
+ links_to_set.clear
341
+
342
+ copy = Obj.find(self.id)
343
+
344
+ linklists.each do |linklist|
345
+ original_link_ids = copy.__read_link(linklist).original_link_ids
346
+ i = 0
347
+ common = [original_link_ids.length,
348
+ new_links[linklist].length].min
366
349
 
367
- @__crul_attributes = nil
350
+ # replace existing links
351
+ while i < common
352
+ link = new_links[linklist][i]
353
+ link[:link_id] = link_id = original_link_ids[i]
368
354
 
369
- true
355
+ links_to_set << [link_id, link]
356
+ i += 1
357
+ end
358
+
359
+ # add appended links
360
+ while i < new_links[linklist].length
361
+ link = new_links[linklist][i]
362
+
363
+ links_to_add << [linklist, link]
364
+ i += 1
365
+ end
366
+
367
+ # remove trailing links
368
+ while i < original_link_ids.length
369
+ links_to_remove << original_link_ids[i]
370
+ i += 1
371
+ end
372
+ end
373
+ end
374
+ end
375
+
376
+ def __read_link(name)
377
+ self[name.to_sym] || RailsConnector::LinkList.new([])
370
378
  end
371
379
 
372
380
  private
@@ -391,32 +399,14 @@ module Reactor
391
399
  @crul_obj = Reactor::Cm::Obj.create(name, parent, klass)
392
400
  end
393
401
 
394
- def crul_store_links
395
- crul_attributes.each do |field, (value, options)|
396
- if self.send(:attribute_type, field) == :linklist then
397
- crul_store_links_for_attribute(field, value)
398
- end
399
- end
400
- # self.class.send(:instance_variable_get, '@_o_allowed_attrs').each do |attr|
401
- # if self.send(:attribute_type, attr) == :linklist #&& self.send(attr).try(:changed?) then
402
- # crul_store_links_for_attribute(attr, self.send(attr))
403
- # end
404
- # end
405
- end
406
-
407
- def crul_store_links_for_attribute(attr, links)
408
- # FIXME: l.link_id ??
409
- crul_obj.set_links(attr, links.map {|l| {:link_id => l.id, :title => l.title, :destination_url => (l.internal? ? l.destination_object.path : l.url)} })
410
- end
411
-
412
402
  def create
413
403
  run_callbacks(:create) do
414
404
  c_name = self.name
415
405
  c_parent= self.class.path_from_anything(self.parent_obj_id)
416
406
  c_objcl = self.obj_class
417
407
  crul_obj_create(c_name, c_parent, c_objcl)
418
- crul_obj_save if crul_attributes_set? || crul_links_changed?
419
408
  self.id = @crul_obj.obj_id
409
+ crul_obj_save if crul_attributes_set? || crul_links_changed?
420
410
  self.reload # ?
421
411
  self.id
422
412
  end
@@ -544,7 +534,6 @@ module Reactor
544
534
  end
545
535
 
546
536
  protected
547
- # TODO: TESTME!!!!
548
537
  def attribute_methods_overriden?
549
538
  self.name != 'RailsConnector::AbstractObj'
550
539
  end
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Reactor
3
- VERSION = "1.9.0.beta2"
3
+ VERSION = "1.9.1"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark_reactor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0.beta2
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomasz Przedmojski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-14 00:00:00.000000000 Z
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -149,9 +149,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
149
  version: '0'
150
150
  required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  requirements:
152
- - - '>'
152
+ - - '>='
153
153
  - !ruby/object:Gem::Version
154
- version: 1.3.1
154
+ version: '0'
155
155
  requirements: []
156
156
  rubyforge_project:
157
157
  rubygems_version: 2.0.14