infopark_cloud_connector 6.8.0.210.ed204b0 → 6.8.0.322.c003f11

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 (37) hide show
  1. data/.yardopts +5 -0
  2. data/README +5 -0
  3. data/app/helpers/rails_connector/marker_helper.rb +1 -1
  4. data/lib/infopark_cloud_connector.rb +1 -0
  5. data/lib/rails_connector/blob.rb +50 -33
  6. data/lib/rails_connector/cache.rb +0 -1
  7. data/lib/rails_connector/cache_middleware.rb +0 -1
  8. data/lib/rails_connector/chain.rb +0 -1
  9. data/lib/rails_connector/cloud_engine.rb +1 -1
  10. data/lib/rails_connector/cms_api_search_request.rb +3 -0
  11. data/lib/rails_connector/cms_base_model.rb +2 -3
  12. data/lib/rails_connector/cms_rest_api.rb +0 -2
  13. data/lib/rails_connector/content_cache.rb +0 -1
  14. data/lib/rails_connector/content_service.rb +9 -0
  15. data/lib/rails_connector/date_attribute.rb +1 -1
  16. data/lib/rails_connector/default_search_request.rb +2 -1
  17. data/lib/rails_connector/dict_storage.rb +1 -1
  18. data/lib/rails_connector/errors.rb +2 -0
  19. data/lib/rails_connector/link.rb +22 -8
  20. data/lib/rails_connector/named_link.rb +11 -8
  21. data/lib/rails_connector/obj.rb +113 -25
  22. data/lib/rails_connector/obj_data.rb +4 -7
  23. data/lib/rails_connector/obj_data_from_database.rb +0 -1
  24. data/lib/rails_connector/obj_data_from_hash.rb +0 -1
  25. data/lib/rails_connector/obj_data_from_service.rb +6 -1
  26. data/lib/rails_connector/path_conversion.rb +1 -1
  27. data/lib/rails_connector/revision.rb +0 -1
  28. data/lib/rails_connector/s3_blob.rb +17 -12
  29. data/lib/rails_connector/service_blob.rb +48 -0
  30. data/lib/rails_connector/service_cms_backend.rb +24 -19
  31. data/lib/rails_connector/version.rb +0 -1
  32. data/lib/rails_connector/workspace.rb +0 -1
  33. data/lib/rails_connector/workspace_data_from_database.rb +0 -1
  34. data/lib/rails_connector/workspace_data_from_service.rb +0 -1
  35. data/lib/rails_connector/workspace_selection_middleware.rb +0 -1
  36. metadata +23 -23
  37. data/lib/rails_connector/obj_body.rb +0 -60
@@ -4,13 +4,13 @@ require 'kvom'
4
4
 
5
5
  module RailsConnector
6
6
  # The CMS file class
7
+ # @api public
7
8
  class Obj
8
9
  extend ActiveModel::Naming
9
10
  include Kvom::ModelIdentity
10
11
 
11
12
  include DateAttribute
12
13
  include SEO
13
- include ObjBody
14
14
 
15
15
  # Create a new Obj instance with the given values and attributes.
16
16
  # Normally this method should not be used.
@@ -25,11 +25,12 @@ module RailsConnector
25
25
 
26
26
  # instantiate an Obj instance from obj_data.
27
27
  # May result in an instance of a subclass of Obj according to STI rules.
28
- def self.instantiate(obj_data) # :nodoc:
28
+ def self.instantiate(obj_data)
29
29
  obj_class = obj_data.value_of("_obj_class")
30
30
  Obj.compute_type(obj_class).new(obj_data)
31
31
  end
32
32
 
33
+ # @api public
33
34
  def id
34
35
  read_attribute('_id')
35
36
  end
@@ -38,6 +39,7 @@ module RailsConnector
38
39
 
39
40
  # Find an Obj by it's id.
40
41
  # If the paremeter is an Array containing ids, return a list of corresponding Objs.
42
+ # @api public
41
43
  def self.find(id_or_list)
42
44
  case id_or_list
43
45
  when Array
@@ -51,23 +53,24 @@ module RailsConnector
51
53
  # (notice: not yet implemented)
52
54
  # Returns a list of all Objs.
53
55
  # If invoked on a subclass of Obj, the result will be restricted to Obj of that subclass.
54
- def self.all # :nodoc:
56
+ def self.all
55
57
  raise "not yet implemented!"
56
58
  end
57
59
 
58
60
  # (notice: not yet implemented)
59
61
  # returns an Array of all Objs with the given obj_class.
60
- def self.find_all_by_obj_class(obj_class) # :nodoc:
62
+ def self.find_all_by_obj_class(obj_class)
61
63
  raise "not yet implemented!"
62
64
  end
63
65
 
64
66
  # Find the Obj with the given path.
65
67
  # Returns nil if no matching Obj exists.
68
+ # @api public
66
69
  def self.find_by_path(path)
67
70
  find_objs_by(:path, [path]).first.first
68
71
  end
69
72
 
70
- def self.find_many_by_paths(pathes) # :nodoc:
73
+ def self.find_many_by_paths(pathes)
71
74
  find_objs_by(:path, pathes).map(&:first)
72
75
  end
73
76
 
@@ -75,22 +78,24 @@ module RailsConnector
75
78
  # Find an Obj with the given name.
76
79
  # If several Objs exist with the given name, one of them is chosen and returned.
77
80
  # If no Obj with the name exits, nil is returned.
78
- def self.find_by_name(name) # :nodoc:
81
+ def self.find_by_name(name)
79
82
  raise "not yet implemented!"
80
83
  end
81
84
 
82
85
  # (notice: not yet implemented)
83
86
  # Find all Objs with the given name.
84
- def self.find_all_by_name(name) # :nodoc:
87
+ def self.find_all_by_name(name)
85
88
  raise "not yet implemented!"
86
89
  end
87
90
 
88
91
  # Return the Obj with the given permalink or nil if no matching Obj exists.
92
+ # @api public
89
93
  def self.find_by_permalink(permalink)
90
94
  find_objs_by(:permalink, [permalink]).first.first
91
95
  end
92
96
 
93
97
  # Return the Obj with the given permalink or raise ResourceNotFound if no matching Obj exists.
98
+ # @api public
94
99
  def self.find_by_permalink!(permalink)
95
100
  find_by_permalink(permalink) or
96
101
  raise ResourceNotFound, "Could not find #{self} with permalink '#{permalink}'"
@@ -98,17 +103,17 @@ module RailsConnector
98
103
 
99
104
  # accepts the name of an "obj_by" - view and a list of keys.
100
105
  # returns a list of lists of Objs: a list of Objs for each given keys.
101
- def self.find_objs_by(view, keys) # :nodoc:
106
+ def self.find_objs_by(view, keys)
102
107
  CmsBackend.find_obj_data_by(Workspace.current.data, view, keys).map do |list|
103
108
  list.map { |obj_data| Obj.instantiate(obj_data) }
104
109
  end
105
110
  end
106
111
 
107
- def to_param # :nodoc:
112
+ def to_param
108
113
  id
109
114
  end
110
115
 
111
- def self.configure_for_content(mode) # :nodoc:
116
+ def self.configure_for_content(mode)
112
117
  # this method exists only for compatibility with the fiona connector.
113
118
  end
114
119
 
@@ -120,21 +125,23 @@ module RailsConnector
120
125
  # * An invalid model name
121
126
  #
122
127
  # Rails' STI mechanism only considers the first case.
123
- # In any other case, RailsConnector::Obj is used, except when explicitely asked
128
+ # In any other case, RailsConnector::Obj is used, except when explicitly asked
124
129
  # for a model in the RailsConnector namespace (RailsConnector::Permission etc.)
125
130
 
126
- def self.compute_type(type_name) # :nodoc:
131
+ def self.compute_type(type_name)
127
132
  @compute_type_cache ||= {}
128
133
  @compute_type_cache [type_name] ||= try_type { type_name.constantize } || self
129
134
  end
130
135
 
131
136
  # return the Obj that is the parent of this Obj.
132
137
  # returns nil for the root Obj.
138
+ # @api public
133
139
  def parent
134
140
  root? ? nil : Obj.find_by_path(parent_path)
135
141
  end
136
142
 
137
143
  # Returns an Array of all the ancestor objects, starting at the root and ending at this object's parent.
144
+ # @api public
138
145
  def ancestors
139
146
  return [] if root?
140
147
  ancestor_paths = parent_path.scan(/\/[^\/]+/).inject([""]) do |list, component|
@@ -145,6 +152,7 @@ module RailsConnector
145
152
  end
146
153
 
147
154
  # return a list of all child Objs.
155
+ # @api public
148
156
  def children
149
157
  Obj.find_objs_by(:ppath, [path]).first
150
158
  end
@@ -152,11 +160,13 @@ module RailsConnector
152
160
  ### ATTRIBUTES #################
153
161
 
154
162
  # returns the Obj's path as a String.
163
+ # @api public
155
164
  def path
156
165
  read_attribute('_path') or raise "Obj without path"
157
166
  end
158
167
 
159
168
  # returns the Obj's name, i.e. the last component of the path.
169
+ # @api public
160
170
  def name
161
171
  if root?
162
172
  ""
@@ -189,17 +199,20 @@ module RailsConnector
189
199
  end
190
200
 
191
201
  # Returns the root Obj, i.e. the Obj with the path "/"
202
+ # @api public
192
203
  def self.root
193
204
  Obj.find_by_path("/") or raise ResourceNotFound, "Obj.root not found: There is no Obj with path '/'."
194
205
  end
195
206
 
196
207
  # Returns the homepage object. This can be overwritten in your application's +ObjExtensions+.
197
208
  # Use <tt>Obj#homepage?</tt> to check if an object is the homepage.
209
+ # @api public
198
210
  def self.homepage
199
211
  root
200
212
  end
201
213
 
202
214
  # returns the obj's permalink.
215
+ # @api public
203
216
  def permalink
204
217
  read_attribute('_permalink')
205
218
  end
@@ -208,6 +221,7 @@ module RailsConnector
208
221
  # By default a controller matching the Obj's obj_class will be used.
209
222
  # If the controller does not exist, the CmsController will be used as a fallback.
210
223
  # Overwrite this method to force a different controller to be used.
224
+ # @api public
211
225
  def controller_name
212
226
  obj_class
213
227
  end
@@ -215,20 +229,24 @@ module RailsConnector
215
229
  # This method determines the action that should be invoked when the Obj is requested.
216
230
  # The default action is 'index'.
217
231
  # Overwrite this method to force a different action to be used.
232
+ # @api public
218
233
  def controller_action_name
219
234
  "index"
220
235
  end
221
236
 
222
237
  # Returns true if the current object is the homepage object.
238
+ # @api public
223
239
  def homepage?
224
240
  self == self.class.homepage
225
241
  end
226
242
 
227
243
  # Returns the title of the content or the name.
244
+ # @api public
228
245
  def display_title
229
246
  self.title || name
230
247
  end
231
248
 
249
+ # @api public
232
250
  def title
233
251
  read_attribute('title')
234
252
  end
@@ -264,6 +282,7 @@ module RailsConnector
264
282
  end
265
283
 
266
284
  # Returns true if this object is active (time_when is in object's time interval)
285
+ # @api public
267
286
  def active?(time_when = nil)
268
287
  return false unless valid_from
269
288
  time_then = time_when || Obj.preview_time
@@ -271,7 +290,7 @@ module RailsConnector
271
290
  end
272
291
 
273
292
  # compatibility with legacy apps.
274
- def suppress_export # :nodoc:
293
+ def suppress_export
275
294
  suppressed? ? 1 : 0
276
295
  end
277
296
 
@@ -307,12 +326,14 @@ module RailsConnector
307
326
  end
308
327
 
309
328
  # Returns true if this object is the root object.
329
+ # @api public
310
330
  def root?
311
331
  path == "/"
312
332
  end
313
333
 
314
334
  # Returns a list of exportable? children excluding the binary? ones unless :all is specfied.
315
335
  # This is mainly used for navigations.
336
+ # @api public
316
337
  def toclist(*args)
317
338
  return [] unless publication?
318
339
  time = args.detect {|value| value.kind_of? Time}
@@ -322,6 +343,7 @@ module RailsConnector
322
343
  end
323
344
 
324
345
  # Returns the sorted +toclist+, respecting sort order and type of this Obj.
346
+ # @api public
325
347
  def sorted_toclist(*args)
326
348
  list = self.toclist(*args)
327
349
  return [] if list.blank?
@@ -353,36 +375,37 @@ module RailsConnector
353
375
  return self.sort_order == "descending" ? sorted_list.reverse : sorted_list
354
376
  end
355
377
 
356
- def sort_order # :nodoc:
378
+ def sort_order
357
379
  read_attribute('_sort_order') == 1 ? "descending" : "ascending"
358
380
  end
359
381
 
360
- def sort_type1 # :nodoc:
382
+ def sort_type1
361
383
  converted_sort_type('_sort_type1')
362
384
  end
363
385
 
364
- def sort_type2 # :nodoc:
386
+ def sort_type2
365
387
  converted_sort_type('_sort_type2')
366
388
  end
367
389
 
368
- def sort_type3 # :nodoc:
390
+ def sort_type3
369
391
  converted_sort_type('_sort_type3')
370
392
  end
371
393
 
372
- def sort_key1 # :nodoc:
394
+ def sort_key1
373
395
  read_attribute('_sort_key1')
374
396
  end
375
397
 
376
- def sort_key2 # :nodoc:
398
+ def sort_key2
377
399
  read_attribute('_sort_key2')
378
400
  end
379
401
 
380
- def sort_key3 # :nodoc:
402
+ def sort_key3
381
403
  read_attribute('_sort_key3')
382
404
  end
383
405
 
384
406
  # Returns the Object with the given name next in the hierarchy
385
407
  # returns nil if no object with the given name was found.
408
+ # @api public
386
409
  def find_nearest(name)
387
410
  obj = self.class.find_by_path(root? ? "/#{name}" : "#{path}/#{name}")
388
411
  return obj if obj and obj.active?
@@ -416,6 +439,7 @@ module RailsConnector
416
439
 
417
440
  # Returns the value of an internal or external attribute specified by its name.
418
441
  # Passing an invalid key will not raise an error, but return nil.
442
+ # @api public
419
443
  def [](key)
420
444
  key = key.to_s
421
445
  if OLD_INTERNAL_KEYS.include?(key)
@@ -433,6 +457,7 @@ module RailsConnector
433
457
  # Reloads the attributes of this object from the database.
434
458
  # Notice that the ruby class of this Obj instance will NOT change,
435
459
  # even if the obj_class in the database has changed.
460
+ # @api public
436
461
  def reload
437
462
  obj_data = CmsBackend.find_obj_data_by(Workspace.current.data, :id, [id.to_s]).first.first
438
463
  update_data(obj_data)
@@ -442,18 +467,22 @@ module RailsConnector
442
467
  read_attribute('_text_links')
443
468
  end
444
469
 
470
+ # @api public
445
471
  def obj_class
446
472
  read_attribute('_obj_class')
447
473
  end
448
474
 
475
+ # @api public
449
476
  def last_changed
450
477
  read_attribute('_last_changed')
451
478
  end
452
479
 
480
+ # @api public
453
481
  def valid_from
454
482
  read_attribute('_valid_from')
455
483
  end
456
484
 
485
+ # @api public
457
486
  def valid_until
458
487
  read_attribute('_valid_until')
459
488
  end
@@ -463,6 +492,7 @@ module RailsConnector
463
492
  # Override this method in subclasses to define a different content_type.
464
493
  # Note that only Objs with content_type "text/html"
465
494
  # will be rendered with layout and templates by the DefaultCmsController.
495
+ # @api public
466
496
  def content_type
467
497
  if binary?
468
498
  body_content_type
@@ -474,15 +504,68 @@ module RailsConnector
474
504
 
475
505
  # returns the extension (the part after the last dot) from the Obj's name.
476
506
  # returns an empty string if no extension is present in the Obj's name.
507
+ # @api public
477
508
  def file_extension
478
509
  File.extname(name)[1..-1] || ""
479
510
  end
480
511
 
481
- def to_liquid # :nodoc:
512
+ # Returns the body (main content) of the Obj for non-binary Objs.
513
+ # Returns nil for binary Objs.
514
+ # @api public
515
+ def body
516
+ if binary?
517
+ nil
518
+ else
519
+ StringTagging.tag_as_html(read_attribute('body'), self)
520
+ end
521
+ end
522
+
523
+ # for binary Objs body_length equals the file size
524
+ # for non-binary Objs body_length equals the number of characters in the body (main content)
525
+ # @api public
526
+ def body_length
527
+ if binary?
528
+ blob = find_blob
529
+ blob ? blob.length : 0
530
+ else
531
+ (body || "").length
532
+ end
533
+ end
534
+
535
+ # returns an URL to retrieve the Obj's body for binary Objs.
536
+ # returns nil for non-binary Objs.
537
+ # @api public
538
+ def body_data_url
539
+ if binary?
540
+ blob = find_blob
541
+ blob.url if blob
542
+ end
543
+ end
544
+
545
+ def body_data_path
546
+ # not needed/supported when using cloud connector.
547
+ nil
548
+ end
549
+
550
+ # returns the content type of the Obj's body for binary Objs.
551
+ # returns nil for non-binary Objs.
552
+ # @api public
553
+ def body_content_type
554
+ if binary?
555
+ blob = find_blob
556
+ if blob
557
+ blob.content_type
558
+ else
559
+ "application/octet-stream"
560
+ end
561
+ end
562
+ end
563
+
564
+ def to_liquid
482
565
  LiquidSupport::ObjDrop.new(self)
483
566
  end
484
567
 
485
- def respond_to?(method_id, include_private=false) # :nodoc:
568
+ def respond_to?(method_id, include_private=false)
486
569
  if has_attribute?(method_id)
487
570
  true
488
571
  else
@@ -490,11 +573,11 @@ module RailsConnector
490
573
  end
491
574
  end
492
575
 
493
- def self.preview_time=(t) # :nodoc:
576
+ def self.preview_time=(t)
494
577
  Thread.current[:preview_time] = t
495
578
  end
496
579
 
497
- def self.preview_time # :nodoc:
580
+ def self.preview_time
498
581
  Thread.current[:preview_time] || Time.now
499
582
  end
500
583
 
@@ -547,7 +630,12 @@ module RailsConnector
547
630
  DateAttribute.parse(value) unless value.nil?
548
631
  end
549
632
 
550
- def method_missing(method_name, *args) # :nodoc:
633
+ def find_blob
634
+ blob_spec = read_attribute('blob')
635
+ Blob.find(blob_spec["id"]) if blob_spec
636
+ end
637
+
638
+ def method_missing(method_name, *args)
551
639
  if has_attribute?(method_name)
552
640
  read_attribute(method_name.to_s)
553
641
  else
@@ -1,4 +1,3 @@
1
- #:enddoc:
2
1
  module RailsConnector
3
2
 
4
3
  class ObjData
@@ -24,14 +23,12 @@ module RailsConnector
24
23
  case key
25
24
  when "_text_links"
26
25
  "linklist"
27
- when "_valid_from"
26
+ when "_valid_from", "_valid_until", "_last_changed"
28
27
  "date"
29
- when "_valid_until"
30
- "date"
31
- when "_last_changed"
32
- "date"
33
- when "title"
28
+ when "title", "body"
34
29
  "html"
30
+ when "blob"
31
+ "binary"
35
32
  else
36
33
  nil
37
34
  end