alchemy_cms 3.2.0.beta → 3.2.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +661 -863
- data/README.md +5 -63
- data/app/assets/javascripts/alchemy/alchemy.base.js.coffee +11 -10
- data/app/assets/javascripts/alchemy/alchemy.initializer.js.coffee +6 -0
- data/app/assets/stylesheets/alchemy/_extends.scss +0 -6
- data/app/assets/stylesheets/alchemy/_mixins.scss +6 -0
- data/app/assets/stylesheets/alchemy/buttons.scss +1 -1
- data/app/assets/stylesheets/alchemy/elements.scss +1 -1
- data/app/assets/stylesheets/alchemy/menubar.scss +1 -1
- data/app/assets/stylesheets/alchemy/selects.scss +5 -1
- data/app/assets/stylesheets/alchemy/upload.scss +1 -1
- data/app/controllers/alchemy/admin/pages_controller.rb +1 -1
- data/app/controllers/alchemy/base_controller.rb +4 -57
- data/app/controllers/alchemy/messages_controller.rb +2 -2
- data/app/controllers/alchemy/pages_controller.rb +22 -31
- data/app/controllers/alchemy/pictures_controller.rb +2 -2
- data/app/helpers/alchemy/admin/base_helper.rb +7 -0
- data/app/helpers/alchemy/admin/elements_helper.rb +31 -15
- data/app/helpers/alchemy/admin/pages_helper.rb +17 -0
- data/app/helpers/alchemy/base_helper.rb +0 -28
- data/app/helpers/alchemy/pages_helper.rb +18 -12
- data/app/helpers/alchemy/url_helper.rb +2 -2
- data/app/models/alchemy/cell.rb +1 -1
- data/app/models/alchemy/content/factory.rb +12 -6
- data/app/models/alchemy/element.rb +3 -3
- data/app/models/alchemy/element/definitions.rb +1 -1
- data/app/models/alchemy/element_to_page.rb +7 -0
- data/app/models/alchemy/language.rb +1 -1
- data/app/models/alchemy/page.rb +8 -1
- data/app/models/alchemy/page/page_cells.rb +2 -2
- data/app/models/alchemy/page/page_elements.rb +23 -5
- data/app/models/alchemy/page/page_natures.rb +3 -3
- data/app/models/alchemy/page/page_scopes.rb +1 -1
- data/app/models/alchemy/picture.rb +1 -1
- data/app/views/alchemy/admin/pages/_create_language_form.html.erb +1 -1
- data/app/views/alchemy/admin/pages/_form.html.erb +1 -1
- data/app/views/alchemy/admin/pictures/_picture_to_assign.html.erb +1 -1
- data/app/views/alchemy/breadcrumb/_page.html.erb +3 -2
- data/app/views/alchemy/breadcrumb/_separator.html.erb +1 -0
- data/app/views/alchemy/breadcrumb/_wrapper.html.erb +13 -0
- data/app/views/alchemy/language_links/_language.html.erb +1 -1
- data/app/views/alchemy/navigation/_link.html.erb +1 -1
- data/app/views/alchemy/pages/show.rss.builder +5 -7
- data/app/views/layouts/alchemy/admin.html.erb +5 -0
- data/config/routes.rb +13 -10
- data/lib/alchemy/configuration_methods.rb +29 -0
- data/lib/alchemy/controller_actions.rb +12 -4
- data/lib/alchemy/engine.rb +3 -0
- data/lib/alchemy/errors.rb +1 -1
- data/lib/alchemy/essence.rb +14 -12
- data/lib/alchemy/on_page_layout.rb +58 -0
- data/lib/alchemy/page_layout.rb +1 -1
- data/lib/alchemy/permissions.rb +21 -16
- data/lib/alchemy/routing_constraints.rb +49 -0
- data/lib/alchemy/seeder.rb +4 -2
- data/lib/alchemy/ssl_protection.rb +30 -0
- data/lib/alchemy/test_support/essence_shared_examples.rb +118 -25
- data/lib/alchemy/test_support/factories.rb +5 -8
- data/lib/alchemy/test_support/integration_helpers.rb +16 -10
- data/lib/alchemy/upgrader/three_point_two.rb +34 -4
- data/lib/alchemy/version.rb +1 -1
- data/lib/rails/generators/alchemy/{scaffold → install}/files/_article_editor.html.erb +0 -0
- data/lib/rails/generators/alchemy/{scaffold → install}/files/_article_view.html.erb +0 -0
- data/lib/rails/generators/alchemy/{scaffold → install}/files/_standard.html.erb +0 -0
- data/lib/rails/generators/alchemy/{scaffold → install}/files/alchemy.de.yml +0 -0
- data/lib/rails/generators/alchemy/{scaffold → install}/files/alchemy.elements.css.scss +0 -0
- data/lib/rails/generators/alchemy/{scaffold → install}/files/alchemy.en.yml +0 -0
- data/lib/rails/generators/alchemy/{scaffold → install}/files/alchemy.es.yml +0 -0
- data/lib/rails/generators/alchemy/{scaffold → install}/files/application.html.erb +0 -0
- data/lib/rails/generators/alchemy/install/install_generator.rb +69 -0
- data/lib/rails/generators/alchemy/{scaffold/files/elements.yml → install/templates/elements.yml.tt} +2 -0
- data/lib/rails/generators/alchemy/{scaffold → install}/templates/page_layouts.yml.tt +2 -0
- data/lib/rails/generators/alchemy/views/views_generator.rb +41 -0
- data/lib/rails/templates/alchemy.rb +2 -2
- data/lib/tasks/alchemy/db.rake +0 -5
- data/lib/tasks/alchemy/install.rake +10 -5
- data/lib/tasks/alchemy/tidy.rake +2 -0
- data/spec/controllers/admin/attachments_controller_spec.rb +1 -1
- data/spec/controllers/admin/clipboard_controller_spec.rb +1 -1
- data/spec/controllers/admin/contents_controller_spec.rb +1 -1
- data/spec/controllers/admin/dashboard_controller_spec.rb +2 -2
- data/spec/controllers/admin/elements_controller_spec.rb +1 -1
- data/spec/controllers/admin/essence_files_controller_spec.rb +1 -1
- data/spec/controllers/admin/essence_pictures_controller_spec.rb +1 -1
- data/spec/controllers/admin/languages_controller_spec.rb +1 -1
- data/spec/controllers/admin/layoutpages_controller_spec.rb +1 -1
- data/spec/controllers/admin/pages_controller_spec.rb +4 -4
- data/spec/controllers/admin/pictures_controller_spec.rb +1 -1
- data/spec/controllers/admin/resources_controller_spec.rb +1 -1
- data/spec/controllers/admin/trash_controller_spec.rb +1 -1
- data/spec/controllers/alchemy/admin/tags_controller_spec.rb +1 -1
- data/spec/controllers/attachments_controller_spec.rb +1 -1
- data/spec/controllers/base_controller_spec.rb +22 -0
- data/spec/controllers/elements_controller_spec.rb +1 -1
- data/spec/controllers/pages_controller_spec.rb +15 -16
- data/spec/controllers/pictures_controller_spec.rb +212 -162
- data/spec/dummy/app/controllers/login_controller.rb +5 -0
- data/spec/dummy/app/models/dummy_model.rb +3 -0
- data/spec/dummy/config/alchemy/cells.yml +4 -1
- data/spec/dummy/config/alchemy/elements.yml +8 -0
- data/spec/dummy/config/alchemy/page_layouts.yml +5 -1
- data/spec/dummy/config/routes.rb +1 -2
- data/spec/dummy/db/migrate/20150412103152_create_dummy_model.rb +7 -0
- data/spec/dummy/db/schema.rb +30 -26
- data/spec/features/admin/dashboard_spec.rb +11 -9
- data/spec/features/admin/language_tree_feature_spec.rb +5 -6
- data/spec/features/admin/legacy_page_url_management_spec.rb +1 -1
- data/spec/features/admin/link_overlay_spec.rb +1 -1
- data/spec/features/admin/locale_select_feature_spec.rb +1 -1
- data/spec/features/admin/modules_integration_spec.rb +1 -1
- data/spec/features/admin/navigation_feature_spec.rb +1 -1
- data/spec/features/admin/page_creation_feature_spec.rb +1 -1
- data/spec/features/admin/page_editing_feature_spec.rb +3 -3
- data/spec/features/admin/picture_library_integration_spec.rb +1 -1
- data/spec/features/admin/resources_integration_spec.rb +1 -1
- data/spec/features/admin/site_select_feature_spec.rb +32 -0
- data/spec/features/admin/tinymce_feature_spec.rb +1 -3
- data/spec/features/page_feature_spec.rb +36 -27
- data/spec/features/security_spec.rb +1 -1
- data/spec/features/translation_integration_spec.rb +3 -3
- data/spec/helpers/admin/elements_helper_spec.rb +103 -26
- data/spec/helpers/admin/pages_helper_spec.rb +32 -1
- data/spec/helpers/base_helper_spec.rb +0 -45
- data/spec/helpers/pages_helper_spec.rb +18 -17
- data/spec/helpers/url_helper_spec.rb +8 -5
- data/spec/libraries/controller_actions_spec.rb +2 -2
- data/spec/libraries/on_page_layout_spec.rb +112 -0
- data/spec/libraries/page_layout_spec.rb +5 -1
- data/spec/libraries/permissions_spec.rb +13 -15
- data/spec/models/cell_spec.rb +4 -0
- data/spec/models/content_spec.rb +6 -0
- data/spec/models/dummy_model_spec.rb +11 -0
- data/spec/models/element_spec.rb +6 -1
- data/spec/models/element_to_page_spec.rb +14 -0
- data/spec/models/page_spec.rb +111 -19
- data/spec/routing/routing_spec.rb +120 -101
- data/spec/spec_helper.rb +3 -3
- metadata +36 -21
- data/app/views/alchemy/breadcrumb/_spacer.html.erb +0 -1
- data/lib/alchemy/capistrano.rb +0 -230
- data/lib/alchemy/test_support/auth_helpers.rb +0 -35
- data/lib/rails/generators/alchemy/deploy_script/deploy_script_generator.rb +0 -90
- data/lib/rails/generators/alchemy/deploy_script/templates/deploy.rb.tt +0 -113
- data/lib/rails/generators/alchemy/scaffold/scaffold_generator.rb +0 -63
- data/spec/dummy/app/controllers/errors_controller.rb +0 -5
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/alchemy_cms.svg)](http://badge.fury.io/rb/alchemy_cms)
|
2
|
-
[![Build Status](https://travis-ci.org/AlchemyCMS/alchemy_cms.svg?branch=
|
3
|
-
|
4
|
-
**CAUTION: This master branch is a development branch that *can* contain bugs. For productive environments you should use the [current Ruby gem version](https://rubygems.org/gems/alchemy_cms/versions/3.0.0), or the [latest stable branch (3.1-stable)](https://github.com/AlchemyCMS/alchemy_cms/tree/3.1-stable).**
|
2
|
+
[![Build Status](https://travis-ci.org/AlchemyCMS/alchemy_cms.svg?branch=3.2-stable)](https://travis-ci.org/AlchemyCMS/alchemy_cms) [![Code Climate](https://codeclimate.com/github/AlchemyCMS/alchemy_cms.svg)](https://codeclimate.com/github/AlchemyCMS/alchemy_cms) [![Test Coverage](https://codeclimate.com/github/AlchemyCMS/alchemy_cms/badges/coverage.svg)](https://codeclimate.com/github/AlchemyCMS/alchemy_cms)
|
5
3
|
|
6
4
|
|
7
5
|
## About
|
@@ -75,7 +73,7 @@ $ alchemy --help
|
|
75
73
|
Put this into your `Gemfile`:
|
76
74
|
|
77
75
|
```ruby
|
78
|
-
gem 'alchemy_cms', github: 'AlchemyCMS/alchemy_cms', branch: '
|
76
|
+
gem 'alchemy_cms', github: 'AlchemyCMS/alchemy_cms', branch: '3.2-stable'
|
79
77
|
```
|
80
78
|
|
81
79
|
**NOTE:** You normally want to use a stable branch, like `3.0-stable`.
|
@@ -104,7 +102,7 @@ the Devise based user model that Alchemy provides and was extracted [into its ow
|
|
104
102
|
If you don't have your own user class, you can use the Alchemy user model. Just add the following gem into your `Gemfile`:
|
105
103
|
|
106
104
|
```ruby
|
107
|
-
gem 'alchemy-devise', github: 'AlchemyCMS/alchemy-devise', branch: '
|
105
|
+
gem 'alchemy-devise', github: 'AlchemyCMS/alchemy-devise', branch: '3.2-stable'
|
108
106
|
```
|
109
107
|
|
110
108
|
**NOTE:** You normally want to use a stable branch, like `2.0-stable`.
|
@@ -194,70 +192,14 @@ Also, `git diff` is your friend. You are using git to track changes of your proj
|
|
194
192
|
|
195
193
|
## Deployment
|
196
194
|
|
197
|
-
Alchemy
|
198
|
-
|
199
|
-
### 1. Add Capistrano gem
|
200
|
-
|
201
|
-
First you need to add Capistrano to your `Gemfile`:
|
202
|
-
|
203
|
-
```ruby
|
204
|
-
# Gemfile
|
205
|
-
gem 'capistrano', '2.15.5', group: 'development'
|
206
|
-
```
|
207
|
-
|
208
|
-
**A note about Capistrano version:**
|
209
|
-
|
210
|
-
Alchemy's deploy script is currently **only compatible with Capistrano 2.x** ([See this pull request](https://github.com/AlchemyCMS/alchemy_cms/pull/616) if you want to help us upgrade to 3.x).
|
211
|
-
|
212
|
-
### 2. Generate the deploy file
|
213
|
-
|
214
|
-
To generate the deploy file you need to use this generator:
|
215
|
-
|
216
|
-
```shell
|
217
|
-
$ bin/rails g alchemy:deploy_script
|
218
|
-
```
|
219
|
-
|
220
|
-
and follow the instructions.
|
221
|
-
|
222
|
-
If you *have your own Capistrano receipts* you can require the Alchemy tasks in your `config/deploy.rb` file:
|
223
|
-
|
224
|
-
```ruby
|
225
|
-
# deploy.rb
|
226
|
-
require 'alchemy/capistrano'
|
227
|
-
```
|
228
|
-
|
229
|
-
### Synchronize your data
|
230
|
-
|
231
|
-
Alchemy Capistrano receipts offer much more then only deployment related tasks. We also have tasks to make your local development easier. To get a list of all receipts type:
|
195
|
+
Alchemy has an official Capistrano extension which takes care of everything you need to deploy an Alchemy site.
|
232
196
|
|
233
|
-
|
234
|
-
$ bundle exec cap -T alchemy
|
235
|
-
```
|
236
|
-
|
237
|
-
#### Import data from server
|
238
|
-
|
239
|
-
```shell
|
240
|
-
$ bundle exec cap alchemy:import:all
|
241
|
-
```
|
242
|
-
|
243
|
-
This imports your servers data onto your local development machine. This is very handy if you want to clone the current server state.
|
244
|
-
|
245
|
-
#### Export data to server
|
246
|
-
|
247
|
-
That even works the other way around:
|
248
|
-
|
249
|
-
```shell
|
250
|
-
$ bundle exec cap alchemy:export:all
|
251
|
-
```
|
252
|
-
|
253
|
-
**NOTE:** This will **overwrite the database** on your server. But calm down my dear friend, Alchemy will ask you to perform a backup before overwriting it.
|
197
|
+
Please use https://github.com/AlchemyCMS/capistrano-alchemy, if you want to deploy with Capistrano.
|
254
198
|
|
255
199
|
### Without Capistrano
|
256
200
|
|
257
201
|
If you don't use Capistrano you have to **make sure** that the `uploads`, `tmp/cache/assets`, `public/assets` and `public/pictures` folders get **shared between deployments**, otherwise you **will loose data**. No, not really, but you know, just keep them in sync.
|
258
202
|
|
259
|
-
Please take a look into Alchemys [Capistrano receipt](https://github.com/AlchemyCMS/alchemy_cms/blob/master/lib/alchemy/capistrano.rb) in order to see how you could achieve this.
|
260
|
-
|
261
203
|
|
262
204
|
## Testing
|
263
205
|
|
@@ -46,16 +46,17 @@ $.extend Alchemy,
|
|
46
46
|
# fades the image after its been loaded
|
47
47
|
ImageLoader: (scope = document, options = {color: '#fff'}) ->
|
48
48
|
$('img', scope).each ->
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
49
|
+
if !this.complete
|
50
|
+
image = $(this).hide()
|
51
|
+
$parent = image.parent()
|
52
|
+
spinner = Alchemy.Spinner.small options
|
53
|
+
spinner.spin $parent[0]
|
54
|
+
image.on 'load', ->
|
55
|
+
spinner.stop()
|
56
|
+
image.fadeIn 400
|
57
|
+
image.on 'error', ->
|
58
|
+
spinner.stop()
|
59
|
+
$parent.html('<span class="icon warn"/>')
|
59
60
|
|
60
61
|
removePicture: (selector) ->
|
61
62
|
$form_field = $(selector)
|
@@ -30,6 +30,12 @@ Alchemy.Initializer = ->
|
|
30
30
|
delimiter = if url.match(/\?/) then '&' else '?'
|
31
31
|
window.location.href = "#{url}#{delimiter}locale=#{$(this).val()}"
|
32
32
|
|
33
|
+
# Site select handler
|
34
|
+
$('select#change_site').on 'change', (e) ->
|
35
|
+
url = window.location.pathname
|
36
|
+
delimiter = if url.match(/\?/) then '&' else '?'
|
37
|
+
window.location.href = "#{url}#{delimiter}site_id=#{$(this).val()}"
|
38
|
+
|
33
39
|
# Submit forms of selects with `data-autosubmit="true"`
|
34
40
|
$('select[data-auto-submit="true"]').on 'change', (e) ->
|
35
41
|
Alchemy.pleaseWaitOverlay()
|
@@ -47,12 +47,6 @@
|
|
47
47
|
line-height: 0;
|
48
48
|
}
|
49
49
|
|
50
|
-
%button-defaults {
|
51
|
-
@include sassy-button('simple', $sb-border-radius, $sb-font-size, $sb-base-color, $sb-second-color, $sb-text-color, $sb-text-style, $sb-pseudo-states, $sb-ie-support);
|
52
|
-
border-color: $button-border-color;
|
53
|
-
margin: $default-form-field-margin;
|
54
|
-
}
|
55
|
-
|
56
50
|
%field-with-error {
|
57
51
|
border-color: $error_border_color;
|
58
52
|
color: $error_text_color;
|
@@ -9,6 +9,12 @@
|
|
9
9
|
}
|
10
10
|
}
|
11
11
|
|
12
|
+
@mixin button-defaults {
|
13
|
+
@include sassy-button('simple', $sb-border-radius, $sb-font-size, $sb-base-color, $sb-second-color, $sb-text-color, $sb-text-style, $sb-pseudo-states, $sb-ie-support);
|
14
|
+
border-color: $button-border-color;
|
15
|
+
margin: $default-form-field-margin;
|
16
|
+
}
|
17
|
+
|
12
18
|
@mixin default-label-style {
|
13
19
|
font-size: 10px;
|
14
20
|
text-shadow: #fff 0 1px 2px;
|
@@ -305,12 +305,12 @@ div#cells {
|
|
305
305
|
right: 0;
|
306
306
|
|
307
307
|
.icon_button {
|
308
|
+
@include button-defaults;
|
308
309
|
margin: 0 0 0 4px;
|
309
310
|
padding: 3px;
|
310
311
|
position: absolute;
|
311
312
|
bottom: 4px;
|
312
313
|
right: 28px;
|
313
|
-
@extend %button-defaults;
|
314
314
|
@include border-radius(0);
|
315
315
|
|
316
316
|
&.unlink {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
select {
|
2
|
-
@
|
2
|
+
@include button-defaults;
|
3
3
|
height: 29px;
|
4
4
|
padding: 0.4em 0.6em;
|
5
5
|
}
|
@@ -137,6 +137,10 @@ select {
|
|
137
137
|
|
138
138
|
.select2-search {
|
139
139
|
margin: $default-margin 0;
|
140
|
+
|
141
|
+
.select2-input {
|
142
|
+
width: inherit;
|
143
|
+
}
|
140
144
|
}
|
141
145
|
|
142
146
|
&.select2-with-searchbox .select2-results > .select2-result:first-child {
|
@@ -153,7 +153,7 @@ module Alchemy
|
|
153
153
|
|
154
154
|
def visit
|
155
155
|
@page.unlock!
|
156
|
-
redirect_to show_page_path(:
|
156
|
+
redirect_to show_page_path(urlname: @page.urlname, locale: multi_language? ? @page.language_code : nil)
|
157
157
|
end
|
158
158
|
|
159
159
|
# Sets the page public and updates the published_at attribute that is used as cache_key
|
@@ -2,16 +2,16 @@
|
|
2
2
|
#
|
3
3
|
module Alchemy
|
4
4
|
class BaseController < ApplicationController
|
5
|
+
include Alchemy::ConfigurationMethods
|
5
6
|
include Alchemy::ControllerActions
|
6
7
|
include Alchemy::Modules
|
8
|
+
include Alchemy::SSLProtection
|
7
9
|
|
8
10
|
protect_from_forgery
|
9
11
|
|
10
12
|
before_action :mailer_set_url_options
|
11
13
|
before_action :set_locale
|
12
14
|
|
13
|
-
helper_method :multi_site?
|
14
|
-
|
15
15
|
helper 'alchemy/admin/form'
|
16
16
|
|
17
17
|
rescue_from CanCan::AccessDenied do |exception|
|
@@ -26,24 +26,8 @@ module Alchemy
|
|
26
26
|
::I18n.locale = Language.current.code
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
# Config file is in +config/alchemy/config.yml+
|
32
|
-
#
|
33
|
-
def configuration(name)
|
34
|
-
Alchemy::Config.get(name)
|
35
|
-
end
|
36
|
-
|
37
|
-
def multi_language?
|
38
|
-
Language.published.count > 1
|
39
|
-
end
|
40
|
-
|
41
|
-
def multi_site?
|
42
|
-
Site.count > 1
|
43
|
-
end
|
44
|
-
|
45
|
-
def raise_not_found_error
|
46
|
-
raise ActionController::RoutingError.new('Not Found')
|
29
|
+
def not_found_error!(msg = "Not found \"#{request.fullpath}\"")
|
30
|
+
raise ActionController::RoutingError.new(msg)
|
47
31
|
end
|
48
32
|
|
49
33
|
# Shortcut for Alchemy::I18n.translate method
|
@@ -61,38 +45,6 @@ module Alchemy
|
|
61
45
|
ActionMailer::Base.default_url_options[:host] = request.host_with_port
|
62
46
|
end
|
63
47
|
|
64
|
-
def render_404(exception = nil)
|
65
|
-
if exception
|
66
|
-
logger.info "Rendering 404: #{exception.message}"
|
67
|
-
end
|
68
|
-
render :file => Rails.root.join("public/404.html"), :status => 404, :layout => false
|
69
|
-
end
|
70
|
-
|
71
|
-
# Enforce ssl for login and all admin modules.
|
72
|
-
#
|
73
|
-
# Default is +false+
|
74
|
-
#
|
75
|
-
# === Usage
|
76
|
-
#
|
77
|
-
# # config/alchemy/config.yml
|
78
|
-
# ...
|
79
|
-
# require_ssl: true
|
80
|
-
# ...
|
81
|
-
#
|
82
|
-
# === Note
|
83
|
-
#
|
84
|
-
# You have to create a ssl certificate
|
85
|
-
# if you want to use the ssl protection.
|
86
|
-
#
|
87
|
-
def ssl_required?
|
88
|
-
!Rails.env.test? && configuration(:require_ssl)
|
89
|
-
end
|
90
|
-
|
91
|
-
# Redirects current request to https.
|
92
|
-
def enforce_ssl
|
93
|
-
redirect_to url_for(request.params.merge(protocol: 'https'))
|
94
|
-
end
|
95
|
-
|
96
48
|
protected
|
97
49
|
|
98
50
|
def permission_denied(exception = nil)
|
@@ -150,10 +102,5 @@ WARN
|
|
150
102
|
Rails.logger.error("\n#{e.class} #{e.message} in #{e.backtrace.first}")
|
151
103
|
Rails.logger.error(e.backtrace[1..50].each { |l| l.gsub(/#{Rails.root.to_s}/, '') }.join("\n"))
|
152
104
|
end
|
153
|
-
|
154
|
-
def raise_authorization_exception(exception)
|
155
|
-
raise("Not permitted to #{exception.action} #{exception.subject}")
|
156
|
-
end
|
157
|
-
|
158
105
|
end
|
159
106
|
end
|
@@ -47,7 +47,7 @@ module Alchemy
|
|
47
47
|
helper 'alchemy/pages'
|
48
48
|
|
49
49
|
def index #:nodoc:
|
50
|
-
redirect_to show_page_path(urlname: @page.urlname,
|
50
|
+
redirect_to show_page_path(urlname: @page.urlname, locale: multi_language? ? @page.language_code : nil)
|
51
51
|
end
|
52
52
|
|
53
53
|
def new #:nodoc:
|
@@ -99,7 +99,7 @@ module Alchemy
|
|
99
99
|
else
|
100
100
|
urlname = Language.current_root_page.urlname
|
101
101
|
end
|
102
|
-
redirect_to show_page_path(urlname: urlname,
|
102
|
+
redirect_to show_page_path(urlname: urlname, locale: multi_language? ? Language.current.code : nil)
|
103
103
|
end
|
104
104
|
|
105
105
|
def get_page
|
@@ -1,12 +1,5 @@
|
|
1
1
|
module Alchemy
|
2
2
|
class PagesController < Alchemy::BaseController
|
3
|
-
# We need to include this helper because we need the breadcrumb method.
|
4
|
-
# And we cannot define the breadcrump method as helper_method, because rspec does not see helper_methods.
|
5
|
-
# Not the best solution, but's working.
|
6
|
-
# Anyone with a better idea please provide a patch.
|
7
|
-
include Alchemy::BaseHelper
|
8
|
-
|
9
|
-
rescue_from ActionController::RoutingError, :with => :render_404
|
10
3
|
|
11
4
|
before_action :enforce_primary_host_for_site
|
12
5
|
before_action :render_page_or_redirect, only: [:show]
|
@@ -28,6 +21,8 @@ module Alchemy
|
|
28
21
|
end
|
29
22
|
end
|
30
23
|
end
|
24
|
+
rescue ActionController::UnknownFormat
|
25
|
+
page_not_found!
|
31
26
|
end
|
32
27
|
|
33
28
|
# Renders a search engine compatible xml sitemap.
|
@@ -50,7 +45,7 @@ module Alchemy
|
|
50
45
|
Page.contentpages.where(
|
51
46
|
urlname: params[:urlname],
|
52
47
|
language_id: Language.current.id,
|
53
|
-
language_code: params[:
|
48
|
+
language_code: params[:locale] || Language.current.code
|
54
49
|
).first
|
55
50
|
else
|
56
51
|
# No urlname was given, so just load the language root for the
|
@@ -73,25 +68,24 @@ module Alchemy
|
|
73
68
|
|
74
69
|
def render_page_or_redirect
|
75
70
|
@page ||= load_page
|
71
|
+
|
76
72
|
if signup_required?
|
77
73
|
redirect_to Alchemy.signup_path
|
78
|
-
elsif @page.nil? && last_legacy_url
|
74
|
+
elsif (@page.nil? || request.format.nil?) && last_legacy_url
|
79
75
|
@page = last_legacy_url.page
|
80
|
-
|
81
76
|
# This drops the given query string.
|
82
77
|
redirect_legacy_page
|
83
|
-
|
84
78
|
elsif @page.blank?
|
85
|
-
|
86
|
-
elsif multi_language? && params[:
|
87
|
-
redirect_page(
|
88
|
-
elsif multi_language? && params[:urlname].blank? && !params[:
|
89
|
-
redirect_page(
|
79
|
+
page_not_found!
|
80
|
+
elsif multi_language? && params[:locale].blank?
|
81
|
+
redirect_page(locale: Language.current.code)
|
82
|
+
elsif multi_language? && params[:urlname].blank? && !params[:locale].blank? && configuration(:redirect_index)
|
83
|
+
redirect_page(locale: params[:locale])
|
90
84
|
elsif configuration(:redirect_to_public_child) && !@page.public?
|
91
85
|
redirect_to_public_child
|
92
86
|
elsif params[:urlname].blank? && configuration(:redirect_index)
|
93
87
|
redirect_page
|
94
|
-
elsif !multi_language? && !params[:
|
88
|
+
elsif !multi_language? && !params[:locale].blank?
|
95
89
|
redirect_page
|
96
90
|
elsif @page.has_controller?
|
97
91
|
redirect_to main_app.url_for(@page.controller_and_action)
|
@@ -114,17 +108,13 @@ module Alchemy
|
|
114
108
|
|
115
109
|
def redirect_to_public_child
|
116
110
|
@page = @page.self_and_descendants.published.not_restricted.first
|
117
|
-
|
118
|
-
redirect_page
|
119
|
-
else
|
120
|
-
raise_not_found_error
|
121
|
-
end
|
111
|
+
@page ? redirect_page : page_not_found!
|
122
112
|
end
|
123
113
|
|
124
114
|
# Redirects page to given url with 301 status while keeping all additional params
|
125
115
|
def redirect_page(options = {})
|
126
116
|
options = {
|
127
|
-
|
117
|
+
locale: (multi_language? ? @page.language_code : nil),
|
128
118
|
urlname: @page.urlname
|
129
119
|
}.merge(options)
|
130
120
|
|
@@ -135,11 +125,11 @@ module Alchemy
|
|
135
125
|
# Don't use query string of legacy urlname
|
136
126
|
def redirect_legacy_page(options={})
|
137
127
|
defaults = {
|
138
|
-
:
|
139
|
-
:
|
128
|
+
locale: (multi_language? ? @page.language_code : nil),
|
129
|
+
urlname: @page.urlname
|
140
130
|
}
|
141
131
|
options = defaults.merge(options)
|
142
|
-
redirect_to show_page_path(options), :
|
132
|
+
redirect_to show_page_path(options), status: 301
|
143
133
|
end
|
144
134
|
|
145
135
|
# Returns url parameters that are not internal show page params.
|
@@ -147,20 +137,18 @@ module Alchemy
|
|
147
137
|
# * action
|
148
138
|
# * controller
|
149
139
|
# * urlname
|
150
|
-
# *
|
140
|
+
# * locale
|
151
141
|
#
|
152
142
|
def additional_params
|
153
143
|
params.symbolize_keys.delete_if do |key, _|
|
154
|
-
[:action, :controller, :urlname, :
|
144
|
+
[:action, :controller, :urlname, :locale].include?(key)
|
155
145
|
end
|
156
146
|
end
|
157
147
|
|
158
148
|
def legacy_urls
|
159
|
-
|
160
149
|
# /slug/tree => slug/tree
|
161
150
|
urlname = (request.fullpath[1..-1] if request.fullpath[0] == '/') || request.fullpath
|
162
|
-
|
163
|
-
LegacyPageUrl.joins(:page).where(urlname: urlname, alchemy_pages: {language_id: Language.current.id})
|
151
|
+
LegacyPageUrl.joins(:page).where(urlname: urlname, Page.table_name => {language_id: Language.current.id})
|
164
152
|
end
|
165
153
|
|
166
154
|
def last_legacy_url
|
@@ -216,5 +204,8 @@ module Alchemy
|
|
216
204
|
public: !@page.restricted)
|
217
205
|
end
|
218
206
|
|
207
|
+
def page_not_found!
|
208
|
+
not_found_error!("Alchemy::Page not found \"#{request.fullpath}\"")
|
209
|
+
end
|
219
210
|
end
|
220
211
|
end
|