infopark_rails_connector 6.8.0.beta.200.621.4c8e1b0
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.
- data/README +59 -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/images/ratings/star.gif +0 -0
- data/app/assets/images/time_machine/calendar-menuarrow.gif +0 -0
- data/app/assets/images/time_machine/calendar_bg.png +0 -0
- data/app/assets/images/time_machine/icon.png +0 -0
- data/app/assets/images/time_machine/slider_bg.png +0 -0
- data/app/assets/images/time_machine/slider_handle.png +0 -0
- data/app/assets/images/time_machine/timemachine_bg.png +0 -0
- data/app/assets/javascripts/comments.js +29 -0
- data/app/assets/javascripts/editmarker.js +240 -0
- data/app/assets/javascripts/infopark_rails_connector.js.erb +3 -0
- data/app/assets/javascripts/initializer.js +9 -0
- data/app/assets/javascripts/ratings.js +26 -0
- data/app/assets/javascripts/time_machine/calendar-setup.js +200 -0
- data/app/assets/javascripts/time_machine/calendar.js +1806 -0
- data/app/assets/javascripts/time_machine/lang/calendar-de.js +127 -0
- data/app/assets/javascripts/time_machine/lang/calendar-en.js +127 -0
- data/app/assets/javascripts/time_machine/lang/calendar-es.js +129 -0
- data/app/assets/javascripts/time_machine/lang/calendar-fr.js +125 -0
- data/app/assets/javascripts/time_machine/lang/calendar-it.js +124 -0
- data/app/assets/javascripts/time_machine/slider.js +278 -0
- data/app/assets/javascripts/time_machine.js +8 -0
- data/app/assets/stylesheets/editmarker.css +70 -0
- data/app/assets/stylesheets/infopark_rails_connector.css.erb +4 -0
- data/app/assets/stylesheets/ratings.css +97 -0
- data/app/assets/stylesheets/time_machine/time_machine.css +292 -0
- data/app/assets/stylesheets/time_machine.css +6 -0
- data/app/controllers/cms_controller.rb +6 -0
- data/app/controllers/comments_controller.rb +6 -0
- data/app/controllers/crm_form_controller.rb +2 -0
- data/app/controllers/pdf_controller.rb +6 -0
- data/app/controllers/rails_connector/default_cms_controller.rb +40 -0
- data/app/controllers/rails_connector/default_comments_controller.rb +71 -0
- data/app/controllers/rails_connector/default_crm_form_controller.rb +167 -0
- data/app/controllers/rails_connector/default_pdf_controller.rb +136 -0
- data/app/controllers/rails_connector/default_ratings_controller.rb +84 -0
- data/app/controllers/rails_connector/default_rss_controller.rb +29 -0
- data/app/controllers/rails_connector/default_search_controller.rb +60 -0
- data/app/controllers/rails_connector/default_user_controller.rb +267 -0
- data/app/controllers/rails_connector/pdf_external_controller.rb +54 -0
- data/app/controllers/rails_connector/time_machine_controller.rb +48 -0
- data/app/controllers/ratings_controller.rb +6 -0
- data/app/controllers/rss_controller.rb +6 -0
- data/app/controllers/search_controller.rb +2 -0
- data/app/controllers/seo_sitemap_controller.rb +12 -0
- data/app/controllers/user_controller.rb +2 -0
- data/app/helpers/cms_helper.rb +6 -0
- data/app/helpers/cms_routing_helper.rb +6 -0
- data/app/helpers/crm_form_helper.rb +3 -0
- data/app/helpers/rails_connector/cms_asset_helper.rb +51 -0
- data/app/helpers/rails_connector/default_cms_helper.rb +27 -0
- data/app/helpers/rails_connector/default_cms_routing_helper.rb +93 -0
- data/app/helpers/rails_connector/default_crm_form_helper.rb +58 -0
- data/app/helpers/rails_connector/default_ratings_helper.rb +38 -0
- data/app/helpers/rails_connector/default_user_helper.rb +90 -0
- data/app/helpers/rails_connector/display_helper.rb +117 -0
- data/app/helpers/rails_connector/error_messages_helper.rb +23 -0
- data/app/helpers/rails_connector/layout_helper.rb +30 -0
- data/app/helpers/rails_connector/link_helper.rb +88 -0
- data/app/helpers/rails_connector/mandatory_label_helper.rb +10 -0
- data/app/helpers/rails_connector/marker_helper.rb +363 -0
- data/app/helpers/rails_connector/menu_helper.rb +72 -0
- data/app/helpers/rails_connector/micronav_helper.rb +107 -0
- data/app/helpers/rails_connector/seo_helper.rb +44 -0
- data/app/helpers/rails_connector/table_of_contents_helper.rb +20 -0
- data/app/helpers/rails_connector/time_machine_helper.rb +24 -0
- data/app/helpers/rails_connector/tracking_helper.rb +32 -0
- data/app/helpers/ratings_helper.rb +4 -0
- data/app/helpers/user_helper.rb +3 -0
- data/app/mailers/confirmation_mailer.rb +13 -0
- data/app/models/crm_form.rb +2 -0
- data/app/models/named_link.rb +2 -0
- data/app/models/obj.rb +9 -0
- data/app/models/rails_connector/default_comment.rb +28 -0
- data/app/models/rails_connector/default_rating.rb +20 -0
- data/app/models/rails_connector/link_list.rb +30 -0
- data/app/views/cms/_comments.html.erb +44 -0
- data/app/views/cms/_index.html.erb +7 -0
- data/app/views/cms/_rating.html.erb +31 -0
- data/app/views/cms/index.html.erb +3 -0
- data/app/views/comments/_comment.html.erb +28 -0
- data/app/views/confirmation_mailer/register_confirmation.erb +5 -0
- data/app/views/confirmation_mailer/reset_password.erb +5 -0
- data/app/views/crm_form/_flash_messages.html.erb +11 -0
- data/app/views/crm_form/_form.html.erb +17 -0
- data/app/views/crm_form/confirmation.html.erb +3 -0
- data/app/views/crm_form/index.html.erb +5 -0
- data/app/views/crm_form/not_logged_in.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/app/views/layouts/rails_connector/time_machine.html.erb +12 -0
- data/app/views/pdf/index.html.erb +7 -0
- data/app/views/pdf/index.xsl +1240 -0
- data/app/views/rails_connector/time_machine/index.html.erb +88 -0
- data/app/views/rss/_item.rss.builder +11 -0
- data/app/views/rss/index.rss.builder +11 -0
- data/app/views/search/_hit.html.erb +12 -0
- data/app/views/search/_hits.html.erb +11 -0
- data/app/views/search/_mini_panel.html.erb +4 -0
- data/app/views/search/_pagination.html.erb +5 -0
- data/app/views/search/_panel.html.erb +4 -0
- data/app/views/search/search.html.erb +12 -0
- data/app/views/seo_sitemap/show.xml.builder +16 -0
- data/app/views/user/_flash_messages.html.erb +11 -0
- data/app/views/user/edit.html.erb +6 -0
- data/app/views/user/edit_password.html.erb +11 -0
- data/app/views/user/forgot_password.html.erb +7 -0
- data/app/views/user/login.html.erb +15 -0
- data/app/views/user/new.html.erb +11 -0
- data/app/views/user/profile.html.erb +8 -0
- data/app/views/user/register_pending.html.erb +1 -0
- data/app/views/user/set_password.html.erb +14 -0
- data/config/cms_routes.rb +13 -0
- data/config/locales/de.rails_connector.controllers.yml +30 -0
- data/config/locales/de.rails_connector.errors.yml +11 -0
- data/config/locales/de.rails_connector.helpers.yml +9 -0
- data/config/locales/de.rails_connector.lib.yml +6 -0
- data/config/locales/de.rails_connector.models.yml +8 -0
- data/config/locales/de.rails_connector.views.yml +87 -0
- data/config/locales/en.rails_connector.controllers.yml +30 -0
- data/config/locales/en.rails_connector.errors.yml +10 -0
- data/config/locales/en.rails_connector.helpers.yml +9 -0
- data/config/locales/en.rails_connector.lib.yml +6 -0
- data/config/locales/en.rails_connector.models.yml +8 -0
- data/config/locales/en.rails_connector.views.yml +87 -0
- data/config/routes.rb +37 -0
- data/lib/generators/rails_connector/comments/comments_generator.rb +21 -0
- data/lib/generators/rails_connector/comments/templates/migration.rb +17 -0
- data/lib/generators/rails_connector/install/install_generator.rb +38 -0
- data/lib/generators/rails_connector/install/templates/initializers/rails_connector.rb +58 -0
- data/lib/generators/rails_connector/install/templates/local/configuration.rb +2 -0
- data/lib/generators/rails_connector/install/templates/obj_extensions.rb +25 -0
- data/lib/generators/rails_connector/ratings/ratings_generator.rb +21 -0
- data/lib/generators/rails_connector/ratings/templates/migration.rb +15 -0
- data/lib/infopark_rails_connector.rb +31 -0
- data/lib/obj_extensions.rb +6 -0
- data/lib/rails_connector/authenticable.rb +30 -0
- data/lib/rails_connector/cms_accessible.rb +114 -0
- data/lib/rails_connector/cms_dispatch_controller.rb +47 -0
- data/lib/rails_connector/cms_env.rb +55 -0
- data/lib/rails_connector/cms_test_request.rb +23 -0
- data/lib/rails_connector/commentable.rb +23 -0
- data/lib/rails_connector/configuration/google_analytics.rb +29 -0
- data/lib/rails_connector/configuration/pdf_generator.rb +15 -0
- data/lib/rails_connector/configuration/rss.rb +46 -0
- data/lib/rails_connector/configuration.rb +235 -0
- data/lib/rails_connector/core_extensions/time.rb +18 -0
- data/lib/rails_connector/core_extensions.rb +1 -0
- data/lib/rails_connector/crm.rb +282 -0
- data/lib/rails_connector/engine.rb +78 -0
- data/lib/rails_connector/fop.rb +18 -0
- data/lib/rails_connector/fop_on_rails/document/dom_tree.rb +42 -0
- data/lib/rails_connector/fop_on_rails/document/images.rb +34 -0
- data/lib/rails_connector/fop_on_rails/document/tables.rb +67 -0
- data/lib/rails_connector/fop_on_rails/document.rb +25 -0
- data/lib/rails_connector/fop_on_rails.rb +92 -0
- data/lib/rails_connector/googlebot_checker.rb +47 -0
- data/lib/rails_connector/html_string.rb +19 -0
- data/lib/rails_connector/infopark_base.rb +2 -0
- data/lib/rails_connector/link_resolvable.rb +9 -0
- data/lib/rails_connector/liquid_support/action_marker.rb +69 -0
- data/lib/rails_connector/liquid_support/field_value_drop.rb +22 -0
- data/lib/rails_connector/liquid_support/general_helper_tag.rb +44 -0
- data/lib/rails_connector/liquid_support/link_drop.rb +22 -0
- data/lib/rails_connector/liquid_support/liquid_template_handler.rb +162 -0
- data/lib/rails_connector/liquid_support/named_object_drop.rb +14 -0
- data/lib/rails_connector/liquid_support/obj_drop.rb +43 -0
- data/lib/rails_connector/liquid_support/obj_filters.rb +77 -0
- data/lib/rails_connector/liquid_support.rb +23 -0
- data/lib/rails_connector/markdown_string.rb +19 -0
- data/lib/rails_connector/rateable.rb +57 -0
- data/lib/rails_connector/seo.rb +52 -0
- data/lib/rails_connector/ses.rb +72 -0
- data/lib/rails_connector/string_tagging.rb +29 -0
- data/lib/rails_connector/syndicateable.rb +11 -0
- data/lib/search_request.rb +2 -0
- data/lib/tasks/check.rake +25 -0
- data/lib/tasks/cms_license_check.rake +17 -0
- metadata +489 -0
@@ -0,0 +1,235 @@
|
|
1
|
+
require "helpful_configuration"
|
2
|
+
|
3
|
+
require "rails_connector/cms_base_model"
|
4
|
+
require "rails_connector/blob"
|
5
|
+
|
6
|
+
module RailsConnector
|
7
|
+
|
8
|
+
# RailsConnector::Configuration is used to en/disable and initialize addons.
|
9
|
+
class Configuration
|
10
|
+
DEFAULT_MODE = :live
|
11
|
+
|
12
|
+
#
|
13
|
+
# Default fields which the +DefaultUserController+ will store in the session.
|
14
|
+
#
|
15
|
+
DEFAULT_STORE_USER_ATTRS_IN_SESSION = [:login, :first_name, :last_name, :email, :id]
|
16
|
+
|
17
|
+
@features = {}
|
18
|
+
|
19
|
+
class << self
|
20
|
+
# Automatically generate editmarkers when rendering liquid templates in editor mode.
|
21
|
+
attr_accessor :auto_liquid_editmarkers
|
22
|
+
|
23
|
+
# there are three available modes for the rails connector:
|
24
|
+
# <tt>live</tt> (show released contents only),
|
25
|
+
# <tt>preview</tt> (show edited contents)
|
26
|
+
# <tt>editor</tt> (show edited contents and editor interface (e.g. edit markers))
|
27
|
+
# Default mode is <tt>live</tt>.
|
28
|
+
attr_accessor :mode
|
29
|
+
|
30
|
+
# default options for SearchRequest
|
31
|
+
attr_writer :search_options
|
32
|
+
|
33
|
+
def search_options
|
34
|
+
@search_options || local_config_file["search"].symbolize_keys
|
35
|
+
end
|
36
|
+
|
37
|
+
def mode=(new_mode) #:nodoc:#
|
38
|
+
new_mode = new_mode.to_sym
|
39
|
+
raise ArgumentError, "Unknown Mode #{new_mode}" unless [:editor, :preview, :live].include?(new_mode)
|
40
|
+
@mode = new_mode
|
41
|
+
end
|
42
|
+
|
43
|
+
def mode #:nodoc:#
|
44
|
+
@mode || DEFAULT_MODE
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Sets the array of fields which the +DefaultUserController+ will store in the session.
|
49
|
+
# Defaults to +DEFAULT_STORE_USER_ATTRS_IN_SESSION+.
|
50
|
+
#
|
51
|
+
attr_writer :store_user_attrs_in_session
|
52
|
+
|
53
|
+
#
|
54
|
+
# Returns fields which the +DefaultUserController+ stores in the session.
|
55
|
+
#
|
56
|
+
def store_user_attrs_in_session
|
57
|
+
@store_user_attrs_in_session || DEFAULT_STORE_USER_ATTRS_IN_SESSION
|
58
|
+
end
|
59
|
+
|
60
|
+
def editor_interface_enabled? #:nodoc:#
|
61
|
+
mode == :editor
|
62
|
+
end
|
63
|
+
|
64
|
+
def use_edited_content? #:nodoc:#
|
65
|
+
mode == :preview || mode == :editor
|
66
|
+
end
|
67
|
+
|
68
|
+
def register_features(*features) #:nodoc:
|
69
|
+
features.each do |f|
|
70
|
+
@features.merge!(f.to_sym => false)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
alias :register_feature :register_features
|
74
|
+
|
75
|
+
def registered_features #:nodoc:
|
76
|
+
@features.keys
|
77
|
+
end
|
78
|
+
|
79
|
+
# Rails Connector Addons can be enabled as follows (in <tt>config/rails_connector.rb</tt>):
|
80
|
+
#
|
81
|
+
# RailsConnector::Configuration.enable(
|
82
|
+
# :search,
|
83
|
+
# :time_machine,
|
84
|
+
# :pdf_generator,
|
85
|
+
# :crm
|
86
|
+
# )
|
87
|
+
#
|
88
|
+
def enable(*features)
|
89
|
+
features.each do |f|
|
90
|
+
assert_feature_is_known(f)
|
91
|
+
@features[f.to_sym] = true
|
92
|
+
end
|
93
|
+
initialize_addon_mixins
|
94
|
+
end
|
95
|
+
|
96
|
+
# Returns true if +feature+ is enabled, else false.
|
97
|
+
def enabled?(feature)
|
98
|
+
assert_feature_is_known(feature)
|
99
|
+
@features[feature.to_sym] == true
|
100
|
+
end
|
101
|
+
|
102
|
+
# Configures your CMS instance name.
|
103
|
+
#
|
104
|
+
# Example call as to be used in <tt>rails_connector.rb</tt>:
|
105
|
+
# RailsConnector::Configuration.instance_name = 'internet'
|
106
|
+
def instance_name=(name)
|
107
|
+
RailsConnector::CmsBaseModel.instance_name = name
|
108
|
+
end
|
109
|
+
|
110
|
+
def after_initialize #:nodoc:
|
111
|
+
enable_authentication
|
112
|
+
# Hier muss explizit der Namespace verwendet werden, da diese Methode von Rails
|
113
|
+
# während der Initialisierung aufgerufen wird.
|
114
|
+
::RailsConnector::Obj.configure_for_content(
|
115
|
+
::RailsConnector::Configuration.use_edited_content? ? :edited : :released
|
116
|
+
)
|
117
|
+
end
|
118
|
+
|
119
|
+
def to_prepare #:nodoc:
|
120
|
+
unless Rails.configuration.cache_classes
|
121
|
+
after_initialize
|
122
|
+
NamedLink.reset_cache
|
123
|
+
initialize_addon_mixins
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def configure_cms_database
|
128
|
+
if RailsConnector::CmsBaseModel.superclass.to_s == "ActiveRecord::Base"
|
129
|
+
CmsBaseModel.configure_database("cms")
|
130
|
+
else
|
131
|
+
CmsBaseModel.configure_database(local_config_file["cms_database"])
|
132
|
+
Blob.configure(local_config_file["cms_blob_storage"])
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def license #:nodoc:
|
137
|
+
license_file.read
|
138
|
+
end
|
139
|
+
|
140
|
+
def license_file #:nodoc:
|
141
|
+
@license_file.presence || Rails.root + "config" + "license.xml"
|
142
|
+
end
|
143
|
+
|
144
|
+
def license_file=(license_file) #:nodoc:
|
145
|
+
@license_file = license_file.presence && Pathname(license_file)
|
146
|
+
end
|
147
|
+
|
148
|
+
def cms_routes(*args) #:nodoc:
|
149
|
+
raise <<-EOS.gsub(/\s+/, ' ')
|
150
|
+
Calling RailsConnector::Configuration.cms_routes is not needed anymore.
|
151
|
+
Please remove it from config/routes.rb
|
152
|
+
EOS
|
153
|
+
end
|
154
|
+
|
155
|
+
def use_x_sendfile=(value) #:nodoc:
|
156
|
+
raise 'Configuration.use_x_sendfile is now available as Rails configuration:'\
|
157
|
+
' config.action_dispatch.x_sendfile_header = "X-Sendfile"'
|
158
|
+
end
|
159
|
+
|
160
|
+
def initialize_addon_mixins #:nodoc:
|
161
|
+
::ApplicationController.__send__(:helper, :cms)
|
162
|
+
if enabled?(:search)
|
163
|
+
require "rails_connector/ses"
|
164
|
+
RailsConnector::SES.enable
|
165
|
+
end
|
166
|
+
RailsConnector::Crm.enable if enabled?(:crm)
|
167
|
+
::Obj.__send__(:include, RailsConnector::Syndicateable) if enabled?(:rss)
|
168
|
+
::Obj.__send__(:include, RailsConnector::Commentable) if enabled?(:comments)
|
169
|
+
::Obj.__send__(:include, RailsConnector::Rateable) if enabled?(:ratings)
|
170
|
+
end
|
171
|
+
|
172
|
+
def local_config_file #:nodoc:
|
173
|
+
@local_config_file ||= read_local_config_file
|
174
|
+
end
|
175
|
+
|
176
|
+
def local_config_file_name #:nodoc:
|
177
|
+
(Rails.root + "config/rails_connector.yml").expand_path
|
178
|
+
end
|
179
|
+
|
180
|
+
# for test purposes only
|
181
|
+
def reset_local_config_file_cache #:nodoc:
|
182
|
+
@local_config_file = nil
|
183
|
+
end
|
184
|
+
|
185
|
+
protected
|
186
|
+
|
187
|
+
def read_local_config_file
|
188
|
+
contents = YAML.load_file(local_config_file_name) if File.exists?(local_config_file_name)
|
189
|
+
contents ||= {}
|
190
|
+
|
191
|
+
config = HelpfulConfiguration.new(
|
192
|
+
contents,
|
193
|
+
local_config_file_name
|
194
|
+
)
|
195
|
+
config.explain(
|
196
|
+
"cms_database",
|
197
|
+
"a hash of options, including type, that specify the database configuration"
|
198
|
+
)
|
199
|
+
config.explain(
|
200
|
+
"cms_blob_storage",
|
201
|
+
"a hash of options, including type, that specify the cms blob storage configuration"
|
202
|
+
)
|
203
|
+
config.explain(
|
204
|
+
"search",
|
205
|
+
"a hash of options that specify access to the search server"
|
206
|
+
)
|
207
|
+
|
208
|
+
config
|
209
|
+
end
|
210
|
+
|
211
|
+
def assert_feature_is_known(f) #:nodoc:
|
212
|
+
raise ArgumentError, "unknown feature: #{f.inspect}" unless @features.keys.include?(f.to_sym)
|
213
|
+
end
|
214
|
+
|
215
|
+
def enable_authentication #:nodoc:
|
216
|
+
# Wenn das OMC-Features an ist, dann braucht man keine Standardimplementierung
|
217
|
+
# für die Authentifizierung.
|
218
|
+
unless enabled?(:crm)
|
219
|
+
::ApplicationController.__send__(:include, RailsConnector::Authenticable)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
# defaults
|
225
|
+
self.auto_liquid_editmarkers = true
|
226
|
+
|
227
|
+
register_features(
|
228
|
+
:search, :time_machine, :pdf_generator, :rss, :comments, :ratings,
|
229
|
+
:crm, :seo_sitemap, :google_analytics
|
230
|
+
)
|
231
|
+
end
|
232
|
+
|
233
|
+
class ConfigurationError < StandardError # :nodoc:
|
234
|
+
end
|
235
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Time #:nodoc:
|
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
|
@@ -0,0 +1 @@
|
|
1
|
+
require "rails_connector/core_extensions/time"
|
@@ -0,0 +1,282 @@
|
|
1
|
+
module RailsConnector
|
2
|
+
|
3
|
+
# This module provides high-level access to the Infopark Online Marketing Cockpit.
|
4
|
+
#
|
5
|
+
# Methods from the +AuthenticationSupport+ module are included
|
6
|
+
# in all controllers when enabling the Crm feature in your RailsConnector configuration:
|
7
|
+
#
|
8
|
+
# RailsConnector::Configuration.enable(
|
9
|
+
# :crm
|
10
|
+
# )
|
11
|
+
module Crm
|
12
|
+
|
13
|
+
# This method requires the omc_connector gem.
|
14
|
+
#
|
15
|
+
# If the gem is available, it does the following:
|
16
|
+
# * require it
|
17
|
+
# * include +AuthenticationSupport+ in +ApplicationController+
|
18
|
+
# * declares helper methods in +ApplicationController+
|
19
|
+
# * adds a class-inheritable array to +ApplicationController+ for convenience
|
20
|
+
# (see +session_attributes_for+)
|
21
|
+
#
|
22
|
+
# If not, it raises a +LoadError+.
|
23
|
+
def self.enable #:nodoc:
|
24
|
+
require 'infopark_crm_connector'
|
25
|
+
ApplicationController.__send__(:include, AuthenticationSupport)
|
26
|
+
end
|
27
|
+
|
28
|
+
module AuthenticationSupport
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def self.included(base) # :nodoc:
|
33
|
+
base.helper_method :logged_in?, :current_user, :admin?
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Returns a hash of attributes for the given user that are to be stored in the session.
|
38
|
+
#
|
39
|
+
# Uses the array +RailsConnector::Configuration.store_user_attrs_in_session+ to determine which
|
40
|
+
# fields to store.
|
41
|
+
# Because the field <tt>:id</tt> must always be stored in the session, it is always in the array
|
42
|
+
# returned by +session_attributes_for+, independent on the fields specified by
|
43
|
+
# +RailsConnector::Configuration.store_user_attrs_in_session+.
|
44
|
+
#
|
45
|
+
# User live_server_groups are stored in the session by default.
|
46
|
+
#
|
47
|
+
def session_attributes_for(user) # :nodoc:
|
48
|
+
attributes = {}
|
49
|
+
serialized_attributes = \
|
50
|
+
user.attributes.merge(:live_server_groups => user.live_server_groups).symbolize_keys
|
51
|
+
(RailsConnector::Configuration.store_user_attrs_in_session + [:id]).each do |attr|
|
52
|
+
attributes[attr.to_sym] = serialized_attributes[attr.to_sym]
|
53
|
+
end
|
54
|
+
attributes[:live_server_groups] = serialized_attributes[:live_server_groups]
|
55
|
+
attributes
|
56
|
+
end
|
57
|
+
|
58
|
+
# Determines if the user is logged in.
|
59
|
+
# Defined as helper method in +ApplicationController+ when enabling the Crm feature.
|
60
|
+
def logged_in?
|
61
|
+
!session[:user].blank?
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Returns a +Contact+ object with attributes stored in the session.
|
66
|
+
#
|
67
|
+
# To change which fields +DefaultUserController+ stores in the session use
|
68
|
+
# +RailsConnector::Configuration.store_user_attrs_in_session+.
|
69
|
+
#
|
70
|
+
def current_user
|
71
|
+
@current_user ||= if logged_in?
|
72
|
+
user_session = session[:user].dup
|
73
|
+
live_server_groups = user_session.delete(:live_server_groups)
|
74
|
+
user = Infopark::Crm::Contact.new(user_session || {})
|
75
|
+
user.live_server_groups = live_server_groups
|
76
|
+
user
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Takes a +Contact+ object and stores its user attributes in the session.
|
81
|
+
#
|
82
|
+
# This can be helpful if you want to set a user for e.g. Googlebot.
|
83
|
+
def current_user=(user)
|
84
|
+
@current_user = user
|
85
|
+
session[:user] = user.nil? ? nil : session_attributes_for(user)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Reloads the +Contact+ object in +current_user+ from the WebCRM,
|
89
|
+
# and updates the user attribute cached in the session.
|
90
|
+
def reload_current_user
|
91
|
+
user = current_user
|
92
|
+
user.reload
|
93
|
+
self.current_user = user
|
94
|
+
end
|
95
|
+
|
96
|
+
# Determines if the current user is admin (+false+ by default).
|
97
|
+
# Being admin eables to user to delete comments and reset ratings.
|
98
|
+
# Defined as helper method in +ApplicationController+ when enabling the CRM feature.
|
99
|
+
#
|
100
|
+
# To change the default behavior overwride <tt>admin?</tt> in your ApplicationController.
|
101
|
+
#
|
102
|
+
# class ApplicationController < ActionController::Base
|
103
|
+
#
|
104
|
+
# private
|
105
|
+
#
|
106
|
+
# def admin?
|
107
|
+
# logged_in? && current_user.live_server_groups.include?("admins")
|
108
|
+
# end
|
109
|
+
#
|
110
|
+
# end
|
111
|
+
def admin?
|
112
|
+
false
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
# :stopdoc:
|
118
|
+
module Localizable
|
119
|
+
# --------------------------------------------
|
120
|
+
# This module can be included in controllers
|
121
|
+
# that interface the WebCRM so error messages
|
122
|
+
# are localized
|
123
|
+
# --------------------------------------------
|
124
|
+
def self.included(base)
|
125
|
+
base.before_filter :set_crm_language
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def set_crm_language
|
131
|
+
Infopark::Crm.configure {|config| config.locale = I18n.locale.to_s }
|
132
|
+
end
|
133
|
+
end
|
134
|
+
# :startdoc:
|
135
|
+
|
136
|
+
# :stopdoc:
|
137
|
+
module Sanitization
|
138
|
+
# --------------------------------------------
|
139
|
+
# This module is included in controllers to
|
140
|
+
# sanitize user input, in reference to a given
|
141
|
+
# whitelist
|
142
|
+
# --------------------------------------------
|
143
|
+
|
144
|
+
private
|
145
|
+
|
146
|
+
def sanitize_user_params(user_params_or_nil, whitelist)
|
147
|
+
user_params = user_params_or_nil || {}
|
148
|
+
|
149
|
+
filtered_contact_attrs = filter_params_hash(
|
150
|
+
user_params, whitelist[:contact]
|
151
|
+
)
|
152
|
+
|
153
|
+
filtered_contact_attrs
|
154
|
+
end
|
155
|
+
|
156
|
+
def filter_params_hash(source_hash, allowed_keys_unstringified)
|
157
|
+
return {} unless source_hash
|
158
|
+
allowed_keys = allowed_keys_unstringified.map(&:to_s)
|
159
|
+
source_hash.reject { |key, value| !allowed_keys.include?(key) }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
# :startdoc:
|
163
|
+
|
164
|
+
# This module is included in +DefaultUserController+ to provide callbacks for user functionality.
|
165
|
+
#
|
166
|
+
# If you want to add behavior before or after authentication, logout or register, override any of
|
167
|
+
# the methods included in this module in your +UserController+.
|
168
|
+
module Callbacks
|
169
|
+
|
170
|
+
# :stopdoc:
|
171
|
+
# --------------------------------------------
|
172
|
+
# This module is documented in sections
|
173
|
+
# because RDoc orders methods alphabetically,
|
174
|
+
# which doesn't make sense here.
|
175
|
+
# --------------------------------------------
|
176
|
+
# :startdoc:
|
177
|
+
|
178
|
+
private
|
179
|
+
|
180
|
+
# :section: "Before" callbacks
|
181
|
+
|
182
|
+
# Called by +DefaultUserController+ on POST requests before a user is authenticated,
|
183
|
+
# i.e. the user has already provided credentials in a form.
|
184
|
+
#
|
185
|
+
# By default, it doesn't do anything.
|
186
|
+
def before_authenticate
|
187
|
+
end
|
188
|
+
|
189
|
+
# Called by +DefaultUserController+ before a user is logged out,
|
190
|
+
# i.e. the session is reset.
|
191
|
+
#
|
192
|
+
# By default, it doesn't do anything.
|
193
|
+
def before_logout
|
194
|
+
end
|
195
|
+
|
196
|
+
# Called by +DefaultUserController+ on POST requests before a user is created,
|
197
|
+
# i.e. the user has already provided name, e-mail etc. in a form.
|
198
|
+
#
|
199
|
+
# By default, it doesn't do anything.
|
200
|
+
def before_register
|
201
|
+
end
|
202
|
+
|
203
|
+
# :section: "After" callbacks
|
204
|
+
|
205
|
+
# Called by +DefaultUserController+ on POST requests after a user is authenticated,
|
206
|
+
# i.e. the user has already provided correct credentials but the session has not yet been set.
|
207
|
+
#
|
208
|
+
# By default, it doesn't do anything.
|
209
|
+
def after_authenticate
|
210
|
+
end
|
211
|
+
|
212
|
+
# Called by +DefaultUserController+ after a user is logged out,
|
213
|
+
# i.e. the session is reset.
|
214
|
+
#
|
215
|
+
# By default, it doesn't do anything.
|
216
|
+
def after_logout
|
217
|
+
end
|
218
|
+
|
219
|
+
# Called by +DefaultUserController+ on POST requests after a user is created,
|
220
|
+
# i.e. a WebCRM activity has been created or the user has been created directly in the WebCRM.
|
221
|
+
#
|
222
|
+
# By default, it doesn't do anything.
|
223
|
+
def after_register
|
224
|
+
end
|
225
|
+
|
226
|
+
# :section: WebCRM error handling
|
227
|
+
|
228
|
+
# Called by +DefaultUserController+ whenever requests to the WebCRM fail.
|
229
|
+
# This includes <tt>Errno::ECONNREFUSED</tt> or the ActiveResource errors +ForbiddenAccess+,
|
230
|
+
# +UnauthorizedAccess+, and +BadRequest+.
|
231
|
+
#
|
232
|
+
# By default, it raises an error so that administrators are notified immediately
|
233
|
+
# if the WebCRM is down or not configured properly.
|
234
|
+
def on_crm_error(exception)
|
235
|
+
raise exception
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
239
|
+
|
240
|
+
# :stopdoc:
|
241
|
+
# Default attributes for WebCRM's Contact.
|
242
|
+
#
|
243
|
+
# Helpers like +form_for+ will fail on +ActiveResource+ attributes
|
244
|
+
# until those attributes are set.
|
245
|
+
# See http://www.ruby-forum.com/topic/113542
|
246
|
+
#
|
247
|
+
# This constant provides default values for nearly all attributes.
|
248
|
+
#
|
249
|
+
# You are free to use any of these attributes in your views.
|
250
|
+
# If you try to use others, +form_for+ will fail.
|
251
|
+
CONTACT_DEFAULT_ATTRS = {
|
252
|
+
:id => '',
|
253
|
+
:account_id => '',
|
254
|
+
:org_name_address => '',
|
255
|
+
:org_unit_address => '',
|
256
|
+
:extended_address => '',
|
257
|
+
:street_address => '',
|
258
|
+
:postalcode => '',
|
259
|
+
:locality => '',
|
260
|
+
:region => '',
|
261
|
+
:country => '',
|
262
|
+
:email => '',
|
263
|
+
:fax => '',
|
264
|
+
:first_name => '',
|
265
|
+
:gender => 'N',
|
266
|
+
:job_title => '',
|
267
|
+
:language => 'en',
|
268
|
+
:last_name => '',
|
269
|
+
:login => '',
|
270
|
+
:mobile_phone => '',
|
271
|
+
:name_prefix => '',
|
272
|
+
:phone => '',
|
273
|
+
:want_geo_location => '',
|
274
|
+
:want_email => 0,
|
275
|
+
:want_phonecall => 0,
|
276
|
+
:want_snailmail => 0
|
277
|
+
}.stringify_keys
|
278
|
+
# :startdoc:
|
279
|
+
|
280
|
+
end
|
281
|
+
|
282
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "rails"
|
2
|
+
require "action_view"
|
3
|
+
require "will_paginate"
|
4
|
+
|
5
|
+
require 'jquery-rails'
|
6
|
+
|
7
|
+
require 'rails_connector/configuration'
|
8
|
+
|
9
|
+
module ::RailsConnector
|
10
|
+
class Engine < Rails::Engine #:nodoc:
|
11
|
+
config.to_prepare { RailsConnector::Configuration.to_prepare }
|
12
|
+
config.after_initialize { RailsConnector::Configuration.after_initialize }
|
13
|
+
|
14
|
+
initializer "rails_connector.add_cms_routing_paths", :after => :add_routing_paths do |app|
|
15
|
+
cms_route = File.expand_path("cms_routes.rb", paths['config'].to_a.first)
|
16
|
+
app.routes_reloader.paths.push(cms_route)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Expose rails connector runtime to controller for logging.
|
20
|
+
initializer "rails_connector.log_runtime" do |app|
|
21
|
+
runtime =
|
22
|
+
begin
|
23
|
+
RailsConnector::ControllerRuntime
|
24
|
+
rescue NameError
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
if runtime
|
29
|
+
RailsConnector::LogSubscriber.attach_to :rails_connector
|
30
|
+
ActiveSupport.on_load(:action_controller) do
|
31
|
+
include runtime
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# make sure our exceptions cause an adequate error page and http status code
|
37
|
+
initializer "rails_connector.register_exceptions" do |app|
|
38
|
+
responses = ActionDispatch::ShowExceptions.rescue_responses
|
39
|
+
responses["RailsConnector::ResourceNotFound"] = :not_found
|
40
|
+
end
|
41
|
+
|
42
|
+
initializer "rails_connector.configure_database" do |app|
|
43
|
+
RailsConnector::Configuration.configure_cms_database
|
44
|
+
end
|
45
|
+
|
46
|
+
initializer "rails_connector.liquid_support" do
|
47
|
+
# Liquid Gem integration
|
48
|
+
ActionView::Template.register_template_handler(
|
49
|
+
:liquid, ::RailsConnector::LiquidSupport::LiquidTemplateHandler
|
50
|
+
)
|
51
|
+
if Rails.env.test? && ::RailsConnector::LiquidSupport.raise_template_errors == nil
|
52
|
+
::RailsConnector::LiquidSupport.raise_template_errors = true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
initializer "rails_connector.routing_helpers" do
|
57
|
+
if Rails.env == 'test'
|
58
|
+
ActionDispatch::TestRequest.__send__(:include, RailsConnector::CmsTestRequest)
|
59
|
+
end
|
60
|
+
|
61
|
+
ActionController::Base.__send__(:include, CmsRoutingHelper)
|
62
|
+
ActionView::Base.__send__(:include, CmsRoutingHelper)
|
63
|
+
end
|
64
|
+
|
65
|
+
initializer "rails_connector.config_local", :after => :load_config_initializers,
|
66
|
+
:before => :engines_blank_point do
|
67
|
+
Dir.glob(Rails.root.join('config', 'local', '*.rb')).each do |file|
|
68
|
+
require file
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
config.autoload_paths += paths['lib'].to_a
|
73
|
+
config.autoload_once_paths += paths['app/helpers'].to_a + paths['lib'].to_a
|
74
|
+
|
75
|
+
RailsConnector.rack_middlewares.each { |middleware| config.app_middleware.use middleware }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RailsConnector
|
2
|
+
module Fop
|
3
|
+
#
|
4
|
+
# Is raised if the PDF generation fails.
|
5
|
+
# The error message contains the Java error stack trace of the Apache FOP.
|
6
|
+
#
|
7
|
+
class GenerationFailed < RuntimeError; end
|
8
|
+
|
9
|
+
CMD = 'fop -xml "%s" -xsl "%s" -pdf "%s" 2>&1' # :nodoc:
|
10
|
+
|
11
|
+
def self.generate_pdf(xml, xsl, pdf) # :nodoc:
|
12
|
+
output = `#{CMD % [xml, xsl, pdf]}`
|
13
|
+
unless `file -pb "#{pdf}"`.include?('PDF')
|
14
|
+
raise GenerationFailed, output
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'tidy'
|
2
|
+
require "rexml/document"
|
3
|
+
|
4
|
+
module RailsConnector
|
5
|
+
module FopOnRails
|
6
|
+
module Document # :nodoc: all
|
7
|
+
module DomTree
|
8
|
+
TIDY_CONF = {
|
9
|
+
'clean' => true,
|
10
|
+
'doctype' => 'omit',
|
11
|
+
'output-xhtml' => true,
|
12
|
+
'numeric-entities' => true,
|
13
|
+
'drop-font-tags' => true,
|
14
|
+
'enclose-block-text' => true,
|
15
|
+
'char-encoding' => 'utf8'
|
16
|
+
}
|
17
|
+
|
18
|
+
def self.repair(data)
|
19
|
+
xml = REXML::Document.new(tidy(data))
|
20
|
+
clean_namespace(xml)
|
21
|
+
return xml
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def self.tidy(data)
|
27
|
+
%w(dylib so).each do |ext|
|
28
|
+
if File.exist?(path = "/usr/lib/libtidy.#{ext}")
|
29
|
+
Tidy.path = path
|
30
|
+
break
|
31
|
+
end
|
32
|
+
end
|
33
|
+
Tidy.open(TIDY_CONF) { |tidy| tidy.clean(data) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.clean_namespace(xml)
|
37
|
+
xml.root.delete_namespace
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|