infopark_fiona_connector 7.0.1 → 7.0.1.5.2.3.rc4

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
- SHA1:
3
- metadata.gz: f4b2e0a718e2f67d4a2092754a69789925df1aac
4
- data.tar.gz: 025f28744570d96a908356714bd2dddd94e2fe35
2
+ SHA256:
3
+ metadata.gz: 3016968e6569e5825fbaf32c6dfebc557246474586a6912e594257661241dd1c
4
+ data.tar.gz: 2da35bdfdbba9df92e6b7f5d40684540c0ee7c197c40b0e222f90fe332a1fbbf
5
5
  SHA512:
6
- metadata.gz: bc4deff1c8bc5c50d1c7df11659aee44c7a2a5ea77c7b3abd094971ed10ab38116da33c6c3308f9352fc52bdc24ee63e4bdf8d066bf0885ad3d5baa1f07473fd
7
- data.tar.gz: 25d4c796dd127a0a45a740a232bede4d40e1d8a0a26d0fae2289cd6895253736b7097571ed62333c9edbbb0e4899052fac1d7a1305521d26173c92e16a0435d6
6
+ metadata.gz: ed81faf6eb5b8093042ce75b6c69b3d7c33cba47d2bb5bf66f90441be4f1ee109b5a6d0c91d7e7538bafde5611fbd8fa301ae917117b7cdb68e601e087adef2c
7
+ data.tar.gz: 65a581c015442b5e8639c84dabd2903e74bfbf59f4165cafec1732acb8bbd0aafe65193bebec5433e62c5241d47657c8eaf97d3ccd193661e5959d82021d4459
@@ -7,10 +7,10 @@ module RailsConnector
7
7
  # @api public
8
8
  class DefaultCmsController < ApplicationController
9
9
  include CmsAccessible
10
- before_filter :load_object
11
- before_filter :ensure_object_is_active
12
- before_filter :ensure_object_is_permitted
13
- before_filter :set_google_expire_header
10
+ before_action :load_object
11
+ before_action :ensure_object_is_active
12
+ before_action :ensure_object_is_permitted
13
+ before_action :set_google_expire_header
14
14
 
15
15
  # Default Action. Delivers files directly if their mime type is not text/html
16
16
  # @api public
@@ -20,8 +20,9 @@ end
20
20
 
21
21
  require 'rails_connector/core_extensions'
22
22
  require 'rails_connector/rack_middlewares'
23
- require 'rails_connector/core_extensions'
24
- require "rails_connector/errors"
23
+ require 'rails_connector/errors'
24
+ require 'rails_connector/fiona_datetime'
25
+ ActiveRecord::Type.register(:fiona_datetime, ::FionaDateTime)
25
26
 
26
27
  # @api public
27
28
  module RailsConnector
@@ -39,5 +40,5 @@ module RailsConnector
39
40
  autoload_all_sources
40
41
  end
41
42
 
42
- require "rails_connector/engine" if defined?(Rails)
43
- require "rails_connector/fiona_engine" if defined?(Rails)
43
+ require 'rails_connector/engine' if defined?(Rails)
44
+ require 'rails_connector/fiona_engine' if defined?(Rails)
@@ -0,0 +1 @@
1
+ require "rails_connector/meta/eager_loader"
@@ -9,7 +9,6 @@ module RailsConnector
9
9
  #
10
10
  # Any custom Attribute can be accessed directly or via [].
11
11
  class AttrDict
12
- include DateAttribute
13
12
 
14
13
  def initialize(object, keys_and_values = {}, defs = {})
15
14
  @object = object
@@ -29,7 +28,7 @@ module RailsConnector
29
28
  end
30
29
 
31
30
  def sort_keys
32
- [sort_key1, sort_key2, sort_key3]
31
+ [sort_key1, sort_key2, sort_key3].compact
33
32
  end
34
33
 
35
34
  # The body attribute may contain binary data for Obj.binary? or be an HtmlString.
@@ -78,17 +77,9 @@ module RailsConnector
78
77
 
79
78
  private
80
79
 
81
- def object
82
- @object
83
- end
84
-
85
- def blob_dict
86
- @blob_dict
87
- end
80
+ attr_reader :object, :blob_dict, :attr_defs
88
81
 
89
- def attr_defs
90
- @attr_defs
91
- end
82
+ delegate :obj_class_def, to: :object, allow_nil: true
92
83
 
93
84
  def textual_body
94
85
  return nil if object.binary?
@@ -118,25 +109,49 @@ module RailsConnector
118
109
  when :markdown
119
110
  StringTagging.tag_as_markdown(raw, self)
120
111
  when :html
121
- StringTagging.tag_as_html(raw, self)
112
+ StringTagging.tag_as_html(raw.to_s, self)
113
+ when :string, :text
114
+ raw.to_s
122
115
  when :date
123
- DateAttribute.parse raw if raw
116
+ DateAttribute.parse(raw) if raw
124
117
  when :linklist
125
118
  LinkList.new(raw)
119
+ when :multienum
120
+ raw || []
126
121
  else
127
122
  raw
128
123
  end
129
124
  end
130
125
 
126
+ # this attributes are defined by cms
127
+ # but if not set, are not existend in attr_defs
128
+ def predefined_attribute?(key)
129
+ [:channels, :sort_key1, :sort_key2, :sort_key3].include?(key.to_sym)
130
+ end
131
+
131
132
  def has_attribute(key)
132
133
  key = key.to_sym
133
- !(blob_dict[key] || attr_defs[key]).nil?
134
+ return true if predefined_attribute?(key)
135
+ blob_dict.key?(key) || attr_defs.key?(key) || class_defined_attributes.key?(key)
134
136
  end
135
137
 
136
138
  def type_of(key)
137
139
  key = key.to_sym
138
140
  return :linklist if key == :text_links
139
- attr_defs[key]['type'].to_sym rescue nil
141
+ return :multienum if key == :channels
142
+ type_from_attr_defs(key) || type_from_class_defined_attributes(key)
143
+ end
144
+
145
+ def type_from_attr_defs(key)
146
+ attr_defs[key]['type'].to_sym rescue nil
147
+ end
148
+
149
+ def type_from_class_defined_attributes(key)
150
+ class_defined_attributes[key].type.to_sym rescue nil
151
+ end
152
+
153
+ def class_defined_attributes
154
+ obj_class_def.try(:custom_attributes) || {}
140
155
  end
141
156
  end
142
157
 
@@ -0,0 +1,96 @@
1
+ module RailsConnector
2
+
3
+ # The methods date?, enum?, html?, linklist?, markdown?, multienum?, string? and
4
+ # text? are created by meta programming have no documentation of their own.
5
+ # Warning: Dependent on the setup of your DB replication, most tables
6
+ # with meta information will not be available on your live system!
7
+ class Attribute < CmsBaseModel
8
+
9
+ # The possible types of an attribute.
10
+ TYPES = %w{date enum html linklist markdown multienum string text}
11
+
12
+ self.primary_key = :attribute_id
13
+
14
+ has_and_belongs_to_many :obj_class_definitions, :class_name => '::RailsConnector::ObjClass',
15
+ :join_table => "#{table_name_prefix}obj_class_attrs"
16
+
17
+ alias_method :obj_class_defs, :obj_class_definitions
18
+ alias_attribute :name, :attribute_name
19
+ alias_attribute :type, :attribute_type
20
+
21
+ # The (human readable) title.
22
+ def title(language = :de)
23
+ blob_data['titles'].presence && blob_data['titles'][language.to_s]
24
+ end
25
+
26
+ # The description of the attribute.
27
+ def help_text(language = :de)
28
+ blob_data['helpTexts'].presence && blob_data['helpTexts'][language.to_s]
29
+ end
30
+
31
+ # Searchable in Content Manager.
32
+ def searchable_in_cm?
33
+ blob_data['isSearchableInCM'].to_i != 0
34
+ end
35
+
36
+ # Returns the possible values if attribute is of type `enum' or `multienum'.
37
+ def values
38
+ blob_data['values']
39
+ end
40
+
41
+ def max_size
42
+ blob_data["maxSize"]
43
+ end
44
+
45
+ def min_size
46
+ blob_data["minSize"]
47
+ end
48
+
49
+ def edit_field
50
+ blob_data["editField"]
51
+ end
52
+
53
+ def callback
54
+ blob_data["callback"]
55
+ end
56
+
57
+ TYPES.each do |type|
58
+ self.class_eval <<EOM, __FILE__, __LINE__ + 1
59
+ def #{type}?
60
+ self.attribute_type == "#{type}"
61
+ end
62
+ EOM
63
+ end
64
+
65
+ # Convenience method for find_by_attribute_name
66
+ def self.find_by_name(*args)
67
+ self.find_by_attribute_name(*args)
68
+ end
69
+
70
+ # Returns the blob as a JSON object.
71
+ def self.read_blob_data(name) #:nodoc:
72
+ blob = RailsConnector::Meta.hello_im_rails_and_im_retarted_so_please_be_patient do # these queries really pollute our logs!
73
+ blob_name = if RailsConnector::BlobMapping.exists?
74
+ RailsConnector::BlobMapping.get_fingerprint("#{name}.jsonAttributeDict")
75
+ else
76
+ "#{name}.jsonAttributeDict"
77
+ end
78
+
79
+ RailsConnector::Blob.find_without_excluded_blob_data(blob_name)
80
+ end
81
+
82
+ return {} unless blob && blob.blob_data?
83
+
84
+ JSON.parse(blob.blob_data)
85
+ end
86
+
87
+ private
88
+
89
+ # load attribute details from blob
90
+ def blob_data #:nodoc:
91
+ @blob_data ||= self.class.read_blob_data(self.attribute_name)
92
+ end
93
+
94
+ end
95
+
96
+ end
@@ -1,5 +1,6 @@
1
1
  require "json"
2
2
  require 'openssl'
3
+ require 'rails_connector/fiona_datetime'
3
4
 
4
5
  module RailsConnector
5
6
 
@@ -9,14 +10,23 @@ module RailsConnector
9
10
  # [parent] the Obj of which this one is a child - nil for the root object
10
11
  # @api public
11
12
  class BasicObj < CmsBaseModel
13
+ include RailsConnector::Meta
14
+
12
15
  CRYPT_KEY = "\xd7\x28\x9c\x63\xd6\x29\xdf\x20\xcd\x32\xcf\x30\xcf\x30\xcf\x30\xdf\x20\xb6\x49"\
13
16
  "\x91\x6e\x99\x66\x90\x6f\x8f\x70\x9e\x61\x8d\x72\x94\x6b\xdf\x20\xbe\x41\xb8\x47\xc4\x3b"\
14
17
  "\xdf\x20\xbd\x42\x9a\x65\x8d\x72\x93\x6c\x96\x69\x91\x6e".freeze
15
18
 
16
- include DateAttribute
19
+ PREDEFINED_ATTRIBUTES = %w(blob body title channels sort_key1 sort_type1 sort_key2 sort_type2
20
+ sort_key3 sort_type3 sort_order).freeze
21
+
17
22
 
18
23
  self.store_full_sti_class = false
19
24
 
25
+ def self.inherited(subclass)
26
+ super
27
+ subclass.delegate_attributes
28
+ end
29
+
20
30
  def self.configure_for_content(which)
21
31
  case which
22
32
  when :released then configure_column_information("objs", true)
@@ -36,10 +46,59 @@ module RailsConnector
36
46
  self.inheritance_column = "obj_class"
37
47
 
38
48
  @@use_cached_permissions = use_cached_permissions
49
+ descendants.each do |klass|
50
+ klass.reset_table_name
51
+ klass.initialize_attributes
52
+ end
53
+
54
+ RailsConnector::Meta::EagerLoader.instance.obj_classes.each do |class_name, obj_class|
55
+ next unless obj_class
56
+
57
+ if class_name =~ /^[A-Z]/
58
+ klass = class_name.safe_constantize
59
+ next unless klass
60
+ if klass < RailsConnector::BasicObj
61
+ klass.initialize_attributes
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ def self.initialize_attributes
68
+ PREDEFINED_ATTRIBUTES.each do |attribute|
69
+ self.send(:define_attribute, attribute, ActiveRecord::Type::String.new)
70
+ end
71
+
72
+ return if obj_class_definition.blank?
73
+
74
+ obj_class_definition.custom_attributes.each_key do |attribute|
75
+ self.send(:define_attribute, attribute, ActiveRecord::Type::String.new)
76
+ end
77
+ end
78
+
79
+ def self.delegate_attributes
80
+ PREDEFINED_ATTRIBUTES.each do |attribute|
81
+ delegate attribute, to: :attr_dict
82
+ end
83
+
84
+ return if obj_class_definition.blank?
85
+
86
+ obj_class_definition.custom_attributes.each_key do |attribute|
87
+ delegate attribute, to: :attr_dict
88
+ end
39
89
  end
40
90
 
41
- # use released contents as a default
42
- configure_for_content(:released)
91
+ attribute :last_changed, :fiona_datetime
92
+ attribute :valid_from, :fiona_datetime
93
+ attribute :valid_until, :fiona_datetime
94
+ attribute :suppress_export, :boolean
95
+ attribute :is_edited, :boolean
96
+ attribute :is_released, :boolean
97
+
98
+ delegate :sort_keys, to: :attr_dict
99
+ delegate :body_data_path, to: :attr_dict
100
+ delegate :empty?, to: :attr_dict
101
+ delegate :text_links, to: :attr_dict
43
102
 
44
103
  # Patch to avoid a type_condition being added by ActiveRecord::Base.add_conditions! for Obj.find(params):
45
104
  def self.descends_from_active_record?
@@ -65,6 +124,11 @@ module RailsConnector
65
124
  # We don't cache types at all here.
66
125
  end
67
126
 
127
+ def self.reset_reflections
128
+ has_many :children, :class_name => 'Obj', :foreign_key => 'parent_obj_id'
129
+ belongs_to :parent, :class_name => 'Obj', :foreign_key => 'parent_obj_id'
130
+ end
131
+
68
132
  # @api public
69
133
  def permissions
70
134
  @@use_cached_permissions ? attr_dict.permissions : arel_permissions
@@ -101,12 +165,6 @@ module RailsConnector
101
165
  @@homepage_id = nil
102
166
  end
103
167
 
104
- # returns the obj's permalink.
105
- # @api public
106
- def permalink
107
- self[:permalink]
108
- end
109
-
110
168
  # This method determines the controller that should be invoked when the Obj is requested.
111
169
  # By default a controller matching the Obj's obj_class will be used.
112
170
  # If the controller does not exist, the CmsController will be used as a fallback.
@@ -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?
@@ -253,9 +311,7 @@ module RailsConnector
253
311
  def root?
254
312
  parent_obj_id.nil?
255
313
  end
256
-
257
- has_many :children, :class_name => 'Obj', :foreign_key => 'parent_obj_id'
258
- belongs_to :parent, :class_name => 'Obj', :foreign_key => 'parent_obj_id'
314
+ #
259
315
 
260
316
  # Returns a list of exportable? children excluding the binary? ones unless :all is specfied.
261
317
  # This is mainly used for navigations.
@@ -300,18 +356,6 @@ module RailsConnector
300
356
  return self.sort_order == "descending" ? sorted_list.reverse : sorted_list
301
357
  end
302
358
 
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]
313
- end
314
-
315
359
  # Returns an Array of all the ancestor objects, starting at the root and ending at this object's parent.
316
360
  # @api public
317
361
  def ancestors
@@ -336,26 +380,17 @@ module RailsConnector
336
380
  # Passing an invalid key will not raise an error, but return nil.
337
381
  # @api public
338
382
  def [](key)
339
- # convenience access to name
340
- return name if key.to_sym == :name
383
+ if has_attribute?(key)
384
+ begin
385
+ if attr_dict.respond_to?(key)
386
+ return attr_dict.send(key)
387
+ end
341
388
 
342
- # regular activerecord attributes
343
- if @attributes.key?(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)
389
+ read_attribute(key)
390
+ rescue NoMethodError
391
+ nil
348
392
  end
349
393
  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
394
  end
360
395
 
361
396
  # Reloads the attributes of this object from the database, invalidates custom attributes
@@ -384,9 +419,7 @@ module RailsConnector
384
419
  # for binary Objs body_length equals the file size
385
420
  # for non-binary Objs body_length equals the number of characters in the body (main content)
386
421
  # @api public
387
- def body_length
388
- attr_dict.body_length
389
- end
422
+ delegate :body_length, to: :attr_dict
390
423
 
391
424
  # Override this method to provide an external url
392
425
  # where the content (the body) of this Obj can be downloaded.
@@ -462,27 +495,6 @@ module RailsConnector
462
495
  rslt
463
496
  end
464
497
 
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
498
  # Returns the MIME-type as determined from the file_extension - see MIME::Types
487
499
  # @api public
488
500
  def mime_type
@@ -503,30 +515,6 @@ module RailsConnector
503
515
 
504
516
  private
505
517
 
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
518
  def fiona_fields
531
519
  @fiona_fields ||=
532
520
  ['name', 'obj_class', 'workflow', 'suppressexport', 'permalink'].inject({}) do |all,field|
@@ -574,4 +562,3 @@ module RailsConnector
574
562
  end
575
563
 
576
564
  end
577
-