From 1a60ef5643e81b0fe438c2e4b21a4ade9d562029 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Fri, 11 May 2012 15:03:40 -0300 Subject: [PATCH] Moving methods to the protected section --- app/controllers/my_profile/cms_controller.rb | 54 ++++++++++++++++++++++++++++-------------------------- test/functional/cms_controller_test.rb | 46 +++++++++++++++++++++++++++------------------- 2 files changed, 55 insertions(+), 45 deletions(-) diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 6827662..12b866e 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -15,6 +15,7 @@ class CmsController < MyProfileController end before_filter :login_required, :except => [:suggest_an_article] + protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish] do |c, user, profile| user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile)) end @@ -27,32 +28,6 @@ class CmsController < MyProfileController profile end - include CmsHelper - - def available_article_types - articles = [ - TinyMceArticle, - TextileArticle, - Event - ] - articles += special_article_types if params && params[:cms] - parent_id = params ? params[:parent_id] : nil - if profile.enterprise? - articles << EnterpriseHomepage - end - if @parent && @parent.blog? - articles -= Article.folder_types.map(&:constantize) - end - if user.is_admin?(profile.environment) - articles << RawHTMLArticle - end - articles - end - - def special_article_types - [Folder, Blog, UploadedFile, Forum, Gallery, RssFeed] + @plugins.dispatch(:content_types) - end - def view @article = profile.articles.find(params[:id]) conditions = [] @@ -303,6 +278,33 @@ class CmsController < MyProfileController protected + include CmsHelper + + def available_article_types + articles = [ + TinyMceArticle, + TextileArticle, + Event + ] + articles += special_article_types if params && params[:cms] + parent_id = params ? params[:parent_id] : nil + if profile.enterprise? + articles << EnterpriseHomepage + end + if @parent && @parent.blog? + articles -= Article.folder_types.map(&:constantize) + end + if user.is_admin?(profile.environment) + articles << RawHTMLArticle + end + articles + end + + def special_article_types + [Folder, Blog, UploadedFile, Forum, Gallery, RssFeed] + @plugins.dispatch(:content_types) + end + + def record_coming if request.post? @back_to = params[:back_to] diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index f851a16..01301bc 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -601,12 +601,12 @@ class CmsControllerTest < ActionController::TestCase should 'not make enterprise homepage available to person' do @controller.stubs(:profile).returns(profile) - assert_not_includes @controller.available_article_types, EnterpriseHomepage + assert_not_includes available_article_types, EnterpriseHomepage end should 'make enterprise homepage available to enterprises' do @controller.stubs(:profile).returns(fast_create(Enterprise, :name => 'test_ent', :identifier => 'test_ent')) - assert_includes @controller.available_article_types, EnterpriseHomepage + assert_includes available_article_types, EnterpriseHomepage end should 'update categories' do @@ -841,7 +841,7 @@ class CmsControllerTest < ActionController::TestCase blog = Blog.create!(:name => 'Blog for test', :profile => profile) @controller.stubs(:params).returns({ :parent_id => blog.id }) - assert_not_includes @controller.available_article_types, Folder + assert_not_includes available_article_types, Folder end should 'not offer rssfeed to blog articles' do @@ -849,7 +849,7 @@ class CmsControllerTest < ActionController::TestCase blog = Blog.create!(:name => 'Blog for test', :profile => profile) @controller.stubs(:params).returns({ :parent_id => blog.id }) - assert_not_includes @controller.available_article_types, RssFeed + assert_not_includes available_article_types, RssFeed end should 'update blog posts_per_page setting' do @@ -1206,7 +1206,7 @@ class CmsControllerTest < ActionController::TestCase forum = Forum.create!(:name => 'Forum for test', :profile => profile) @controller.stubs(:params).returns({ :parent_id => forum.id }) - assert_not_includes @controller.available_article_types, Folder + assert_not_includes available_article_types, Folder end should 'not offer rssfeed to forum articles' do @@ -1214,7 +1214,7 @@ class CmsControllerTest < ActionController::TestCase forum = Forum.create!(:name => 'Forum for test', :profile => profile) @controller.stubs(:params).returns({ :parent_id => forum.id }) - assert_not_includes @controller.available_article_types, RssFeed + assert_not_includes available_article_types, RssFeed end should 'update forum posts_per_page setting' do @@ -1499,20 +1499,11 @@ class CmsControllerTest < ActionController::TestCase assert_nil data[1]['error'] end - protected - - # FIXME this is to avoid adding an extra dependency for a proper JSON parser. - # For now we are assuming that the JSON is close enough to Ruby and just - # making some adjustments. - def parse_json_response - eval(@response.body.gsub('":', '"=>').gsub('null', 'nil')) - end - should 'make RawHTMLArticle available only to environment admins' do @controller.stubs(:profile).returns(profile) - assert_not_includes @controller.available_article_types, RawHTMLArticle + assert_not_includes available_article_types, RawHTMLArticle profile.environment.add_admin(profile) - assert_includes @controller.available_article_types, RawHTMLArticle + assert_includes available_article_types, RawHTMLArticle end should 'include new contents special types from plugins' do @@ -1526,8 +1517,25 @@ class CmsControllerTest < ActionController::TestCase get :index, :profile => profile.identifier - assert_includes @controller.special_article_types, Integer - assert_includes @controller.special_article_types, Float + assert_includes special_article_types, Integer + assert_includes special_article_types, Float + end + + protected + + # FIXME this is to avoid adding an extra dependency for a proper JSON parser. + # For now we are assuming that the JSON is close enough to Ruby and just + # making some adjustments. + def parse_json_response + eval(@response.body.gsub('":', '"=>').gsub('null', 'nil')) + end + + def available_article_types + @controller.send(:available_article_types) + end + + def special_article_types + @controller.send(:special_article_types) end end -- libgit2 0.21.2