infopark_fiona_connector 6.9.4 → 7.0.1.5.2.3.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/app/assets/images/admin/minus.gif +0 -0
  3. data/app/assets/images/bg80.png +0 -0
  4. data/app/assets/images/edit.png +0 -0
  5. data/app/assets/images/icons/mm_generic.png +0 -0
  6. data/app/assets/images/icons/mm_menu.png +0 -0
  7. data/app/assets/javascripts/editmarker.js +240 -0
  8. data/app/assets/javascripts/infopark_rails_connector.js.erb +0 -0
  9. data/app/assets/stylesheets/editmarker.css +70 -0
  10. data/app/assets/stylesheets/infopark_rails_connector.css.erb +0 -0
  11. data/app/controllers/cms_controller.rb +7 -0
  12. data/app/controllers/rails_connector/default_cms_controller.rb +43 -0
  13. data/app/helpers/cms_helper.rb +7 -0
  14. data/app/helpers/cms_routing_helper.rb +7 -0
  15. data/app/helpers/rails_connector/cms_asset_helper.rb +2 -1
  16. data/app/helpers/rails_connector/default_cms_helper.rb +23 -0
  17. data/app/helpers/rails_connector/default_cms_routing_helper.rb +120 -0
  18. data/app/helpers/rails_connector/display_helper.rb +5 -5
  19. data/app/helpers/rails_connector/layout_helper.rb +29 -0
  20. data/app/helpers/rails_connector/marker_helper.rb +1 -3
  21. data/app/helpers/rails_connector/table_of_contents_helper.rb +22 -0
  22. data/app/models/named_link.rb +2 -0
  23. data/app/views/cms/_index.html.erb +7 -0
  24. data/app/views/cms/index.html.erb +1 -0
  25. data/app/views/errors/403_forbidden.html.erb +3 -0
  26. data/app/views/errors/410_gone.html.erb +7 -0
  27. data/config/cms_routes.rb +17 -0
  28. data/config/locales/de.rails_connector.errors.yml +11 -0
  29. data/config/locales/de.rails_connector.lib.yml +6 -0
  30. data/config/locales/de.rails_connector.views.yml +9 -0
  31. data/config/locales/en.rails_connector.errors.yml +10 -0
  32. data/config/locales/en.rails_connector.lib.yml +6 -0
  33. data/config/locales/en.rails_connector.views.yml +9 -0
  34. data/lib/gem_dependencies.rb +67 -0
  35. data/lib/infopark_fiona_connector.rb +26 -3
  36. data/lib/meta_eager_loader.rb +1 -0
  37. data/lib/obj.rb +3 -0
  38. data/lib/rails_connector/attr_dict.rb +31 -16
  39. data/lib/rails_connector/attribute.rb +96 -0
  40. data/lib/rails_connector/authenticable.rb +30 -0
  41. data/lib/rails_connector/basic_obj.rb +82 -95
  42. data/lib/rails_connector/blob.rb +14 -6
  43. data/lib/rails_connector/blob_mapping.rb +16 -0
  44. data/lib/rails_connector/blob_mysql.rb +1 -1
  45. data/lib/rails_connector/blob_oracle.rb +1 -1
  46. data/lib/rails_connector/channel.rb +19 -0
  47. data/lib/rails_connector/cms_accessible.rb +112 -0
  48. data/lib/rails_connector/cms_base_model.rb +9 -0
  49. data/lib/rails_connector/cms_dispatch_controller.rb +46 -0
  50. data/lib/rails_connector/cms_env.rb +68 -0
  51. data/lib/rails_connector/cms_test_request.rb +8 -0
  52. data/lib/rails_connector/configuration.rb +3 -1
  53. data/lib/rails_connector/content.rb +11 -0
  54. data/lib/rails_connector/core_extensions.rb +1 -0
  55. data/lib/rails_connector/core_extensions/time.rb +18 -0
  56. data/lib/rails_connector/date_attribute.rb +1 -1
  57. data/lib/rails_connector/engine.rb +68 -0
  58. data/lib/rails_connector/fiona_datetime.rb +14 -0
  59. data/lib/rails_connector/html_string.rb +19 -0
  60. data/lib/rails_connector/job.rb +13 -0
  61. data/lib/rails_connector/link_list.rb +32 -0
  62. data/lib/rails_connector/link_resolvable.rb +9 -0
  63. data/lib/rails_connector/markdown_string.rb +19 -0
  64. data/lib/rails_connector/meta.rb +148 -0
  65. data/lib/rails_connector/meta/eager_loader.rb +82 -0
  66. data/lib/rails_connector/named_link.rb +16 -1
  67. data/lib/rails_connector/news.rb +7 -3
  68. data/lib/rails_connector/obj_class.rb +140 -0
  69. data/lib/rails_connector/obj_class_attr.rb +5 -0
  70. data/lib/rails_connector/object_with_meta_data.rb +18 -0
  71. data/lib/rails_connector/rack_middlewares.rb +1 -2
  72. data/lib/rails_connector/string_tagging.rb +29 -0
  73. data/lib/version.rb +7 -0
  74. metadata +168 -42
  75. data/README +0 -5
@@ -19,8 +19,8 @@ module RailsConnector
19
19
  case value
20
20
  when MarkdownString then markdown(convert_links(value)).html_safe
21
21
  when HtmlString then convert_links(value).html_safe
22
- when String then h(value)
23
- when Time then h(l(value))
22
+ when String then html_escape_once(value).html_safe
23
+ when Time then html_escape_once(l(value)).html_safe
24
24
  else value
25
25
  end
26
26
  end
@@ -106,9 +106,9 @@ module RailsConnector
106
106
  ['title', begin link.title unless link.title.blank? end]
107
107
  end
108
108
  if value
109
- subst << %( #{name}="#{h(value)}")
109
+ subst << %( #{name}="#{html_escape_once(value)}")
110
110
  end
111
- subst << %( target="#{h(link.target)}") unless link.target.blank?
111
+ subst << %( target="#{html_escape_once(link.target)}") unless link.target.blank?
112
112
  subst
113
113
  end
114
114
 
@@ -117,7 +117,7 @@ module RailsConnector
117
117
  unless link.title.blank?
118
118
  case link.markdown_type
119
119
  when 'inline', 'reference'
120
- subst << %( "#{h(link.title)}")
120
+ subst << %( "#{html_escape_once(link.title)}")
121
121
  end
122
122
  end
123
123
  subst
@@ -0,0 +1,29 @@
1
+ module RailsConnector
2
+
3
+ # This module contains helpers that render tags for the html head
4
+ # and the end of the html body.
5
+ # @api public
6
+ module LayoutHelper
7
+
8
+ # Renders all tags needed in the html head.
9
+ # @api public
10
+ def rails_connector_header_tags
11
+ html = "".html_safe
12
+ html += tag('meta', :name => 'generator',
13
+ :content => "Rails Connector for Infopark CMS Fiona by Infopark AG (www.infopark.de)")
14
+ html += include_edit_marker_support
15
+ html += include_editing_stylesheet
16
+ html
17
+ end
18
+
19
+ # Renders all tags needed at the end of the body tag.
20
+ # @api public
21
+ def rails_connector_after_content_tags
22
+ html = "".html_safe
23
+ html += render_marker_code
24
+ html += include_editing_javascript
25
+ html
26
+ end
27
+ end
28
+
29
+ end
@@ -141,9 +141,7 @@ module RailsConnector
141
141
  size = options.delete(:size)
142
142
  target = options.delete(:target) || "_blank"
143
143
 
144
- link_to_function(name.to_s,
145
- "inline_editing.openEditDialog('#{obj.id}', '#{attr}', '#{context.id || 'null'}', '#{size || 'null'}', '#{target || 'null'}')"
146
- )
144
+ link_to name.to_s, '#', onclick: "inline_editing.openEditDialog('#{obj.id}', '#{attr}', '#{context.id || 'null'}', '#{size || 'null'}', '#{target || 'null'}'); return false;"
147
145
  end
148
146
  end
149
147
 
@@ -0,0 +1,22 @@
1
+ module RailsConnector
2
+
3
+ #
4
+ # This module contains a helper that can be used to build a table of contents of an object.
5
+ #
6
+ # @api public
7
+ module TableOfContentsHelper
8
+
9
+ #
10
+ # The <tt>table_of_contents</tt> helper method gets an object as argument and returns an array,
11
+ # which can be used as the table of contents of the given object.
12
+ #
13
+ # The returned array consists of the child objects of the given object.
14
+ # The array is sorted according to the configured sort order and the sort keys.
15
+ # It also contains only objects which the current user is permitted to view.
16
+ #
17
+ # @api public
18
+ def table_of_contents(obj)
19
+ obj.sorted_toclist.reject { |o| not o.permitted_for_user?(current_user) }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,2 @@
1
+ # ::NamedLink is just a shortcut
2
+ ::NamedLink = RailsConnector::NamedLink
@@ -0,0 +1,7 @@
1
+ <h1 class="cms_title"><%= display_field @obj, :title %></h1>
2
+ <ul class="cms_toclist">
3
+ <% @obj.toclist.each do |item| %>
4
+ <li><%= link_to display_field(item, :title), cms_path(item) %></li>
5
+ <% end %>
6
+ </ul>
7
+ <%= display_field @obj, :body %>
@@ -0,0 +1 @@
1
+ <%= render :partial => 'index' %>
@@ -0,0 +1,3 @@
1
+ <h1><%= t(:'rails_connector.lib.cms_accessible.protected') %></h1>
2
+
3
+ <p><%= t(:"rails_connector.views.errors.forbidden.no_permissions") %></p>
@@ -0,0 +1,7 @@
1
+ <h1><%= t(:'rails_connector.lib.cms_accessible.not_released') %></h1>
2
+
3
+ <% if @valid_until && @valid_until < Time.now %>
4
+ <%= raw t(:"rails_connector.views.errors.gone.not_released_anymore", :valid_until => "<strong>#{l @valid_until}</strong>") %>
5
+ <% elsif @valid_from && Time.now < @valid_from %>
6
+ <%= raw t(:"rails_connector.views.errors.gone.not_yet_released", :valid_from => "<strong>#{l @valid_from}</strong>") %>
7
+ <% end %>
@@ -0,0 +1,17 @@
1
+ Rails.application.routes.draw do
2
+ root to: 'rails_connector/cms_dispatch#index'
3
+ match ':id(/*slug)',
4
+ to: 'rails_connector/cms_dispatch#index',
5
+ constraints: { id: /\d+|[0-9a-f]{16}/ },
6
+ as: "cms_id",
7
+ via: :all
8
+ match 'toggle_markers/:id',
9
+ to: 'rails_connector/cms_dispatch#toggle_editmarkers',
10
+ as: "toggle_markers",
11
+ via: :all
12
+ match '/*permalink',
13
+ to: 'rails_connector/cms_dispatch#index',
14
+ as: 'cms_permalink',
15
+ format: false,
16
+ via: :all
17
+ end
@@ -0,0 +1,11 @@
1
+ de:
2
+ rails_connector:
3
+ errors:
4
+ messages:
5
+ blank: "darf nicht leer sein"
6
+ forbidden:
7
+ no_permissions: "Sie haben nicht die notwendigen Zugriffsrechte"
8
+ gone:
9
+ not_released_anymore: "Die Datei war nur bis zum %{valid_until} veröffentlicht."
10
+ not_yet_released: "Die Datei wird erst am %{valid_from} veröffentlicht."
11
+
@@ -0,0 +1,6 @@
1
+ de:
2
+ rails_connector:
3
+ lib:
4
+ cms_accessible:
5
+ protected: "Die Datei ist geschützt"
6
+ not_released: "Die Datei wurde nicht veröffentlicht"
@@ -0,0 +1,9 @@
1
+ de:
2
+ rails_connector:
3
+ views:
4
+ errors:
5
+ forbidden:
6
+ no_permissions: "Sie haben nicht die notwendigen Zugriffsrechte"
7
+ gone:
8
+ not_released_anymore: "Die Datei war nur bis zum %{valid_until} veröffentlicht."
9
+ not_yet_released: "Die Datei wird erst am %{valid_from} veröffentlicht."
@@ -0,0 +1,10 @@
1
+ en:
2
+ rails_connector:
3
+ errors:
4
+ messages:
5
+ blank: "cannot be blank"
6
+ forbidden:
7
+ no_permissions: "You don't have the required permissions"
8
+ gone:
9
+ not_released_anymore: "The file was released only until %{valid_until}"
10
+ not_yet_released: "The file will be released on %{valid_from}"
@@ -0,0 +1,6 @@
1
+ en:
2
+ rails_connector:
3
+ lib:
4
+ cms_accessible:
5
+ protected: "This file is protected"
6
+ not_released: "The file has not been released"
@@ -0,0 +1,9 @@
1
+ en:
2
+ rails_connector:
3
+ views:
4
+ errors:
5
+ forbidden:
6
+ no_permissions: "You don't have the required permissions"
7
+ gone:
8
+ not_released_anymore: "The file was released only until %{valid_until}"
9
+ not_yet_released: "The file will be released on %{valid_from}"
@@ -0,0 +1,67 @@
1
+ class GemDependencies
2
+ def self.dependency_for(gem_name)
3
+ dependencies.detect{ |dep| dep[:name] == gem_name }
4
+ end
5
+
6
+ # generates code that should be included or eval'ed inside a Gemfile.
7
+ # for every rc dependency, a 'gem' statement is generated.
8
+ # this statement specifies that dependency using the _minimum_ allowed version.
9
+ #
10
+ # example:
11
+ # if the RC depends on "json", "~> 1.2.3", the following statement will be generated:
12
+ # gem "json", "= 1.2.3"
13
+ def self.minimum_version_gemfile_code(options = {})
14
+ dependencies_minimum_versions = dependencies.map do |dependency|
15
+ minimum_version = calculate_minimum_version(dependency[:version])
16
+ if minimum_version
17
+ dependency.merge(:version => "= #{minimum_version}")
18
+ else
19
+ dependency.delete(:version)
20
+ end
21
+ dependency
22
+ end
23
+
24
+ dependencies_minimum_versions.map do |dependency|
25
+ gem_name = dependency[:name]
26
+ next if gem_name == 'rails'
27
+ gem_options = ""
28
+ gem_options << ", '#{dependency[:version]}'" if dependency[:version]
29
+ gem_options <<
30
+ if options[:internal] && dependency[:git]
31
+ ", :git => '#{dependency[:git]}', :ref => '#{dependency[:ref]}', :submodules => true"
32
+ elsif options[:internal] && dependency[:path]
33
+ ", :path => '#{dependency[:path]}'"
34
+ else
35
+ ""
36
+ end
37
+ # do not require the gems here, the rails connector gem needs to do that on it's own.
38
+ # if these gems were loaded without :require => false,
39
+ # the tests would not detect a failure of the rails connector to require them.
40
+ "gem '#{gem_name}'#{gem_options}, :require => false"
41
+ end.join("\n")
42
+ end
43
+
44
+ def self.minimum_version_for(gem, version=nil)
45
+ version ||= dependencies.select do |dep|
46
+ dep[:name] == gem
47
+ end.first[:version]
48
+
49
+ calculate_minimum_version(version)
50
+ end
51
+
52
+ def self.calculate_minimum_version(version)
53
+ gem_requirement = Gem::Requirement.new(version)
54
+
55
+ minimum_requirements = gem_requirement.requirements.select do |requirement|
56
+ ["=", ">=", "~>"].include?(requirement[0])
57
+ end
58
+
59
+ if minimum_requirements.length > 1
60
+ raise "multiple minimum version requirements found for version requirement #{version}"
61
+ elsif minimum_requirements.length < 1
62
+ return nil
63
+ end
64
+
65
+ minimum_requirements[0][1]
66
+ end
67
+ end
@@ -1,6 +1,28 @@
1
- require 'rails_connector/rack_middlewares'
1
+ # @api public
2
+ module ::RailsConnector
3
+ PLATFORM_CLOUD = :cloud.freeze
4
+ PLATFORM_FIONA = :fiona.freeze
5
+
6
+ # return either <tt>:fiona</tt> or <tt>:cloud</tt> depending on the app's configuration.
7
+ # @return [Symbol]
8
+ def self.platform
9
+ PLATFORM_FIONA
10
+ end
11
+
12
+ def self.platform_cloud?
13
+ false
14
+ end
15
+
16
+ def self.platform_fiona?
17
+ true
18
+ end
19
+ end
20
+
2
21
  require 'rails_connector/core_extensions'
3
- require "rails_connector/errors"
22
+ require 'rails_connector/rack_middlewares'
23
+ require 'rails_connector/errors'
24
+ require 'rails_connector/fiona_datetime'
25
+ ActiveRecord::Type.register(:fiona_datetime, ::FionaDateTime)
4
26
 
5
27
  # @api public
6
28
  module RailsConnector
@@ -18,4 +40,5 @@ module RailsConnector
18
40
  autoload_all_sources
19
41
  end
20
42
 
21
- 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"
@@ -0,0 +1,3 @@
1
+ # empty implementation for Obj
2
+ # only unsed in case the app does not define Obj itself
3
+ ::Obj = Class.new(RailsConnector::BasicObj)
@@ -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