infopark_fiona_connector 7.0.0 → 7.0.1.5.2.3.rc6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +5 -5
  2. data/app/controllers/cms_controller.rb +1 -1
  3. data/app/controllers/rails_connector/default_cms_controller.rb +4 -6
  4. data/app/helpers/cms_helper.rb +1 -1
  5. data/app/helpers/cms_routing_helper.rb +1 -1
  6. data/app/helpers/rails_connector/cms_asset_helper.rb +4 -5
  7. data/app/helpers/rails_connector/cms_tag_helper.rb +0 -3
  8. data/app/helpers/rails_connector/default_cms_helper.rb +0 -2
  9. data/app/helpers/rails_connector/default_cms_routing_helper.rb +15 -16
  10. data/app/helpers/rails_connector/display_helper.rb +31 -33
  11. data/app/helpers/rails_connector/editing_helper.rb +2 -8
  12. data/app/helpers/rails_connector/layout_helper.rb +2 -5
  13. data/app/helpers/rails_connector/marker_helper.rb +63 -64
  14. data/app/helpers/rails_connector/table_of_contents_helper.rb +1 -3
  15. data/config/cms_routes.rb +15 -15
  16. data/lib/gem_dependencies.rb +8 -7
  17. data/lib/generators/rails_connector/install/install_generator.rb +6 -6
  18. data/lib/generators/rails_connector/install/templates/initializers/rails_connector.rb +1 -1
  19. data/lib/infopark_fiona_connector.rb +7 -6
  20. data/lib/meta_eager_loader.rb +1 -0
  21. data/lib/rails_connector/attr_dict.rb +54 -31
  22. data/lib/rails_connector/attribute.rb +93 -0
  23. data/lib/rails_connector/authenticable.rb +12 -5
  24. data/lib/rails_connector/basic_obj.rb +126 -132
  25. data/lib/rails_connector/blob.rb +4 -5
  26. data/lib/rails_connector/blob_mapping.rb +15 -0
  27. data/lib/rails_connector/blob_mysql.rb +3 -5
  28. data/lib/rails_connector/blob_oracle.rb +5 -7
  29. data/lib/rails_connector/channel.rb +18 -0
  30. data/lib/rails_connector/cms_accessible.rb +21 -24
  31. data/lib/rails_connector/cms_base_model.rb +11 -4
  32. data/lib/rails_connector/cms_dispatch_controller.rb +9 -12
  33. data/lib/rails_connector/cms_env.rb +4 -7
  34. data/lib/rails_connector/cms_test_request.rb +1 -16
  35. data/lib/rails_connector/configuration.rb +14 -16
  36. data/lib/rails_connector/content.rb +7 -0
  37. data/lib/rails_connector/core_extensions/time.rb +3 -4
  38. data/lib/rails_connector/date_attribute.rb +2 -4
  39. data/lib/rails_connector/default_search_request.rb +1 -1
  40. data/lib/rails_connector/engine.rb +18 -17
  41. data/lib/rails_connector/errors.rb +2 -5
  42. data/lib/rails_connector/fiona_datetime.rb +14 -0
  43. data/lib/rails_connector/fiona_engine.rb +3 -4
  44. data/lib/rails_connector/html_string.rb +0 -2
  45. data/lib/rails_connector/job.rb +10 -0
  46. data/lib/rails_connector/link.rb +7 -4
  47. data/lib/rails_connector/link_list.rb +1 -5
  48. data/lib/rails_connector/link_resolvable.rb +1 -5
  49. data/lib/rails_connector/lucene_search_request.rb +20 -24
  50. data/lib/rails_connector/markdown_string.rb +0 -2
  51. data/lib/rails_connector/meta.rb +143 -0
  52. data/lib/rails_connector/meta/eager_loader.rb +84 -0
  53. data/lib/rails_connector/named_link.rb +25 -14
  54. data/lib/rails_connector/news.rb +8 -4
  55. data/lib/rails_connector/obj_class.rb +138 -0
  56. data/lib/rails_connector/obj_class_attr.rb +5 -0
  57. data/lib/rails_connector/object_with_meta_data.rb +13 -0
  58. data/lib/rails_connector/permission.rb +2 -6
  59. data/lib/rails_connector/rack_middlewares.rb +1 -2
  60. data/lib/rails_connector/ses.rb +3 -8
  61. data/lib/rails_connector/ses/verity_accessor.rb +43 -46
  62. data/lib/rails_connector/string_tagging.rb +0 -3
  63. data/lib/rails_connector/verity_search_request.rb +6 -9
  64. data/lib/search_request.rb +1 -1
  65. data/lib/version.rb +1 -1
  66. metadata +44 -38
@@ -1,28 +1,36 @@
1
1
  require "json"
2
- require 'openssl'
2
+ require "openssl"
3
+ require "rails_connector/fiona_datetime"
3
4
 
4
5
  module RailsConnector
5
-
6
6
  # The CMS file class
7
7
  #
8
8
  # [children] an Array of objects, Obj, of which this one is the parent
9
9
  # [parent] the Obj of which this one is a child - nil for the root object
10
10
  # @api public
11
11
  class BasicObj < CmsBaseModel
12
+ include RailsConnector::Meta
13
+
12
14
  CRYPT_KEY = "\xd7\x28\x9c\x63\xd6\x29\xdf\x20\xcd\x32\xcf\x30\xcf\x30\xcf\x30\xdf\x20\xb6\x49"\
13
15
  "\x91\x6e\x99\x66\x90\x6f\x8f\x70\x9e\x61\x8d\x72\x94\x6b\xdf\x20\xbe\x41\xb8\x47\xc4\x3b"\
14
16
  "\xdf\x20\xbd\x42\x9a\x65\x8d\x72\x93\x6c\x96\x69\x91\x6e".freeze
15
17
 
16
- include DateAttribute
18
+ PREDEFINED_ATTRIBUTES = %w(blob body title channels sort_key1 sort_type1 sort_key2 sort_type2
19
+ sort_key3 sort_type3 sort_order).freeze
17
20
 
18
21
  self.store_full_sti_class = false
19
22
 
23
+ def self.inherited(subclass)
24
+ super
25
+ subclass.delegate_attributes
26
+ end
27
+
20
28
  def self.configure_for_content(which)
21
29
  case which
22
30
  when :released then configure_column_information("objs", true)
23
31
  when :edited
24
32
  configure_column_information("preview_objs", false)
25
- has_many(:arel_permissions, :class_name => "::RailsConnector::Permission", :foreign_key => "object_id")
33
+ has_many(:arel_permissions, class_name: "::RailsConnector::Permission", foreign_key: "object_id")
26
34
  else
27
35
  raise "configure_for_content called with unknown parameter #{which}"
28
36
  end
@@ -36,10 +44,58 @@ module RailsConnector
36
44
  self.inheritance_column = "obj_class"
37
45
 
38
46
  @@use_cached_permissions = use_cached_permissions
47
+ descendants.each do |klass|
48
+ klass.reset_table_name
49
+ klass.initialize_attributes
50
+ end
51
+
52
+ RailsConnector::Meta::EagerLoader.instance.obj_classes.each do |class_name, obj_class|
53
+ next unless obj_class
54
+
55
+ next unless /^[A-Z]/.match?(class_name)
56
+
57
+ klass = class_name.safe_constantize
58
+ next unless klass
59
+
60
+ klass.initialize_attributes if klass < RailsConnector::BasicObj
61
+ end
39
62
  end
40
63
 
41
- # use released contents as a default
42
- configure_for_content(:released)
64
+ def self.initialize_attributes
65
+ PREDEFINED_ATTRIBUTES.each do |attribute|
66
+ send(:define_attribute, attribute, ActiveRecord::Type::String.new)
67
+ end
68
+
69
+ return if obj_class_definition.blank?
70
+
71
+ obj_class_definition.custom_attributes.each_key do |attribute|
72
+ send(:define_attribute, attribute, ActiveRecord::Type::String.new)
73
+ end
74
+ end
75
+
76
+ def self.delegate_attributes
77
+ PREDEFINED_ATTRIBUTES.each do |attribute|
78
+ delegate attribute, to: :attr_dict
79
+ end
80
+
81
+ return if obj_class_definition.blank?
82
+
83
+ obj_class_definition.custom_attributes.each_key do |attribute|
84
+ delegate attribute, to: :attr_dict
85
+ end
86
+ end
87
+
88
+ attribute :last_changed, :fiona_datetime
89
+ attribute :valid_from, :fiona_datetime
90
+ attribute :valid_until, :fiona_datetime
91
+ attribute :suppress_export, :boolean
92
+ attribute :is_edited, :boolean
93
+ attribute :is_released, :boolean
94
+
95
+ delegate :sort_keys, to: :attr_dict
96
+ delegate :body_data_path, to: :attr_dict
97
+ delegate :empty?, to: :attr_dict
98
+ delegate :text_links, to: :attr_dict
43
99
 
44
100
  # Patch to avoid a type_condition being added by ActiveRecord::Base.add_conditions! for Obj.find(params):
45
101
  def self.descends_from_active_record?
@@ -65,6 +121,11 @@ module RailsConnector
65
121
  # We don't cache types at all here.
66
122
  end
67
123
 
124
+ def self.reset_reflections
125
+ has_many :children, class_name: "Obj", foreign_key: "parent_obj_id"
126
+ belongs_to :parent, class_name: "Obj", foreign_key: "parent_obj_id"
127
+ end
128
+
68
129
  # @api public
69
130
  def permissions
70
131
  @@use_cached_permissions ? attr_dict.permissions : arel_permissions
@@ -101,12 +162,6 @@ module RailsConnector
101
162
  @@homepage_id = nil
102
163
  end
103
164
 
104
- # returns the obj's permalink.
105
- # @api public
106
- def permalink
107
- self[:permalink]
108
- end
109
-
110
165
  # This method determines the controller that should be invoked when the Obj is requested.
111
166
  # By default a controller matching the Obj's obj_class will be used.
112
167
  # If the controller does not exist, the CmsController will be used as a fallback.
@@ -131,7 +186,7 @@ module RailsConnector
131
186
  # and thus requires no extra database access.
132
187
  # @api public
133
188
  def homepage?
134
- self.id == (@@homepage_id ||= self.class.homepage.id)
189
+ id == (@@homepage_id ||= self.class.homepage.id)
135
190
  end
136
191
 
137
192
  # This method is used to calculate a part of a URL of an obj.
@@ -150,15 +205,17 @@ module RailsConnector
150
205
  # Returns the title of the content or the name.
151
206
  # @api public
152
207
  def display_title
153
- self.title || name
208
+ title || name
154
209
  end
155
210
 
156
- OBJECT_TYPES = {
157
- '2' => :document,
158
- '5' => :publication,
159
- 'B' => :image,
160
- 'C' => :generic
161
- }.freeze unless defined?(OBJECT_TYPES)
211
+ unless defined?(OBJECT_TYPES)
212
+ OBJECT_TYPES = {
213
+ "2" => :document,
214
+ "5" => :publication,
215
+ "B" => :image,
216
+ "C" => :generic
217
+ }.freeze
218
+ end
162
219
 
163
220
  # Returns the type of the object: :document, :publication, :image or :generic
164
221
  # @api public
@@ -169,7 +226,7 @@ module RailsConnector
169
226
  # Returns true if image? or generic?
170
227
  # @api public
171
228
  def binary?
172
- [:image, :generic].include? object_type
229
+ %i(image generic).include? object_type
173
230
  end
174
231
 
175
232
  # Returns true if object_type == :image
@@ -199,7 +256,8 @@ module RailsConnector
199
256
  # Returns true if this object is active.
200
257
  # @api public
201
258
  def active?
202
- return false if !valid_from
259
+ return false unless valid_from
260
+
203
261
  valid_from <= Time.now && (!valid_until || Time.now <= valid_until)
204
262
  end
205
263
 
@@ -208,13 +266,13 @@ module RailsConnector
208
266
  # and edited? will always return false in this case.
209
267
  # @api public
210
268
  def edited?
211
- (is_edited == 1)
269
+ is_edited
212
270
  end
213
271
 
214
272
  # Returns true if this object has released content
215
273
  # @api public
216
274
  def released?
217
- (is_released == 1)
275
+ is_released
218
276
  end
219
277
 
220
278
  # Returns true if the Obj is suppressed.
@@ -223,7 +281,7 @@ module RailsConnector
223
281
  # as a standalone web page.
224
282
  # @api public
225
283
  def suppressed?
226
- suppress_export == 1
284
+ suppress_export
227
285
  end
228
286
 
229
287
  # Returns true if the export of the object is not suppressed and the content is active?
@@ -254,15 +312,13 @@ module RailsConnector
254
312
  parent_obj_id.nil?
255
313
  end
256
314
 
257
- has_many :children, :class_name => 'Obj', :foreign_key => 'parent_obj_id'
258
- belongs_to :parent, :class_name => 'Obj', :foreign_key => 'parent_obj_id'
259
-
260
315
  # Returns a list of exportable? children excluding the binary? ones unless :all is specfied.
261
316
  # This is mainly used for navigations.
262
317
  # @api public
263
318
  def toclist(*args)
264
319
  return [] unless publication?
265
- toclist = children.to_a.select{ |toc| toc.exportable? }
320
+
321
+ toclist = children.to_a.select { |toc| toc.exportable? }
266
322
  toclist = toclist.reject { |toc| toc.binary? } unless args.include?(:all)
267
323
  toclist
268
324
  end
@@ -270,20 +326,20 @@ module RailsConnector
270
326
  # Returns the sorted +toclist+, respecting sort order and type of this Obj.
271
327
  # @api public
272
328
  def sorted_toclist(*args)
273
- list = self.toclist(*args)
329
+ list = toclist(*args)
274
330
  return [] if list.blank?
275
331
 
276
- cached_sort_key1 = self.sort_key1
277
- cached_sort_type1 = self.sort_type1
332
+ cached_sort_key1 = sort_key1
333
+ cached_sort_type1 = sort_type1
278
334
 
279
335
  sorted_list =
280
336
  if cached_sort_key1.blank?
281
- list.sort { |left_obj, right_obj| left_obj.name <=> right_obj.name }
337
+ list.sort_by(&:name)
282
338
  else
283
- cached_sort_key2 = self.sort_key2
284
- cached_sort_type2 = self.sort_type2
285
- cached_sort_key3 = self.sort_key3
286
- cached_sort_type3 = self.sort_type3
339
+ cached_sort_key2 = sort_key2
340
+ cached_sort_type2 = sort_type2
341
+ cached_sort_key3 = sort_key3
342
+ cached_sort_type3 = sort_type3
287
343
 
288
344
  list.sort do |left_obj, right_obj|
289
345
  compare = compare_on_sort_key(left_obj, right_obj, cached_sort_key1, cached_sort_type1)
@@ -297,19 +353,7 @@ module RailsConnector
297
353
  end
298
354
  end
299
355
 
300
- return self.sort_order == "descending" ? sorted_list.reverse : sorted_list
301
- end
302
-
303
- def sort_key1
304
- self[:sort_key1]
305
- end
306
-
307
- def sort_key2
308
- self[:sort_key2]
309
- end
310
-
311
- def sort_key3
312
- self[:sort_key3]
356
+ sort_order == "descending" ? sorted_list.reverse : sorted_list
313
357
  end
314
358
 
315
359
  # Returns an Array of all the ancestor objects, starting at the root and ending at this object's parent.
@@ -326,9 +370,10 @@ module RailsConnector
326
370
  # returns nil if no object with the given name was found.
327
371
  # @api public
328
372
  def find_nearest(name)
329
- obj = self.children.find_by_name(name)
330
- return obj if obj and obj.active?
331
- parent.find_nearest(name) unless self.root?
373
+ obj = children.find_by_name(name)
374
+ return obj if obj&.active?
375
+
376
+ parent.find_nearest(name) unless root?
332
377
  end
333
378
 
334
379
  # Returns the value of the attribute specified by its name.
@@ -336,26 +381,15 @@ module RailsConnector
336
381
  # Passing an invalid key will not raise an error, but return nil.
337
382
  # @api public
338
383
  def [](key)
339
- # convenience access to name
340
- return name if key.to_sym == :name
384
+ if has_attribute?(key)
385
+ begin
386
+ return attr_dict.send(key) if attr_dict.respond_to?(key)
341
387
 
342
- # regular activerecord attributes
343
- if @attributes.include?(key.to_s)
344
- if key == :valid_from or key == :valid_until or key == :last_changed
345
- return as_date(super(key))
346
- else
347
- return super(key)
388
+ read_attribute(key)
389
+ rescue NoMethodError
390
+ nil
348
391
  end
349
392
  end
350
-
351
- # Unknown Obj attributes are delegated to the corresponding instance of AttrDict.
352
- begin
353
- return (attr_dict.send key)
354
- rescue NoMethodError
355
- end
356
-
357
- # fallback
358
- return nil
359
393
  end
360
394
 
361
395
  # Reloads the attributes of this object from the database, invalidates custom attributes
@@ -384,9 +418,7 @@ module RailsConnector
384
418
  # for binary Objs body_length equals the file size
385
419
  # for non-binary Objs body_length equals the number of characters in the body (main content)
386
420
  # @api public
387
- def body_length
388
- attr_dict.body_length
389
- end
421
+ delegate :body_length, to: :attr_dict
390
422
 
391
423
  # Override this method to provide an external url
392
424
  # where the content (the body) of this Obj can be downloaded.
@@ -422,11 +454,13 @@ module RailsConnector
422
454
  @attr_values ||= begin
423
455
  encoded_and_encrypted_attr_values = read_attribute(:attr_values)
424
456
  return {} unless encoded_and_encrypted_attr_values
457
+
425
458
  encrypted_attr_values = Base64.decode64(encoded_and_encrypted_attr_values)
426
- if !encrypted_attr_values.starts_with?('Salted__') || encrypted_attr_values.length < 16
427
- raise 'attr_values has wrong format'
459
+ if !encrypted_attr_values.starts_with?("Salted__") || encrypted_attr_values.length < 16
460
+ raise "attr_values has wrong format"
428
461
  end
429
- cipher = OpenSSL::Cipher.new('rc4')
462
+
463
+ cipher = OpenSSL::Cipher.new("rc4")
430
464
  cipher.decrypt
431
465
  salt = encrypted_attr_values[8..15]
432
466
  cipher.pkcs5_keyivgen(CRYPT_KEY, salt, 1)
@@ -462,40 +496,19 @@ module RailsConnector
462
496
  rslt
463
497
  end
464
498
 
465
- # @api public
466
- def last_changed
467
- self[:last_changed]
468
- end
469
-
470
- # @api public
471
- def valid_from
472
- self[:valid_from]
473
- end
474
-
475
- # @api public
476
- def valid_until
477
- self[:valid_until]
478
- end
479
-
480
- # deprecated, use file_extension instead
481
- def content_type
482
- logger.warn "DEPRECATION WARNING: Obj#content_type is deprecated, use file_extension instead"
483
- file_extension
484
- end
485
-
486
499
  # Returns the MIME-type as determined from the file_extension - see MIME::Types
487
500
  # @api public
488
501
  def mime_type
489
502
  @mime_type ||= compute_mime_type
490
503
  end
491
504
 
492
- def respond_to?(method_id, include_private=false)
505
+ def respond_to?(method_id, include_private = false)
493
506
  if super
494
507
  true
495
508
  elsif %w(_attr_dict _attr_defs _attr_values).include?(method_id.to_s)
496
509
  # prevent infinite recursion when calling "attr_*" below,
497
510
  # since rails checks the absence of an "_attr_*" method internally
498
- return false
511
+ false
499
512
  else
500
513
  attr_dict.respond_to?(method_id)
501
514
  end
@@ -503,44 +516,20 @@ module RailsConnector
503
516
 
504
517
  private
505
518
 
506
- def as_date(value)
507
- DateAttribute.parse(value) unless value.nil?
508
- end
509
-
510
- # Forwards any unknown method call to a corresponding instance
511
- # of AttrDict and thus provides access to object fields, i.e. content.
512
- #
513
- # In case of an invalid method call, an error is raised.
514
- #
515
- # Hint: Use [] instead to suppress error messages.
516
- def method_missing(method_id, *args)
517
- super
518
- rescue NoMethodError, NameError
519
- # prevent infinite recursion when calling "attr_*" below,
520
- # since rails checks the absence of an "_attr_*" method internally
521
- raise if %w(_attr_dict _attr_defs _attr_values).include?(method_id.to_s)
522
-
523
- if attr_dict.respond_to?(method_id)
524
- attr_dict.send method_id, *args
525
- else
526
- raise
527
- end
528
- end
529
-
530
519
  def fiona_fields
531
520
  @fiona_fields ||=
532
- ['name', 'obj_class', 'workflow', 'suppressexport', 'permalink'].inject({}) do |all,field|
521
+ %w(name obj_class workflow suppressexport permalink).inject({}) do |all, field|
533
522
  all.merge! field => {
534
- 'titles' => {'de' => field.humanize, 'en' => field.humanize},
535
- 'type' => 'string',
536
- 'help_texts' => {'de' => field, 'en' => field}
523
+ "titles" => { "de" => field.humanize, "en" => field.humanize },
524
+ "type" => "string",
525
+ "help_texts" => { "de" => field, "en" => field }
537
526
  }
538
527
  end
539
528
  end
540
529
 
541
530
  def compute_mime_type
542
531
  MIME::Types.type_for(file_extension).first.content_type
543
- rescue
532
+ rescue StandardError
544
533
  binary? ? "application/octet-stream" : "text/plain"
545
534
  end
546
535
 
@@ -557,7 +546,15 @@ module RailsConnector
557
546
  left_value <=> right_value
558
547
  else
559
548
  if my_sort_type == "numeric"
560
- (left_value.to_i rescue 0) <=> (right_value.to_i rescue 0)
549
+ (begin
550
+ left_value.to_i
551
+ rescue StandardError
552
+ 0
553
+ end) <=> (begin
554
+ right_value.to_i
555
+ rescue StandardError
556
+ 0
557
+ end)
561
558
  else
562
559
  left_value.to_s.downcase <=> right_value.to_s.downcase
563
560
  end
@@ -570,8 +567,5 @@ module RailsConnector
570
567
  rescue NameError, ActiveRecord::ActiveRecordError
571
568
  nil
572
569
  end
573
-
574
570
  end
575
-
576
571
  end
577
-