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 443 end
444 444  
445 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 447 end
450 448  
451 449 def per_page
... ...
app/models/article.rb
... ... @@ -864,6 +864,10 @@ class Article < ApplicationRecord
864 864 HashWithIndifferentAccess.new :name => name, :abstract => abstract, :body => body, :id => id, :parent_id => parent_id, :author => author
865 865 end
866 866  
  867 + def self.can_display_blocks?
  868 + true
  869 + end
  870 +
867 871 private
868 872  
869 873 def sanitize_tag_list
... ...
app/models/event.rb
... ... @@ -134,6 +134,10 @@ class Event < Article
134 134 true
135 135 end
136 136  
  137 + def self.can_display_blocks?
  138 + false
  139 + end
  140 +
137 141 include Noosfero::TranslatableContent
138 142 include MaybeAddHttp
139 143  
... ...
app/models/textile_article.rb
... ... @@ -29,6 +29,10 @@ class TextileArticle < TextArticle
29 29 true
30 30 end
31 31  
  32 + def self.can_display_blocks?
  33 + false
  34 + end
  35 +
32 36 protected
33 37  
34 38 def convert_to_html(textile)
... ...
app/models/tiny_mce_article.rb
... ... @@ -32,4 +32,8 @@ class TinyMceArticle < TextArticle
32 32 true
33 33 end
34 34  
  35 + def self.can_display_blocks?
  36 + false
  37 + end
  38 +
35 39 end
... ...
plugins/comment_paragraph/test/unit/discussion_test.rb
... ... @@ -29,4 +29,8 @@ class DiscussionTest < ActiveSupport::TestCase
29 29 discussion = CommentParagraphPlugin::Discussion.create!(profile: profile, name: "discussion", start_date: Time.now + 1.day, end_date: Time.now + 2.days)
30 30 assert !discussion.accept_comments?
31 31 end
  32 +
  33 + should 'have can_display_blocks with default false' do
  34 + assert !CommentParagraphPlugin::Discussion.can_display_blocks?
  35 + end
32 36 end
... ...
plugins/products/models/products_plugin/enterprise_homepage.rb
... ... @@ -48,5 +48,9 @@ module ProductsPlugin
48 48 true
49 49 end
50 50  
  51 + def self.can_display_blocks?
  52 + false
  53 + end
  54 +
51 55 end
52 56 end
... ...
plugins/products/test/unit/products_plugin/enterprise_homepage_test.rb
... ... @@ -30,4 +30,7 @@ class EnterpriseHomepageTest < ActiveSupport::TestCase
30 30 assert a.can_display_media_panel?
31 31 end
32 32  
  33 + should 'have can_display_blocks with default false' do
  34 + assert !EnterpriseHomepage.can_display_blocks?
  35 + end
33 36 end
... ...
test/functional/cms_controller_test.rb
... ... @@ -1993,6 +1993,39 @@ class CmsControllerTest < ActionController::TestCase
1993 1993 assert_match main_article.body, @response.body
1994 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 2029 protected
1997 2030  
1998 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 2327 assert_match 'Parent folder is archived', err.message
2328 2328 end
2329 2329  
  2330 + should 'have can_display_blocks with default true' do
  2331 + assert Article.can_display_blocks?
  2332 + end
2330 2333 end
... ...
test/unit/event_test.rb
... ... @@ -333,4 +333,7 @@ class EventTest < ActiveSupport::TestCase
333 333 assert_equal 1, e.duration
334 334 end
335 335  
  336 + should 'have can_display_blocks with default false' do
  337 + assert !Event.can_display_blocks?
  338 + end
336 339 end
... ...
test/unit/textile_article_test.rb
... ... @@ -178,6 +178,10 @@ class TextileArticleTest < ActiveSupport::TestCase
178 178 assert a.can_display_media_panel?
179 179 end
180 180  
  181 + should 'have can_display_blocks with default false' do
  182 + assert !TextileArticle.can_display_blocks?
  183 + end
  184 +
181 185 protected
182 186  
183 187 def build_article(input = nil, options = {})
... ...
test/unit/tiny_mce_article_test.rb
... ... @@ -237,4 +237,7 @@ class TinyMceArticleTest < ActiveSupport::TestCase
237 237 assert a.can_display_media_panel?
238 238 end
239 239  
  240 + should 'have can_display_blocks with default false' do
  241 + assert !TinyMceArticle.can_display_blocks?
  242 + end
240 243 end
... ...