diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 9988217..3fac1a9 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -142,7 +142,8 @@ class CmsController < MyProfileController end.compact unless params[:marked_groups].nil? if request.post? @marked_groups.each do |item| - PublishedArticle.create!(:reference_article => @article, :profile => item[:group], :name => item[:name]) + task = ApproveArticle.create!(:article => @article, :name => item[:name], :target => item[:group], :requestor => profile) + task.finish unless item[:group].moderated_articles? end end end diff --git a/app/models/approve_article.rb b/app/models/approve_article.rb new file mode 100644 index 0000000..77153be --- /dev/null +++ b/app/models/approve_article.rb @@ -0,0 +1,31 @@ +class ApproveArticle < Task + serialize :data, Hash + + def data + self[:data] ||= {} + end + + def article + Article.find_by_id data[:article_id] + end + + def article= value + data[:article_id] = value.id + end + + def name + data[:name] + end + + def name= value + data[:name] = value + end + + def perform + PublishedArticle.create(:name => name, :profile => target, :reference_article => article) + end + + def sends_email? + true + end +end diff --git a/app/models/organization.rb b/app/models/organization.rb index 48e376f..e3cf621 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -6,6 +6,11 @@ class Organization < Profile closed end + settings_items :moderated_articles, :type => :boolean, :default => false + def moderated_articles? + moderated_articles + end + has_one :validation_info has_many :validations, :class_name => 'CreateEnterprise', :foreign_key => :target_id diff --git a/app/views/cms/_published_article.rhtml b/app/views/cms/_published_article.rhtml new file mode 100644 index 0000000..5be82c8 --- /dev/null +++ b/app/views/cms/_published_article.rhtml @@ -0,0 +1,2 @@ +<%= f.text_field 'name', :size => '64' %> + diff --git a/app/views/cms/publish.rhtml b/app/views/cms/publish.rhtml new file mode 100644 index 0000000..d9c7f5c --- /dev/null +++ b/app/views/cms/publish.rhtml @@ -0,0 +1,14 @@ +

<%= _('Select the groups where you want to publish your article') %>

+ +<% form_tag do%> + <% @groups.each do |group| %> + <%= labelled_check_box group.name, 'marked_groups[][group_id]', group.id, @marked_groups.include?(group) %>
+ <%= labelled_text_field _('Title') + ': ', 'marked_groups[][name]', @article.name %> +
+ <% end %> + + <% button_bar do %> + <%= submit_button 'menu-community', _('Publish') %> + <% end %> +<% end %> + diff --git a/app/views/profile_editor/_organization.rhtml b/app/views/profile_editor/_organization.rhtml index ff3d38e..96def6c 100644 --- a/app/views/profile_editor/_organization.rhtml +++ b/app/views/profile_editor/_organization.rhtml @@ -28,3 +28,20 @@ <%= _('After joining this group (a moderator can always desactivate access for users later).') %> + +
+
+ <%= _('New articles must be approved:')%> +
+
+ <%= radio_button 'profile_data', 'moderated_articles', 'true', :style => 'float: left' %> +
+ <%= _('Before being published in this group (a moderator has to accept the article in pending request before the article be listed as a article of this group.') %> +
+
+
+ <%= radio_button 'profile_data', 'moderated_articles', 'false', :style => 'float: left' %> +
+ <%= _('After being published in this group (a moderator can always remove publicated articles later).') %> +
+
diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index c9171fe..dea7b07 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -565,8 +565,8 @@ class CmsControllerTest < Test::Unit::TestCase assert_template 'publish' end - should 'publish the article in the selected community' do - c = Community.create!(:name => 'test comm', :identifier => 'test_comm') + should 'publish the article in the selected community if community is not moderated' do + c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => false) c.affiliate(profile, Profile::Roles.all_roles) a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') @@ -575,5 +575,20 @@ class CmsControllerTest < Test::Unit::TestCase assert_equal [{'group' => c, 'name' => 'bli'}], assigns(:marked_groups) 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) + 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 + 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 + end + end end diff --git a/test/unit/approve_article_test.rb b/test/unit/approve_article_test.rb new file mode 100644 index 0000000..94a5ce1 --- /dev/null +++ b/test/unit/approve_article_test.rb @@ -0,0 +1,26 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ApproveArticleTest < ActiveSupport::TestCase + + should 'have name, reference article and profile' do + profile = create_user('test_user').person + article = profile.articles.create!(:name => 'test article') + + a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile) + + assert_equal 'test name', a.name + assert_equal article, a.article + assert_equal profile, a.target + end + + should 'create published article when finished' do + profile = create_user('test_user').person + article = profile.articles.create!(:name => 'test article') + a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile) + + assert_difference PublishedArticle, :count do + a.finish + end + + end +end -- libgit2 0.21.2