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,5 +1,4 @@
1
1
  module RailsConnector
2
-
3
2
  # A binary containing the blob data of a Content or CMS management
4
3
  # data of Attribute (fields), ObjClass (object classes), for example.
5
4
  class Blob < CmsBaseModel
@@ -11,7 +10,8 @@ module RailsConnector
11
10
  select(:blob_name, :blob_length).find(primary_key)
12
11
  end
13
12
 
14
- alias_method_chain :find, :excluded_blob_data
13
+ alias_method :find_without_excluded_blob_data, :find
14
+ alias_method :find, :find_with_excluded_blob_data
15
15
  end
16
16
 
17
17
  def length
@@ -23,7 +23,7 @@ module RailsConnector
23
23
  end
24
24
 
25
25
  def path_of_stored_data(use_cached_file_if_older_than = Time.now)
26
- store_data if !File.exists?(path) || file_size_differs? || stale?(use_cached_file_if_older_than)
26
+ store_data if !File.exist?(path) || file_size_differs? || stale?(use_cached_file_if_older_than)
27
27
  path
28
28
  end
29
29
 
@@ -36,7 +36,7 @@ module RailsConnector
36
36
  case adapter_name
37
37
  when /mysql$/i
38
38
  raise "Adapter 'mysql' no longer supported. " +
39
- "Please change adapter in your database.yml to 'mysql2'."
39
+ "Please change adapter in your database.yml to 'mysql2'."
40
40
  when /mysql2/i
41
41
  require "rails_connector/blob_mysql"
42
42
  include BlobMysql
@@ -72,5 +72,4 @@ module RailsConnector
72
72
  blob_length != File.stat(path).size
73
73
  end
74
74
  end
75
-
76
75
  end
@@ -0,0 +1,15 @@
1
+ module RailsConnector
2
+ class BlobMapping < CmsBaseModel
3
+ def self.exists?
4
+ table_exists?
5
+ end
6
+
7
+ def self.get_fingerprint(name)
8
+ find_by_blob_name(name).fingerprint
9
+ end
10
+
11
+ def self.get_fingerprint_map(blob_names)
12
+ Hash[where(blob_name: blob_names).select(%i(blob_name fingerprint)).map { |b| [b.blob_name, b.fingerprint] }]
13
+ end
14
+ end
15
+ end
@@ -1,13 +1,12 @@
1
- require 'mysql2'
2
- require 'mysql_blob_streaming'
1
+ require "mysql2"
2
+ require "mysql_blob_streaming"
3
3
 
4
4
  module RailsConnector
5
-
6
5
  module BlobMysql
7
6
  def self.included(base)
8
7
  base.instance_eval do
9
8
  define_method :store_data do
10
- store_data_atomically {|f| fetch_into_file(f)}
9
+ store_data_atomically { |f| fetch_into_file(f) }
11
10
  end
12
11
  end
13
12
  end
@@ -28,5 +27,4 @@ module RailsConnector
28
27
  end
29
28
  end
30
29
  end
31
-
32
30
  end
@@ -1,10 +1,9 @@
1
1
  module RailsConnector
2
-
3
2
  module BlobOracle
4
3
  def self.included(base)
5
4
  base.instance_eval do
6
5
  define_method :store_data do
7
- store_data_atomically {|f| fetch_into_file(f)}
6
+ store_data_atomically { |f| fetch_into_file(f) }
8
7
  end
9
8
  end
10
9
  end
@@ -17,17 +16,17 @@ module RailsConnector
17
16
  GC.start
18
17
  end
19
18
  ensure
20
- blob.close if blob
19
+ blob&.close
21
20
  end
22
21
 
23
22
  private
24
23
 
25
24
  def sql
26
- %{
25
+ %(
27
26
  SELECT blob_data
28
27
  FROM #{self.class.table_name}
29
28
  WHERE #{self.class.primary_key} = :1
30
- }
29
+ )
31
30
  end
32
31
 
33
32
  def blob_handle
@@ -35,5 +34,4 @@ module RailsConnector
35
34
  con.exec(sql, id).fetch.first
36
35
  end
37
36
  end
38
-
39
- end
37
+ end
@@ -0,0 +1,18 @@
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
+ -> { 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
+ end
18
+ end
@@ -1,18 +1,17 @@
1
1
  module RailsConnector
2
-
3
2
  # @api public
4
3
  module CmsAccessible
5
-
6
- protected
4
+ protected
7
5
 
8
6
  # Filter method to load a CMS object.
9
7
  #
10
8
  # To require the loading for all actions, use this in your controllers:
11
- # before_filter :load_object
9
+ # before_action :load_object
12
10
  def load_object
13
11
  CmsEnv.new(request.env).load
14
12
  loaded_obj = request.env[CmsEnv::OBJ_ENV_KEY]
15
13
  raise loaded_obj if loaded_obj.is_a?(StandardError)
14
+
16
15
  @obj = loaded_obj
17
16
  end
18
17
 
@@ -20,32 +19,30 @@ module RailsConnector
20
19
  # not, a 410 Gone error message will be generate (by calling render_obj_error).
21
20
  #
22
21
  # To require the check for all actions, use this in your controllers:
23
- # before_filter :load_object
24
- # before_filter :ensure_object_is_active
22
+ # before_action :load_object
23
+ # before_action :ensure_object_is_active
25
24
  def ensure_object_is_active
26
25
  unless @obj.active?
27
26
  @valid_from = @obj.valid_from
28
27
  @valid_until = @obj.valid_until
29
28
  @obj = nil
30
29
  render_obj_error(410, "gone")
31
- return false
32
30
  end
33
- return true
31
+ true
34
32
  end
35
33
 
36
34
  # Filter method to check if access to the loaded object is permitted. If it is
37
35
  # not, a 403 Forbidden error message will be generated (by calling render_obj_error)
38
36
  #
39
37
  # To require the check for all actions, use this in your controllers:
40
- # before_filter :load_object
41
- # before_filter :ensure_object_is_permitted
38
+ # before_action :load_object
39
+ # before_action :ensure_object_is_permitted
42
40
  def ensure_object_is_permitted
43
41
  unless is_permitted(@obj)
44
42
  @obj = nil
45
43
  render_obj_error(403, "forbidden")
46
- return false
47
44
  end
48
- return true
45
+ true
49
46
  end
50
47
 
51
48
  # This method is called when rendering an error caused by either {ensure_object_is_permitted}
@@ -56,10 +53,10 @@ module RailsConnector
56
53
  def render_obj_error(status, name)
57
54
  force_html_format
58
55
  render(
59
- :template => "errors/#{status}_#{name}",
60
- :layout => false,
61
- :status => status,
62
- :content_type => Mime::HTML
56
+ template: "errors/#{status}_#{name}",
57
+ layout: false,
58
+ status: status,
59
+ content_type: Mime[:html]
63
60
  )
64
61
  end
65
62
 
@@ -83,7 +80,7 @@ module RailsConnector
83
80
  # to the valid_until date of the current object.
84
81
  def set_google_expire_header
85
82
  if @obj && (date = @obj.valid_until)
86
- headers['X-Robots-Tag: unavailable_after'] = date.rfc822
83
+ headers["X-Robots-Tag: unavailable_after"] = date.rfc822
87
84
  end
88
85
  end
89
86
 
@@ -93,20 +90,20 @@ module RailsConnector
93
90
  def deliver_file
94
91
  if @obj.body_data_url
95
92
  redirect_to enforce_protocol_from_request(@obj.body_data_url)
96
- elsif stale?(:last_modified => @obj.last_changed.utc)
93
+ elsif stale?(last_modified: @obj.last_changed.utc)
97
94
  mime_type = @obj.mime_type
98
- mime_type += '; charset=utf-8' if mime_type =~ /^text\//
95
+ mime_type += "; charset=utf-8" if %r{^text/}.match?(mime_type)
99
96
 
100
97
  if (filepath = @obj.body_data_path).present?
101
98
  send_file(File.expand_path(filepath), {
102
- :type => mime_type,
103
- :filename => @obj.filename,
104
- :disposition => 'inline',
105
- })
99
+ type: mime_type,
100
+ filename: @obj.filename,
101
+ disposition: "inline"
102
+ })
106
103
  else
107
104
  # generics should send its body, empty files should be delivered as
108
105
  # empty files - and not lead to an application error
109
- send_data @obj.body || '', :type => mime_type, :filename => @obj.filename, :disposition => 'inline'
106
+ send_data @obj.body || "", type: mime_type, filename: @obj.filename, disposition: "inline"
110
107
  end
111
108
  end
112
109
  end
@@ -1,12 +1,11 @@
1
1
  module RailsConnector
2
-
3
2
  # This is the abstract class from which all CMS models derive.
4
3
  # The database connection is set to "infopark_rails_connector_${RAILS_ENV}" and the table prefix is
5
4
  # determined from the instance_name.
6
5
  #
7
6
  # [instance_name] the name of the CMS instance
8
7
  class CmsBaseModel < ActiveRecord::Base
9
- @@instance_name = 'default'
8
+ @@instance_name = "default"
10
9
  cattr_accessor :instance_name
11
10
  self.abstract_class = true
12
11
 
@@ -25,6 +24,15 @@ module RailsConnector
25
24
  true
26
25
  end
27
26
 
27
+ # FIXME: Find a more stable solution for this
28
+ #
29
+ # Since ActiveRecord 4.2 finding Objs by name is no longer consistent when
30
+ # switching between edited and released content at runtime. As long as we
31
+ # find a better solution this mitigates the behaviour.
32
+ def self.find_by(arg, *args)
33
+ where(arg, *args).take
34
+ end
35
+
28
36
  def readonly?
29
37
  true
30
38
  end
@@ -37,9 +45,8 @@ module RailsConnector
37
45
  #
38
46
  # ActiveRecord::Base::primary_key_prefix_type has no effect here.
39
47
  def table_name_prefix
40
- @@instance_name.blank? ? '' : (@@instance_name + '_')
48
+ @@instance_name.blank? ? "" : (@@instance_name + "_")
41
49
  end
42
50
  end
43
51
  end
44
-
45
52
  end
@@ -1,24 +1,22 @@
1
1
  module RailsConnector
2
-
3
2
  class CmsDispatchController < ActionController::Metal
4
3
  def process(action)
5
- CmsEnv.new(env).load
6
- controller = target_controller(env)
7
- env["action_dispatch.request.path_parameters"]["controller"] = controller.controller_path
4
+ CmsEnv.new(request.env).load
5
+ controller = target_controller(request.env)
6
+ request.env["action_dispatch.request.path_parameters"][:controller] = controller.controller_path
8
7
 
9
- if !obj_not_found? && action == 'index'
10
- action = loaded_obj.controller_action_name
11
- end
8
+ action = loaded_obj.controller_action_name if !obj_not_found? && action == "index"
12
9
 
13
- env["action_dispatch.request.path_parameters"]["action"] = action
10
+ request.env["action_dispatch.request.path_parameters"][:action] = action
14
11
 
15
- self.response = controller.action(action).call(env)
12
+ self.response = controller.action(action).call(request.env)
16
13
  end
17
14
 
18
15
  private
19
16
 
20
- def target_controller(env)
17
+ def target_controller(_env)
21
18
  return default_controller if obj_not_found?
19
+
22
20
  controller = "#{loaded_obj.controller_name}Controller".constantize
23
21
 
24
22
  if controller.respond_to?(:use_for_obj_dispatch?) && controller.use_for_obj_dispatch?
@@ -31,7 +29,7 @@ module RailsConnector
31
29
  end
32
30
 
33
31
  def loaded_obj
34
- env[CmsEnv::OBJ_ENV_KEY]
32
+ request.env[CmsEnv::OBJ_ENV_KEY]
35
33
  end
36
34
 
37
35
  def obj_not_found?
@@ -42,5 +40,4 @@ module RailsConnector
42
40
  CmsController
43
41
  end
44
42
  end
45
-
46
43
  end
@@ -1,8 +1,6 @@
1
1
  module RailsConnector
2
-
3
2
  class CmsEnv
4
-
5
- OBJ_ENV_KEY = "INFOPARK_OBJ"
3
+ OBJ_ENV_KEY = "INFOPARK_OBJ".freeze
6
4
 
7
5
  def initialize(env)
8
6
  @env = env
@@ -10,6 +8,7 @@ module RailsConnector
10
8
 
11
9
  def load
12
10
  return if env[OBJ_ENV_KEY]
11
+
13
12
  load_object
14
13
  end
15
14
 
@@ -48,7 +47,7 @@ module RailsConnector
48
47
 
49
48
  if found_obj.suppressed?
50
49
  raise RailsConnector::ResourceNotFound,
51
- "Tried to access Obj #{found_obj.inspect}, but it is suppressed (suppress_export is set)!"
50
+ "Tried to access Obj #{found_obj.inspect}, but it is suppressed (suppress_export is set)!"
52
51
  end
53
52
 
54
53
  found_obj
@@ -59,10 +58,8 @@ module RailsConnector
59
58
  end
60
59
 
61
60
  def self.find_permalink_by_param(permalink_param)
62
- permalink = Array(permalink_param).join("/")
61
+ permalink = Array(permalink_param).join("/")
63
62
  Obj.find_by_permalink!(permalink)
64
63
  end
65
-
66
64
  end
67
-
68
65
  end
@@ -1,23 +1,8 @@
1
1
  module RailsConnector
2
2
  module CmsTestRequest
3
- def for_cms_object(test_obj=nil)
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::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,23 +1,21 @@
1
1
  require "helpful_configuration"
2
- require 'rails_connector/cms_base_model'
2
+ require "rails_connector/cms_base_model"
3
3
  require "rails_connector/blob"
4
4
 
5
5
  module RailsConnector
6
-
7
6
  # @api public
8
7
  class Configuration
9
8
  # @api public
10
9
  DEFAULT_MODE = :live
11
10
 
12
11
  class << self
13
-
14
12
  # there are three available modes for the rails connector:
15
13
  # <tt>live</tt> (show released contents only),
16
14
  # <tt>preview</tt> (show edited contents)
17
15
  # <tt>editor</tt> (show edited contents and editor interface (e.g. edit markers))
18
16
  # Default mode is <tt>live</tt>.
19
17
  # @api public
20
- attr_accessor :mode
18
+ attr_accessor :blob_cache_dir, :choose_homepage_callback
21
19
 
22
20
  # default options for {SearchRequest}
23
21
  # @api public
@@ -32,12 +30,12 @@ module RailsConnector
32
30
  # define a non-default blob cache dir.
33
31
  # +fiona connector+ only. has no effect when used with the +cloud connector+.
34
32
  # @api public
35
- attr_accessor :blob_cache_dir
36
33
 
37
34
  # @api public
38
35
  def mode=(new_mode)
39
36
  new_mode = new_mode.to_sym
40
- raise ArgumentError, "Unknown Mode #{new_mode}" unless [:editor, :preview, :live].include?(new_mode)
37
+ raise ArgumentError, "Unknown Mode #{new_mode}" unless %i(editor preview live).include?(new_mode)
38
+
41
39
  @mode = new_mode
42
40
  end
43
41
 
@@ -77,6 +75,8 @@ module RailsConnector
77
75
  end
78
76
 
79
77
  def to_prepare
78
+ BasicObj.reset_reflections
79
+
80
80
  unless Rails.configuration.cache_classes
81
81
  after_initialize
82
82
  NamedLink.reset_cache
@@ -89,8 +89,6 @@ module RailsConnector
89
89
  RailsConnector::CmsBaseModel.configure_database(:cms)
90
90
  end
91
91
 
92
- attr_accessor :choose_homepage_callback
93
-
94
92
  # Configure a callback to be invoked when the rails connector delivers the homepage.
95
93
  # The given callback will receive the rack env
96
94
  # and must return an Obj to be used as the homepage.
@@ -100,15 +98,15 @@ module RailsConnector
100
98
  self.choose_homepage_callback = block
101
99
  end
102
100
 
103
- def cms_routes(*args)
104
- raise <<-EOS.gsub(/\s+/, ' ')
101
+ def cms_routes(*_args)
102
+ raise <<-EOS.gsub(/\s+/, " ")
105
103
  Calling RailsConnector::Configuration.cms_routes is not needed anymore.
106
104
  Please remove it from config/routes.rb
107
105
  EOS
108
106
  end
109
107
 
110
- def use_x_sendfile=(value)
111
- raise 'Configuration.use_x_sendfile is now available as Rails configuration:'\
108
+ def use_x_sendfile=(_value)
109
+ raise "Configuration.use_x_sendfile is now available as Rails configuration:"\
112
110
  ' config.action_dispatch.x_sendfile_header = "X-Sendfile"'
113
111
  end
114
112
 
@@ -128,11 +126,11 @@ module RailsConnector
128
126
  protected
129
127
 
130
128
  def enable_authentication
131
- ::ApplicationController.__send__(:include, RailsConnector::Authenticable)
129
+ ::ApplicationController.include RailsConnector::Authenticable
132
130
  end
133
131
 
134
132
  def read_local_config_file
135
- contents = YAML.load_file(local_config_file_name) if File.exists?(local_config_file_name)
133
+ contents = YAML.load_file(local_config_file_name) if File.exist?(local_config_file_name)
136
134
  contents ||= {}
137
135
 
138
136
  config = HelpfulConfiguration.new(
@@ -159,12 +157,12 @@ module RailsConnector
159
157
  "cms_api",
160
158
  "a hash of options that specify access to the cms api"
161
159
  )
162
- config.explain 'content_service', 'a hash of options that specify access to content service'
160
+ config.explain "content_service", "a hash of options that specify access to content service"
163
161
  config
164
162
  end
165
163
 
166
164
  def enable_ses
167
- require 'rails_connector/ses'
165
+ require "rails_connector/ses"
168
166
 
169
167
  RailsConnector::SES.enable
170
168
  end