infopark_cloud_connector 6.9.4 → 6.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +15 -0
  2. data/README +1 -3
  3. data/app/controllers/cms_controller.rb +7 -0
  4. data/app/controllers/rails_connector/default_cms_controller.rb +43 -0
  5. data/app/controllers/rails_connector/objs_controller.rb +29 -0
  6. data/app/controllers/rails_connector/widget_renderer.rb +1 -1
  7. data/app/controllers/rails_connector/workspaces_controller.rb +4 -0
  8. data/app/helpers/cms_helper.rb +7 -0
  9. data/app/helpers/cms_routing_helper.rb +7 -0
  10. data/app/helpers/rails_connector/cms_asset_helper.rb +24 -17
  11. data/app/helpers/rails_connector/cms_tag_helper.rb +9 -6
  12. data/app/helpers/rails_connector/default_cms_helper.rb +23 -0
  13. data/app/helpers/rails_connector/default_cms_routing_helper.rb +101 -0
  14. data/app/helpers/rails_connector/display_helper.rb +4 -30
  15. data/app/helpers/rails_connector/editing_helper.rb +3 -0
  16. data/app/helpers/rails_connector/layout_helper.rb +29 -0
  17. data/app/helpers/rails_connector/table_of_contents_helper.rb +22 -0
  18. data/app/models/named_link.rb +2 -0
  19. data/app/views/cms/_index.html.erb +7 -0
  20. data/app/views/cms/index.html.erb +1 -0
  21. data/app/views/errors/403_forbidden.html.erb +3 -0
  22. data/app/views/errors/410_gone.html.erb +7 -0
  23. data/app/views/rails_connector/_editing_javascript.html.erb +2 -0
  24. data/config/ca-bundle.crt +1 -1
  25. data/config/cms_routes.rb +14 -0
  26. data/config/locales/de.rails_connector.errors.yml +11 -0
  27. data/config/locales/de.rails_connector.lib.yml +6 -0
  28. data/config/locales/de.rails_connector.views.yml +9 -0
  29. data/config/locales/en.rails_connector.errors.yml +10 -0
  30. data/config/locales/en.rails_connector.lib.yml +6 -0
  31. data/config/locales/en.rails_connector.views.yml +9 -0
  32. data/config/routes.rb +4 -0
  33. data/lib/assets/javascripts/infopark_editing.js +689 -285
  34. data/lib/assets/stylesheets/infopark_editing.css +17 -0
  35. data/lib/infopark_cloud_connector.rb +22 -0
  36. data/lib/obj.rb +3 -0
  37. data/lib/rails_connector/attribute_content.rb +190 -0
  38. data/lib/rails_connector/authenticable.rb +30 -0
  39. data/lib/rails_connector/basic_obj.rb +25 -139
  40. data/lib/rails_connector/basic_widget.rb +35 -0
  41. data/lib/rails_connector/cms_accessible.rb +114 -0
  42. data/lib/rails_connector/cms_cache_storage.rb +1 -1
  43. data/lib/rails_connector/cms_dispatch_controller.rb +46 -0
  44. data/lib/rails_connector/cms_env.rb +68 -0
  45. data/lib/rails_connector/cms_test_request.rb +23 -0
  46. data/lib/rails_connector/configuration.rb +3 -2
  47. data/lib/rails_connector/core_extensions.rb +1 -0
  48. data/lib/rails_connector/core_extensions/time.rb +18 -0
  49. data/lib/rails_connector/date_attribute.rb +1 -17
  50. data/lib/rails_connector/engine.rb +57 -0
  51. data/lib/rails_connector/html_string.rb +19 -0
  52. data/lib/rails_connector/link.rb +102 -17
  53. data/lib/rails_connector/link_resolvable.rb +9 -0
  54. data/lib/rails_connector/migrations/migrator.rb +8 -4
  55. data/lib/rails_connector/migrations/workspace_lock.rb +3 -2
  56. data/lib/rails_connector/named_link.rb +1 -1
  57. data/lib/rails_connector/obj_data_from_service.rb +18 -0
  58. data/lib/rails_connector/string_tagging.rb +29 -0
  59. data/lib/rails_connector/type_computer.rb +30 -0
  60. data/lib/widget.rb +3 -0
  61. metadata +103 -18
@@ -0,0 +1,35 @@
1
+ module RailsConnector
2
+
3
+ class BasicWidget
4
+ include AttributeContent
5
+
6
+ def self.type_computer
7
+ @_type_computer ||= TypeComputer.new(RailsConnector::BasicWidget, ::Widget)
8
+ end
9
+
10
+ def self.reset_type_computer!
11
+ @_type_computer = nil
12
+ end
13
+
14
+ attr_accessor :id, :obj
15
+
16
+ alias_method :initialize, :update_data
17
+
18
+ def obj_class
19
+ data_from_cms.value_of('_obj_class')
20
+ end
21
+
22
+ def ==(other)
23
+ other.respond_to?(:obj) && obj == other.obj && other.respond_to?(:id) && id == other.id
24
+ end
25
+
26
+ def eql?(other)
27
+ self == other
28
+ end
29
+
30
+ def hash
31
+ (id + obj.id).hash
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,114 @@
1
+ module RailsConnector
2
+
3
+ # @api public
4
+ module CmsAccessible
5
+
6
+ protected
7
+
8
+ # Filter method to load a CMS object.
9
+ #
10
+ # To require the loading for all actions, use this in your controllers:
11
+ # before_filter :load_object
12
+ def load_object
13
+ CmsEnv.new(request.env).load
14
+ loaded_obj = request.env[CmsEnv::OBJ_ENV_KEY]
15
+ raise loaded_obj if loaded_obj.is_a?(StandardError)
16
+ @obj = loaded_obj
17
+ end
18
+
19
+ # Filter method to check if the already loaded object is active. If it is
20
+ # not, a 410 Gone error message will be generate (by calling render_obj_error).
21
+ #
22
+ # To require the check for all actions, use this in your controllers:
23
+ # before_filter :load_object
24
+ # before_filter :ensure_object_is_active
25
+ def ensure_object_is_active
26
+ unless @obj.active?
27
+ @valid_from = @obj.valid_from
28
+ @valid_until = @obj.valid_until
29
+ @obj = nil
30
+ render_obj_error(410, "gone")
31
+ return false
32
+ end
33
+ return true
34
+ end
35
+
36
+ # Filter method to check if access to the loaded object is permitted. If it is
37
+ # not, a 403 Forbidden error message will be generated (by calling render_obj_error)
38
+ #
39
+ # To require the check for all actions, use this in your controllers:
40
+ # before_filter :load_object
41
+ # before_filter :ensure_object_is_permitted
42
+ def ensure_object_is_permitted
43
+ unless is_permitted(@obj)
44
+ @obj = nil
45
+ render_obj_error(403, "forbidden")
46
+ return false
47
+ end
48
+ return true
49
+ end
50
+
51
+ # This method is called when rendering an error caused by either {ensure_object_is_permitted}
52
+ # or {ensure_object_is_active} before filter. It renders an error template located in
53
+ # "errors/*.html.erb" with given HTTP status and content type "text/html" and with no layout.
54
+ # Overwrite this method to change the error page.
55
+ # @api public
56
+ def render_obj_error(status, name)
57
+ force_html_format
58
+ render(
59
+ :template => "errors/#{status}_#{name}",
60
+ :layout => false,
61
+ :status => status,
62
+ :content_type => Mime::HTML
63
+ )
64
+ end
65
+
66
+ # Enforce "html" as template format.
67
+ # @api public
68
+ def force_html_format
69
+ request.format = :html
70
+ end
71
+
72
+ # Inclusion hook to make is_permitted available as helper method.
73
+ def self.included(base)
74
+ base.__send__ :helper_method, :is_permitted
75
+ end
76
+
77
+ # Helper method to check live permissions
78
+ def is_permitted(obj)
79
+ obj.permitted_for_user?(current_user)
80
+ end
81
+
82
+ # Filter method which sets the header 'X-Robots-Tag: unavailable_after'
83
+ # to the valid_until date of the current object.
84
+ def set_google_expire_header
85
+ if @obj && (date = @obj.valid_until)
86
+ headers['X-Robots-Tag: unavailable_after'] = date.rfc822
87
+ end
88
+ end
89
+
90
+ # Deliver the obj's body as response by file or data.
91
+ # May respond with status 304 if a If-Modified-Since header is found.
92
+ # @api public
93
+ def deliver_file
94
+ if @obj.body_data_url
95
+ redirect_to enforce_protocol_from_request(@obj.body_data_url)
96
+ elsif stale?(:last_modified => @obj.last_changed.utc)
97
+ mime_type = @obj.mime_type
98
+ mime_type += '; charset=utf-8' if mime_type =~ /^text\//
99
+
100
+ if (filepath = @obj.body_data_path).present?
101
+ send_file(File.expand_path(filepath), {
102
+ :type => mime_type,
103
+ :filename => @obj.filename,
104
+ :disposition => 'inline',
105
+ })
106
+ else
107
+ # generics should send its body, empty files should be delivered as
108
+ # empty files - and not lead to an application error
109
+ send_data @obj.body || '', :type => mime_type, :filename => @obj.filename, :disposition => 'inline'
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -21,7 +21,7 @@ module CmsCacheStorage
21
21
  end
22
22
 
23
23
  def backend_cache
24
- @backend_cache || Rails.cache
24
+ @backend_cache || ActiveSupport::Cache::FileStore.new(Rails.root + 'tmp/infopark_cache')
25
25
  end
26
26
 
27
27
  def read_workspace_data(workspace_id)
@@ -0,0 +1,46 @@
1
+ module RailsConnector
2
+
3
+ class CmsDispatchController < ActionController::Metal
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
8
+
9
+ if !obj_not_found? && action == 'index'
10
+ action = loaded_obj.controller_action_name
11
+ end
12
+
13
+ env["action_dispatch.request.path_parameters"]["action"] = action
14
+
15
+ self.response = controller.action(action).call(env)
16
+ end
17
+
18
+ private
19
+
20
+ def target_controller(env)
21
+ return default_controller if obj_not_found?
22
+ controller = "#{loaded_obj.controller_name}Controller".constantize
23
+
24
+ if controller.respond_to?(:use_for_obj_dispatch?) && controller.use_for_obj_dispatch?
25
+ controller
26
+ else
27
+ default_controller
28
+ end
29
+ rescue NameError
30
+ default_controller
31
+ end
32
+
33
+ def loaded_obj
34
+ env[CmsEnv::OBJ_ENV_KEY]
35
+ end
36
+
37
+ def obj_not_found?
38
+ loaded_obj.is_a?(StandardError)
39
+ end
40
+
41
+ def default_controller
42
+ CmsController
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,68 @@
1
+ module RailsConnector
2
+
3
+ class CmsEnv
4
+
5
+ OBJ_ENV_KEY = "INFOPARK_OBJ"
6
+
7
+ def initialize(env)
8
+ @env = env
9
+ end
10
+
11
+ def load
12
+ return if env[OBJ_ENV_KEY]
13
+ load_object
14
+ end
15
+
16
+ protected
17
+
18
+ attr_reader :env
19
+
20
+ def load_object
21
+ env[OBJ_ENV_KEY] =
22
+ begin
23
+ find_obj
24
+ rescue StandardError => e
25
+ e
26
+ end
27
+ end
28
+
29
+ def find_obj
30
+ found_obj =
31
+ if params[:id]
32
+ Obj.find(params[:id])
33
+ elsif params[:permalink].present?
34
+ self.class.find_permalink_by_param(params[:permalink])
35
+ else
36
+ if callback = RailsConnector::Configuration.choose_homepage_callback
37
+ callback_result = callback.call(env)
38
+ if callback_result.is_a?(Obj)
39
+ callback_result
40
+ else
41
+ raise "choose_homepage callback did not return an Obj. "\
42
+ "Instead saw #{callback_result.class}."
43
+ end
44
+ else
45
+ Obj.homepage
46
+ end
47
+ end
48
+
49
+ if found_obj.suppressed?
50
+ raise RailsConnector::ResourceNotFound,
51
+ "Tried to access Obj #{found_obj.inspect}, but it is suppressed (suppress_export is set)!"
52
+ end
53
+
54
+ found_obj
55
+ end
56
+
57
+ def params
58
+ env["action_dispatch.request.path_parameters"]
59
+ end
60
+
61
+ def self.find_permalink_by_param(permalink_param)
62
+ permalink = Array(permalink_param).join("/")
63
+ Obj.find_by_permalink!(permalink)
64
+ end
65
+
66
+ end
67
+
68
+ end
@@ -0,0 +1,23 @@
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
+ 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
+ end
22
+ end
23
+ end
@@ -40,7 +40,7 @@ module RailsConnector
40
40
 
41
41
  # The +RailsConnector+ makes heavy use of filesystem caching.
42
42
  # Use this method to configure the directory that should be used to store cached data.
43
- # By default, +RAILS_ROOT/tmp/cache+ will be used.
43
+ # By default, +RAILS_ROOT/tmp/infopark_cache+ will be used.
44
44
  # @param path [String] Path to directory that should be used to store cached data.
45
45
  # @example Configure +RailsConnector+ to store it's cache under +/tmp/my_cache+.
46
46
  # RailsConnector::Configuration.cache_path = '/tmp/my_cache'
@@ -143,7 +143,8 @@ module RailsConnector
143
143
  unless Rails.configuration.cache_classes
144
144
  after_initialize
145
145
  NamedLink.reset_cache
146
- BasicObj.reset_type_cache
146
+ BasicObj.reset_type_computer!
147
+ BasicWidget.reset_type_computer!
147
148
  ::ApplicationController.__send__(:helper, :cms)
148
149
  end
149
150
  end
@@ -0,0 +1 @@
1
+ require "rails_connector/core_extensions/time"
@@ -0,0 +1,18 @@
1
+ class Time
2
+
3
+ # Returns a new Time created from the ISO date format String "YYYYMMDDhhmmss"
4
+ def self.from_iso(t)
5
+ return nil unless t
6
+ if t.to_s =~ /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/
7
+ utc($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $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
+
18
+ end
@@ -2,22 +2,6 @@ module RailsConnector
2
2
 
3
3
  # Adds support for string columns which contain ISO dates
4
4
  module DateAttribute
5
- module ClassMethods
6
- def date_attribute(*names)
7
- names.each do |name|
8
- module_eval %Q!
9
- def #{name}
10
- DateAttribute.parse(#{name}_before_type_cast) unless #{name}_before_type_cast.nil?
11
- end
12
- !
13
- end
14
- end
15
- end
16
-
17
- def self.included(base)
18
- base.extend(ClassMethods)
19
- end
20
-
21
5
  def self.parse(iso_date_time)
22
6
  Time.from_iso(iso_date_time).in_time_zone
23
7
  rescue ArgumentError
@@ -25,4 +9,4 @@ module RailsConnector
25
9
  end
26
10
  end
27
11
 
28
- end
12
+ end
@@ -0,0 +1,57 @@
1
+ require "rails"
2
+ require "action_view"
3
+
4
+ require 'jquery-rails'
5
+
6
+ require 'rails_connector/configuration'
7
+
8
+ module ::RailsConnector
9
+ class Engine < Rails::Engine
10
+ config.to_prepare { RailsConnector::Configuration.to_prepare }
11
+ config.after_initialize { RailsConnector::Configuration.after_initialize }
12
+
13
+ # make sure our exceptions cause an adequate error page and http status code
14
+ config.action_dispatch.rescue_responses.merge!("RailsConnector::ResourceNotFound" => :not_found)
15
+
16
+ initializer "rails_connector.add_cms_routing_paths", :after => :add_routing_paths do |app|
17
+ cms_route = File.expand_path("cms_routes.rb", paths['config'].to_a.first)
18
+ app.routes_reloader.paths.push(cms_route)
19
+ end
20
+
21
+ # Expose rails connector runtime to controller for logging.
22
+ initializer "rails_connector.log_runtime" do |app|
23
+ runtime =
24
+ begin
25
+ RailsConnector::ControllerRuntime
26
+ rescue NameError
27
+ nil
28
+ end
29
+
30
+ if runtime
31
+ RailsConnector::LogSubscriber.attach_to :rails_connector
32
+ ActiveSupport.on_load(:action_controller) do
33
+ include runtime
34
+ end
35
+ end
36
+ end
37
+
38
+ initializer "rails_connector.configure_database", :before => :load_config_initializers do |app|
39
+ RailsConnector::Configuration.configure_cms_database
40
+ end
41
+
42
+ initializer "rails_connector.routing_helpers" do
43
+ if Rails.env == 'test'
44
+ ActionDispatch::TestRequest.__send__(:include, RailsConnector::CmsTestRequest)
45
+ end
46
+
47
+ ActionController::Base.__send__(:include, CmsRoutingHelper)
48
+ ActionView::Base.__send__(:include, CmsRoutingHelper)
49
+ end
50
+
51
+ config.autoload_paths += paths['lib'].to_a
52
+ config.autoload_once_paths += paths['lib'].to_a
53
+
54
+ RailsConnector.rack_middlewares.each { |middleware| config.app_middleware.use middleware }
55
+ end
56
+ end
57
+
@@ -0,0 +1,19 @@
1
+ module RailsConnector
2
+
3
+ # Include this module in order to tag the string as one with HTML content
4
+ module HtmlString
5
+ include LinkResolvable
6
+ # Returns whether the String contains HTML (default to true, overrides String.html?).
7
+ def html?
8
+ true
9
+ end
10
+ end
11
+
12
+ end
13
+
14
+ class String
15
+ # Returns whether the String contains HTML (default to false).
16
+ def html?
17
+ false
18
+ end
19
+ end