Commit 8c14cce34d74073835603bfbc2dce842e9e7c759
Exists in
ratings_minor_fixes
and in
4 other branches
Merge branch 'comment-paragraph-content' into 'master'
comment_paragraph: add discussion content type See merge request !903
Showing
20 changed files
with
180 additions
and
6 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/lib/comment_paragraph_plugin.rb
... | ... | @@ -46,7 +46,7 @@ class CommentParagraphPlugin < Noosfero::Plugin |
46 | 46 | |
47 | 47 | def article_extra_toolbar_buttons(article) |
48 | 48 | user = context.send :user |
49 | - return [] if !article.comment_paragraph_plugin_enabled? || !article.allow_edit?(user) | |
49 | + return [] if !article.comment_paragraph_plugin_enabled? || !article.allow_edit?(user) || article.kind_of?(CommentParagraphPlugin::Discussion) | |
50 | 50 | { |
51 | 51 | :title => article.comment_paragraph_plugin_activated? ? _('Deactivate Comments') : _('Activate Comments'), |
52 | 52 | :url => {:controller => 'comment_paragraph_plugin_myprofile', :profile => article.profile.identifier, :action => 'toggle_activation', :id => article.id}, |
... | ... | @@ -59,6 +59,10 @@ class CommentParagraphPlugin < Noosfero::Plugin |
59 | 59 | [CommentParagraphPlugin::API] |
60 | 60 | end |
61 | 61 | |
62 | + def content_types | |
63 | + [CommentParagraphPlugin::Discussion] | |
64 | + end | |
65 | + | |
62 | 66 | end |
63 | 67 | |
64 | 68 | require_dependency 'comment_paragraph_plugin/macros/allow_comment' | ... | ... |
plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion.rb
0 → 100644
... | ... | @@ -0,0 +1,30 @@ |
1 | +class CommentParagraphPlugin::Discussion < Event | |
2 | + | |
3 | + def self.type_name | |
4 | + _('Comments Discussion') | |
5 | + end | |
6 | + | |
7 | + def self.short_description | |
8 | + _('Comments Discussion') | |
9 | + end | |
10 | + | |
11 | + def self.description | |
12 | + _('Article with paragraph comments') | |
13 | + end | |
14 | + | |
15 | + def accept_comments? | |
16 | + current_time = Time.now | |
17 | + super && | |
18 | + (start_date.nil? || current_time >= start_date) && | |
19 | + (end_date.nil? || current_time <= end_date) | |
20 | + end | |
21 | + | |
22 | + def comment_paragraph_plugin_activated? | |
23 | + environment.plugin_enabled?(CommentParagraphPlugin) | |
24 | + end | |
25 | + | |
26 | + def comment_paragraph_plugin_activation_mode | |
27 | + "auto" | |
28 | + end | |
29 | + | |
30 | +end | ... | ... |
plugins/comment_paragraph/lib/ext/article.rb
... | ... | @@ -12,7 +12,7 @@ class Article |
12 | 12 | settings_items :comment_paragraph_plugin_activate, :type => :boolean, :default => false |
13 | 13 | |
14 | 14 | def comment_paragraph_plugin_enabled? |
15 | - environment.plugin_enabled?(CommentParagraphPlugin) && self.kind_of?(TextArticle) | |
15 | + environment.plugin_enabled?(CommentParagraphPlugin) && (self.kind_of?(TextArticle) || self.kind_of?(CommentParagraphPlugin::Discussion)) | |
16 | 16 | end |
17 | 17 | |
18 | 18 | def comment_paragraph_plugin_activated? |
... | ... | @@ -55,7 +55,11 @@ class Article |
55 | 55 | |
56 | 56 | def comment_paragraph_plugin_set_initial_value |
57 | 57 | self.comment_paragraph_plugin_activate = comment_paragraph_plugin_enabled? && |
58 | - comment_paragraph_plugin_settings.activation_mode == 'auto' | |
58 | + comment_paragraph_plugin_activation_mode == 'auto' | |
59 | + end | |
60 | + | |
61 | + def comment_paragraph_plugin_activation_mode | |
62 | + comment_paragraph_plugin_settings.activation_mode | |
59 | 63 | end |
60 | 64 | |
61 | 65 | def comment_paragraph_plugin_settings | ... | ... |
plugins/comment_paragraph/test/unit/api_test.rb
... | ... | @@ -81,4 +81,13 @@ class APITest < ActiveSupport::TestCase |
81 | 81 | json = JSON.parse(last_response.body) |
82 | 82 | assert_equivalent [comment1.id], json['comments'].map {|c| c['id']} |
83 | 83 | end |
84 | + | |
85 | + should "create discussion article" do | |
86 | + article = fast_create(Article, :profile_id => person.id) | |
87 | + params[:article] = {name: "Title", type: "CommentParagraphPlugin::Discussion"} | |
88 | + post "/api/v1/articles/#{article.id}/children?#{params.to_query}" | |
89 | + json = JSON.parse(last_response.body) | |
90 | + assert_equal "CommentParagraphPlugin::Discussion", json["article"]["type"] | |
91 | + assert json["article"]["setting"]["comment_paragraph_plugin_activate"] | |
92 | + end | |
84 | 93 | end | ... | ... |
plugins/comment_paragraph/test/unit/article_test.rb
... | ... | @@ -170,4 +170,7 @@ class ArticleTest < ActiveSupport::TestCase |
170 | 170 | assert_equal nil, article.comment_paragraph_plugin_paragraph_content(1) |
171 | 171 | end |
172 | 172 | |
173 | + should 'be enabled if plugin is enabled and article is a kind of Discussion' do | |
174 | + assert fast_create(CommentParagraphPlugin::Discussion, profile_id: profile.id).comment_paragraph_plugin_enabled? | |
175 | + end | |
173 | 176 | end | ... | ... |
plugins/comment_paragraph/test/unit/comment_paragraph_plugin_test.rb
... | ... | @@ -84,4 +84,12 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase |
84 | 84 | assert_equal 'Deactivate Comments', plugin.article_extra_toolbar_buttons(article)[:title] |
85 | 85 | end |
86 | 86 | |
87 | + should 'not display button to toggle comment paragraph if article is a discussion' do | |
88 | + profile = fast_create(Profile) | |
89 | + article = fast_create(CommentParagraphPlugin::Discussion, :profile_id => profile.id) | |
90 | + article.expects(:comment_paragraph_plugin_enabled?).returns(true) | |
91 | + article.expects(:allow_edit?).with(user).returns(true) | |
92 | + | |
93 | + assert_equal [], plugin.article_extra_toolbar_buttons(article) | |
94 | + end | |
87 | 95 | end | ... | ... |
... | ... | @@ -0,0 +1,36 @@ |
1 | +require_relative '../test_helper' | |
2 | + | |
3 | +class DiscussionTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @profile = fast_create(Community) | |
7 | + @discussion = fast_create(TextArticle, :profile_id => profile.id) | |
8 | + @environment = Environment.default | |
9 | + @environment.enable_plugin(CommentParagraphPlugin) | |
10 | + end | |
11 | + | |
12 | + attr_reader :discussion, :environment, :profile | |
13 | + | |
14 | + should 'parse html when save discussion' do | |
15 | + discussion = CommentParagraphPlugin::Discussion.new(profile: profile, name: "discussion", start_date: Time.now, end_date: Time.now + 1.day) | |
16 | + discussion.body = '<ul><li class="custom_class">item1</li><li>item2</li></ul>' | |
17 | + discussion.save! | |
18 | + assert discussion.comment_paragraph_plugin_activate | |
19 | + assert_mark_paragraph discussion.body, 'li', 'item1' | |
20 | + assert_mark_paragraph discussion.body, 'li', 'item2' | |
21 | + end | |
22 | + | |
23 | + should 'not allow comments after end date' do | |
24 | + discussion = CommentParagraphPlugin::Discussion.create!(profile: profile, name: "discussion", start_date: Time.now - 2.days, end_date: Time.now - 1.day) | |
25 | + assert !discussion.accept_comments? | |
26 | + end | |
27 | + | |
28 | + should 'not allow comments before start date' do | |
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? | |
31 | + end | |
32 | + | |
33 | + should 'have can_display_blocks with default false' do | |
34 | + assert !CommentParagraphPlugin::Discussion.can_display_blocks? | |
35 | + end | |
36 | +end | ... | ... |
plugins/comment_paragraph/views/cms/comment_paragraph_plugin/_discussion.html.erb
0 → 100644
... | ... | @@ -0,0 +1,13 @@ |
1 | +<%= required_fields_message %> | |
2 | + | |
3 | +<%= render :file => 'shared/tiny_mce' %> | |
4 | + | |
5 | +<div> | |
6 | + <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %> | |
7 | + | |
8 | + <%= render :partial => 'text_fields' %> | |
9 | + <%= render :partial => 'general_fields' %> | |
10 | + <%= render :partial => 'translatable' %> | |
11 | + <%= date_range_field('article[start_date]', 'article[end_date]', @article.start_date, @article.end_date, {:time => true}, {:id => 'article_start_date'} ) %> | |
12 | + <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true} %> | |
13 | +</div> | ... | ... |
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