alchemy_cms 2.8.3 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/README.md +108 -25
- data/alchemy_cms.gemspec +0 -1
- data/app/assets/stylesheets/alchemy/archive.scss +2 -2
- data/app/assets/stylesheets/alchemy/base.scss +0 -37
- data/app/assets/stylesheets/alchemy/elements.scss +1 -1
- data/app/assets/stylesheets/alchemy/flash.scss +1 -1
- data/app/assets/stylesheets/alchemy/form_elements.scss +1 -1
- data/app/assets/stylesheets/alchemy/icon-font.css.scss +40 -40
- data/app/assets/stylesheets/alchemy/icons.scss +4 -32
- data/app/assets/stylesheets/alchemy/jquery-ui.scss +4 -4
- data/app/assets/stylesheets/alchemy/menubar.css.scss +20 -12
- data/app/assets/stylesheets/alchemy/modules.scss +0 -4
- data/app/assets/stylesheets/alchemy/search.scss +1 -1
- data/app/assets/stylesheets/alchemy/sitemap.scss +1 -1
- data/app/assets/stylesheets/tiny_mce/plugins/inlinepopups/skins/alchemy-tinymce-dialog/window.css.scss +3 -3
- data/app/controllers/alchemy/admin/base_controller.rb +12 -8
- data/app/controllers/alchemy/admin/dashboard_controller.rb +10 -5
- data/app/controllers/alchemy/admin/elements_controller.rb +1 -1
- data/app/controllers/alchemy/admin/essence_pictures_controller.rb +8 -1
- data/app/controllers/alchemy/admin/layoutpages_controller.rb +1 -1
- data/app/controllers/alchemy/admin/pages_controller.rb +11 -6
- data/app/controllers/alchemy/admin/resources_controller.rb +2 -2
- data/app/controllers/alchemy/admin/users_controller.rb +1 -1
- data/app/controllers/alchemy/base_controller.rb +71 -37
- data/app/controllers/alchemy/elements_controller.rb +1 -1
- data/app/controllers/alchemy/pages_controller.rb +9 -3
- data/app/controllers/alchemy/pictures_controller.rb +1 -0
- data/app/helpers/alchemy/admin/base_helper.rb +2 -10
- data/app/helpers/alchemy/admin/pages_helper.rb +1 -1
- data/app/helpers/alchemy/base_helper.rb +1 -1
- data/app/helpers/alchemy/pages_helper.rb +1 -1
- data/app/models/alchemy/attachment.rb +3 -4
- data/app/models/alchemy/cell.rb +1 -1
- data/app/models/alchemy/content.rb +3 -4
- data/app/models/alchemy/element.rb +5 -6
- data/app/models/alchemy/folded_page.rb +1 -1
- data/app/models/alchemy/language.rb +1 -1
- data/app/models/alchemy/message.rb +1 -7
- data/app/models/alchemy/page.rb +12 -10
- data/app/models/alchemy/page/{cells.rb → page_cells.rb} +2 -2
- data/app/models/alchemy/page/{elements.rb → page_elements.rb} +2 -2
- data/app/models/alchemy/page/{naming.rb → page_naming.rb} +1 -1
- data/app/models/alchemy/page/{natures.rb → page_natures.rb} +3 -3
- data/app/models/alchemy/page/{scopes.rb → page_scopes.rb} +3 -3
- data/app/models/alchemy/page/page_users.rb +33 -0
- data/app/models/alchemy/picture.rb +3 -3
- data/app/models/alchemy/site.rb +2 -2
- data/app/views/alchemy/admin/dashboard/_locked_pages.html.erb +1 -1
- data/app/views/alchemy/admin/dashboard/_recent_pages.html.erb +1 -1
- data/app/views/alchemy/admin/dashboard/_sites.html.erb +1 -1
- data/app/views/alchemy/admin/dashboard/index.html.erb +10 -4
- data/app/views/alchemy/admin/pages/_page.html.erb +1 -1
- data/app/views/alchemy/admin/pages/update.js.erb +1 -1
- data/app/views/alchemy/{user_sessions → base}/leave.html.erb +2 -2
- data/app/views/alchemy/base/permission_denied.js.erb +3 -2
- data/app/views/layouts/alchemy/admin.html.erb +6 -3
- data/config/alchemy/config.yml +1 -11
- data/config/alchemy/modules.yml +0 -12
- data/config/locales/alchemy.de.yml +3 -40
- data/config/locales/alchemy.en.yml +2 -22
- data/config/routes.rb +2 -27
- data/db/migrate/20130827094554_alchemy_two_point_six.rb +0 -31
- data/lib/alchemy/auth_accessors.rb +54 -0
- data/lib/alchemy/capistrano.rb +5 -17
- data/lib/alchemy/engine.rb +7 -7
- data/lib/alchemy/errors.rb +6 -0
- data/lib/alchemy/essence.rb +2 -2
- data/lib/alchemy/seeder.rb +1 -1
- data/lib/alchemy/tasks/helpers.rb +83 -0
- data/lib/alchemy/test_support/auth_helpers.rb +35 -0
- data/lib/alchemy/test_support/controller_requests.rb +37 -0
- data/{spec/support → lib/alchemy/test_support}/factories.rb +7 -28
- data/{spec/support/alchemy → lib/alchemy/test_support}/integration_helpers.rb +9 -36
- data/lib/alchemy/upgrader.rb +8 -7
- data/lib/alchemy/upgrader/two_point_nine.rb +33 -0
- data/lib/alchemy/userstamp.rb +10 -0
- data/lib/alchemy/version.rb +1 -3
- data/lib/rails/templates/alchemy.rb +1 -0
- data/lib/tasks/alchemy/db.rake +5 -5
- data/spec/controllers/admin/attachments_controller_spec.rb +3 -3
- data/spec/controllers/admin/dashboard_controller_spec.rb +55 -34
- data/spec/controllers/admin/elements_controller_spec.rb +1 -1
- data/spec/controllers/admin/essence_pictures_controller_spec.rb +22 -6
- data/spec/controllers/admin/pages_controller_spec.rb +41 -58
- data/spec/controllers/admin/resources_controller_spec.rb +30 -5
- data/spec/controllers/admin/trash_controller_spec.rb +1 -1
- data/spec/controllers/attachments_controller_spec.rb +26 -44
- data/spec/controllers/base_controller_spec.rb +8 -33
- data/spec/controllers/elements_controller_spec.rb +1 -1
- data/spec/controllers/pages_controller_spec.rb +7 -15
- data/spec/controllers/pictures_controller_spec.rb +44 -5
- data/spec/dummy/app/controllers/application_controller.rb +9 -1
- data/spec/dummy/app/models/user.rb +14 -0
- data/spec/dummy/db/migrate/20130827094554_alchemy_two_point_six.rb +0 -31
- data/spec/dummy/db/schema.rb +0 -31
- data/spec/features/admin/language_tree_feature_spec.rb +34 -0
- data/spec/features/admin/pages_controller_spec.rb +1 -1
- data/spec/features/pages_controller_spec.rb +5 -12
- data/spec/features/picture_security_spec.rb +2 -2
- data/spec/features/security_spec.rb +6 -45
- data/spec/features/translation_integration_spec.rb +11 -20
- data/spec/{support → fixtures}/80x60.png +0 -0
- data/spec/support/image with spaces.png b/data/spec/fixtures/image with → spaces.png +0 -0
- data/spec/{support → fixtures}/image.png +0 -0
- data/spec/{support → fixtures}/image2.PNG +0 -0
- data/spec/{support → fixtures}/image3.jpeg +0 -0
- data/spec/helpers/admin/base_helper_spec.rb +31 -43
- data/spec/helpers/admin/pages_helper_spec.rb +4 -2
- data/spec/helpers/base_helper_spec.rb +10 -3
- data/spec/helpers/pages_helper_spec.rb +32 -22
- data/spec/models/attachment_spec.rb +1 -1
- data/spec/models/element_spec.rb +33 -57
- data/spec/models/message_spec.rb +0 -16
- data/spec/models/page_spec.rb +62 -26
- data/spec/models/picture_spec.rb +5 -5
- data/spec/spec_helper.rb +13 -4
- data/spec/tasks/helpers_spec.rb +213 -0
- metadata +33 -75
- data/app/controllers/alchemy/passwords_controller.rb +0 -35
- data/app/controllers/alchemy/user_sessions_controller.rb +0 -67
- data/app/controllers/alchemy/users_controller.rb +0 -46
- data/app/mailers/alchemy/notifications.rb +0 -33
- data/app/models/alchemy/page/users.rb +0 -25
- data/app/models/alchemy/user.rb +0 -183
- data/app/views/alchemy/admin/users/_table.html.erb +0 -69
- data/app/views/alchemy/admin/users/_user.html.erb +0 -39
- data/app/views/alchemy/admin/users/edit.html.erb +0 -6
- data/app/views/alchemy/admin/users/index.html.erb +0 -58
- data/app/views/alchemy/admin/users/new.html.erb +0 -6
- data/app/views/alchemy/notifications/admin_user_created.de.text.erb +0 -15
- data/app/views/alchemy/notifications/admin_user_created.en.text.erb +0 -15
- data/app/views/alchemy/notifications/registered_user_created.de.text.erb +0 -13
- data/app/views/alchemy/notifications/registered_user_created.en.text.erb +0 -13
- data/app/views/alchemy/notifications/reset_password_instructions.de.text.erb +0 -8
- data/app/views/alchemy/notifications/reset_password_instructions.en.text.erb +0 -8
- data/app/views/alchemy/passwords/edit.html.erb +0 -35
- data/app/views/alchemy/passwords/new.html.erb +0 -30
- data/app/views/alchemy/user_sessions/new.html.erb +0 -48
- data/app/views/alchemy/users/new.html.erb +0 -14
- data/config/initializers/devise.rb +0 -242
- data/config/locales/devise.de.yml +0 -58
- data/config/locales/devise.en.yml +0 -60
- data/lib/rails/generators/alchemy/devise/devise_generator.rb +0 -29
- data/spec/controllers/admin/users_controller_spec.rb +0 -132
- data/spec/controllers/passwords_controller_spec.rb +0 -16
- data/spec/controllers/user_sessions_controller_spec.rb +0 -22
- data/spec/controllers/users_controller_spec.rb +0 -66
- data/spec/mailers/notifications_spec.rb +0 -67
- data/spec/models/user_spec.rb +0 -252
- data/spec/support/alchemy/controller_helpers.rb +0 -35
@@ -565,7 +565,7 @@
|
|
565
565
|
|
566
566
|
.ui-icon-refresh {
|
567
567
|
background: none !important;
|
568
|
-
@extend .icon-ccw;
|
568
|
+
@extend .alchemy-icon-ccw;
|
569
569
|
|
570
570
|
&:before {
|
571
571
|
text-indent: 0;
|
@@ -578,7 +578,7 @@
|
|
578
578
|
.ui-icon-fullscreen {
|
579
579
|
background: none !important;
|
580
580
|
position: relative;
|
581
|
-
@extend .icon-fullscreen;
|
581
|
+
@extend .alchemy-icon-fullscreen;
|
582
582
|
|
583
583
|
&:before {
|
584
584
|
text-indent: 0;
|
@@ -592,7 +592,7 @@
|
|
592
592
|
.ui-icon-exit-fullscreen {
|
593
593
|
background: none !important;
|
594
594
|
position: relative;
|
595
|
-
@extend .icon-fullscreen-exit;
|
595
|
+
@extend .alchemy-icon-fullscreen-exit;
|
596
596
|
|
597
597
|
&:before {
|
598
598
|
text-indent: 0;
|
@@ -769,7 +769,7 @@
|
|
769
769
|
.ui-icon-closethick {
|
770
770
|
background: none !important;
|
771
771
|
position: relative;
|
772
|
-
@extend .icon-cross;
|
772
|
+
@extend .alchemy-icon-cross;
|
773
773
|
|
774
774
|
&:before {
|
775
775
|
text-indent: 0;
|
@@ -97,19 +97,27 @@
|
|
97
97
|
@include inline-block;
|
98
98
|
list-style-type: none;
|
99
99
|
text-align: center;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
a, button {
|
104
|
+
@extend %button-defaults;
|
105
|
+
padding-left: $default-padding;
|
106
|
+
padding-right: $default-padding;
|
107
|
+
width: 100%;
|
108
|
+
display: block;
|
109
|
+
line-height: 14px;
|
110
|
+
font-weight: normal;
|
111
|
+
text-decoration: none;
|
112
|
+
text-transform: none;
|
113
|
+
text-align: center;
|
114
|
+
color: $text-color;
|
115
|
+
font-family: $default-font-face;
|
100
116
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
width: 100%;
|
106
|
-
display: block;
|
107
|
-
line-height: 14px;
|
108
|
-
font-weight: normal;
|
109
|
-
text-decoration: none !important;
|
110
|
-
color: $text-color !important;
|
111
|
-
font-family: $default-font-face;
|
112
|
-
}
|
117
|
+
// reset potentially icons that the website appends to all buttons
|
118
|
+
&:before, &:after {
|
119
|
+
display: none;
|
120
|
+
content: '';
|
113
121
|
}
|
114
122
|
}
|
115
123
|
}
|
@@ -199,7 +199,7 @@ a.mceMove {
|
|
199
199
|
}
|
200
200
|
|
201
201
|
.alchemy-tinymce-dialog .mceClose {
|
202
|
-
@extend .icon-cross;
|
202
|
+
@extend .alchemy-icon-cross;
|
203
203
|
width: 16px;
|
204
204
|
height: 16px;
|
205
205
|
top: 7px;
|
@@ -223,7 +223,7 @@ a.mceMove {
|
|
223
223
|
right: 28px;
|
224
224
|
width: 16px;
|
225
225
|
height: 16px;
|
226
|
-
@extend .icon-fullscreen-exit;
|
226
|
+
@extend .alchemy-icon-fullscreen-exit;
|
227
227
|
top: 6px;
|
228
228
|
padding-top: 3px;
|
229
229
|
}
|
@@ -233,7 +233,7 @@ a.mceMove {
|
|
233
233
|
right: 28px;
|
234
234
|
width: 16px;
|
235
235
|
height: 16px;
|
236
|
-
@extend .icon-fullscreen;
|
236
|
+
@extend .alchemy-icon-fullscreen;
|
237
237
|
top: 6px;
|
238
238
|
padding-top: 3px;
|
239
239
|
}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Alchemy
|
2
2
|
module Admin
|
3
3
|
class BaseController < Alchemy::BaseController
|
4
|
-
|
5
4
|
include Userstamp
|
5
|
+
|
6
6
|
before_filter { enforce_ssl if ssl_required? && !request.ssl? }
|
7
7
|
before_filter :set_translation
|
8
8
|
|
@@ -14,7 +14,7 @@ module Alchemy
|
|
14
14
|
|
15
15
|
layout 'alchemy/admin'
|
16
16
|
|
17
|
-
|
17
|
+
private
|
18
18
|
|
19
19
|
# Handles exceptions
|
20
20
|
def exception_handler(e)
|
@@ -30,7 +30,7 @@ module Alchemy
|
|
30
30
|
@error = e
|
31
31
|
# truncate the message, because very long error messages (i.e from mysql2) causes cookie overflow errors
|
32
32
|
@notice = e.message[0..255]
|
33
|
-
@trace = e.backtrace[0..
|
33
|
+
@trace = e.backtrace[0..50]
|
34
34
|
if request.xhr?
|
35
35
|
render :action => "error_notice", :layout => false
|
36
36
|
else
|
@@ -68,17 +68,21 @@ module Alchemy
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def set_stamper
|
71
|
-
|
71
|
+
if Alchemy.user_class < ActiveRecord::Base
|
72
|
+
Alchemy.user_class.stamper = current_alchemy_user
|
73
|
+
end
|
72
74
|
end
|
73
75
|
|
74
76
|
def reset_stamper
|
75
|
-
|
77
|
+
if Alchemy.user_class < ActiveRecord::Base
|
78
|
+
Alchemy.user_class.reset_stamper
|
79
|
+
end
|
76
80
|
end
|
77
81
|
|
78
|
-
# Returns true if the
|
82
|
+
# Returns true if the current_alchemy_user (The logged-in Alchemy User) has the admin role.
|
79
83
|
def is_admin?
|
80
|
-
return false if !
|
81
|
-
|
84
|
+
return false if !current_alchemy_user
|
85
|
+
current_alchemy_user.admin?
|
82
86
|
end
|
83
87
|
|
84
88
|
# Displays errors in a #errors div if any errors are present on the object.
|
@@ -6,11 +6,16 @@ module Alchemy
|
|
6
6
|
class DashboardController < Alchemy::Admin::BaseController
|
7
7
|
|
8
8
|
def index
|
9
|
-
@last_edited_pages = Page.from_current_site.all_last_edited_from(
|
9
|
+
@last_edited_pages = Page.from_current_site.all_last_edited_from(current_alchemy_user)
|
10
10
|
@locked_pages = Page.from_current_site.all_locked
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
if Alchemy.user_class.respond_to?(:logged_in)
|
12
|
+
@online_users = Alchemy.user_class.logged_in.to_a - [current_alchemy_user]
|
13
|
+
end
|
14
|
+
if current_alchemy_user.respond_to?(:sign_in_count) && current_alchemy_user.respond_to?(:last_sign_in_at)
|
15
|
+
@last_sign_at = current_alchemy_user.last_sign_in_at
|
16
|
+
@first_time = current_alchemy_user.sign_in_count == 1 && @last_sign_at.nil?
|
17
|
+
end
|
18
|
+
@sites = Site.all
|
14
19
|
end
|
15
20
|
|
16
21
|
def info
|
@@ -29,7 +34,7 @@ module Alchemy
|
|
29
34
|
render :text => e, :status => 503
|
30
35
|
end
|
31
36
|
|
32
|
-
|
37
|
+
private
|
33
38
|
|
34
39
|
# Returns latest alchemy version.
|
35
40
|
def latest_alchemy_version
|
@@ -75,7 +75,14 @@ module Alchemy
|
|
75
75
|
|
76
76
|
def sizes_from_essence
|
77
77
|
return if @essence_picture.render_size.blank?
|
78
|
-
@essence_picture.render_size.split('x')
|
78
|
+
size_x, size_y = @essence_picture.render_size.split('x').map(&:to_i)
|
79
|
+
if size_x.zero? || size_y.nil? || size_y.zero?
|
80
|
+
size_x_of_original = @essence_picture.picture.image_file_width
|
81
|
+
size_y_of_original = @essence_picture.picture.image_file_height
|
82
|
+
size_x = size_x_of_original * size_y / size_y_of_original if size_x.zero?
|
83
|
+
size_y = size_y_of_original * size_x / size_x_of_original if size_y.nil? || size_y.zero?
|
84
|
+
end
|
85
|
+
[size_x, size_y]
|
79
86
|
end
|
80
87
|
|
81
88
|
def sizes_string
|
@@ -3,7 +3,7 @@ module Alchemy
|
|
3
3
|
class LayoutpagesController < Alchemy::Admin::BaseController
|
4
4
|
|
5
5
|
def index
|
6
|
-
@locked_pages = Page.from_current_site.all_locked_by(
|
6
|
+
@locked_pages = Page.from_current_site.all_locked_by(current_alchemy_user)
|
7
7
|
@layout_root = Page.find_or_create_layout_root_for(session[:language_id])
|
8
8
|
@languages = Language.all
|
9
9
|
end
|
@@ -15,7 +15,7 @@ module Alchemy
|
|
15
15
|
|
16
16
|
def index
|
17
17
|
@page_root = Page.language_root_for(session[:language_id])
|
18
|
-
@locked_pages = Page.from_current_site.all_locked_by(
|
18
|
+
@locked_pages = Page.from_current_site.all_locked_by(current_alchemy_user)
|
19
19
|
@languages = Language.all
|
20
20
|
if !@page_root
|
21
21
|
if @languages.length == 1
|
@@ -73,12 +73,12 @@ module Alchemy
|
|
73
73
|
# Edit the content of the page and all its elements and contents.
|
74
74
|
def edit
|
75
75
|
# fetching page via before filter
|
76
|
-
if
|
76
|
+
if page_is_locked?
|
77
77
|
flash[:notice] = _t("This page is locked by %{name}", name: @page.locker_name)
|
78
78
|
redirect_to admin_pages_path
|
79
79
|
else
|
80
|
-
@page.lock!(
|
81
|
-
@locked_pages = Page.from_current_site.all_locked_by(
|
80
|
+
@page.lock!(current_alchemy_user)
|
81
|
+
@locked_pages = Page.from_current_site.all_locked_by(current_alchemy_user)
|
82
82
|
end
|
83
83
|
@layoutpage = @page.layoutpage?
|
84
84
|
end
|
@@ -144,7 +144,7 @@ module Alchemy
|
|
144
144
|
|
145
145
|
def fold
|
146
146
|
# @page is fetched via before filter
|
147
|
-
@page.fold!(
|
147
|
+
@page.fold!(current_alchemy_user.id, !@page.folded?(current_alchemy_user.id))
|
148
148
|
respond_to do |format|
|
149
149
|
format.js
|
150
150
|
end
|
@@ -155,7 +155,7 @@ module Alchemy
|
|
155
155
|
# fetching page via before filter
|
156
156
|
@page.unlock!
|
157
157
|
flash[:notice] = _t(:unlocked_page, :name => @page.name)
|
158
|
-
@pages_locked_by_user = Page.from_current_site.all_locked_by(
|
158
|
+
@pages_locked_by_user = Page.from_current_site.all_locked_by(current_alchemy_user)
|
159
159
|
respond_to do |format|
|
160
160
|
format.js
|
161
161
|
format.html {
|
@@ -337,6 +337,11 @@ module Alchemy
|
|
337
337
|
end
|
338
338
|
end
|
339
339
|
|
340
|
+
def page_is_locked?
|
341
|
+
return if !@page.locker.try(:logged_in?)
|
342
|
+
@page.locked? && @page.locker != current_alchemy_user
|
343
|
+
end
|
344
|
+
|
340
345
|
end
|
341
346
|
end
|
342
347
|
end
|
@@ -157,9 +157,9 @@ module Alchemy
|
|
157
157
|
def search_query(search_terms)
|
158
158
|
resource_handler.searchable_attributes.map do |attribute|
|
159
159
|
if relation = attribute[:relation]
|
160
|
-
"#{relation[:model_association].klass.table_name}.#{relation[:attr_method]} LIKE #{search_terms}"
|
160
|
+
"LOWER(#{relation[:model_association].klass.table_name}.#{relation[:attr_method]}) LIKE #{search_terms}"
|
161
161
|
else
|
162
|
-
"#{resource_handler.model.table_name}.#{attribute[:name]} LIKE #{search_terms}"
|
162
|
+
"LOWER(#{resource_handler.model.table_name}.#{attribute[:name]}) LIKE #{search_terms}"
|
163
163
|
end
|
164
164
|
end.join(" OR ")
|
165
165
|
end
|
@@ -2,7 +2,7 @@ module Alchemy
|
|
2
2
|
module Admin
|
3
3
|
class UsersController < ResourcesController
|
4
4
|
|
5
|
-
filter_access_to [:edit, :update, :destroy], :attribute_check => true, :load_method => :load_user, :model => Alchemy
|
5
|
+
filter_access_to [:edit, :update, :destroy], :attribute_check => true, :load_method => :load_user, :model => Alchemy.user_class
|
6
6
|
filter_access_to [:index, :new, :create], :attribute_check => false
|
7
7
|
|
8
8
|
before_filter :set_roles_and_genders, :except => [:index, :destroy]
|
@@ -8,10 +8,18 @@ module Alchemy
|
|
8
8
|
before_filter :set_current_site
|
9
9
|
before_filter :set_language
|
10
10
|
before_filter :mailer_set_url_options
|
11
|
-
before_filter :store_user_request_time
|
12
11
|
before_filter :set_authorization_user
|
13
12
|
|
14
|
-
helper_method :
|
13
|
+
helper_method :current_alchemy_user,
|
14
|
+
:current_site,
|
15
|
+
:multi_site?,
|
16
|
+
:current_server
|
17
|
+
|
18
|
+
def leave
|
19
|
+
render layout: !request.xhr?
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
15
23
|
|
16
24
|
# Returns a host string with the domain the app is running on.
|
17
25
|
def current_server
|
@@ -43,7 +51,25 @@ module Alchemy
|
|
43
51
|
I18n.t(key, *args)
|
44
52
|
end
|
45
53
|
|
46
|
-
|
54
|
+
# The current authorized user.
|
55
|
+
#
|
56
|
+
# In order to have Alchemy's authorization work, you have to
|
57
|
+
# provide a +current_user+ method in your app's ApplicationController,
|
58
|
+
# that returns the current user.
|
59
|
+
#
|
60
|
+
# If you don't have an App that can provide a +current_user+ object,
|
61
|
+
# you can install the `alchemy-devise` gem that provides everything you need.
|
62
|
+
#
|
63
|
+
def current_alchemy_user
|
64
|
+
raise NoCurrentUserFoundError if !defined?(current_user)
|
65
|
+
current_user
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns true if a +current_alchemy_user+ is present
|
69
|
+
#
|
70
|
+
def alchemy_user_signed_in?
|
71
|
+
current_alchemy_user.present?
|
72
|
+
end
|
47
73
|
|
48
74
|
# Returns the current site.
|
49
75
|
#
|
@@ -61,7 +87,7 @@ module Alchemy
|
|
61
87
|
# Stores the current_user for declarative_authorization
|
62
88
|
#
|
63
89
|
def set_authorization_user
|
64
|
-
Authorization.current_user =
|
90
|
+
Authorization.current_user = current_alchemy_user
|
65
91
|
end
|
66
92
|
|
67
93
|
# Sets Alchemy's GUI translation to users preffered language and stores it in the session.
|
@@ -77,8 +103,8 @@ module Alchemy
|
|
77
103
|
::I18n.locale = session[:current_locale]
|
78
104
|
elsif params[:locale].present? && ::I18n.available_locales.include?(params[:locale].to_sym)
|
79
105
|
session[:current_locale] = ::I18n.locale = params[:locale]
|
80
|
-
elsif
|
81
|
-
::I18n.locale =
|
106
|
+
elsif current_alchemy_user && current_alchemy_user.respond_to?(:language) && current_alchemy_user.language.present?
|
107
|
+
::I18n.locale = current_alchemy_user.language
|
82
108
|
else
|
83
109
|
::I18n.locale = request.env['HTTP_ACCEPT_LANGUAGE'].try(:scan, /^[a-z]{2}/).try(:first) || ::I18n.default_locale
|
84
110
|
end
|
@@ -137,42 +163,50 @@ module Alchemy
|
|
137
163
|
redirect_to url_for(protocol: 'https')
|
138
164
|
end
|
139
165
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
166
|
+
protected
|
167
|
+
|
168
|
+
def permission_denied(exception = nil)
|
169
|
+
Rails.logger.debug <<-WARN
|
170
|
+
|
171
|
+
/!\\ No permissions to request #{request.path} for:
|
172
|
+
#{current_alchemy_user.inspect}
|
173
|
+
WARN
|
174
|
+
if current_alchemy_user
|
175
|
+
handle_redirect_for_user
|
176
|
+
else
|
177
|
+
handle_redirect_for_guest
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def handle_redirect_for_user
|
182
|
+
flash[:warning] = _t('You are not authorized')
|
183
|
+
if permitted_to? :index, :alchemy_admin_dashboard
|
184
|
+
redirect_or_render_notice
|
185
|
+
else
|
186
|
+
redirect_to('/')
|
144
187
|
end
|
145
188
|
end
|
146
189
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
elsif request.xhr?
|
155
|
-
respond_to do |format|
|
156
|
-
format.js { render status: 403 }
|
157
|
-
format.html {
|
158
|
-
render :partial => 'alchemy/admin/partials/flash', :locals => {:message => _t('You are not authorized'), :flash_type => 'warning'}
|
159
|
-
}
|
160
|
-
end
|
161
|
-
else
|
162
|
-
flash[:error] = _t('You are not authorized')
|
163
|
-
redirect_to alchemy.admin_dashboard_path
|
164
|
-
end
|
165
|
-
else
|
166
|
-
redirect_to alchemy.root_path
|
190
|
+
def redirect_or_render_notice
|
191
|
+
if request.xhr?
|
192
|
+
respond_to do |format|
|
193
|
+
format.js { render status: 403 }
|
194
|
+
format.html {
|
195
|
+
render(partial: 'alchemy/admin/partials/flash', locals: {message: _t('You are not authorized'), flash_type: 'warning'})
|
196
|
+
}
|
167
197
|
end
|
168
198
|
else
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
199
|
+
redirect_to(alchemy.admin_dashboard_path)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def handle_redirect_for_guest
|
204
|
+
flash[:info] = _t('Please log in')
|
205
|
+
if request.xhr?
|
206
|
+
render :permission_denied
|
207
|
+
else
|
208
|
+
store_location
|
209
|
+
redirect_to Alchemy.login_path
|
176
210
|
end
|
177
211
|
end
|
178
212
|
|