trusty-cms 4.1.1 → 4.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -3
- data/Gemfile.lock +107 -107
- data/README.md +1 -1
- data/Rakefile +7 -7
- data/app/assets/javascripts/admin/assets.js +1 -1
- data/app/assets/javascripts/rad_social/rad_ajax_form.js +3 -0
- data/app/assets/javascripts/rad_social/rad_email.js +0 -1
- data/app/assets/javascripts/rad_social/rad_email_form.js +2 -7
- data/app/assets/stylesheets/admin/partials/_forms.scss +1 -1
- data/app/assets/stylesheets/rad_social/rad_screen.scss +0 -4
- data/app/controllers/admin/assets_controller.rb +21 -31
- data/app/controllers/admin/configuration_controller.rb +9 -11
- data/app/controllers/admin/extensions_controller.rb +3 -3
- data/app/controllers/admin/layouts_controller.rb +3 -4
- data/app/controllers/admin/page_attachments_controller.rb +5 -5
- data/app/controllers/admin/page_fields_controller.rb +3 -4
- data/app/controllers/admin/page_parts_controller.rb +4 -5
- data/app/controllers/admin/pages_controller.rb +55 -56
- data/app/controllers/admin/references_controller.rb +1 -1
- data/app/controllers/admin/resource_controller.rb +132 -130
- data/app/controllers/admin/sites_controller.rb +4 -4
- data/app/controllers/admin/snippets_controller.rb +3 -4
- data/app/controllers/admin/users_controller.rb +16 -16
- data/app/controllers/application_controller.rb +47 -48
- data/app/controllers/site_controller.rb +51 -48
- data/app/controllers/social_mailer_controller.rb +12 -22
- data/app/helpers/admin/configuration_helper.rb +19 -20
- data/app/helpers/admin/layouts_helper.rb +0 -1
- data/app/helpers/admin/node_helper.rb +27 -24
- data/app/helpers/admin/pages_helper.rb +2 -2
- data/app/helpers/admin/preferences_helper.rb +0 -1
- data/app/helpers/admin/references_helper.rb +9 -10
- data/app/helpers/admin/regions_helper.rb +3 -3
- data/app/helpers/application_helper.rb +32 -33
- data/app/helpers/rad_social_helper.rb +8 -11
- data/app/helpers/scoped_helper.rb +1 -3
- data/app/helpers/sites_helper.rb +4 -4
- data/app/mailers/devise_mailer.rb +3 -4
- data/app/mailers/rad_social_mailer.rb +8 -8
- data/app/models/asset.rb +62 -63
- data/app/models/asset_type.rb +38 -39
- data/app/models/deprecated_tags.rb +3 -4
- data/app/models/file_not_found_page.rb +1 -3
- data/app/models/haml_filter.rb +1 -1
- data/app/models/layout.rb +4 -5
- data/app/models/legacy_user.rb +2 -2
- data/app/models/menu_renderer.rb +16 -18
- data/app/models/page.rb +96 -93
- data/app/models/page_attachment.rb +1 -2
- data/app/models/page_context.rb +11 -12
- data/app/models/page_part.rb +3 -4
- data/app/models/rails_page.rb +10 -12
- data/app/models/site.rb +22 -21
- data/app/models/snippet.rb +6 -8
- data/app/models/snippet_finder.rb +3 -3
- data/app/models/snippet_tags.rb +4 -4
- data/app/models/standard_tags.rb +258 -252
- data/app/models/status.rb +8 -8
- data/app/models/trusty_cms/config.rb +25 -25
- data/app/models/trusty_cms/page_response_cache_director.rb +2 -3
- data/app/models/user.rb +15 -14
- data/app/models/user_action_observer.rb +3 -3
- data/app/views/admin/assets/edit.html.haml +3 -9
- data/app/views/admin/assets/new.html.haml +0 -3
- data/app/views/admin/assets/remove.html.haml +1 -1
- data/app/views/admin/layouts/remove.html.haml +3 -2
- data/app/views/admin/page_parts/_page_part.html.haml +1 -1
- data/app/views/admin/snippets/remove.html.haml +3 -2
- data/app/views/rad_social_mailer/social_mail_form.html.haml +1 -3
- data/app/views/widget/_email_form.html.haml +0 -5
- data/bin/rails +4 -4
- data/bin/trusty_cms +3 -5
- data/config.ru +1 -1
- data/config/application.rb +14 -15
- data/config/boot.rb +1 -2
- data/config/environment.rb +1 -1
- data/config/environments/production.rb +0 -1
- data/config/environments/test.rb +1 -2
- data/config/initializers/devise.rb +1 -1
- data/config/initializers/kraken.rb +2 -2
- data/config/initializers/tmp.rb +1 -1
- data/config/initializers/trusty_cms_config.rb +48 -48
- data/config/locales/en.yml +5 -4
- data/config/routes.rb +6 -7
- data/lib/active_record_extensions/active_record_extensions.rb +1 -2
- data/lib/annotatable.rb +3 -5
- data/lib/configuration_extensions/configuration_extensions.rb +1 -1
- data/lib/inheritable_class_attributes.rb +13 -9
- data/lib/login_system.rb +73 -73
- data/lib/method_observer.rb +13 -12
- data/lib/ostruct.rb +7 -10
- data/lib/simpleton.rb +0 -4
- data/lib/string_extensions/string_extensions.rb +3 -3
- data/lib/symbol_extensions/symbol_extensions.rb +1 -1
- data/lib/tasks/database.rake +28 -28
- data/lib/tasks/extensions.rake +18 -18
- data/lib/tasks/framework.rake +68 -68
- data/lib/tasks/radiant_config.rake +4 -4
- data/lib/tasks/snippets_extension_tasks.rake +11 -11
- data/lib/tasks/translate.rake +14 -14
- data/lib/tasks/upgrade_to_devise.rake +1 -1
- data/lib/translation_support.rb +22 -22
- data/lib/trusty_cms.rb +2 -2
- data/lib/trusty_cms/admin_ui.rb +19 -16
- data/lib/trusty_cms/admin_ui/region_partials.rb +4 -3
- data/lib/trusty_cms/admin_ui/region_set.rb +4 -5
- data/lib/trusty_cms/available_locales.rb +2 -4
- data/lib/trusty_cms/config/definition.rb +11 -8
- data/lib/trusty_cms/engine.rb +13 -14
- data/lib/trusty_cms/extension.rb +14 -16
- data/lib/trusty_cms/extension_loader.rb +6 -6
- data/lib/trusty_cms/extension_migrator.rb +42 -41
- data/lib/trusty_cms/extension_path.rb +20 -19
- data/lib/trusty_cms/initializer.rb +5 -8
- data/lib/trusty_cms/pagination/controller.rb +7 -10
- data/lib/trusty_cms/pagination/link_renderer.rb +2 -2
- data/lib/trusty_cms/resource_responses.rb +3 -3
- data/lib/trusty_cms/setup.rb +130 -132
- data/lib/trusty_cms/taggable.rb +19 -22
- data/lib/trusty_cms/task_support.rb +9 -6
- data/package.json +1 -1
- data/public/dispatch.fcgi +1 -1
- data/public/dispatch.rb +2 -2
- data/script/extension +1 -1
- data/script/rails +2 -2
- data/spec/dummy/package.json +1 -1
- data/spec/dummy/yarn.lock +3 -3
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/core.js +126 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/index.js +4 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/map.js +56 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/seq.js +43 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/string.js +28 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/index.js +36 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/json.js +76 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/options.js +23 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/binary.js +87 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/index.js +157 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/omap.js +142 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/pairs.js +81 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/set.js +114 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/timestamp.js +97 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/core.js +114 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/index.js +17 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/map.js +37 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/seq.js +34 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/string.js +40 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/index.js +62 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/json.js +60 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/options.js +35 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/binary.js +97 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/index.js +131 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/omap.js +105 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/pairs.js +80 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/set.js +91 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/timestamp.js +93 -0
- data/trusty_cms.gemspec +25 -25
- data/vendor/extensions/clipped-extension/lib/clipped_admin_ui.rb +1 -1
- data/yarn.lock +7 -7
- metadata +7609 -105
- data/app/assets/javascripts/rad_social/captcha.js +0 -42
- data/app/views/admin/assets/refresh.html.haml +0 -14
@@ -2,7 +2,7 @@ class Admin::ReferencesController < ApplicationController
|
|
2
2
|
def show
|
3
3
|
respond_to do |format|
|
4
4
|
render_allowed_type(params[:type])
|
5
|
-
format.any { render :
|
5
|
+
format.any { render action: @type, content_type: 'text/html', layout: false }
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
@@ -5,10 +5,10 @@ class Admin::ResourceController < ApplicationController
|
|
5
5
|
helper_method :model, :current_object, :models, :current_objects, :model_symbol, :plural_model_symbol, :model_class, :model_name, :plural_model_name
|
6
6
|
before_action :populate_format
|
7
7
|
before_action :never_cache
|
8
|
-
before_action :load_models, :
|
9
|
-
before_action :load_model, :
|
10
|
-
before_action :set_owner_or_editor, :
|
11
|
-
after_action :clear_model_cache, :
|
8
|
+
before_action :load_models, only: :index
|
9
|
+
before_action :load_model, only: %i[new create edit update remove destroy]
|
10
|
+
before_action :set_owner_or_editor, only: %i[new create update]
|
11
|
+
after_action :clear_model_cache, only: %i[create update destroy]
|
12
12
|
|
13
13
|
cattr_reader :paginated
|
14
14
|
cattr_accessor :default_per_page, :will_paginate_options
|
@@ -23,18 +23,18 @@ class Admin::ResourceController < ApplicationController
|
|
23
23
|
r.plural.publish(:xml, :json) { render format_symbol => models }
|
24
24
|
|
25
25
|
r.singular.publish(:xml, :json) { render format_symbol => model }
|
26
|
-
r.singular.default { redirect_to edit_model_path if action_name ==
|
26
|
+
r.singular.default { redirect_to edit_model_path if action_name == 'show' }
|
27
27
|
|
28
28
|
r.not_found.publish(:xml, :json) { head :not_found }
|
29
|
-
r.not_found.default { announce_not_found; redirect_to :
|
29
|
+
r.not_found.default { announce_not_found; redirect_to action: 'index' }
|
30
30
|
|
31
31
|
r.invalid.publish(:xml, :json) { render format_symbol => model.errors, :status => :unprocessable_entity }
|
32
|
-
r.invalid.default { announce_validation_errors; render :
|
32
|
+
r.invalid.default { announce_validation_errors; render action: template_name }
|
33
33
|
|
34
34
|
r.stale.publish(:xml, :json) { head :conflict }
|
35
|
-
r.stale.default { announce_update_conflict; render :
|
35
|
+
r.stale.default { announce_update_conflict; render action: template_name }
|
36
36
|
|
37
|
-
r.create.publish(:xml, :json) { render format_symbol => model, :status => :created, :location => url_for(:
|
37
|
+
r.create.publish(:xml, :json) { render format_symbol => model, :status => :created, :location => url_for(format: format_symbol, id: model) }
|
38
38
|
r.create.default { redirect_to continue_url(params) }
|
39
39
|
|
40
40
|
r.update.publish(:xml, :json) { head :ok }
|
@@ -48,7 +48,7 @@ class Admin::ResourceController < ApplicationController
|
|
48
48
|
response_for :plural
|
49
49
|
end
|
50
50
|
|
51
|
-
[
|
51
|
+
%i[show new edit remove].each do |action|
|
52
52
|
class_eval %{
|
53
53
|
def #{action} # def show
|
54
54
|
response_for :singular # response_for :singular
|
@@ -56,7 +56,7 @@ class Admin::ResourceController < ApplicationController
|
|
56
56
|
}, __FILE__, __LINE__
|
57
57
|
end
|
58
58
|
|
59
|
-
[
|
59
|
+
%i[create update].each do |action|
|
60
60
|
class_eval %{
|
61
61
|
def #{action} # def create
|
62
62
|
model.update_attributes!(permitted_params[model_symbol]) # model.update_attributes!(params[model_symbol])
|
@@ -71,7 +71,7 @@ class Admin::ResourceController < ApplicationController
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def self.model_class(model_class = nil)
|
74
|
-
@model_class ||= (model_class ||
|
74
|
+
@model_class ||= (model_class || controller_name).to_s.singularize.camelize.constantize
|
75
75
|
end
|
76
76
|
|
77
77
|
# call paginate_models to declare that will_paginate should be used in the index view
|
@@ -81,9 +81,9 @@ class Admin::ResourceController < ApplicationController
|
|
81
81
|
# Class MyController < Admin::ResourceController
|
82
82
|
# paginate_models :per_page => 100
|
83
83
|
|
84
|
-
def self.paginate_models(options={})
|
84
|
+
def self.paginate_models(options = {})
|
85
85
|
@@paginated = true
|
86
|
-
@@will_paginate_options = options.slice(:class, :previous_label, :next_label, :inner_window, :outer_window, :separator, :container).merge(:
|
86
|
+
@@will_paginate_options = options.slice(:class, :previous_label, :next_label, :inner_window, :outer_window, :separator, :container).merge(param_name: :p)
|
87
87
|
@@default_per_page = options[:per_page]
|
88
88
|
end
|
89
89
|
|
@@ -111,151 +111,153 @@ class Admin::ResourceController < ApplicationController
|
|
111
111
|
pp = params[:pp] || TrustyCms.config['admin.pagination.per_page']
|
112
112
|
pp = (self.class.default_per_page || 50) if pp.blank?
|
113
113
|
{
|
114
|
-
:
|
115
|
-
:
|
114
|
+
page: (params[:p] || 1).to_i,
|
115
|
+
per_page: pp.to_i,
|
116
116
|
}
|
117
117
|
end
|
118
118
|
|
119
119
|
protected
|
120
120
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
end
|
121
|
+
def rescue_action(exception)
|
122
|
+
case exception
|
123
|
+
when ActiveRecord::RecordInvalid
|
124
|
+
response_for :invalid
|
125
|
+
when ActiveRecord::StaleObjectError
|
126
|
+
response_for :stale
|
127
|
+
when ActiveRecord::RecordNotFound
|
128
|
+
response_for :not_found
|
129
|
+
else
|
130
|
+
super
|
132
131
|
end
|
132
|
+
end
|
133
133
|
|
134
|
-
|
135
|
-
|
136
|
-
|
134
|
+
def model_class
|
135
|
+
self.class.model_class
|
136
|
+
end
|
137
137
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
end
|
138
|
+
def set_owner_or_editor
|
139
|
+
if model.has_attribute? :created_by_id
|
140
|
+
model.created_by_id = current_user.id if model.id == nil
|
141
|
+
model.updated_by_id = current_user.id
|
143
142
|
end
|
143
|
+
end
|
144
144
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
def load_model
|
153
|
-
self.model = if params[:id]
|
154
|
-
model_class.find(params[:id])
|
155
|
-
else
|
156
|
-
model_class.new()
|
157
|
-
end
|
158
|
-
end
|
145
|
+
def model
|
146
|
+
instance_variable_get("@#{model_symbol}") || load_model
|
147
|
+
end
|
148
|
+
alias :current_object :model
|
149
|
+
def model=(object)
|
150
|
+
instance_variable_set("@#{model_symbol}", object)
|
151
|
+
end
|
159
152
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
instance_variable_set("@#{plural_model_symbol}", objects)
|
166
|
-
end
|
167
|
-
def load_models
|
168
|
-
self.models = paginated? ? model_class.paginate(pagination_parameters) : model_class.all
|
153
|
+
def load_model
|
154
|
+
self.model = if params[:id]
|
155
|
+
model_class.find(params[:id])
|
156
|
+
else
|
157
|
+
model_class.new
|
169
158
|
end
|
159
|
+
end
|
170
160
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
161
|
+
def models
|
162
|
+
instance_variable_get("@#{plural_model_symbol}") || load_models
|
163
|
+
end
|
164
|
+
alias :current_objects :models
|
165
|
+
def models=(objects)
|
166
|
+
instance_variable_set("@#{plural_model_symbol}", objects)
|
167
|
+
end
|
178
168
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
def plural_model_symbol
|
183
|
-
model_name.pluralize.underscore.intern
|
184
|
-
end
|
185
|
-
alias :models_symbol :plural_model_symbol
|
169
|
+
def load_models
|
170
|
+
self.models = paginated? ? model_class.paginate(pagination_parameters) : model_class.all
|
171
|
+
end
|
186
172
|
|
187
|
-
|
188
|
-
|
189
|
-
|
173
|
+
def model_name
|
174
|
+
model_class.name
|
175
|
+
end
|
190
176
|
|
191
|
-
|
192
|
-
|
193
|
-
|
177
|
+
def plural_model_name
|
178
|
+
model_name.pluralize
|
179
|
+
end
|
180
|
+
alias :models_name :plural_model_name
|
194
181
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
p = (i / pagination_parameters[:per_page].to_i) + 1
|
199
|
-
parts[:p] = p if p && p > 1
|
200
|
-
end
|
201
|
-
parts
|
202
|
-
end
|
182
|
+
def model_symbol
|
183
|
+
model_name.underscore.intern
|
184
|
+
end
|
203
185
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
186
|
+
def plural_model_symbol
|
187
|
+
model_name.pluralize.underscore.intern
|
188
|
+
end
|
189
|
+
alias :models_symbol :plural_model_symbol
|
208
190
|
|
209
|
-
|
210
|
-
|
211
|
-
|
191
|
+
def humanized_model_name
|
192
|
+
t(model_name.underscore.downcase)
|
193
|
+
end
|
212
194
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
end
|
195
|
+
def continue_url(options)
|
196
|
+
options[:redirect_to] || (params[:continue] ? { action: 'edit', id: model.id } : index_page_for_model)
|
197
|
+
end
|
217
198
|
|
218
|
-
|
219
|
-
|
199
|
+
def index_page_for_model
|
200
|
+
parts = { action: 'index' }
|
201
|
+
if paginated? && model && i = model_class.all.index(model)
|
202
|
+
p = (i / pagination_parameters[:per_page].to_i) + 1
|
203
|
+
parts[:p] = p if p && p > 1
|
220
204
|
end
|
205
|
+
parts
|
206
|
+
end
|
221
207
|
|
222
|
-
|
223
|
-
|
224
|
-
|
208
|
+
def edit_model_path
|
209
|
+
method = "edit_admin_#{model_name.underscore}_path"
|
210
|
+
send method.to_sym, params[:id]
|
211
|
+
end
|
225
212
|
|
226
|
-
|
227
|
-
|
228
|
-
|
213
|
+
def announce_validation_errors
|
214
|
+
flash.now[:error] = t('resource_controller.validation_errors')
|
215
|
+
end
|
229
216
|
|
230
|
-
|
231
|
-
|
232
|
-
|
217
|
+
def announce_removed
|
218
|
+
ActiveSupport::Deprecation.warn('announce_removed is no longer encouraged in TrustyCms 0.9.x.', caller)
|
219
|
+
flash[:notice] = t('resource_controller.removed', humanized_model_name: humanized_model_name)
|
220
|
+
end
|
233
221
|
|
234
|
-
|
235
|
-
|
236
|
-
|
222
|
+
def announce_not_found
|
223
|
+
flash[:notice] = t('resource_controller.not_found', humanized_model_name: humanized_model_name)
|
224
|
+
end
|
237
225
|
|
226
|
+
def announce_update_conflict
|
227
|
+
flash.now[:error] = t('resource_controller.update_conflict', humanized_model_name: humanized_model_name)
|
228
|
+
end
|
238
229
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
expires_now
|
243
|
-
end
|
230
|
+
def clear_model_cache
|
231
|
+
Rails.cache.clear
|
232
|
+
end
|
244
233
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
params[:format] ||= 'html' unless request.xhr?
|
249
|
-
end
|
234
|
+
def format_symbol
|
235
|
+
format.to_sym
|
236
|
+
end
|
250
237
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
valid_symbols = model_symbols & keys
|
255
|
-
valid_symbols.each do |symbol|
|
256
|
-
params[symbol].permit!
|
257
|
-
end
|
258
|
-
params
|
259
|
-
end
|
238
|
+
def format
|
239
|
+
params[:format] || 'html'
|
240
|
+
end
|
260
241
|
|
242
|
+
# I would like to set this to expires_in(1.minute, :private => true) to allow for more fluid navigation
|
243
|
+
# but the annoyance for concurrent authors would be too great.
|
244
|
+
def never_cache
|
245
|
+
expires_now
|
246
|
+
end
|
247
|
+
|
248
|
+
# Assist with user agents that cause improper content-negotiation
|
249
|
+
# warn "Remove default HTML format, Accept header no longer used. (#{__FILE__}: #{__LINE__})" if Rails.version !~ /^2\.1/
|
250
|
+
def populate_format
|
251
|
+
params[:format] ||= 'html' unless request.xhr?
|
252
|
+
end
|
253
|
+
|
254
|
+
def permitted_params
|
255
|
+
model_symbols = ActiveRecord::Base.descendants.map { |a| a.name.underscore.to_sym }
|
256
|
+
keys = params.keys.map { |k| k.underscore.to_sym }
|
257
|
+
valid_symbols = model_symbols & keys
|
258
|
+
valid_symbols.each do |symbol|
|
259
|
+
params[symbol].permit!
|
260
|
+
end
|
261
|
+
params
|
262
|
+
end
|
261
263
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
class Admin::SitesController < Admin::ResourceController
|
2
2
|
helper :sites
|
3
3
|
only_allow_access_to :index, :show, :new, :create, :edit, :update, :remove, :destroy,
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
when: :admin,
|
5
|
+
denied_url: { controller: 'pages', action: 'index' },
|
6
|
+
denied_message: 'You must have administrative privileges to perform this action.'
|
7
|
+
|
8
8
|
%w(move_higher move_lower move_to_top move_to_bottom).each do |action|
|
9
9
|
define_method action do
|
10
10
|
model.send(action)
|
@@ -1,8 +1,7 @@
|
|
1
1
|
class Admin::SnippetsController < Admin::ResourceController
|
2
2
|
paginate_models
|
3
3
|
only_allow_access_to :index, :show, :new, :create, :edit, :update, :remove, :destroy,
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
when: %i[designer admin],
|
5
|
+
denied_url: { controller: 'admin/pages', action: 'index' },
|
6
|
+
denied_message: 'You must have designer privileges to perform this action.'
|
8
7
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
class Admin::UsersController < Admin::ResourceController
|
2
2
|
paginate_models
|
3
3
|
only_allow_access_to :index, :show, :new, :create, :edit, :update, :remove, :destroy,
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
when: :admin,
|
5
|
+
denied_url: { controller: 'pages', action: 'index' },
|
6
|
+
denied_message: 'You must have administrative privileges to perform this action.'
|
7
7
|
|
8
|
-
before_action :ensure_deletable, :
|
8
|
+
before_action :ensure_deletable, only: %i[remove destroy]
|
9
9
|
|
10
10
|
def show
|
11
11
|
redirect_to edit_admin_user_path(params[:id])
|
@@ -20,7 +20,7 @@ class Admin::UsersController < Admin::ResourceController
|
|
20
20
|
flash[:error] = 'There was an error saving the user. Please try again.'
|
21
21
|
render :new
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
24
24
|
|
25
25
|
def update
|
26
26
|
user_params = params[model_symbol].permit!
|
@@ -34,7 +34,7 @@ class Admin::UsersController < Admin::ResourceController
|
|
34
34
|
else
|
35
35
|
flash[:error] = 'There was an error saving the user. Please try again.'
|
36
36
|
render :edit
|
37
|
-
end
|
37
|
+
end
|
38
38
|
end
|
39
39
|
|
40
40
|
def ensure_deletable
|
@@ -46,16 +46,16 @@ class Admin::UsersController < Admin::ResourceController
|
|
46
46
|
|
47
47
|
private
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
def user_params
|
50
|
+
params.require(:user).permit(:first_name, :last_name, :admin, :designer,
|
51
|
+
:password, :password_confirmation, :email, :site_id, :notes)
|
52
|
+
end
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
def announce_cannot_delete_self
|
55
|
+
flash[:error] = t('users_controller.cannot_delete_self')
|
56
|
+
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
def announce_cannot_remove_self_from_admin_role
|
59
|
+
flash[:error] = 'You cannot remove yourself from the admin role.'
|
60
|
+
end
|
61
61
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
#require_dependency 'trusty_cms'
|
1
|
+
# require_dependency 'trusty_cms'
|
2
2
|
require 'login_system'
|
3
3
|
|
4
4
|
class ApplicationController < ActionController::Base
|
5
5
|
include LoginSystem
|
6
6
|
prepend_view_path("#{TRUSTY_CMS_ROOT}/app/views")
|
7
|
-
|
7
|
+
|
8
8
|
protect_from_forgery with: :exception
|
9
9
|
before_action :authenticate_user!
|
10
10
|
before_action :set_timezone
|
11
11
|
before_action :set_user_locale
|
12
12
|
before_action :set_javascripts_and_stylesheets
|
13
13
|
before_action :force_utf8_params if RUBY_VERSION =~ /1\.9/
|
14
|
-
before_action :set_standard_body_style, :
|
14
|
+
before_action :set_standard_body_style, only: %i[new edit update create]
|
15
15
|
before_action :set_mailer
|
16
16
|
|
17
17
|
attr_accessor :trusty_config, :cache
|
@@ -23,15 +23,15 @@ class ApplicationController < ActionController::Base
|
|
23
23
|
@trusty_config = TrustyCms::Config
|
24
24
|
end
|
25
25
|
|
26
|
-
def after_sign_in_path_for(
|
26
|
+
def after_sign_in_path_for(_resource)
|
27
27
|
admin_pages_path
|
28
28
|
end
|
29
29
|
|
30
30
|
def template_name
|
31
|
-
case
|
31
|
+
case action_name
|
32
32
|
when 'index'
|
33
33
|
'index'
|
34
|
-
when 'new','create'
|
34
|
+
when 'new', 'create'
|
35
35
|
'new'
|
36
36
|
when 'show'
|
37
37
|
'show'
|
@@ -40,58 +40,57 @@ class ApplicationController < ActionController::Base
|
|
40
40
|
when 'remove', 'destroy'
|
41
41
|
'remove'
|
42
42
|
else
|
43
|
-
|
43
|
+
action_name
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
private
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
def set_mailer
|
50
|
+
ActionMailer::Base.default_url_options[:host] = request.host_with_port
|
51
|
+
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
def set_user_locale
|
54
|
+
I18n.locale = current_user && !current_user.locale.blank? ? current_user.locale : TrustyCms::Config['default_locale']
|
55
|
+
end
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
def set_timezone
|
58
|
+
Time.zone = !TrustyCms::Config['local.timezone'].nil? && TrustyCms::Config['local.timezone'].empty? ? Time.zone_default : TrustyCms::Config['local.timezone']
|
59
|
+
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
def set_javascripts_and_stylesheets
|
62
|
+
@stylesheets ||= []
|
63
|
+
@stylesheets.concat %w(admin/main)
|
64
|
+
@javascripts ||= []
|
65
|
+
end
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
def set_standard_body_style
|
68
|
+
@body_classes ||= []
|
69
|
+
@body_classes.concat(%w(reversed))
|
70
|
+
end
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
89
|
-
object
|
90
|
-
end
|
91
|
-
force_encoding = lambda do |o|
|
92
|
-
o.force_encoding(Encoding::UTF_8) if o.respond_to?(:force_encoding)
|
72
|
+
# When using TrustyCms with Ruby 1.9, the strings that come in from forms are ASCII-8BIT encoded.
|
73
|
+
# That causes problems, especially when using special chars and with certain DBs, like DB2
|
74
|
+
# That's why we force the encoding of the params to UTF-8
|
75
|
+
# That's what's happening in Rails 3, too: https://github.com/rails/rails/commit/25215d7285db10e2c04d903f251b791342e4dd6a
|
76
|
+
#
|
77
|
+
# See http://stackoverflow.com/questions/8268778/rails-2-3-9-encoding-of-query-parameters
|
78
|
+
# See https://rails.lighthouseapp.com/projects/8994/tickets/4807
|
79
|
+
# See http://jasoncodes.com/posts/ruby19-rails2-encodings (thanks for the following code, Jason!)
|
80
|
+
def force_utf8_params
|
81
|
+
traverse = lambda do |object, block|
|
82
|
+
if object.is_a?(Hash)
|
83
|
+
object.each_value { |o| traverse.call(o, block) }
|
84
|
+
elsif object.is_a?(Array)
|
85
|
+
object.each { |o| traverse.call(o, block) }
|
86
|
+
else
|
87
|
+
block.call(object)
|
93
88
|
end
|
94
|
-
|
89
|
+
object
|
95
90
|
end
|
96
|
-
|
91
|
+
force_encoding = lambda do |o|
|
92
|
+
o.force_encoding(Encoding::UTF_8) if o.respond_to?(:force_encoding)
|
93
|
+
end
|
94
|
+
traverse.call(params, force_encoding)
|
95
|
+
end
|
97
96
|
end
|