comfortable_mexican_sofa 1.12.2 → 1.12.3
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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/comfortable_mexican_sofa/admin/application.js +1 -1
- data/app/assets/javascripts/comfortable_mexican_sofa/application.js.coffee +50 -57
- data/app/assets/javascripts/comfortable_mexican_sofa/cms/files.js.coffee +29 -0
- data/app/assets/javascripts/comfortable_mexican_sofa/cms/uploader.js.coffee +139 -0
- data/app/assets/stylesheets/comfortable_mexican_sofa/admin/application.css +1 -1
- data/app/assets/stylesheets/comfortable_mexican_sofa/application.css.sass +1 -0
- data/app/assets/stylesheets/comfortable_mexican_sofa/base.css.sass +67 -84
- data/app/controllers/comfy/admin/cms/base_controller.rb +11 -8
- data/app/controllers/comfy/admin/cms/categories_controller.rb +10 -9
- data/app/controllers/comfy/admin/cms/files_controller.rb +38 -69
- data/app/controllers/comfy/admin/cms/layouts_controller.rb +4 -3
- data/app/controllers/comfy/admin/cms/pages_controller.rb +17 -11
- data/app/controllers/comfy/admin/cms/revisions_controller.rb +10 -9
- data/app/controllers/comfy/admin/cms/sites_controller.rb +2 -1
- data/app/controllers/comfy/admin/cms/snippets_controller.rb +3 -2
- data/app/controllers/comfy/cms/assets_controller.rb +17 -9
- data/app/controllers/comfy/cms/content_controller.rb +20 -14
- data/app/models/comfy/cms/file.rb +16 -15
- data/app/models/comfy/cms/page.rb +2 -1
- data/app/models/comfy/cms/site.rb +5 -0
- data/app/views/comfy/admin/cms/files/_file.html.haml +26 -13
- data/app/views/comfy/admin/cms/files/_form.html.haml +8 -5
- data/app/views/comfy/admin/cms/files/_modal.html.haml +4 -0
- data/app/views/comfy/admin/cms/files/create.js.erb +1 -0
- data/app/views/comfy/admin/cms/files/destroy.js.coffee +2 -2
- data/app/views/comfy/admin/cms/files/index.html.haml +33 -31
- data/app/views/comfy/admin/cms/layouts/_form.html.haml +2 -5
- data/app/views/comfy/admin/cms/pages/_form.html.haml +7 -8
- data/app/views/comfy/admin/cms/pages/_form_blocks.html.haml +3 -3
- data/app/views/comfy/admin/cms/sites/_form.html.haml +2 -2
- data/app/views/comfy/admin/cms/sites/index.html.haml +1 -2
- data/app/views/comfy/admin/cms/snippets/_form.html.haml +5 -8
- data/app/views/kaminari/comfy/_paginator.html.haml +10 -11
- data/app/views/layouts/comfy/admin/cms.html.haml +3 -2
- data/app/views/layouts/comfy/admin/cms/_body.html.haml +8 -7
- data/app/views/layouts/comfy/admin/cms/{_center.html.haml → _flash.html.haml} +0 -3
- data/app/views/layouts/comfy/admin/cms/_footer_js.html.haml +0 -4
- data/app/views/layouts/comfy/admin/cms/_left.html.haml +10 -5
- data/comfortable_mexican_sofa.gemspec +9 -8
- data/config/cms_routes.rb +2 -2
- data/config/initializers/comfortable_mexican_sofa.rb +31 -13
- data/config/initializers/plupload.rb +9 -0
- data/config/locales/en.yml +18 -16
- data/db/upgrade_migrations/08_upgrade_to_1_12_0.rb +3 -0
- data/lib/comfortable_mexican_sofa.rb +6 -5
- data/lib/comfortable_mexican_sofa/access_control/admin_authentication.rb +20 -0
- data/lib/comfortable_mexican_sofa/access_control/admin_authorization.rb +8 -0
- data/lib/comfortable_mexican_sofa/access_control/public_authentication.rb +8 -0
- data/lib/comfortable_mexican_sofa/configuration.rb +11 -3
- data/lib/comfortable_mexican_sofa/engine.rb +1 -0
- data/lib/comfortable_mexican_sofa/fixture.rb +7 -5
- data/lib/comfortable_mexican_sofa/fixture/category.rb +10 -3
- data/lib/comfortable_mexican_sofa/form_builder.rb +1 -1
- data/lib/comfortable_mexican_sofa/routes/cms.rb +3 -0
- data/lib/comfortable_mexican_sofa/version.rb +1 -1
- data/lib/generators/comfy/cms/assets_generator.rb +15 -0
- data/lib/generators/comfy/cms/cms_generator.rb +19 -12
- data/lib/generators/comfy/cms/controllers_generator.rb +13 -0
- data/lib/generators/comfy/cms/models_generator.rb +13 -0
- data/lib/generators/comfy/cms/views_generator.rb +13 -0
- data/test/controllers/comfy/admin/cms/files_controller_test.rb +22 -95
- data/test/controllers/comfy/admin/cms/layouts_controller_test.rb +9 -10
- data/test/controllers/comfy/admin/cms/pages_controller_test.rb +26 -27
- data/test/controllers/comfy/admin/cms/snippets_controller_test.rb +7 -8
- data/test/controllers/comfy/cms/content_controller_test.rb +30 -4
- data/test/gemfiles/Gemfile.rails.4.0 +3 -2
- data/test/gemfiles/Gemfile.rails.4.1 +3 -2
- data/test/gemfiles/Gemfile.rails.master +3 -2
- data/test/generators/cms_assets_generator_test.rb +13 -0
- data/test/generators/cms_controllers_generator_test.rb +12 -0
- data/test/generators/cms_generator_test.rb +10 -8
- data/test/generators/cms_models_generator_test.rb +12 -0
- data/test/generators/cms_views_generator_test.rb +12 -0
- data/test/generators/scaffold_generator_test.rb +6 -7
- data/test/integration/access_control_test.rb +141 -0
- data/test/integration/routing_test.rb +19 -0
- data/test/lib/configuration_test.rb +8 -7
- data/test/lib/fixtures/categories_test.rb +1 -0
- data/test/lib/fixtures/files_test.rb +5 -0
- data/test/lib/fixtures/pages_test.rb +17 -1
- data/test/lib/fixtures/snippets_test.rb +5 -0
- data/test/models/page_test.rb +6 -0
- data/test/models/site_test.rb +9 -0
- data/test/test_helper.rb +28 -19
- metadata +82 -48
- data/app/views/comfy/admin/cms/files/_index.html.haml +0 -11
- data/lib/comfortable_mexican_sofa/authentication/dummy_auth.rb +0 -8
- data/lib/comfortable_mexican_sofa/authentication/http_auth.rb +0 -25
- data/test/integration/authentication_test.rb +0 -48
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
class Comfy::Admin::Cms::BaseController < ComfortableMexicanSofa.config.base_controller.to_s.constantize
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# Authentication module must have #authenticate method
|
|
3
|
+
# Authentication module must have `authenticate` method
|
|
6
4
|
include ComfortableMexicanSofa.config.admin_auth.to_s.constantize
|
|
7
5
|
|
|
6
|
+
# Authorization module must have `authorize` method
|
|
7
|
+
include ComfortableMexicanSofa.config.admin_authorization.to_s.constantize
|
|
8
|
+
|
|
9
|
+
protect_from_forgery
|
|
10
|
+
|
|
8
11
|
before_action :authenticate,
|
|
9
12
|
:load_admin_site,
|
|
10
13
|
:set_locale,
|
|
11
14
|
:load_fixtures,
|
|
12
15
|
:except => :jump
|
|
13
|
-
|
|
16
|
+
|
|
14
17
|
layout 'comfy/admin/cms'
|
|
15
|
-
|
|
18
|
+
|
|
16
19
|
if ComfortableMexicanSofa.config.admin_cache_sweeper.present?
|
|
17
20
|
cache_sweeper *ComfortableMexicanSofa.config.admin_cache_sweeper
|
|
18
21
|
end
|
|
19
|
-
|
|
22
|
+
|
|
20
23
|
def jump
|
|
21
24
|
path = ComfortableMexicanSofa.config.admin_route_redirect
|
|
22
25
|
return redirect_to(path) unless path.blank?
|
|
23
26
|
load_admin_site
|
|
24
27
|
redirect_to comfy_admin_cms_site_pages_path(@site) if @site
|
|
25
28
|
end
|
|
26
|
-
|
|
29
|
+
|
|
27
30
|
protected
|
|
28
|
-
|
|
31
|
+
|
|
29
32
|
def load_admin_site
|
|
30
33
|
if @site = ::Comfy::Cms::Site.find_by_id(params[:site_id] || session[:site_id]) || ::Comfy::Cms::Site.first
|
|
31
34
|
session[:site_id] = @site.id
|
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
class Comfy::Admin::Cms::CategoriesController < Comfy::Admin::Cms::BaseController
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
before_action :load_category, :only => [:edit, :update, :destroy]
|
|
4
|
-
|
|
4
|
+
before_action :authorize
|
|
5
|
+
|
|
5
6
|
def edit
|
|
6
7
|
render
|
|
7
8
|
end
|
|
8
|
-
|
|
9
|
+
|
|
9
10
|
def create
|
|
10
11
|
@category = @site.categories.create!(category_params)
|
|
11
12
|
rescue ActiveRecord::RecordInvalid
|
|
12
13
|
render :nothing => true
|
|
13
14
|
end
|
|
14
|
-
|
|
15
|
+
|
|
15
16
|
def update
|
|
16
17
|
@category.update_attributes!(category_params)
|
|
17
18
|
rescue ActiveRecord::RecordInvalid
|
|
18
19
|
render :nothing => true
|
|
19
20
|
end
|
|
20
|
-
|
|
21
|
+
|
|
21
22
|
def destroy
|
|
22
23
|
@category.destroy
|
|
23
24
|
end
|
|
24
|
-
|
|
25
|
+
|
|
25
26
|
protected
|
|
26
|
-
|
|
27
|
+
|
|
27
28
|
def load_category
|
|
28
29
|
@category = @site.categories.find(params[:id])
|
|
29
30
|
rescue ActiveRecord::RecordNotFound
|
|
30
31
|
render :nothing => true
|
|
31
32
|
end
|
|
32
|
-
|
|
33
|
+
|
|
33
34
|
def category_params
|
|
34
35
|
params.fetch(:category, {}).permit!
|
|
35
36
|
end
|
|
36
|
-
|
|
37
|
+
|
|
37
38
|
end
|
|
@@ -1,77 +1,52 @@
|
|
|
1
1
|
class Comfy::Admin::Cms::FilesController < Comfy::Admin::Cms::BaseController
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
skip_before_action :load_fixtures
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
before_action :build_file, :only => [:new, :create]
|
|
6
6
|
before_action :load_file, :only => [:edit, :update, :destroy]
|
|
7
|
-
|
|
7
|
+
before_action :authorize
|
|
8
|
+
|
|
8
9
|
def index
|
|
9
|
-
@files = @site.files.not_page_file.includes(:categories).for_category(params[:category])
|
|
10
|
-
|
|
11
|
-
if params[:ajax]
|
|
12
|
-
if params[:not_images]
|
|
13
|
-
files = @files.not_images.collect do |file|
|
|
14
|
-
{ :label => file.label,
|
|
15
|
-
:filename => file.file_file_name,
|
|
16
|
-
:url => file.file.url }
|
|
17
|
-
end
|
|
18
|
-
else
|
|
19
|
-
files = @files.images.collect do |file|
|
|
20
|
-
{ :thumb => file.file.url(:cms_thumb),
|
|
21
|
-
:image => file.file.url }
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
render :json => files
|
|
25
|
-
else
|
|
26
|
-
return redirect_to :action => :new if @site.files.count == 0
|
|
27
|
-
end
|
|
10
|
+
@files = @site.files.not_page_file.includes(:categories).for_category(params[:category])
|
|
11
|
+
.order('comfy_cms_files.position').page(params[:page]).per(50)
|
|
28
12
|
end
|
|
29
|
-
|
|
13
|
+
|
|
30
14
|
def new
|
|
31
15
|
render
|
|
32
16
|
end
|
|
33
17
|
|
|
34
18
|
def create
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
19
|
+
respond_to do |format|
|
|
20
|
+
if @file.save
|
|
21
|
+
format.html do
|
|
22
|
+
flash[:success] = I18n.t('comfy.admin.cms.files.created')
|
|
23
|
+
redirect_to :action => :edit, :id => @file
|
|
24
|
+
end
|
|
25
|
+
format.plupload do
|
|
26
|
+
render :text => render_to_string(:partial => 'file', :object => @file, :formats => [:html])
|
|
27
|
+
end
|
|
28
|
+
else
|
|
29
|
+
format.html do
|
|
30
|
+
flash.now[:danger] = I18n.t('comfy.admin.cms.files.creation_failure')
|
|
31
|
+
render :action => :new
|
|
32
|
+
end
|
|
33
|
+
format.plupload do
|
|
34
|
+
render :text => @file.errors.full_messages.to_sentence, :status => :unprocessable_entity
|
|
35
|
+
end
|
|
36
|
+
end
|
|
47
37
|
end
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
flash[:success] = I18n.t('comfy.admin.cms.files.created')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def update
|
|
41
|
+
if @file.update(file_params)
|
|
42
|
+
flash[:success] = I18n.t('comfy.admin.cms.files.updated')
|
|
54
43
|
redirect_to :action => :edit, :id => @file
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
rescue ActiveRecord::RecordInvalid
|
|
58
|
-
if params[:ajax]
|
|
59
|
-
render :nothing => true, :status => :unprocessable_entity
|
|
60
44
|
else
|
|
61
|
-
flash.now[:danger] = I18n.t('comfy.admin.cms.files.
|
|
62
|
-
render :action => :
|
|
45
|
+
flash.now[:danger] = I18n.t('comfy.admin.cms.files.update_failure')
|
|
46
|
+
render :action => :edit
|
|
63
47
|
end
|
|
64
48
|
end
|
|
65
|
-
|
|
66
|
-
def update
|
|
67
|
-
@file.update_attributes!(file_params)
|
|
68
|
-
flash[:success] = I18n.t('comfy.admin.cms.files.updated')
|
|
69
|
-
redirect_to :action => :edit, :id => @file
|
|
70
|
-
rescue ActiveRecord::RecordInvalid
|
|
71
|
-
flash.now[:danger] = I18n.t('comfy.admin.cms.files.update_failure')
|
|
72
|
-
render :action => :edit
|
|
73
|
-
end
|
|
74
|
-
|
|
49
|
+
|
|
75
50
|
def destroy
|
|
76
51
|
@file.destroy
|
|
77
52
|
respond_to do |format|
|
|
@@ -82,7 +57,7 @@ class Comfy::Admin::Cms::FilesController < Comfy::Admin::Cms::BaseController
|
|
|
82
57
|
end
|
|
83
58
|
end
|
|
84
59
|
end
|
|
85
|
-
|
|
60
|
+
|
|
86
61
|
def reorder
|
|
87
62
|
(params[:comfy_cms_file] || []).each_with_index do |id, index|
|
|
88
63
|
if (cms_file = ::Comfy::Cms::File.find_by_id(id))
|
|
@@ -91,27 +66,21 @@ class Comfy::Admin::Cms::FilesController < Comfy::Admin::Cms::BaseController
|
|
|
91
66
|
end
|
|
92
67
|
render :nothing => true
|
|
93
68
|
end
|
|
94
|
-
|
|
69
|
+
|
|
95
70
|
protected
|
|
96
71
|
|
|
97
72
|
def build_file
|
|
98
|
-
@file = @site.files.new
|
|
73
|
+
@file = @site.files.new(file_params)
|
|
99
74
|
end
|
|
100
|
-
|
|
75
|
+
|
|
101
76
|
def load_file
|
|
102
77
|
@file = @site.files.find(params[:id])
|
|
103
78
|
rescue ActiveRecord::RecordNotFound
|
|
104
79
|
flash[:danger] = I18n.t('comfy.admin.cms.files.not_found')
|
|
105
80
|
redirect_to :action => :index
|
|
106
81
|
end
|
|
107
|
-
|
|
82
|
+
|
|
108
83
|
def file_params
|
|
109
|
-
# single file upload
|
|
110
|
-
unless (file = params[:file]).is_a?(Hash)
|
|
111
|
-
params[:file] = { }
|
|
112
|
-
params[:file][:file] = [file]
|
|
113
|
-
end
|
|
114
84
|
params.fetch(:file, {}).permit!
|
|
115
85
|
end
|
|
116
|
-
|
|
117
86
|
end
|
|
@@ -2,6 +2,7 @@ class Comfy::Admin::Cms::LayoutsController < Comfy::Admin::Cms::BaseController
|
|
|
2
2
|
|
|
3
3
|
before_action :build_layout, :only => [:new, :create]
|
|
4
4
|
before_action :load_layout, :only => [:edit, :update, :destroy]
|
|
5
|
+
before_action :authorize
|
|
5
6
|
|
|
6
7
|
def index
|
|
7
8
|
return redirect_to :action => :new if @site.layouts.count == 0
|
|
@@ -39,7 +40,7 @@ class Comfy::Admin::Cms::LayoutsController < Comfy::Admin::Cms::BaseController
|
|
|
39
40
|
flash[:success] = I18n.t('comfy.admin.cms.layouts.deleted')
|
|
40
41
|
redirect_to :action => :index
|
|
41
42
|
end
|
|
42
|
-
|
|
43
|
+
|
|
43
44
|
def reorder
|
|
44
45
|
(params[:comfy_cms_layout] || []).each_with_index do |id, index|
|
|
45
46
|
::Comfy::Cms::Layout.where(:id => id).update_all(:position => index)
|
|
@@ -62,9 +63,9 @@ protected
|
|
|
62
63
|
flash[:danger] = I18n.t('comfy.admin.cms.layouts.not_found')
|
|
63
64
|
redirect_to :action => :index
|
|
64
65
|
end
|
|
65
|
-
|
|
66
|
+
|
|
66
67
|
def layout_params
|
|
67
68
|
params.fetch(:layout, {}).permit!
|
|
68
69
|
end
|
|
69
|
-
|
|
70
|
+
|
|
70
71
|
end
|
|
@@ -3,12 +3,14 @@ class Comfy::Admin::Cms::PagesController < Comfy::Admin::Cms::BaseController
|
|
|
3
3
|
before_action :check_for_layouts, :only => [:new, :edit]
|
|
4
4
|
before_action :build_cms_page, :only => [:new, :create]
|
|
5
5
|
before_action :load_cms_page, :only => [:edit, :update, :destroy]
|
|
6
|
+
before_action :authorize
|
|
6
7
|
before_action :preview_cms_page, :only => [:create, :update]
|
|
7
|
-
before_action :build_file, :only => [:new, :edit]
|
|
8
8
|
|
|
9
9
|
def index
|
|
10
|
-
return redirect_to :action => :new if
|
|
11
|
-
|
|
10
|
+
return redirect_to :action => :new if site_has_no_pages?
|
|
11
|
+
|
|
12
|
+
@pages_by_parent = pages_grouped_by_parent
|
|
13
|
+
|
|
12
14
|
if params[:category].present?
|
|
13
15
|
@pages = @site.pages.includes(:categories).for_category(params[:category]).order('label')
|
|
14
16
|
else
|
|
@@ -54,7 +56,7 @@ class Comfy::Admin::Cms::PagesController < Comfy::Admin::Cms::BaseController
|
|
|
54
56
|
end
|
|
55
57
|
|
|
56
58
|
def toggle_branch
|
|
57
|
-
@pages_by_parent =
|
|
59
|
+
@pages_by_parent = pages_grouped_by_parent
|
|
58
60
|
@page = @site.pages.find(params[:id])
|
|
59
61
|
s = (session[:cms_page_tree] ||= [])
|
|
60
62
|
id = @page.id.to_s
|
|
@@ -72,6 +74,14 @@ class Comfy::Admin::Cms::PagesController < Comfy::Admin::Cms::BaseController
|
|
|
72
74
|
|
|
73
75
|
protected
|
|
74
76
|
|
|
77
|
+
def site_has_no_pages?
|
|
78
|
+
@site.pages.count == 0
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def pages_grouped_by_parent
|
|
82
|
+
@site.pages.includes(:categories).group_by(&:parent_id)
|
|
83
|
+
end
|
|
84
|
+
|
|
75
85
|
def check_for_layouts
|
|
76
86
|
if @site.layouts.count == 0
|
|
77
87
|
flash[:danger] = I18n.t('comfy.admin.cms.pages.layout_not_found')
|
|
@@ -85,10 +95,6 @@ protected
|
|
|
85
95
|
@page.layout ||= (@page.parent && @page.parent.layout || @site.layouts.first)
|
|
86
96
|
end
|
|
87
97
|
|
|
88
|
-
def build_file
|
|
89
|
-
@file = Comfy::Cms::File.new
|
|
90
|
-
end
|
|
91
|
-
|
|
92
98
|
def load_cms_page
|
|
93
99
|
@page = @site.pages.find(params[:id])
|
|
94
100
|
@page.attributes = page_params
|
|
@@ -104,14 +110,14 @@ protected
|
|
|
104
110
|
@cms_site = @page.site
|
|
105
111
|
@cms_layout = @page.layout
|
|
106
112
|
@cms_page = @page
|
|
107
|
-
|
|
113
|
+
|
|
108
114
|
# Chrome chokes on content with iframes. Issue #434
|
|
109
115
|
response.headers['X-XSS-Protection'] = '0'
|
|
110
|
-
|
|
116
|
+
|
|
111
117
|
render :inline => @page.render, :layout => layout, :content_type => 'text/html'
|
|
112
118
|
end
|
|
113
119
|
end
|
|
114
|
-
|
|
120
|
+
|
|
115
121
|
def page_params
|
|
116
122
|
params.fetch(:page, {}).permit!
|
|
117
123
|
end
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
class Comfy::Admin::Cms::RevisionsController < Comfy::Admin::Cms::BaseController
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
before_action :load_record
|
|
4
4
|
before_action :load_revision, :except => :index
|
|
5
|
-
|
|
5
|
+
before_action :authorize
|
|
6
|
+
|
|
6
7
|
def index
|
|
7
8
|
redirect_to :action => :show, :id => @record.revisions.first.try(:id) || 0
|
|
8
9
|
end
|
|
9
|
-
|
|
10
|
+
|
|
10
11
|
def show
|
|
11
12
|
case @record
|
|
12
13
|
when Comfy::Cms::Page
|
|
@@ -17,15 +18,15 @@ class Comfy::Admin::Cms::RevisionsController < Comfy::Admin::Cms::BaseController
|
|
|
17
18
|
@versioned_content = @record.revision_fields.inject({}){|c, f| c[f] = @revision.data[f]; c }
|
|
18
19
|
end
|
|
19
20
|
end
|
|
20
|
-
|
|
21
|
+
|
|
21
22
|
def revert
|
|
22
23
|
@record.restore_from_revision(@revision)
|
|
23
24
|
flash[:success] = I18n.t('comfy.admin.cms.revisions.reverted')
|
|
24
25
|
redirect_to_record
|
|
25
26
|
end
|
|
26
|
-
|
|
27
|
+
|
|
27
28
|
protected
|
|
28
|
-
|
|
29
|
+
|
|
29
30
|
def load_record
|
|
30
31
|
@record = if params[:layout_id]
|
|
31
32
|
::Comfy::Cms::Layout.find(params[:layout_id])
|
|
@@ -38,14 +39,14 @@ protected
|
|
|
38
39
|
flash[:danger] = I18n.t('comfy.admin.cms.revisions.record_not_found')
|
|
39
40
|
redirect_to comfy_admin_cms_path
|
|
40
41
|
end
|
|
41
|
-
|
|
42
|
+
|
|
42
43
|
def load_revision
|
|
43
44
|
@revision = @record.revisions.find(params[:id])
|
|
44
45
|
rescue ActiveRecord::RecordNotFound
|
|
45
46
|
flash[:danger] = I18n.t('comfy.admin.cms.revisions.not_found')
|
|
46
47
|
redirect_to_record
|
|
47
48
|
end
|
|
48
|
-
|
|
49
|
+
|
|
49
50
|
def redirect_to_record
|
|
50
51
|
redirect_to case @record
|
|
51
52
|
when ::Comfy::Cms::Layout then edit_comfy_admin_cms_site_layout_path(@site, @record)
|
|
@@ -53,5 +54,5 @@ protected
|
|
|
53
54
|
when ::Comfy::Cms::Snippet then edit_comfy_admin_cms_site_snippet_path(@site, @record)
|
|
54
55
|
end
|
|
55
56
|
end
|
|
56
|
-
|
|
57
|
+
|
|
57
58
|
end
|
|
@@ -5,6 +5,7 @@ class Comfy::Admin::Cms::SitesController < Comfy::Admin::Cms::BaseController
|
|
|
5
5
|
|
|
6
6
|
before_action :build_site, :only => [:new, :create]
|
|
7
7
|
before_action :load_site, :only => [:edit, :update, :destroy]
|
|
8
|
+
before_action :authorize
|
|
8
9
|
|
|
9
10
|
def index
|
|
10
11
|
return redirect_to :action => :new if ::Comfy::Cms::Site.count == 0
|
|
@@ -58,7 +59,7 @@ protected
|
|
|
58
59
|
flash[:danger] = I18n.t('comfy.admin.cms.sites.not_found')
|
|
59
60
|
redirect_to :action => :index
|
|
60
61
|
end
|
|
61
|
-
|
|
62
|
+
|
|
62
63
|
def site_params
|
|
63
64
|
params.fetch(:site, {}).permit!
|
|
64
65
|
end
|
|
@@ -2,6 +2,7 @@ class Comfy::Admin::Cms::SnippetsController < Comfy::Admin::Cms::BaseController
|
|
|
2
2
|
|
|
3
3
|
before_action :build_snippet, :only => [:new, :create]
|
|
4
4
|
before_action :load_snippet, :only => [:edit, :update, :destroy]
|
|
5
|
+
before_action :authorize
|
|
5
6
|
|
|
6
7
|
def index
|
|
7
8
|
return redirect_to :action => :new if @site.snippets.count == 0
|
|
@@ -39,7 +40,7 @@ class Comfy::Admin::Cms::SnippetsController < Comfy::Admin::Cms::BaseController
|
|
|
39
40
|
flash[:success] = I18n.t('comfy.admin.cms.snippets.deleted')
|
|
40
41
|
redirect_to :action => :index
|
|
41
42
|
end
|
|
42
|
-
|
|
43
|
+
|
|
43
44
|
def reorder
|
|
44
45
|
(params[:comfy_cms_snippet] || []).each_with_index do |id, index|
|
|
45
46
|
::Comfy::Cms::Snippet.where(:id => id).update_all(:position => index)
|
|
@@ -59,7 +60,7 @@ protected
|
|
|
59
60
|
flash[:danger] = I18n.t('comfy.admin.cms.snippets.not_found')
|
|
60
61
|
redirect_to :action => :index
|
|
61
62
|
end
|
|
62
|
-
|
|
63
|
+
|
|
63
64
|
def snippet_params
|
|
64
65
|
params.fetch(:snippet, {}).permit!
|
|
65
66
|
end
|
|
@@ -2,29 +2,37 @@ class Comfy::Cms::AssetsController < Comfy::Cms::BaseController
|
|
|
2
2
|
|
|
3
3
|
skip_before_action :verify_authenticity_token
|
|
4
4
|
|
|
5
|
-
before_action :load_cms_layout
|
|
5
|
+
before_action :load_cms_layout,
|
|
6
|
+
:use_null_session
|
|
7
|
+
|
|
8
|
+
after_action :set_cache_control_header
|
|
6
9
|
|
|
7
10
|
def render_css
|
|
8
11
|
render :text => @cms_layout.css, :content_type => 'text/css'
|
|
9
|
-
cache_control_header
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
def render_js
|
|
13
15
|
render :text => @cms_layout.js, :content_type => 'application/javascript'
|
|
14
|
-
cache_control_header
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
protected
|
|
18
19
|
|
|
19
|
-
def cache_control_header
|
|
20
|
-
if params[:cache_buster].present?
|
|
21
|
-
response.headers['Cache-Control'] = "public, max-age=#{1.year.to_i}"
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
20
|
def load_cms_layout
|
|
26
21
|
@cms_layout = @cms_site.layouts.find_by_identifier!(params[:identifier])
|
|
27
22
|
rescue ActiveRecord::RecordNotFound
|
|
28
23
|
render :nothing => true, :status => 404
|
|
29
24
|
end
|
|
25
|
+
|
|
26
|
+
# null_session avoids cookies and flash updates
|
|
27
|
+
def use_null_session
|
|
28
|
+
ActionController::RequestForgeryProtection::ProtectionMethods::NullSession.new(self)
|
|
29
|
+
.handle_unverified_request
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def set_cache_control_header
|
|
33
|
+
if params[:cache_buster].present?
|
|
34
|
+
response.headers['Cache-Control'] = "public, max-age=#{1.year.to_i}"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
30
38
|
end
|