Commit f9b47d6f877b1085574ef06c22b454010adc5b2f
Committed by
Antonio Terceiro
1 parent
5534d8f9
Exists in
master
and in
28 other branches
Communities can publish article in the portal community
(ActionItem1628)
Showing
5 changed files
with
122 additions
and
24 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
... | ... | @@ -242,6 +242,29 @@ class CmsController < MyProfileController |
242 | 242 | end |
243 | 243 | end |
244 | 244 | |
245 | + def publish_on_portal_community | |
246 | + @article = profile.articles.find(params[:id]) | |
247 | + if request.post? | |
248 | + if environment.portal_community | |
249 | + task = ApproveArticle.create!(:article => @article, :name => params[:name], :target => environment.portal_community, :requestor => user) | |
250 | + begin | |
251 | + task.finish unless environment.portal_community.moderated_articles? | |
252 | + flash[:notice] = _("Your publish request was sent successfully") | |
253 | + rescue | |
254 | + flash[:error] = _("Your publish request couldn't be sent.") | |
255 | + end | |
256 | + else | |
257 | + flash[:notice] = _("There is no portal community to publish your article.") | |
258 | + end | |
259 | + | |
260 | + if @back_to | |
261 | + redirect_to @back_to | |
262 | + else | |
263 | + redirect_to @article.view_url | |
264 | + end | |
265 | + end | |
266 | + end | |
267 | + | |
245 | 268 | def media_listing |
246 | 269 | if params[:image_folder_id] |
247 | 270 | folder = profile.articles.find(params[:image_folder_id]) if !params[:image_folder_id].blank? | ... | ... |
... | ... | @@ -0,0 +1,21 @@ |
1 | +<% if environment.portal_community %> | |
2 | + <h1><%= _("Publish your article on portal community") %></h1> | |
3 | + | |
4 | + <% form_tag do%> | |
5 | + <%= hidden_field_tag :back_to, @back_to %> | |
6 | + <%= labelled_text_field _('Title') + ': ', :name, @article.name, :style => 'width: 100%' %> | |
7 | + | |
8 | + <% button_bar do %> | |
9 | + <%= submit_button 'spread', _('Spread this'), :cancel => @back_to %> | |
10 | + <% end %> | |
11 | + <% end %> | |
12 | +<% else %> | |
13 | + <div class='atention'> | |
14 | + <%= _("There is no portal community in this environment.") %> | |
15 | + </div> | |
16 | + | |
17 | + <% button_bar do %> | |
18 | + <%= button :back, _('Back'), :controller => 'cms' %> | |
19 | + <% end %> | |
20 | +<% end %> | |
21 | + | ... | ... |
app/views/cms/view.rhtml
... | ... | @@ -82,6 +82,8 @@ |
82 | 82 | <%= button_without_text :eyes, _('Public view'), item.url %> |
83 | 83 | <% if profile.person? %> |
84 | 84 | <%= button_without_text :spread, _('Spread this'), :action => 'publish', :id => item.id %> |
85 | + <% elsif profile.community? && environment.portal_community %> | |
86 | + <%= button_without_text :spread, _('Spread this'), :action => 'publish_on_portal_community', :id => item.id %> | |
85 | 87 | <% end %> |
86 | 88 | <% if !environment.enabled?('cant_change_homepage') %> |
87 | 89 | <%= button_without_text :home, _('Use as homepage'), { :action => 'set_home_page', :id => item.id }, :method => :post %> | ... | ... |
app/views/content_viewer/view_page.rhtml
... | ... | @@ -40,10 +40,16 @@ |
40 | 40 | profile.admin_url.merge({ :controller => 'cms', :action => 'destroy', :id => @page }), |
41 | 41 | :class => 'button with-text icon-delete' %> |
42 | 42 | <% end %> |
43 | - <% if profile.kind_of?(Person) && !environment.enabled?('disable_cms') && !@page.folder? %> | |
44 | - <%= link_to content_tag( 'span', _('Spread this') ), | |
45 | - profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page }), | |
46 | - :class => 'button with-text icon-spread' %> | |
43 | + <% if !environment.enabled?('disable_cms') && !@page.folder? %> | |
44 | + <% if profile.kind_of?(Person) %> | |
45 | + <%= link_to content_tag( 'span', _('Spread this') ), | |
46 | + profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page }), | |
47 | + :class => 'button with-text icon-spread' %> | |
48 | + <% elsif profile.kind_of?(Community) && environment.portal_community %> | |
49 | + <%= link_to content_tag( 'span', _('Spread this') ), | |
50 | + profile.admin_url.merge({ :controller => 'cms', :action => 'publish_on_portal_community', :id => @page }), | |
51 | + :class => 'button with-text icon-spread' %> | |
52 | + <% end %> | |
47 | 53 | <% end %> |
48 | 54 | <% end %> |
49 | 55 | <% end %> | ... | ... |
test/functional/cms_controller_test.rb
... | ... | @@ -23,11 +23,11 @@ class CmsControllerTest < Test::Unit::TestCase |
23 | 23 | def test_local_files_reference |
24 | 24 | assert_local_files_reference :get, :index, :profile => profile.identifier |
25 | 25 | end |
26 | - | |
26 | + | |
27 | 27 | def test_valid_xhtml |
28 | 28 | assert_valid_xhtml |
29 | 29 | end |
30 | - | |
30 | + | |
31 | 31 | should 'list top level documents on index' do |
32 | 32 | get :index, :profile => profile.identifier |
33 | 33 | |
... | ... | @@ -41,7 +41,7 @@ class CmsControllerTest < Test::Unit::TestCase |
41 | 41 | |
42 | 42 | a = profile.articles.build(:name => 'blablabla') |
43 | 43 | a.save! |
44 | - | |
44 | + | |
45 | 45 | get :view, :profile => profile.identifier, :id => a.id |
46 | 46 | |
47 | 47 | assert_template 'view' |
... | ... | @@ -110,7 +110,7 @@ class CmsControllerTest < Test::Unit::TestCase |
110 | 110 | should 'be able to set home page' do |
111 | 111 | a = profile.articles.build(:name => 'my new home page') |
112 | 112 | a.save! |
113 | - | |
113 | + | |
114 | 114 | assert_not_equal a, profile.home_page |
115 | 115 | |
116 | 116 | post :set_home_page, :profile => profile.identifier, :id => a.id |
... | ... | @@ -156,7 +156,7 @@ class CmsControllerTest < Test::Unit::TestCase |
156 | 156 | a = profile.articles.build(:name => 'my article') |
157 | 157 | a.last_changed_by = other_person |
158 | 158 | a.save! |
159 | - | |
159 | + | |
160 | 160 | login_as(profile.identifier) |
161 | 161 | post :edit, :profile => profile.identifier, :id => a.id, :article => { :body => 'new content for this article' } |
162 | 162 | |
... | ... | @@ -384,7 +384,7 @@ class CmsControllerTest < Test::Unit::TestCase |
384 | 384 | c1 = env.categories.build(:name => "Test category 1"); c1.save! |
385 | 385 | c2 = env.categories.build(:name => "Test category 2"); c2.save! |
386 | 386 | c3 = env.categories.build(:name => "Test Category 3"); c3.save! |
387 | - | |
387 | + | |
388 | 388 | # post is in c1 and c3 |
389 | 389 | post :new, :type => TextileArticle.name, :profile => profile.identifier, :article => { :name => 'adding-categories-test', :category_ids => [ c1.id, c3.id] } |
390 | 390 | |
... | ... | @@ -399,44 +399,44 @@ class CmsControllerTest < Test::Unit::TestCase |
399 | 399 | c1 = env.categories.build(:name => "Test category 1"); c1.save! |
400 | 400 | c2 = env.categories.build(:name => "Test category 2"); c2.save! |
401 | 401 | c3 = env.categories.build(:name => "Test Category 3"); c3.save! |
402 | - | |
402 | + | |
403 | 403 | # post is in c1, c3 and c3 |
404 | 404 | post :new, :type => TextileArticle.name, :profile => profile.identifier, :article => { :name => 'adding-categories-test', :category_ids => [ c1.id, c3.id, c3.id ] } |
405 | 405 | |
406 | 406 | saved = profile.articles.find_by_name('adding-categories-test') |
407 | 407 | assert_equal [c1, c3], saved.categories |
408 | 408 | end |
409 | - | |
409 | + | |
410 | 410 | should 'filter html from textile article name' do |
411 | 411 | post :new, :type => 'TextileArticle', :profile => profile.identifier, :article => { :name => 'a <strong>test</strong> article', :body => 'the text of the article ...' } |
412 | 412 | assert_sanitized assigns(:article).name |
413 | 413 | end |
414 | - | |
414 | + | |
415 | 415 | should 'filter html from textile article abstract' do |
416 | 416 | post :new, :type => 'TextileArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => '<strong>abstract</strong>', :body => 'the text of the article ...' } |
417 | 417 | assert_sanitized assigns(:article).abstract |
418 | 418 | end |
419 | - | |
419 | + | |
420 | 420 | should 'filter html from textile article body' do |
421 | 421 | post :new, :type => 'TextileArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => 'abstract', :body => 'the <b>text</b> of <a href=#>the</a> article ...' } |
422 | 422 | assert_sanitized assigns(:article).body |
423 | 423 | end |
424 | - | |
424 | + | |
425 | 425 | should 'filter html with white_list from tiny mce article name' do |
426 | 426 | post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => "<strong>test</strong>", :body => 'the text of the article ...' } |
427 | 427 | assert_equal "<strong>test</strong>", assigns(:article).name |
428 | 428 | end |
429 | - | |
429 | + | |
430 | 430 | should 'filter html with white_list from tiny mce article abstract' do |
431 | 431 | post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => "<script>alert('test')</script> article", :body => 'the text of the article ...' } |
432 | 432 | assert_equal " article", assigns(:article).abstract |
433 | 433 | end |
434 | - | |
434 | + | |
435 | 435 | should 'filter html with white_list from tiny mce article body' do |
436 | 436 | post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => 'abstract', :body => "the <script>alert('text')</script> of article ..." } |
437 | 437 | assert_equal "the of article ...", assigns(:article).body |
438 | 438 | end |
439 | - | |
439 | + | |
440 | 440 | should 'not filter html tags permitted from tiny mce article body' do |
441 | 441 | post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => 'abstract', :body => "<b>the</b> <script>alert('text')</script> <strong>of</strong> article ..." } |
442 | 442 | assert_equal "<b>the</b> <strong>of</strong> article ...", assigns(:article).body |
... | ... | @@ -653,7 +653,7 @@ class CmsControllerTest < Test::Unit::TestCase |
653 | 653 | |
654 | 654 | should 'create a private article child of private folder' do |
655 | 655 | folder = Folder.new(:name => 'my intranet', :published => false); profile.articles << folder; folder.save! |
656 | - | |
656 | + | |
657 | 657 | post :new, :profile => profile.identifier, :type => 'TextileArticle', :parent_id => folder.id, :article => { :name => 'new-private-article'} |
658 | 658 | folder.reload |
659 | 659 | |
... | ... | @@ -666,7 +666,7 @@ class CmsControllerTest < Test::Unit::TestCase |
666 | 666 | c = Community.create!(:name => 'test comm', :identifier => 'test_comm') |
667 | 667 | c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) |
668 | 668 | a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') |
669 | - | |
669 | + | |
670 | 670 | get :publish, :profile => profile.identifier, :id => a.id |
671 | 671 | |
672 | 672 | assert_equal [c], assigns(:groups) |
... | ... | @@ -677,18 +677,38 @@ class CmsControllerTest < Test::Unit::TestCase |
677 | 677 | c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => false) |
678 | 678 | c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) |
679 | 679 | a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') |
680 | - | |
680 | + | |
681 | 681 | assert_difference PublishedArticle, :count do |
682 | 682 | post :publish, :profile => profile.identifier, :id => a.id, :marked_groups => [{:name => 'bli', :group_id => c.id.to_s}] |
683 | 683 | assert_equal [{'group' => c, 'name' => 'bli'}], assigns(:marked_groups) |
684 | 684 | end |
685 | 685 | end |
686 | - | |
686 | + | |
687 | + should "not crash if there is a post and no portal community defined" do | |
688 | + Environment.any_instance.stubs(:portal_community).returns(nil) | |
689 | + article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') | |
690 | + assert_nothing_raised do | |
691 | + post :publish_on_portal_community, :profile => profile.identifier, :id => article.id, :name => article.name | |
692 | + end | |
693 | + end | |
694 | + | |
695 | + should 'publish the article on portal community if it is not moderated' do | |
696 | + portal_community = fast_create(Community) | |
697 | + portal_community.moderated_articles = false | |
698 | + portal_community.save | |
699 | + Environment.any_instance.stubs(:portal_community).returns(portal_community) | |
700 | + article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') | |
701 | + | |
702 | + assert_difference PublishedArticle, :count do | |
703 | + post :publish_on_portal_community, :profile => profile.identifier, :id => article.id, :name => article.name | |
704 | + end | |
705 | + end | |
706 | + | |
687 | 707 | should 'create a task for article approval if community is moderated' do |
688 | 708 | c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => true) |
689 | 709 | c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) |
690 | 710 | a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') |
691 | - | |
711 | + | |
692 | 712 | assert_no_difference PublishedArticle, :count do |
693 | 713 | assert_difference ApproveArticle, :count do |
694 | 714 | assert_difference c.tasks, :count do |
... | ... | @@ -699,6 +719,22 @@ class CmsControllerTest < Test::Unit::TestCase |
699 | 719 | end |
700 | 720 | end |
701 | 721 | |
722 | + should 'create a task for article approval if portal community is moderated' do | |
723 | + portal_community = fast_create(Community) | |
724 | + portal_community.moderated_articles = true | |
725 | + portal_community.save | |
726 | + Environment.any_instance.stubs(:portal_community).returns(portal_community) | |
727 | + article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') | |
728 | + | |
729 | + assert_no_difference PublishedArticle, :count do | |
730 | + assert_difference ApproveArticle, :count do | |
731 | + assert_difference portal_community.tasks, :count do | |
732 | + post :publish_on_portal_community, :profile => profile.identifier, :id => article.id, :name => article.name | |
733 | + end | |
734 | + end | |
735 | + end | |
736 | + end | |
737 | + | |
702 | 738 | should 'require ssl in general' do |
703 | 739 | Environment.default.update_attribute(:enable_ssl, true) |
704 | 740 | @request.expects(:ssl?).returns(false).at_least_once |
... | ... | @@ -1136,7 +1172,17 @@ class CmsControllerTest < Test::Unit::TestCase |
1136 | 1172 | assert_tag :tag => 'a', :attributes => {:href => "/myprofile/#{profile.identifier}/cms/publish/#{a.id}"} |
1137 | 1173 | end |
1138 | 1174 | |
1139 | - should "not display 'Publish' when profile is not a person" do | |
1175 | + should "display 'Publish' when profile is a community" do | |
1176 | + community = fast_create(Community) | |
1177 | + community.add_member(profile) | |
1178 | + Environment.any_instance.stubs(:portal_community).returns(community) | |
1179 | + a = community.articles.create!(:name => 'my new home page') | |
1180 | + Article.stubs(:short_description).returns('bli') | |
1181 | + get :index, :profile => community.identifier | |
1182 | + assert_tag :tag => 'a', :attributes => {:href => "/myprofile/#{community.identifier}/cms/publish_on_portal_community/#{a.id}"} | |
1183 | + end | |
1184 | + | |
1185 | + should "not display 'Publish' when profile is not a person nor a community" do | |
1140 | 1186 | p = Community.create!(:name => 'community-test') |
1141 | 1187 | p.add_admin(profile) |
1142 | 1188 | a = p.articles.create!(:name => 'my new home page') | ... | ... |