infopark_fiona_connector 7.0.1.5.2.3.rc7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +5 -0
  3. data/app/assets/images/admin/minus.gif +0 -0
  4. data/app/assets/images/bg80.png +0 -0
  5. data/app/assets/images/edit.png +0 -0
  6. data/app/assets/images/icons/mm_generic.png +0 -0
  7. data/app/assets/images/icons/mm_menu.png +0 -0
  8. data/app/assets/javascripts/editmarker.js +240 -0
  9. data/app/assets/javascripts/infopark_rails_connector.js.erb +0 -0
  10. data/app/assets/stylesheets/editmarker.css +70 -0
  11. data/app/assets/stylesheets/infopark_rails_connector.css.erb +0 -0
  12. data/app/controllers/cms_controller.rb +7 -0
  13. data/app/controllers/rails_connector/default_cms_controller.rb +41 -0
  14. data/app/helpers/cms_helper.rb +7 -0
  15. data/app/helpers/cms_routing_helper.rb +7 -0
  16. data/app/helpers/rails_connector/cms_asset_helper.rb +54 -0
  17. data/app/helpers/rails_connector/cms_tag_helper.rb +4 -0
  18. data/app/helpers/rails_connector/default_cms_helper.rb +21 -0
  19. data/app/helpers/rails_connector/default_cms_routing_helper.rb +119 -0
  20. data/app/helpers/rails_connector/display_helper.rb +124 -0
  21. data/app/helpers/rails_connector/editing_helper.rb +7 -0
  22. data/app/helpers/rails_connector/layout_helper.rb +26 -0
  23. data/app/helpers/rails_connector/marker_helper.rb +371 -0
  24. data/app/helpers/rails_connector/table_of_contents_helper.rb +20 -0
  25. data/app/models/named_link.rb +2 -0
  26. data/app/views/cms/_index.html.erb +7 -0
  27. data/app/views/cms/index.html.erb +1 -0
  28. data/app/views/errors/403_forbidden.html.erb +3 -0
  29. data/app/views/errors/410_gone.html.erb +7 -0
  30. data/config/cms_routes.rb +17 -0
  31. data/config/locales/de.rails_connector.errors.yml +11 -0
  32. data/config/locales/de.rails_connector.lib.yml +6 -0
  33. data/config/locales/de.rails_connector.views.yml +9 -0
  34. data/config/locales/en.rails_connector.errors.yml +10 -0
  35. data/config/locales/en.rails_connector.lib.yml +6 -0
  36. data/config/locales/en.rails_connector.views.yml +9 -0
  37. data/lib/gem_dependencies.rb +68 -0
  38. data/lib/generators/rails_connector/install/install_generator.rb +37 -0
  39. data/lib/generators/rails_connector/install/templates/app/models/obj.rb.erb +5 -0
  40. data/lib/generators/rails_connector/install/templates/initializers/rails_connector.rb +2 -0
  41. data/lib/generators/rails_connector/install/templates/local/configuration.rb +2 -0
  42. data/lib/infopark_fiona_connector.rb +44 -0
  43. data/lib/meta_eager_loader.rb +1 -0
  44. data/lib/obj.rb +3 -0
  45. data/lib/rails_connector/attr_dict.rb +169 -0
  46. data/lib/rails_connector/attr_value_provider.bundle +0 -0
  47. data/lib/rails_connector/attr_value_provider.so +0 -0
  48. data/lib/rails_connector/attr_value_provider64.so +0 -0
  49. data/lib/rails_connector/attribute.rb +93 -0
  50. data/lib/rails_connector/authenticable.rb +37 -0
  51. data/lib/rails_connector/basic_obj.rb +571 -0
  52. data/lib/rails_connector/blob.rb +75 -0
  53. data/lib/rails_connector/blob_mapping.rb +15 -0
  54. data/lib/rails_connector/blob_mysql.rb +30 -0
  55. data/lib/rails_connector/blob_oracle.rb +37 -0
  56. data/lib/rails_connector/cache_middleware.rb +13 -0
  57. data/lib/rails_connector/channel.rb +18 -0
  58. data/lib/rails_connector/cms_accessible.rb +111 -0
  59. data/lib/rails_connector/cms_base_model.rb +62 -0
  60. data/lib/rails_connector/cms_dispatch_controller.rb +43 -0
  61. data/lib/rails_connector/cms_env.rb +65 -0
  62. data/lib/rails_connector/cms_test_request.rb +8 -0
  63. data/lib/rails_connector/configuration.rb +174 -0
  64. data/lib/rails_connector/content.rb +7 -0
  65. data/lib/rails_connector/core_extensions.rb +1 -0
  66. data/lib/rails_connector/core_extensions/time.rb +17 -0
  67. data/lib/rails_connector/date_attribute.rb +26 -0
  68. data/lib/rails_connector/default_search_request.rb +6 -0
  69. data/lib/rails_connector/engine.rb +65 -0
  70. data/lib/rails_connector/errors.rb +6 -0
  71. data/lib/rails_connector/fiona_datetime.rb +14 -0
  72. data/lib/rails_connector/fiona_engine.rb +8 -0
  73. data/lib/rails_connector/html_string.rb +17 -0
  74. data/lib/rails_connector/job.rb +10 -0
  75. data/lib/rails_connector/link.rb +148 -0
  76. data/lib/rails_connector/link_list.rb +28 -0
  77. data/lib/rails_connector/link_resolvable.rb +5 -0
  78. data/lib/rails_connector/lucene_search_request.rb +102 -0
  79. data/lib/rails_connector/markdown_string.rb +17 -0
  80. data/lib/rails_connector/meta.rb +143 -0
  81. data/lib/rails_connector/meta/eager_loader.rb +84 -0
  82. data/lib/rails_connector/named_link.rb +90 -0
  83. data/lib/rails_connector/news.rb +20 -0
  84. data/lib/rails_connector/obj_class.rb +138 -0
  85. data/lib/rails_connector/obj_class_attr.rb +5 -0
  86. data/lib/rails_connector/object_with_meta_data.rb +13 -0
  87. data/lib/rails_connector/permission.rb +37 -0
  88. data/lib/rails_connector/rack_middlewares.rb +5 -0
  89. data/lib/rails_connector/ses.rb +78 -0
  90. data/lib/rails_connector/ses/verity_accessor.rb +127 -0
  91. data/lib/rails_connector/string_tagging.rb +26 -0
  92. data/lib/rails_connector/verity_search_request.rb +86 -0
  93. data/lib/search_request.rb +2 -0
  94. data/lib/version.rb +7 -0
  95. metadata +277 -0
@@ -0,0 +1,8 @@
1
+ module RailsConnector
2
+ module CmsTestRequest
3
+ def for_cms_object(test_obj = nil)
4
+ # prepare the env as if the given obj was loaded by CmsEnv
5
+ env[RailsConnector::CmsEnv::OBJ_ENV_KEY] = test_obj if test_obj
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,174 @@
1
+ require "helpful_configuration"
2
+ require "rails_connector/cms_base_model"
3
+ require "rails_connector/blob"
4
+
5
+ module RailsConnector
6
+ # @api public
7
+ class Configuration
8
+ # @api public
9
+ DEFAULT_MODE = :live
10
+
11
+ class << self
12
+ # there are three available modes for the rails connector:
13
+ # <tt>live</tt> (show released contents only),
14
+ # <tt>preview</tt> (show edited contents)
15
+ # <tt>editor</tt> (show edited contents and editor interface (e.g. edit markers))
16
+ # Default mode is <tt>live</tt>.
17
+ # @api public
18
+ attr_accessor :blob_cache_dir, :choose_homepage_callback
19
+
20
+ # default options for {SearchRequest}
21
+ # @api public
22
+ attr_writer :search_options
23
+
24
+ # default options for {SearchRequest}
25
+ # @api public
26
+ def search_options
27
+ @search_options || local_config_file["search"].symbolize_keys
28
+ end
29
+
30
+ # define a non-default blob cache dir.
31
+ # +fiona connector+ only. has no effect when used with the +cloud connector+.
32
+ # @api public
33
+
34
+ # @api public
35
+ def mode=(new_mode)
36
+ new_mode = new_mode.to_sym
37
+ raise ArgumentError, "Unknown Mode #{new_mode}" unless %i(editor preview live).include?(new_mode)
38
+
39
+ @mode = new_mode
40
+ end
41
+
42
+ # there are three available modes for the rails connector:
43
+ # <tt>live</tt> (show released contents only),
44
+ # <tt>preview</tt> (show edited contents)
45
+ # <tt>editor</tt> (show edited contents and editor interface (e.g. edit markers))
46
+ # Default mode is <tt>live</tt>.
47
+ # @api public
48
+ def mode
49
+ @mode || DEFAULT_MODE
50
+ end
51
+
52
+ def editor_interface_enabled?
53
+ mode == :editor
54
+ end
55
+
56
+ def use_edited_content?
57
+ mode == :preview || mode == :editor
58
+ end
59
+
60
+ # Configures your CMS instance name.
61
+ #
62
+ # Example call as to be used in <tt>rails_connector.rb</tt>:
63
+ # RailsConnector::Configuration.instance_name = 'internet'
64
+ # @api public
65
+ def instance_name=(name)
66
+ RailsConnector::CmsBaseModel.instance_name = name if RailsConnector.platform_fiona?
67
+ end
68
+
69
+ def after_initialize
70
+ enable_ses
71
+ enable_authentication
72
+ ::RailsConnector::BasicObj.configure_for_content(
73
+ ::RailsConnector::Configuration.use_edited_content? ? :edited : :released
74
+ )
75
+ end
76
+
77
+ def to_prepare
78
+ BasicObj.reset_reflections
79
+
80
+ unless Rails.configuration.cache_classes
81
+ after_initialize
82
+ NamedLink.reset_cache
83
+ BasicObj.reset_type_cache
84
+ ::ApplicationController.__send__(:helper, :cms)
85
+ end
86
+ end
87
+
88
+ def configure_cms_database
89
+ RailsConnector::CmsBaseModel.configure_database(:cms)
90
+ end
91
+
92
+ # Configure a callback to be invoked when the rails connector delivers the homepage.
93
+ # The given callback will receive the rack env
94
+ # and must return an Obj to be used as the homepage.
95
+ # If no callback is configured, Obj.homepage will be used as the default.
96
+ # @api public
97
+ def choose_homepage(&block)
98
+ self.choose_homepage_callback = block
99
+ end
100
+
101
+ def cms_routes(*_args)
102
+ raise <<-EOS.gsub(/\s+/, " ")
103
+ Calling RailsConnector::Configuration.cms_routes is not needed anymore.
104
+ Please remove it from config/routes.rb
105
+ EOS
106
+ end
107
+
108
+ def use_x_sendfile=(_value)
109
+ raise "Configuration.use_x_sendfile is now available as Rails configuration:"\
110
+ ' config.action_dispatch.x_sendfile_header = "X-Sendfile"'
111
+ end
112
+
113
+ def local_config_file
114
+ @local_config_file ||= read_local_config_file
115
+ end
116
+
117
+ def local_config_file_name
118
+ (Rails.root + "config/rails_connector.yml").expand_path
119
+ end
120
+
121
+ # for test purposes only
122
+ def reset_local_config_file_cache
123
+ @local_config_file = nil
124
+ end
125
+
126
+ protected
127
+
128
+ def enable_authentication
129
+ ::ApplicationController.include RailsConnector::Authenticable
130
+ end
131
+
132
+ def read_local_config_file
133
+ contents = YAML.load_file(local_config_file_name) if File.exist?(local_config_file_name)
134
+ contents ||= {}
135
+
136
+ config = HelpfulConfiguration.new(
137
+ contents,
138
+ local_config_file_name
139
+ )
140
+ config.explain(
141
+ "cms_database",
142
+ "a hash of options, including type, that specify the database configuration"
143
+ )
144
+ config.explain(
145
+ "cms_blob_storage",
146
+ "a hash of options, including type, that specify the cms blob storage configuration"
147
+ )
148
+ config.explain(
149
+ "cms_dict_storage",
150
+ "a hash of options, including type, that specify the cms dict storage configuration"
151
+ )
152
+ config.explain(
153
+ "search",
154
+ "a hash of options that specify access to the search server"
155
+ )
156
+ config.explain(
157
+ "cms_api",
158
+ "a hash of options that specify access to the cms api"
159
+ )
160
+ config.explain "content_service", "a hash of options that specify access to content service"
161
+ config
162
+ end
163
+
164
+ def enable_ses
165
+ require "rails_connector/ses"
166
+
167
+ RailsConnector::SES.enable
168
+ end
169
+ end
170
+ end
171
+
172
+ class ConfigurationError < StandardError
173
+ end
174
+ end
@@ -0,0 +1,7 @@
1
+ module RailsConnector
2
+ # This class allows us to read out the editor of an Obj,
3
+ # if it has edited content
4
+ class Content < CmsBaseModel
5
+ self.primary_key = :content_id
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ require "rails_connector/core_extensions/time"
@@ -0,0 +1,17 @@
1
+ class Time
2
+ # Returns a new Time created from the ISO date format String "YYYYMMDDhhmmss"
3
+ def self.from_iso(t)
4
+ return nil unless t
5
+
6
+ if t.to_s =~ /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/
7
+ utc(Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i, Regexp.last_match(4).to_i, Regexp.last_match(5).to_i, Regexp.last_match(6).to_i)
8
+ else
9
+ raise ArgumentError, "invalid iso time format: #{t}"
10
+ end
11
+ end
12
+
13
+ # Returns the Time as ISO date format String "YYYYMMDDhhmmss"
14
+ def to_iso
15
+ getutc.strftime("%Y%m%d%H%M%S")
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ module RailsConnector
2
+ # Adds support for string columns which contain ISO dates
3
+ module DateAttribute
4
+ module ClassMethods
5
+ def date_attribute(*names)
6
+ names.each do |name|
7
+ module_eval %!
8
+ def #{name}
9
+ DateAttribute.parse(#{name}_before_type_cast) unless #{name}_before_type_cast.nil?
10
+ end
11
+ !
12
+ end
13
+ end
14
+ end
15
+
16
+ def self.included(base)
17
+ base.extend(ClassMethods)
18
+ end
19
+
20
+ def self.parse(iso_date_time)
21
+ Time.from_iso(iso_date_time).in_time_zone
22
+ rescue ArgumentError
23
+ raise "The value is not a valid ISO date time: #{iso_date_time.inspect}"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ module RailsConnector
2
+ # This class provides a default implementation for accessing the search server.
3
+ # It is used by {DefaultSearchController}.
4
+ class DefaultSearchRequest < VeritySearchRequest
5
+ end
6
+ end
@@ -0,0 +1,65 @@
1
+ require "rails"
2
+ require "active_record/railtie"
3
+ require "action_view"
4
+
5
+ require "jquery-rails"
6
+
7
+ require "rails_connector/configuration"
8
+
9
+ module ::RailsConnector
10
+ class Engine < Rails::Engine
11
+ config.to_prepare { RailsConnector::Configuration.to_prepare }
12
+ config.after_initialize { RailsConnector::Configuration.after_initialize }
13
+
14
+ # make sure our exceptions cause an adequate error page and http status code
15
+ config.action_dispatch.rescue_responses["RailsConnector::ResourceNotFound"] = :not_found
16
+
17
+ initializer "rails_connector.add_fiona_time_type" do
18
+ ActiveRecord::Type.register(:fiona_datetime, ::FionaDateTime)
19
+ end
20
+
21
+ initializer "rails_connector.add_cms_routing_paths", after: :add_routing_paths do |app|
22
+ cms_route = File.expand_path("cms_routes.rb", paths["config"].to_a.first)
23
+ app.routes_reloader.paths.push(cms_route)
24
+ end
25
+
26
+ initializer "rails_connector.add_assets" do |app|
27
+ app.config.assets.precompile += %w(
28
+ editmarker.css editmarker.js
29
+ )
30
+ end
31
+
32
+ # Expose rails connector runtime to controller for logging.
33
+ initializer "rails_connector.log_runtime" do |_app|
34
+ runtime =
35
+ begin
36
+ RailsConnector::ControllerRuntime
37
+ rescue NameError
38
+ nil
39
+ end
40
+
41
+ if runtime
42
+ RailsConnector::LogSubscriber.attach_to :rails_connector
43
+ ActiveSupport.on_load(:action_controller) do
44
+ include runtime
45
+ end
46
+ end
47
+ end
48
+
49
+ initializer "rails_connector.configure_database", before: :load_config_initializers do |_app|
50
+ RailsConnector::Configuration.configure_cms_database
51
+ end
52
+
53
+ initializer "rails_connector.routing_helpers" do
54
+ ActionDispatch::TestRequest.include RailsConnector::CmsTestRequest if Rails.env == "test"
55
+
56
+ ActionController::Base.include CmsRoutingHelper
57
+ ActionView::Base.include CmsRoutingHelper
58
+ end
59
+
60
+ config.autoload_paths += paths["lib"].to_a
61
+ config.autoload_once_paths += paths["lib"].to_a
62
+
63
+ RailsConnector.rack_middlewares.each { |middleware| config.app_middleware.use middleware }
64
+ end
65
+ end
@@ -0,0 +1,6 @@
1
+ require "active_record/errors"
2
+
3
+ module RailsConnector
4
+ # @api public
5
+ ResourceNotFound = ActiveRecord::RecordNotFound
6
+ end # module RailsConnector
@@ -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
9
+ end
10
+
11
+ def deserialize(value)
12
+ Time.from_iso(value).in_time_zone if value
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ module ::RailsConnector
2
+ class FionaEngine < Rails::Engine
3
+ initializer "rails_connector.config_local", after: :load_config_initializers,
4
+ before: :engines_blank_point do
5
+ Dir[Rails.root + "config/local/*.rb"].map(&method(:require))
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ module RailsConnector
2
+ # Include this module in order to tag the string as one with HTML content
3
+ module HtmlString
4
+ include LinkResolvable
5
+ # Returns whether the String contains HTML (default to true, overrides String.html?).
6
+ def html?
7
+ true
8
+ end
9
+ end
10
+ end
11
+
12
+ class String
13
+ # Returns whether the String contains HTML (default to false).
14
+ def html?
15
+ false
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ module RailsConnector
2
+ # This class allows us to read out basic information about jobs
3
+ class Job < CmsBaseModel
4
+ self.primary_key = "job_id"
5
+
6
+ def self.table_name
7
+ "#{table_name_prefix}" "jobs"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,148 @@
1
+ module RailsConnector
2
+ # This class provides an interfaces for handling CMS Links.
3
+ # To format a link for rendering in an html page, use the +cms_path+ or +cms_url+ methods.
4
+ # @api public
5
+ class Link
6
+ extend ActiveModel::Naming
7
+
8
+ def initialize(link_data, destination_object = nil)
9
+ @link_data = link_data.symbolize_keys
10
+ @destination_object = destination_object
11
+ end
12
+
13
+ # The link's external url. Only available for external links.
14
+ # Warning: Do not output the url directly unless you know what you are doing.
15
+ # Normally you want to use the +cms_path+ or +cms_url+ methods to format a link.
16
+ # @api public
17
+ def url
18
+ @link_data[:url]
19
+ end
20
+
21
+ # The link's title.
22
+ # @api public
23
+ def title
24
+ @link_data[:title]
25
+ end
26
+
27
+ # Returns the link's query string as in "index.html?query_string".
28
+ # See RFC3986 for details (http://www.ietf.org/rfc/rfc3986.txt).
29
+ # @api public
30
+ def query
31
+ @link_data[:search]
32
+ end
33
+
34
+ # Deprecated: use Link#query instead.
35
+ # Returns the link's query string as in "index.html?query_string".
36
+ # See RFC3986 for details (http://www.ietf.org/rfc/rfc3986.txt).
37
+ # @api public
38
+ def search
39
+ query
40
+ end
41
+
42
+ # Returns the link's anchor as in "index.html#anchor".
43
+ # See RFC3986 for details (http://www.ietf.org/rfc/rfc3986.txt).
44
+ # @api public
45
+ def fragment
46
+ @link_data[:fragment]
47
+ end
48
+
49
+ # Returns the browser window or browser frame to be used as a target for this link.
50
+ # Example: Links that should be opened in a new window will return "_blank" as their target.
51
+ # @api public
52
+ def target
53
+ @link_data[:target]
54
+ end
55
+
56
+ def id
57
+ @link_data[:link_id]
58
+ end
59
+
60
+ def tag_name
61
+ @link_data[:tag_name]
62
+ end
63
+
64
+ def markdown_type
65
+ @link_data[:markdown_type]
66
+ end
67
+
68
+ def markdown?
69
+ "markdown" == @link_data[:source_format]
70
+ end
71
+
72
+ # Returns the file extension (e.g. zip, pdf) of this link's (internal or external) target.
73
+ # Returns an empty string if the file extension is can not be determined.
74
+ # @api public
75
+ def file_extension
76
+ if internal?
77
+ destination_object ? destination_object.file_extension : ""
78
+ else
79
+ path = begin
80
+ URI.parse(url).path
81
+ rescue StandardError
82
+ nil
83
+ end
84
+ path.blank? ? "" : File.extname(path)[1..-1] || ""
85
+ end
86
+ end
87
+
88
+ # Returns the id of the Links' destination_object.
89
+ # @api public
90
+ def destination_object_id
91
+ destination
92
+ end
93
+
94
+ # Returns the title of this Link if it is set.
95
+ # Otherwise it returns the display_title of the destination object for internal Links
96
+ # or the URL for external Links.
97
+ # @api public
98
+ def display_title
99
+ dt = title
100
+ dt = destination_object.display_title if dt.blank? && !external?
101
+ dt = url if dt.blank?
102
+ dt
103
+ end
104
+
105
+ # Returns true this Link links to a CMS Object.
106
+ # @api public
107
+ def internal?
108
+ url.nil?
109
+ end
110
+
111
+ # Returns true if this Link links to an external URL.
112
+ # @api public
113
+ def external?
114
+ !internal?
115
+ end
116
+
117
+ # An internal Link is active if it's destination object is active.
118
+ # An external Link is always active.
119
+ # @api public
120
+ def active?
121
+ external? || destination_object&.active?
122
+ end
123
+
124
+ def external_prefix?
125
+ url =~ /\s?external:/
126
+ end
127
+
128
+ def resolved?
129
+ external? || resolved_internal?
130
+ end
131
+
132
+ # Returns the destination object (+Obj+) of this Link.
133
+ # @api public
134
+ def destination_object
135
+ @destination_object ||= Obj.find(destination) if resolved_internal?
136
+ end
137
+
138
+ private
139
+
140
+ def resolved_internal?
141
+ internal? && !destination.nil?
142
+ end
143
+
144
+ def destination
145
+ @link_data[:destination]
146
+ end
147
+ end
148
+ end