infopark_fiona_connector 6.9.4 → 6.10.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/app/assets/images/admin/minus.gif +0 -0
- data/app/assets/images/bg80.png +0 -0
- data/app/assets/images/edit.png +0 -0
- data/app/assets/images/icons/mm_generic.png +0 -0
- data/app/assets/images/icons/mm_menu.png +0 -0
- data/app/assets/javascripts/editmarker.js +240 -0
- data/app/assets/javascripts/infopark_rails_connector.js.erb +0 -0
- data/app/assets/stylesheets/editmarker.css +70 -0
- data/app/assets/stylesheets/infopark_rails_connector.css.erb +0 -0
- data/app/controllers/cms_controller.rb +7 -0
- data/app/controllers/rails_connector/default_cms_controller.rb +43 -0
- data/app/helpers/cms_helper.rb +7 -0
- data/app/helpers/cms_routing_helper.rb +7 -0
- data/app/helpers/rails_connector/cms_asset_helper.rb +2 -1
- data/app/helpers/rails_connector/default_cms_helper.rb +23 -0
- data/app/helpers/rails_connector/default_cms_routing_helper.rb +120 -0
- data/app/helpers/rails_connector/layout_helper.rb +29 -0
- data/app/helpers/rails_connector/marker_helper.rb +1 -3
- data/app/helpers/rails_connector/table_of_contents_helper.rb +22 -0
- data/app/models/named_link.rb +2 -0
- data/app/views/cms/_index.html.erb +7 -0
- data/app/views/cms/index.html.erb +1 -0
- data/app/views/errors/403_forbidden.html.erb +3 -0
- data/app/views/errors/410_gone.html.erb +7 -0
- data/config/cms_routes.rb +17 -0
- data/config/locales/de.rails_connector.errors.yml +11 -0
- data/config/locales/de.rails_connector.lib.yml +6 -0
- data/config/locales/de.rails_connector.views.yml +9 -0
- data/config/locales/en.rails_connector.errors.yml +10 -0
- data/config/locales/en.rails_connector.lib.yml +6 -0
- data/config/locales/en.rails_connector.views.yml +9 -0
- data/lib/gem_dependencies.rb +67 -0
- data/lib/infopark_fiona_connector.rb +22 -0
- data/lib/obj.rb +3 -0
- data/lib/rails_connector/authenticable.rb +30 -0
- data/lib/rails_connector/basic_obj.rb +2 -2
- data/lib/rails_connector/blob.rb +2 -4
- data/lib/rails_connector/blob_mysql.rb +1 -1
- data/lib/rails_connector/blob_oracle.rb +1 -1
- data/lib/rails_connector/cms_accessible.rb +114 -0
- data/lib/rails_connector/cms_dispatch_controller.rb +46 -0
- data/lib/rails_connector/cms_env.rb +68 -0
- data/lib/rails_connector/cms_test_request.rb +23 -0
- data/lib/rails_connector/core_extensions.rb +1 -0
- data/lib/rails_connector/core_extensions/time.rb +18 -0
- data/lib/rails_connector/engine.rb +64 -0
- data/lib/rails_connector/html_string.rb +19 -0
- data/lib/rails_connector/link_list.rb +32 -0
- data/lib/rails_connector/link_resolvable.rb +9 -0
- data/lib/rails_connector/markdown_string.rb +19 -0
- data/lib/rails_connector/named_link.rb +1 -1
- data/lib/rails_connector/string_tagging.rb +29 -0
- data/lib/version.rb +7 -0
- metadata +155 -35
- data/README +0 -5
@@ -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
|
-
|
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 @@
|
|
1
|
+
<%= render :partial => 'index' %>
|
@@ -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,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,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,3 +1,24 @@
|
|
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
|
+
|
21
|
+
require 'rails_connector/core_extensions'
|
1
22
|
require 'rails_connector/rack_middlewares'
|
2
23
|
require 'rails_connector/core_extensions'
|
3
24
|
require "rails_connector/errors"
|
@@ -18,4 +39,5 @@ module RailsConnector
|
|
18
39
|
autoload_all_sources
|
19
40
|
end
|
20
41
|
|
42
|
+
require "rails_connector/engine" if defined?(Rails)
|
21
43
|
require "rails_connector/fiona_engine" if defined?(Rails)
|
data/lib/obj.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module RailsConnector
|
2
|
+
module Authenticable
|
3
|
+
def self.included(mod)
|
4
|
+
%w(logged_in? admin? current_user).each do |method_name|
|
5
|
+
unless instance_method_defined?(mod, method_name)
|
6
|
+
mod.class_eval do
|
7
|
+
private
|
8
|
+
define_method(method_name, InstanceMethods.method(method_name).to_proc)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
mod.send(:helper_method, method_name)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module InstanceMethods
|
17
|
+
def self.logged_in?; false; end
|
18
|
+
def self.admin?; false; end
|
19
|
+
def self.current_user; nil; end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def self.instance_method_defined?(mod, method_name)
|
25
|
+
(
|
26
|
+
mod.instance_methods + mod.protected_instance_methods + mod.private_instance_methods
|
27
|
+
).map(&:to_s).include?(method_name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -262,7 +262,7 @@ module RailsConnector
|
|
262
262
|
# @api public
|
263
263
|
def toclist(*args)
|
264
264
|
return [] unless publication?
|
265
|
-
toclist = children.
|
265
|
+
toclist = children.to_a.select{ |toc| toc.exportable? }
|
266
266
|
toclist = toclist.reject { |toc| toc.binary? } unless args.include?(:all)
|
267
267
|
toclist
|
268
268
|
end
|
@@ -566,7 +566,7 @@ module RailsConnector
|
|
566
566
|
|
567
567
|
def self.try_type
|
568
568
|
result = yield
|
569
|
-
result if
|
569
|
+
result if result < CmsBaseModel
|
570
570
|
rescue NameError, ActiveRecord::ActiveRecordError
|
571
571
|
nil
|
572
572
|
end
|
data/lib/rails_connector/blob.rb
CHANGED
@@ -7,10 +7,8 @@ module RailsConnector
|
|
7
7
|
|
8
8
|
class << self
|
9
9
|
# Does not retrieve the column blob_data.
|
10
|
-
def find_with_excluded_blob_data(
|
11
|
-
|
12
|
-
args.last[:select] = 'blob_name, blob_length'
|
13
|
-
find_without_excluded_blob_data(*args)
|
10
|
+
def find_with_excluded_blob_data(primary_key)
|
11
|
+
select(:blob_name, :blob_length).find(primary_key)
|
14
12
|
end
|
15
13
|
|
16
14
|
alias_method_chain :find, :excluded_blob_data
|
@@ -13,7 +13,7 @@ module RailsConnector
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def fetch_into_file(file)
|
16
|
-
mysql2_client = connection.
|
16
|
+
mysql2_client = self.class.connection.raw_connection
|
17
17
|
ActiveRecord::Base.logger.debug "Streaming blob from MySQL2 into #{file.path}"
|
18
18
|
|
19
19
|
table_name = mysql2_client.escape(self.class.table_name)
|
@@ -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
|