Commit 1a60ef5643e81b0fe438c2e4b21a4ade9d562029

Authored by Antonio Terceiro
1 parent 48987aaf

Moving methods to the protected section

app/controllers/my_profile/cms_controller.rb
@@ -15,6 +15,7 @@ class CmsController < MyProfileController @@ -15,6 +15,7 @@ class CmsController < MyProfileController
15 end 15 end
16 16
17 before_filter :login_required, :except => [:suggest_an_article] 17 before_filter :login_required, :except => [:suggest_an_article]
  18 +
18 protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish] do |c, user, profile| 19 protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish] do |c, user, profile|
19 user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile)) 20 user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile))
20 end 21 end
@@ -27,32 +28,6 @@ class CmsController < MyProfileController @@ -27,32 +28,6 @@ class CmsController < MyProfileController
27 profile 28 profile
28 end 29 end
29 30
30 - include CmsHelper  
31 -  
32 - def available_article_types  
33 - articles = [  
34 - TinyMceArticle,  
35 - TextileArticle,  
36 - Event  
37 - ]  
38 - articles += special_article_types if params && params[:cms]  
39 - parent_id = params ? params[:parent_id] : nil  
40 - if profile.enterprise?  
41 - articles << EnterpriseHomepage  
42 - end  
43 - if @parent && @parent.blog?  
44 - articles -= Article.folder_types.map(&:constantize)  
45 - end  
46 - if user.is_admin?(profile.environment)  
47 - articles << RawHTMLArticle  
48 - end  
49 - articles  
50 - end  
51 -  
52 - def special_article_types  
53 - [Folder, Blog, UploadedFile, Forum, Gallery, RssFeed] + @plugins.dispatch(:content_types)  
54 - end  
55 -  
56 def view 31 def view
57 @article = profile.articles.find(params[:id]) 32 @article = profile.articles.find(params[:id])
58 conditions = [] 33 conditions = []
@@ -303,6 +278,33 @@ class CmsController &lt; MyProfileController @@ -303,6 +278,33 @@ class CmsController &lt; MyProfileController
303 278
304 protected 279 protected
305 280
  281 + include CmsHelper
  282 +
  283 + def available_article_types
  284 + articles = [
  285 + TinyMceArticle,
  286 + TextileArticle,
  287 + Event
  288 + ]
  289 + articles += special_article_types if params && params[:cms]
  290 + parent_id = params ? params[:parent_id] : nil
  291 + if profile.enterprise?
  292 + articles << EnterpriseHomepage
  293 + end
  294 + if @parent && @parent.blog?
  295 + articles -= Article.folder_types.map(&:constantize)
  296 + end
  297 + if user.is_admin?(profile.environment)
  298 + articles << RawHTMLArticle
  299 + end
  300 + articles
  301 + end
  302 +
  303 + def special_article_types
  304 + [Folder, Blog, UploadedFile, Forum, Gallery, RssFeed] + @plugins.dispatch(:content_types)
  305 + end
  306 +
  307 +
306 def record_coming 308 def record_coming
307 if request.post? 309 if request.post?
308 @back_to = params[:back_to] 310 @back_to = params[:back_to]
test/functional/cms_controller_test.rb
@@ -601,12 +601,12 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -601,12 +601,12 @@ class CmsControllerTest &lt; ActionController::TestCase
601 601
602 should 'not make enterprise homepage available to person' do 602 should 'not make enterprise homepage available to person' do
603 @controller.stubs(:profile).returns(profile) 603 @controller.stubs(:profile).returns(profile)
604 - assert_not_includes @controller.available_article_types, EnterpriseHomepage 604 + assert_not_includes available_article_types, EnterpriseHomepage
605 end 605 end
606 606
607 should 'make enterprise homepage available to enterprises' do 607 should 'make enterprise homepage available to enterprises' do
608 @controller.stubs(:profile).returns(fast_create(Enterprise, :name => 'test_ent', :identifier => 'test_ent')) 608 @controller.stubs(:profile).returns(fast_create(Enterprise, :name => 'test_ent', :identifier => 'test_ent'))
609 - assert_includes @controller.available_article_types, EnterpriseHomepage 609 + assert_includes available_article_types, EnterpriseHomepage
610 end 610 end
611 611
612 should 'update categories' do 612 should 'update categories' do
@@ -841,7 +841,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -841,7 +841,7 @@ class CmsControllerTest &lt; ActionController::TestCase
841 blog = Blog.create!(:name => 'Blog for test', :profile => profile) 841 blog = Blog.create!(:name => 'Blog for test', :profile => profile)
842 @controller.stubs(:params).returns({ :parent_id => blog.id }) 842 @controller.stubs(:params).returns({ :parent_id => blog.id })
843 843
844 - assert_not_includes @controller.available_article_types, Folder 844 + assert_not_includes available_article_types, Folder
845 end 845 end
846 846
847 should 'not offer rssfeed to blog articles' do 847 should 'not offer rssfeed to blog articles' do
@@ -849,7 +849,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -849,7 +849,7 @@ class CmsControllerTest &lt; ActionController::TestCase
849 blog = Blog.create!(:name => 'Blog for test', :profile => profile) 849 blog = Blog.create!(:name => 'Blog for test', :profile => profile)
850 @controller.stubs(:params).returns({ :parent_id => blog.id }) 850 @controller.stubs(:params).returns({ :parent_id => blog.id })
851 851
852 - assert_not_includes @controller.available_article_types, RssFeed 852 + assert_not_includes available_article_types, RssFeed
853 end 853 end
854 854
855 should 'update blog posts_per_page setting' do 855 should 'update blog posts_per_page setting' do
@@ -1206,7 +1206,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1206,7 +1206,7 @@ class CmsControllerTest &lt; ActionController::TestCase
1206 forum = Forum.create!(:name => 'Forum for test', :profile => profile) 1206 forum = Forum.create!(:name => 'Forum for test', :profile => profile)
1207 @controller.stubs(:params).returns({ :parent_id => forum.id }) 1207 @controller.stubs(:params).returns({ :parent_id => forum.id })
1208 1208
1209 - assert_not_includes @controller.available_article_types, Folder 1209 + assert_not_includes available_article_types, Folder
1210 end 1210 end
1211 1211
1212 should 'not offer rssfeed to forum articles' do 1212 should 'not offer rssfeed to forum articles' do
@@ -1214,7 +1214,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1214,7 +1214,7 @@ class CmsControllerTest &lt; ActionController::TestCase
1214 forum = Forum.create!(:name => 'Forum for test', :profile => profile) 1214 forum = Forum.create!(:name => 'Forum for test', :profile => profile)
1215 @controller.stubs(:params).returns({ :parent_id => forum.id }) 1215 @controller.stubs(:params).returns({ :parent_id => forum.id })
1216 1216
1217 - assert_not_includes @controller.available_article_types, RssFeed 1217 + assert_not_includes available_article_types, RssFeed
1218 end 1218 end
1219 1219
1220 should 'update forum posts_per_page setting' do 1220 should 'update forum posts_per_page setting' do
@@ -1499,20 +1499,11 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1499,20 +1499,11 @@ class CmsControllerTest &lt; ActionController::TestCase
1499 assert_nil data[1]['error'] 1499 assert_nil data[1]['error']
1500 end 1500 end
1501 1501
1502 - protected  
1503 -  
1504 - # FIXME this is to avoid adding an extra dependency for a proper JSON parser.  
1505 - # For now we are assuming that the JSON is close enough to Ruby and just  
1506 - # making some adjustments.  
1507 - def parse_json_response  
1508 - eval(@response.body.gsub('":', '"=>').gsub('null', 'nil'))  
1509 - end  
1510 -  
1511 should 'make RawHTMLArticle available only to environment admins' do 1502 should 'make RawHTMLArticle available only to environment admins' do
1512 @controller.stubs(:profile).returns(profile) 1503 @controller.stubs(:profile).returns(profile)
1513 - assert_not_includes @controller.available_article_types, RawHTMLArticle 1504 + assert_not_includes available_article_types, RawHTMLArticle
1514 profile.environment.add_admin(profile) 1505 profile.environment.add_admin(profile)
1515 - assert_includes @controller.available_article_types, RawHTMLArticle 1506 + assert_includes available_article_types, RawHTMLArticle
1516 end 1507 end
1517 1508
1518 should 'include new contents special types from plugins' do 1509 should 'include new contents special types from plugins' do
@@ -1526,8 +1517,25 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1526,8 +1517,25 @@ class CmsControllerTest &lt; ActionController::TestCase
1526 1517
1527 get :index, :profile => profile.identifier 1518 get :index, :profile => profile.identifier
1528 1519
1529 - assert_includes @controller.special_article_types, Integer  
1530 - assert_includes @controller.special_article_types, Float 1520 + assert_includes special_article_types, Integer
  1521 + assert_includes special_article_types, Float
  1522 + end
  1523 +
  1524 + protected
  1525 +
  1526 + # FIXME this is to avoid adding an extra dependency for a proper JSON parser.
  1527 + # For now we are assuming that the JSON is close enough to Ruby and just
  1528 + # making some adjustments.
  1529 + def parse_json_response
  1530 + eval(@response.body.gsub('":', '"=>').gsub('null', 'nil'))
  1531 + end
  1532 +
  1533 + def available_article_types
  1534 + @controller.send(:available_article_types)
  1535 + end
  1536 +
  1537 + def special_article_types
  1538 + @controller.send(:special_article_types)
1531 end 1539 end
1532 1540
1533 end 1541 end