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 +5 -5
- data/app/controllers/rails_connector/default_cms_controller.rb +4 -4
- data/lib/infopark_fiona_connector.rb +5 -4
- data/lib/meta_eager_loader.rb +1 -0
- data/lib/rails_connector/attr_dict.rb +31 -16
- data/lib/rails_connector/attribute.rb +96 -0
- data/lib/rails_connector/basic_obj.rb +80 -93
- data/lib/rails_connector/blob.rb +3 -1
- data/lib/rails_connector/blob_mapping.rb +16 -0
- data/lib/rails_connector/channel.rb +19 -0
- data/lib/rails_connector/cms_accessible.rb +6 -8
- data/lib/rails_connector/cms_dispatch_controller.rb +6 -6
- data/lib/rails_connector/cms_test_request.rb +0 -15
- data/lib/rails_connector/configuration.rb +2 -0
- data/lib/rails_connector/content.rb +11 -0
- data/lib/rails_connector/date_attribute.rb +1 -1
- data/lib/rails_connector/engine.rb +8 -4
- data/lib/rails_connector/fiona_datetime.rb +14 -0
- data/lib/rails_connector/job.rb +13 -0
- data/lib/rails_connector/meta.rb +148 -0
- data/lib/rails_connector/meta/eager_loader.rb +82 -0
- data/lib/rails_connector/named_link.rb +15 -0
- data/lib/rails_connector/news.rb +7 -3
- data/lib/rails_connector/obj_class.rb +140 -0
- data/lib/rails_connector/obj_class_attr.rb +5 -0
- data/lib/rails_connector/object_with_meta_data.rb +18 -0
- data/lib/rails_connector/rack_middlewares.rb +1 -2
- data/lib/version.rb +1 -1
- metadata +31 -20
data/lib/rails_connector/blob.rb
CHANGED
@@ -11,7 +11,9 @@ module RailsConnector
|
|
11
11
|
select(:blob_name, :blob_length).find(primary_key)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
alias_method :find_without_excluded_blob_data, :find
|
15
|
+
alias_method :find, :find_with_excluded_blob_data
|
16
|
+
|
15
17
|
end
|
16
18
|
|
17
19
|
def length
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module RailsConnector
|
3
|
+
class BlobMapping < CmsBaseModel
|
4
|
+
def self.exists?
|
5
|
+
self.table_exists?
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.get_fingerprint(name)
|
9
|
+
find_by_blob_name(name).fingerprint
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get_fingerprint_map(blob_names)
|
13
|
+
Hash[self.where(:blob_name => blob_names).select([:blob_name, :fingerprint]).map {|b| [b.blob_name, b.fingerprint] }]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module RailsConnector
|
2
|
+
class Channel < CmsBaseModel
|
3
|
+
self.primary_key = "channel_name"
|
4
|
+
|
5
|
+
def self.table_name
|
6
|
+
"#{table_name_prefix}" "channels"
|
7
|
+
end
|
8
|
+
|
9
|
+
has_many :news, :class_name => 'RailsConnector::News', :foreign_key => 'channel_name'
|
10
|
+
has_many :active_news,
|
11
|
+
lambda { where(['valid_from <= :now AND valid_until >= :now', {:now => Time.now.to_s(:number)}]) },
|
12
|
+
:class_name => 'RailsConnector::News', :foreign_key => 'channel_name'
|
13
|
+
|
14
|
+
has_many :objects, :through => :news
|
15
|
+
|
16
|
+
scope :with_prefix, -> (prefix) {where(["channel_name LIKE ?", "#{prefix}%"])}
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -8,7 +8,7 @@ module RailsConnector
|
|
8
8
|
# Filter method to load a CMS object.
|
9
9
|
#
|
10
10
|
# To require the loading for all actions, use this in your controllers:
|
11
|
-
#
|
11
|
+
# before_action :load_object
|
12
12
|
def load_object
|
13
13
|
CmsEnv.new(request.env).load
|
14
14
|
loaded_obj = request.env[CmsEnv::OBJ_ENV_KEY]
|
@@ -20,15 +20,14 @@ module RailsConnector
|
|
20
20
|
# not, a 410 Gone error message will be generate (by calling render_obj_error).
|
21
21
|
#
|
22
22
|
# To require the check for all actions, use this in your controllers:
|
23
|
-
#
|
24
|
-
#
|
23
|
+
# before_action :load_object
|
24
|
+
# before_action :ensure_object_is_active
|
25
25
|
def ensure_object_is_active
|
26
26
|
unless @obj.active?
|
27
27
|
@valid_from = @obj.valid_from
|
28
28
|
@valid_until = @obj.valid_until
|
29
29
|
@obj = nil
|
30
30
|
render_obj_error(410, "gone")
|
31
|
-
return false
|
32
31
|
end
|
33
32
|
return true
|
34
33
|
end
|
@@ -37,13 +36,12 @@ module RailsConnector
|
|
37
36
|
# not, a 403 Forbidden error message will be generated (by calling render_obj_error)
|
38
37
|
#
|
39
38
|
# To require the check for all actions, use this in your controllers:
|
40
|
-
#
|
41
|
-
#
|
39
|
+
# before_action :load_object
|
40
|
+
# before_action :ensure_object_is_permitted
|
42
41
|
def ensure_object_is_permitted
|
43
42
|
unless is_permitted(@obj)
|
44
43
|
@obj = nil
|
45
44
|
render_obj_error(403, "forbidden")
|
46
|
-
return false
|
47
45
|
end
|
48
46
|
return true
|
49
47
|
end
|
@@ -59,7 +57,7 @@ module RailsConnector
|
|
59
57
|
:template => "errors/#{status}_#{name}",
|
60
58
|
:layout => false,
|
61
59
|
:status => status,
|
62
|
-
:content_type => Mime
|
60
|
+
:content_type => Mime[:html]
|
63
61
|
)
|
64
62
|
end
|
65
63
|
|
@@ -2,17 +2,17 @@ module RailsConnector
|
|
2
2
|
|
3
3
|
class CmsDispatchController < ActionController::Metal
|
4
4
|
def process(action)
|
5
|
-
CmsEnv.new(env).load
|
6
|
-
controller = target_controller(env)
|
7
|
-
env["action_dispatch.request.path_parameters"][:controller] = controller.controller_path
|
5
|
+
CmsEnv.new(request.env).load
|
6
|
+
controller = target_controller(request.env)
|
7
|
+
request.env["action_dispatch.request.path_parameters"][:controller] = controller.controller_path
|
8
8
|
|
9
9
|
if !obj_not_found? && action == 'index'
|
10
10
|
action = loaded_obj.controller_action_name
|
11
11
|
end
|
12
12
|
|
13
|
-
env["action_dispatch.request.path_parameters"][:action] = action
|
13
|
+
request.env["action_dispatch.request.path_parameters"][:action] = action
|
14
14
|
|
15
|
-
self.response = controller.action(action).call(env)
|
15
|
+
self.response = controller.action(action).call(request.env)
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
@@ -31,7 +31,7 @@ module RailsConnector
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def loaded_obj
|
34
|
-
env[CmsEnv::OBJ_ENV_KEY]
|
34
|
+
request.env[CmsEnv::OBJ_ENV_KEY]
|
35
35
|
end
|
36
36
|
|
37
37
|
def obj_not_found?
|
@@ -3,21 +3,6 @@ module RailsConnector
|
|
3
3
|
def for_cms_object(test_obj=nil)
|
4
4
|
# prepare the env as if the given obj was loaded by CmsEnv
|
5
5
|
env[RailsConnector::CmsEnv::OBJ_ENV_KEY] = test_obj if test_obj
|
6
|
-
class << self
|
7
|
-
# This special behaviour is necessary for testing controllers that descend from DefaultCmsController.
|
8
|
-
# These controllers do not have explicit routes by default.
|
9
|
-
# Instead, they are reached via the CmsDispatchController.
|
10
|
-
# The TestRequest must therefore use CmsDispatchController as a fallback route.
|
11
|
-
def assign_parameters(routes, controller_path, action, parameters = {})
|
12
|
-
super(routes, controller_path, action, parameters)
|
13
|
-
rescue ActionController::UrlGenerationError, ActionController::RoutingError, AbstractController::ActionNotFound => e
|
14
|
-
begin
|
15
|
-
super(routes, "rails_connector/cms_dispatch", action, parameters)
|
16
|
-
rescue ActionController::RoutingError, AbstractController::ActionNotFound
|
17
|
-
raise e
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
6
|
end
|
22
7
|
end
|
23
8
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'rails'
|
2
|
+
require 'active_record/railtie'
|
3
|
+
require 'action_view'
|
4
4
|
|
5
5
|
require 'jquery-rails'
|
6
6
|
|
@@ -14,6 +14,10 @@ module ::RailsConnector
|
|
14
14
|
# make sure our exceptions cause an adequate error page and http status code
|
15
15
|
config.action_dispatch.rescue_responses.merge!("RailsConnector::ResourceNotFound" => :not_found)
|
16
16
|
|
17
|
+
initializer 'rails_connector.add_fiona_time_type' do
|
18
|
+
ActiveRecord::Type.register(:fiona_datetime, ::FionaDateTime)
|
19
|
+
end
|
20
|
+
|
17
21
|
initializer "rails_connector.add_cms_routing_paths", :after => :add_routing_paths do |app|
|
18
22
|
cms_route = File.expand_path("cms_routes.rb", paths['config'].to_a.first)
|
19
23
|
app.routes_reloader.paths.push(cms_route)
|
@@ -55,10 +59,10 @@ module ::RailsConnector
|
|
55
59
|
ActionView::Base.__send__(:include, CmsRoutingHelper)
|
56
60
|
end
|
57
61
|
|
62
|
+
|
58
63
|
config.autoload_paths += paths['lib'].to_a
|
59
64
|
config.autoload_once_paths += paths['lib'].to_a
|
60
65
|
|
61
66
|
RailsConnector.rack_middlewares.each { |middleware| config.app_middleware.use middleware }
|
62
67
|
end
|
63
68
|
end
|
64
|
-
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'active_record/type'
|
2
|
+
class FionaDateTime < ActiveRecord::Type::Time
|
3
|
+
def type
|
4
|
+
:fiona_datetime
|
5
|
+
end
|
6
|
+
|
7
|
+
def serialize(value)
|
8
|
+
value.to_iso if value
|
9
|
+
end
|
10
|
+
|
11
|
+
def deserialize(value)
|
12
|
+
Time.from_iso(value).in_time_zone if value
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
module RailsConnector
|
2
|
+
|
3
|
+
module Meta
|
4
|
+
|
5
|
+
# This method is an equivalent of Rails.logger.silence, which has been deprecated
|
6
|
+
def self.hello_im_rails_and_im_retarted_so_please_be_patient(&block)
|
7
|
+
begin
|
8
|
+
old_logger_level, Rails.logger.level = Rails.logger.level, Logger::ERROR
|
9
|
+
yield self
|
10
|
+
ensure
|
11
|
+
Rails.logger.level = old_logger_level
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.included(base) #:nodoc:
|
16
|
+
# Class enhancements
|
17
|
+
base.extend(ClassMethods)
|
18
|
+
end
|
19
|
+
|
20
|
+
# The RailsConnector::ObjClass object for this file format.
|
21
|
+
# This will always return a proper object, even if no custom
|
22
|
+
# Ruby class exists.
|
23
|
+
def obj_class_definition
|
24
|
+
@obj_class_definition ||= RailsConnector::Meta::EagerLoader.instance.obj_class(self.obj_class)
|
25
|
+
end
|
26
|
+
alias_method :obj_class_def, :obj_class_definition
|
27
|
+
|
28
|
+
# Returns true, if there is a custom Ruby class defined for the object
|
29
|
+
# or false, if it is represented by RailsConnector::Obj
|
30
|
+
def has_custom_ruby_class?
|
31
|
+
self.class.is_custom_ruby_class?
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns the custom attributes in the form of a Hash.
|
35
|
+
def custom_attributes
|
36
|
+
self.obj_class_definition.custom_attributes
|
37
|
+
end
|
38
|
+
|
39
|
+
# Returns true, if the file format has an attribute of the given name.
|
40
|
+
def custom_attribute?(attr)
|
41
|
+
self.obj_class_definition.custom_attribute?(attr)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns an Array of String of all mandatory attributes, no mather if it's
|
45
|
+
# custom or built-in. Built-in attributes are underscored (valid_from,
|
46
|
+
# not validFrom).
|
47
|
+
# Possible +options+ are:
|
48
|
+
# <tt>:only_custom_attributes</tt>:: Return only custom attributes, omit
|
49
|
+
# built-in attributes like content_type or valid_from.
|
50
|
+
def mandatory_attribute_names(options = {})
|
51
|
+
self.obj_class_definition.mandatory_attribute_names(options)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns true, if the file format has an mandatory attribute of the given name.
|
55
|
+
def mandatory_attribute?(attr)
|
56
|
+
self.obj_class_definition.mandatory_attribute?(attr)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns the version of this object. This number is increased every time
|
60
|
+
# this object is released.
|
61
|
+
def version
|
62
|
+
load_meta_details
|
63
|
+
@object_with_meta_data.version.presence.to_i || 0
|
64
|
+
end
|
65
|
+
|
66
|
+
# Returns the time of the reminder, if it is set.
|
67
|
+
def reminder_from
|
68
|
+
load_meta_details
|
69
|
+
@object_with_meta_data.reminder_from.presence &&
|
70
|
+
::ActiveModel::Type::DateTime.new.deserialize(@object_with_meta_data.reminder_from)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns the reminder comment, if a reminder is set.
|
74
|
+
def reminder_comment
|
75
|
+
load_meta_details
|
76
|
+
@object_with_meta_data.reminder_comment
|
77
|
+
end
|
78
|
+
|
79
|
+
# Return the name of the workflow, that is assigned to this object.
|
80
|
+
def workflow_name
|
81
|
+
load_meta_details
|
82
|
+
@object_with_meta_data.workflow_name
|
83
|
+
end
|
84
|
+
|
85
|
+
# Return the current editor as a String. If there is no edited content,
|
86
|
+
# which is always the case in live mode, an empty String is returned.
|
87
|
+
# The 'contents' table is queried for this information.
|
88
|
+
def editor
|
89
|
+
return @editor if @editor
|
90
|
+
|
91
|
+
load_meta_details
|
92
|
+
|
93
|
+
content_id = if self.edited?
|
94
|
+
@object_with_meta_data.edited_content_id
|
95
|
+
else
|
96
|
+
@object_with_meta_data.released_cont_id
|
97
|
+
end
|
98
|
+
|
99
|
+
if content_id
|
100
|
+
content = RailsConnector::Content.find(content_id)
|
101
|
+
@editor = content.editor
|
102
|
+
else
|
103
|
+
@editor = ''
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def committed?
|
108
|
+
load_meta_details
|
109
|
+
!@object_with_meta_data.committed_cont_id.nil?
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
# Load the objects details from the `objects' tables.
|
115
|
+
def load_meta_details #:nodoc:
|
116
|
+
return if @object_with_meta_data
|
117
|
+
|
118
|
+
@object_with_meta_data = RailsConnector::ObjectWithMetaData.find(self.id)
|
119
|
+
|
120
|
+
# reset depending instance variables
|
121
|
+
@editor = nil
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
# the methods in this module will become class methods
|
126
|
+
module ClassMethods
|
127
|
+
|
128
|
+
# The RailsConnector::ObjClass object for this file format.
|
129
|
+
# This will only return a proper object if a custom Ruby class exists
|
130
|
+
# and will throw a RuntimeError otherwise.
|
131
|
+
def obj_class_definition
|
132
|
+
raise "Obtaining the obj_class_definition of an Obj without custom Ruby class " \
|
133
|
+
"is logically impossible." unless is_custom_ruby_class?
|
134
|
+
@obj_class_definition ||= RailsConnector::Meta::EagerLoader.instance.obj_class(self.name)
|
135
|
+
end
|
136
|
+
alias_method :obj_class_def, :obj_class_definition
|
137
|
+
|
138
|
+
# RailsConnector::AbstractObj returns false, everything else true.
|
139
|
+
# TODO: RailsConnector::AbstractObj does not exist here
|
140
|
+
def is_custom_ruby_class?
|
141
|
+
self != RailsConnector::BasicObj
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'singleton'
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
module RailsConnector
|
6
|
+
module Meta
|
7
|
+
class EagerLoader
|
8
|
+
include Singleton
|
9
|
+
attr_reader :obj_classes
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
# Rails.logger.debug "EagerLoader: I am eager to start working"
|
13
|
+
@obj_classes = {}
|
14
|
+
RailsConnector::ObjClass.includes(:custom_attributes_raw).all.each do |obj_class|
|
15
|
+
@obj_classes[obj_class.name] = obj_class if obj_class
|
16
|
+
end
|
17
|
+
preload_attribute_blobs
|
18
|
+
end
|
19
|
+
|
20
|
+
def obj_class(name)
|
21
|
+
name = name.to_s
|
22
|
+
if !@obj_classes.fetch(name, nil).nil?
|
23
|
+
@obj_classes[name]
|
24
|
+
else
|
25
|
+
# TODO: preload_attribute_blobs for obj_class
|
26
|
+
@obj_classes[name] ||= RailsConnector::ObjClass.find_by_obj_class_name(name)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def forget_obj_class(name)
|
31
|
+
@obj_classes.delete(name.to_s)
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
def preload_attribute_blobs
|
36
|
+
attribute_names = Set.new
|
37
|
+
@obj_classes.each do |_, obj_class|
|
38
|
+
obj_class.custom_attributes.each do |attribute_name, _|
|
39
|
+
attribute_names << attribute_name
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
blob_names = attribute_names.map {|attribute_name| "#{attribute_name}.jsonAttributeDict" }
|
44
|
+
# Fiona >= 6.8
|
45
|
+
if RailsConnector::BlobMapping.exists?
|
46
|
+
blob_names = attribute_names.map {|attribute_name| "#{attribute_name}.jsonAttributeDict" }
|
47
|
+
fingerprint_map = RailsConnector::BlobMapping.get_fingerprint_map(blob_names)
|
48
|
+
blob_fingerprints = fingerprint_map.values
|
49
|
+
# NOTE: this is correct!
|
50
|
+
blobs = RailsConnector::Blob.where(:blob_name => blob_fingerprints).to_a
|
51
|
+
blob_map = Hash[blobs.map {|b| [b.blob_name, b]}]
|
52
|
+
|
53
|
+
@obj_classes.each do |_, obj_class|
|
54
|
+
obj_class.custom_attributes.each do |_, attribute|
|
55
|
+
blob_name = "#{attribute.name}.jsonAttributeDict"
|
56
|
+
fingerprint = fingerprint_map[blob_name]
|
57
|
+
blob = blob_map[fingerprint]
|
58
|
+
|
59
|
+
next unless blob && blob.blob_data?
|
60
|
+
attribute.instance_variable_set(:@blob_data, ::JSON.parse(blob.blob_data))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
# Fiona = 6.7
|
64
|
+
else
|
65
|
+
blob_names = attribute_names.map {|attribute_name| "#{attribute_name}.jsonAttributeDict" }
|
66
|
+
blobs = RailsConnector::Blob.where(:blob_name => blob_names).to_a
|
67
|
+
blob_map = Hash[blobs.map {|b| [b.blob_name, b]}]
|
68
|
+
|
69
|
+
@obj_classes.each do |_, obj_class|
|
70
|
+
obj_class.custom_attributes.each do |_, attribute|
|
71
|
+
blob_name = "#{attribute.name}.jsonAttributeDict"
|
72
|
+
blob = blob_map[blob_name]
|
73
|
+
|
74
|
+
next unless blob && blob.blob_data?
|
75
|
+
attribute.instance_variable_set(:@blob_data, ::JSON.parse(blob.blob_data))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|