Commit 5e08910693225d83a2f5d03d738e1eaf38f41f8e

Authored by Victor Costa
1 parent 11216f6b

Define when blocks should be displayed for article edition

app/controllers/my_profile/cms_controller.rb
@@ -443,9 +443,7 @@ class CmsController < MyProfileController @@ -443,9 +443,7 @@ class CmsController < MyProfileController
443 end 443 end
444 444
445 def refuse_blocks 445 def refuse_blocks
446 - if ['TinyMceArticle', 'TextileArticle', 'Event', 'EnterpriseHomepage'].include?(@type)  
447 - @no_design_blocks = true  
448 - end 446 + @no_design_blocks = @type.present? && valid_article_type?(@type) ? !@type.constantize.can_display_blocks? : false
449 end 447 end
450 448
451 def per_page 449 def per_page
app/models/article.rb
@@ -864,6 +864,10 @@ class Article < ApplicationRecord @@ -864,6 +864,10 @@ class Article < ApplicationRecord
864 HashWithIndifferentAccess.new :name => name, :abstract => abstract, :body => body, :id => id, :parent_id => parent_id, :author => author 864 HashWithIndifferentAccess.new :name => name, :abstract => abstract, :body => body, :id => id, :parent_id => parent_id, :author => author
865 end 865 end
866 866
  867 + def self.can_display_blocks?
  868 + true
  869 + end
  870 +
867 private 871 private
868 872
869 def sanitize_tag_list 873 def sanitize_tag_list
app/models/event.rb
@@ -134,6 +134,10 @@ class Event < Article @@ -134,6 +134,10 @@ class Event < Article
134 true 134 true
135 end 135 end
136 136
  137 + def self.can_display_blocks?
  138 + false
  139 + end
  140 +
137 include Noosfero::TranslatableContent 141 include Noosfero::TranslatableContent
138 include MaybeAddHttp 142 include MaybeAddHttp
139 143
app/models/textile_article.rb
@@ -29,6 +29,10 @@ class TextileArticle < TextArticle @@ -29,6 +29,10 @@ class TextileArticle < TextArticle
29 true 29 true
30 end 30 end
31 31
  32 + def self.can_display_blocks?
  33 + false
  34 + end
  35 +
32 protected 36 protected
33 37
34 def convert_to_html(textile) 38 def convert_to_html(textile)
app/models/tiny_mce_article.rb
@@ -32,4 +32,8 @@ class TinyMceArticle < TextArticle @@ -32,4 +32,8 @@ class TinyMceArticle < TextArticle
32 true 32 true
33 end 33 end
34 34
  35 + def self.can_display_blocks?
  36 + false
  37 + end
  38 +
35 end 39 end
plugins/comment_paragraph/test/unit/discussion_test.rb
@@ -29,4 +29,8 @@ class DiscussionTest < ActiveSupport::TestCase @@ -29,4 +29,8 @@ class DiscussionTest < ActiveSupport::TestCase
29 discussion = CommentParagraphPlugin::Discussion.create!(profile: profile, name: "discussion", start_date: Time.now + 1.day, end_date: Time.now + 2.days) 29 discussion = CommentParagraphPlugin::Discussion.create!(profile: profile, name: "discussion", start_date: Time.now + 1.day, end_date: Time.now + 2.days)
30 assert !discussion.accept_comments? 30 assert !discussion.accept_comments?
31 end 31 end
  32 +
  33 + should 'have can_display_blocks with default false' do
  34 + assert !CommentParagraphPlugin::Discussion.can_display_blocks?
  35 + end
32 end 36 end
plugins/products/models/products_plugin/enterprise_homepage.rb
@@ -48,5 +48,9 @@ module ProductsPlugin @@ -48,5 +48,9 @@ module ProductsPlugin
48 true 48 true
49 end 49 end
50 50
  51 + def self.can_display_blocks?
  52 + false
  53 + end
  54 +
51 end 55 end
52 end 56 end
plugins/products/test/unit/products_plugin/enterprise_homepage_test.rb
@@ -30,4 +30,7 @@ class EnterpriseHomepageTest < ActiveSupport::TestCase @@ -30,4 +30,7 @@ class EnterpriseHomepageTest < ActiveSupport::TestCase
30 assert a.can_display_media_panel? 30 assert a.can_display_media_panel?
31 end 31 end
32 32
  33 + should 'have can_display_blocks with default false' do
  34 + assert !EnterpriseHomepage.can_display_blocks?
  35 + end
33 end 36 end
test/functional/cms_controller_test.rb
@@ -1993,6 +1993,39 @@ class CmsControllerTest < ActionController::TestCase @@ -1993,6 +1993,39 @@ class CmsControllerTest < ActionController::TestCase
1993 assert_match main_article.body, @response.body 1993 assert_match main_article.body, @response.body
1994 end 1994 end
1995 1995
  1996 + should 'set no_design_blocks as false when create a new document without type' do
  1997 + get :new, profile: profile.identifier
  1998 + assert !assigns(:no_design_blocks)
  1999 + end
  2000 +
  2001 + should 'set no_design_blocks as false when create a new document with invalid type' do
  2002 + assert_raise RuntimeError do
  2003 + get :new, profile: profile.identifier, type: 'InvalidType'
  2004 + assert !assigns(:no_design_blocks)
  2005 + end
  2006 + end
  2007 +
  2008 + [TextileArticle, Event, TinyMceArticle].each do |klass|
  2009 + should "set no_design_blocks as true when create #{klass.name}" do
  2010 + get :new, profile: profile.identifier, type: klass.name
  2011 + assert assigns(:no_design_blocks)
  2012 + end
  2013 + end
  2014 +
  2015 + should "set no_design_blocks as false when edit Article" do
  2016 + article = fast_create(Article, profile_id: profile.id)
  2017 + get :edit, profile: profile.identifier, id: article.id
  2018 + assert !assigns(:no_design_blocks)
  2019 + end
  2020 +
  2021 + [TextileArticle, Event, TinyMceArticle].each do |klass|
  2022 + should "set no_design_blocks as true when edit #{klass.name}" do
  2023 + article = fast_create(klass, profile_id: profile.id)
  2024 + get :edit, profile: profile.identifier, id: article.id
  2025 + assert assigns(:no_design_blocks)
  2026 + end
  2027 + end
  2028 +
1996 protected 2029 protected
1997 2030
1998 # FIXME this is to avoid adding an extra dependency for a proper JSON parser. 2031 # FIXME this is to avoid adding an extra dependency for a proper JSON parser.
test/unit/article_test.rb
@@ -2327,4 +2327,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -2327,4 +2327,7 @@ class ArticleTest < ActiveSupport::TestCase
2327 assert_match 'Parent folder is archived', err.message 2327 assert_match 'Parent folder is archived', err.message
2328 end 2328 end
2329 2329
  2330 + should 'have can_display_blocks with default true' do
  2331 + assert Article.can_display_blocks?
  2332 + end
2330 end 2333 end
test/unit/event_test.rb
@@ -333,4 +333,7 @@ class EventTest < ActiveSupport::TestCase @@ -333,4 +333,7 @@ class EventTest < ActiveSupport::TestCase
333 assert_equal 1, e.duration 333 assert_equal 1, e.duration
334 end 334 end
335 335
  336 + should 'have can_display_blocks with default false' do
  337 + assert !Event.can_display_blocks?
  338 + end
336 end 339 end
test/unit/textile_article_test.rb
@@ -178,6 +178,10 @@ class TextileArticleTest < ActiveSupport::TestCase @@ -178,6 +178,10 @@ class TextileArticleTest < ActiveSupport::TestCase
178 assert a.can_display_media_panel? 178 assert a.can_display_media_panel?
179 end 179 end
180 180
  181 + should 'have can_display_blocks with default false' do
  182 + assert !TextileArticle.can_display_blocks?
  183 + end
  184 +
181 protected 185 protected
182 186
183 def build_article(input = nil, options = {}) 187 def build_article(input = nil, options = {})
test/unit/tiny_mce_article_test.rb
@@ -237,4 +237,7 @@ class TinyMceArticleTest < ActiveSupport::TestCase @@ -237,4 +237,7 @@ class TinyMceArticleTest < ActiveSupport::TestCase
237 assert a.can_display_media_panel? 237 assert a.can_display_media_panel?
238 end 238 end
239 239
  240 + should 'have can_display_blocks with default false' do
  241 + assert !TinyMceArticle.can_display_blocks?
  242 + end
240 end 243 end