diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index b2d7ab7..9d29e4f 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -242,6 +242,29 @@ class CmsController < MyProfileController end end + def publish_on_portal_community + @article = profile.articles.find(params[:id]) + if request.post? + if environment.portal_community + task = ApproveArticle.create!(:article => @article, :name => params[:name], :target => environment.portal_community, :requestor => user) + begin + task.finish unless environment.portal_community.moderated_articles? + flash[:notice] = _("Your publish request was sent successfully") + rescue + flash[:error] = _("Your publish request couldn't be sent.") + end + else + flash[:notice] = _("There is no portal community to publish your article.") + end + + if @back_to + redirect_to @back_to + else + redirect_to @article.view_url + end + end + end + def media_listing if params[:image_folder_id] folder = profile.articles.find(params[:image_folder_id]) if !params[:image_folder_id].blank? diff --git a/app/views/cms/publish_on_portal_community.rhtml b/app/views/cms/publish_on_portal_community.rhtml new file mode 100644 index 0000000..54d5cef --- /dev/null +++ b/app/views/cms/publish_on_portal_community.rhtml @@ -0,0 +1,21 @@ +<% if environment.portal_community %> +

<%= _("Publish your article on portal community") %>

+ + <% form_tag do%> + <%= hidden_field_tag :back_to, @back_to %> + <%= labelled_text_field _('Title') + ': ', :name, @article.name, :style => 'width: 100%' %> + + <% button_bar do %> + <%= submit_button 'spread', _('Spread this'), :cancel => @back_to %> + <% end %> + <% end %> +<% else %> +
+ <%= _("There is no portal community in this environment.") %> +
+ + <% button_bar do %> + <%= button :back, _('Back'), :controller => 'cms' %> + <% end %> +<% end %> + diff --git a/app/views/cms/view.rhtml b/app/views/cms/view.rhtml index 608a524..94a63bc 100644 --- a/app/views/cms/view.rhtml +++ b/app/views/cms/view.rhtml @@ -82,6 +82,8 @@ <%= button_without_text :eyes, _('Public view'), item.url %> <% if profile.person? %> <%= button_without_text :spread, _('Spread this'), :action => 'publish', :id => item.id %> + <% elsif profile.community? && environment.portal_community %> + <%= button_without_text :spread, _('Spread this'), :action => 'publish_on_portal_community', :id => item.id %> <% end %> <% if !environment.enabled?('cant_change_homepage') %> <%= button_without_text :home, _('Use as homepage'), { :action => 'set_home_page', :id => item.id }, :method => :post %> diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml index e2f4781..c4749b3 100644 --- a/app/views/content_viewer/view_page.rhtml +++ b/app/views/content_viewer/view_page.rhtml @@ -40,10 +40,16 @@ profile.admin_url.merge({ :controller => 'cms', :action => 'destroy', :id => @page }), :class => 'button with-text icon-delete' %> <% end %> - <% if profile.kind_of?(Person) && !environment.enabled?('disable_cms') && !@page.folder? %> - <%= link_to content_tag( 'span', _('Spread this') ), - profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page }), - :class => 'button with-text icon-spread' %> + <% if !environment.enabled?('disable_cms') && !@page.folder? %> + <% if profile.kind_of?(Person) %> + <%= link_to content_tag( 'span', _('Spread this') ), + profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page }), + :class => 'button with-text icon-spread' %> + <% elsif profile.kind_of?(Community) && environment.portal_community %> + <%= link_to content_tag( 'span', _('Spread this') ), + profile.admin_url.merge({ :controller => 'cms', :action => 'publish_on_portal_community', :id => @page }), + :class => 'button with-text icon-spread' %> + <% end %> <% end %> <% end %> <% end %> diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 5d3fd28..7e6eb7d 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -23,11 +23,11 @@ class CmsControllerTest < Test::Unit::TestCase def test_local_files_reference assert_local_files_reference :get, :index, :profile => profile.identifier end - + def test_valid_xhtml assert_valid_xhtml end - + should 'list top level documents on index' do get :index, :profile => profile.identifier @@ -41,7 +41,7 @@ class CmsControllerTest < Test::Unit::TestCase a = profile.articles.build(:name => 'blablabla') a.save! - + get :view, :profile => profile.identifier, :id => a.id assert_template 'view' @@ -110,7 +110,7 @@ class CmsControllerTest < Test::Unit::TestCase should 'be able to set home page' do a = profile.articles.build(:name => 'my new home page') a.save! - + assert_not_equal a, profile.home_page post :set_home_page, :profile => profile.identifier, :id => a.id @@ -156,7 +156,7 @@ class CmsControllerTest < Test::Unit::TestCase a = profile.articles.build(:name => 'my article') a.last_changed_by = other_person a.save! - + login_as(profile.identifier) post :edit, :profile => profile.identifier, :id => a.id, :article => { :body => 'new content for this article' } @@ -384,7 +384,7 @@ class CmsControllerTest < Test::Unit::TestCase c1 = env.categories.build(:name => "Test category 1"); c1.save! c2 = env.categories.build(:name => "Test category 2"); c2.save! c3 = env.categories.build(:name => "Test Category 3"); c3.save! - + # post is in c1 and c3 post :new, :type => TextileArticle.name, :profile => profile.identifier, :article => { :name => 'adding-categories-test', :category_ids => [ c1.id, c3.id] } @@ -399,44 +399,44 @@ class CmsControllerTest < Test::Unit::TestCase c1 = env.categories.build(:name => "Test category 1"); c1.save! c2 = env.categories.build(:name => "Test category 2"); c2.save! c3 = env.categories.build(:name => "Test Category 3"); c3.save! - + # post is in c1, c3 and c3 post :new, :type => TextileArticle.name, :profile => profile.identifier, :article => { :name => 'adding-categories-test', :category_ids => [ c1.id, c3.id, c3.id ] } saved = profile.articles.find_by_name('adding-categories-test') assert_equal [c1, c3], saved.categories end - + should 'filter html from textile article name' do post :new, :type => 'TextileArticle', :profile => profile.identifier, :article => { :name => 'a test article', :body => 'the text of the article ...' } assert_sanitized assigns(:article).name end - + should 'filter html from textile article abstract' do post :new, :type => 'TextileArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => 'abstract', :body => 'the text of the article ...' } assert_sanitized assigns(:article).abstract end - + should 'filter html from textile article body' do post :new, :type => 'TextileArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => 'abstract', :body => 'the text of the article ...' } assert_sanitized assigns(:article).body end - + should 'filter html with white_list from tiny mce article name' do post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => "test", :body => 'the text of the article ...' } assert_equal "test", assigns(:article).name end - + should 'filter html with white_list from tiny mce article abstract' do post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => " article", :body => 'the text of the article ...' } assert_equal " article", assigns(:article).abstract end - + should 'filter html with white_list from tiny mce article body' do post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => 'abstract', :body => "the of article ..." } assert_equal "the of article ...", assigns(:article).body end - + should 'not filter html tags permitted from tiny mce article body' do post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => 'abstract', :body => "the of article ..." } assert_equal "the of article ...", assigns(:article).body @@ -653,7 +653,7 @@ class CmsControllerTest < Test::Unit::TestCase should 'create a private article child of private folder' do folder = Folder.new(:name => 'my intranet', :published => false); profile.articles << folder; folder.save! - + post :new, :profile => profile.identifier, :type => 'TextileArticle', :parent_id => folder.id, :article => { :name => 'new-private-article'} folder.reload @@ -666,7 +666,7 @@ class CmsControllerTest < Test::Unit::TestCase c = Community.create!(:name => 'test comm', :identifier => 'test_comm') c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') - + get :publish, :profile => profile.identifier, :id => a.id assert_equal [c], assigns(:groups) @@ -677,18 +677,38 @@ class CmsControllerTest < Test::Unit::TestCase c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => false) c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') - + assert_difference PublishedArticle, :count do post :publish, :profile => profile.identifier, :id => a.id, :marked_groups => [{:name => 'bli', :group_id => c.id.to_s}] assert_equal [{'group' => c, 'name' => 'bli'}], assigns(:marked_groups) end end - + + should "not crash if there is a post and no portal community defined" do + Environment.any_instance.stubs(:portal_community).returns(nil) + article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') + assert_nothing_raised do + post :publish_on_portal_community, :profile => profile.identifier, :id => article.id, :name => article.name + end + end + + should 'publish the article on portal community if it is not moderated' do + portal_community = fast_create(Community) + portal_community.moderated_articles = false + portal_community.save + Environment.any_instance.stubs(:portal_community).returns(portal_community) + article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') + + assert_difference PublishedArticle, :count do + post :publish_on_portal_community, :profile => profile.identifier, :id => article.id, :name => article.name + end + end + should 'create a task for article approval if community is moderated' do c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => true) c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') - + assert_no_difference PublishedArticle, :count do assert_difference ApproveArticle, :count do assert_difference c.tasks, :count do @@ -699,6 +719,22 @@ class CmsControllerTest < Test::Unit::TestCase end end + should 'create a task for article approval if portal community is moderated' do + portal_community = fast_create(Community) + portal_community.moderated_articles = true + portal_community.save + Environment.any_instance.stubs(:portal_community).returns(portal_community) + article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') + + assert_no_difference PublishedArticle, :count do + assert_difference ApproveArticle, :count do + assert_difference portal_community.tasks, :count do + post :publish_on_portal_community, :profile => profile.identifier, :id => article.id, :name => article.name + end + end + end + end + should 'require ssl in general' do Environment.default.update_attribute(:enable_ssl, true) @request.expects(:ssl?).returns(false).at_least_once @@ -1136,7 +1172,17 @@ class CmsControllerTest < Test::Unit::TestCase assert_tag :tag => 'a', :attributes => {:href => "/myprofile/#{profile.identifier}/cms/publish/#{a.id}"} end - should "not display 'Publish' when profile is not a person" do + should "display 'Publish' when profile is a community" do + community = fast_create(Community) + community.add_member(profile) + Environment.any_instance.stubs(:portal_community).returns(community) + a = community.articles.create!(:name => 'my new home page') + Article.stubs(:short_description).returns('bli') + get :index, :profile => community.identifier + assert_tag :tag => 'a', :attributes => {:href => "/myprofile/#{community.identifier}/cms/publish_on_portal_community/#{a.id}"} + end + + should "not display 'Publish' when profile is not a person nor a community" do p = Community.create!(:name => 'community-test') p.add_admin(profile) a = p.articles.create!(:name => 'my new home page') -- libgit2 0.21.2