Commit 5e08910693225d83a2f5d03d738e1eaf38f41f8e
1 parent
11216f6b
Exists in
ratings_minor_fixes
and in
4 other branches
Define when blocks should be displayed for article edition
Showing
13 changed files
with
74 additions
and
3 deletions
Show diff stats
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
app/models/textile_article.rb
app/models/tiny_mce_article.rb
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
plugins/products/test/unit/products_plugin/enterprise_homepage_test.rb
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
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