Commit 94481abd1c82ed355b2483dbac62cbcd07c249ec
1 parent
35a1c4f5
Exists in
staging
and in
42 other branches
ActionItem234: Initial implementation of article moderation
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2453 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
8 changed files
with
114 additions
and
3 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
| ... | ... | @@ -142,7 +142,8 @@ class CmsController < MyProfileController |
| 142 | 142 | end.compact unless params[:marked_groups].nil? |
| 143 | 143 | if request.post? |
| 144 | 144 | @marked_groups.each do |item| |
| 145 | - PublishedArticle.create!(:reference_article => @article, :profile => item[:group], :name => item[:name]) | |
| 145 | + task = ApproveArticle.create!(:article => @article, :name => item[:name], :target => item[:group], :requestor => profile) | |
| 146 | + task.finish unless item[:group].moderated_articles? | |
| 146 | 147 | end |
| 147 | 148 | end |
| 148 | 149 | end | ... | ... |
| ... | ... | @@ -0,0 +1,31 @@ |
| 1 | +class ApproveArticle < Task | |
| 2 | + serialize :data, Hash | |
| 3 | + | |
| 4 | + def data | |
| 5 | + self[:data] ||= {} | |
| 6 | + end | |
| 7 | + | |
| 8 | + def article | |
| 9 | + Article.find_by_id data[:article_id] | |
| 10 | + end | |
| 11 | + | |
| 12 | + def article= value | |
| 13 | + data[:article_id] = value.id | |
| 14 | + end | |
| 15 | + | |
| 16 | + def name | |
| 17 | + data[:name] | |
| 18 | + end | |
| 19 | + | |
| 20 | + def name= value | |
| 21 | + data[:name] = value | |
| 22 | + end | |
| 23 | + | |
| 24 | + def perform | |
| 25 | + PublishedArticle.create(:name => name, :profile => target, :reference_article => article) | |
| 26 | + end | |
| 27 | + | |
| 28 | + def sends_email? | |
| 29 | + true | |
| 30 | + end | |
| 31 | +end | ... | ... |
app/models/organization.rb
| ... | ... | @@ -6,6 +6,11 @@ class Organization < Profile |
| 6 | 6 | closed |
| 7 | 7 | end |
| 8 | 8 | |
| 9 | + settings_items :moderated_articles, :type => :boolean, :default => false | |
| 10 | + def moderated_articles? | |
| 11 | + moderated_articles | |
| 12 | + end | |
| 13 | + | |
| 9 | 14 | has_one :validation_info |
| 10 | 15 | |
| 11 | 16 | has_many :validations, :class_name => 'CreateEnterprise', :foreign_key => :target_id | ... | ... |
| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | +<h1><%= _('Select the groups where you want to publish your article') %></h1> | |
| 2 | + | |
| 3 | +<% form_tag do%> | |
| 4 | + <% @groups.each do |group| %> | |
| 5 | + <%= labelled_check_box group.name, 'marked_groups[][group_id]', group.id, @marked_groups.include?(group) %><br /> | |
| 6 | + <%= labelled_text_field _('Title') + ': ', 'marked_groups[][name]', @article.name %> | |
| 7 | + <hr /> | |
| 8 | + <% end %> | |
| 9 | + | |
| 10 | + <% button_bar do %> | |
| 11 | + <%= submit_button 'menu-community', _('Publish') %> | |
| 12 | + <% end %> | |
| 13 | +<% end %> | |
| 14 | + | ... | ... |
app/views/profile_editor/_organization.rhtml
| ... | ... | @@ -28,3 +28,20 @@ |
| 28 | 28 | <%= _('<strong>After</strong> joining this group (a moderator can always desactivate access for users later).') %> |
| 29 | 29 | </div> |
| 30 | 30 | </div> |
| 31 | + | |
| 32 | + <br> | |
| 33 | + <div style='margin-bottom: 1em'> | |
| 34 | + <%= _('New articles must be approved:')%> | |
| 35 | + </div> | |
| 36 | + <div style='margin-bottom: 0.5em'> | |
| 37 | + <%= radio_button 'profile_data', 'moderated_articles', 'true', :style => 'float: left' %> | |
| 38 | + <div style='margin-left: 30px'> | |
| 39 | + <%= _('<strong>Before</strong> 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.') %> | |
| 40 | + </div> | |
| 41 | + </div> | |
| 42 | + <div> | |
| 43 | + <%= radio_button 'profile_data', 'moderated_articles', 'false', :style => 'float: left' %> | |
| 44 | + <div style='margin-left: 30px'> | |
| 45 | + <%= _('<strong>After</strong> being published in this group (a moderator can always remove publicated articles later).') %> | |
| 46 | + </div> | |
| 47 | + </div> | ... | ... |
test/functional/cms_controller_test.rb
| ... | ... | @@ -565,8 +565,8 @@ class CmsControllerTest < Test::Unit::TestCase |
| 565 | 565 | assert_template 'publish' |
| 566 | 566 | end |
| 567 | 567 | |
| 568 | - should 'publish the article in the selected community' do | |
| 569 | - c = Community.create!(:name => 'test comm', :identifier => 'test_comm') | |
| 568 | + should 'publish the article in the selected community if community is not moderated' do | |
| 569 | + c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => false) | |
| 570 | 570 | c.affiliate(profile, Profile::Roles.all_roles) |
| 571 | 571 | a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') |
| 572 | 572 | |
| ... | ... | @@ -575,5 +575,20 @@ class CmsControllerTest < Test::Unit::TestCase |
| 575 | 575 | assert_equal [{'group' => c, 'name' => 'bli'}], assigns(:marked_groups) |
| 576 | 576 | end |
| 577 | 577 | end |
| 578 | + | |
| 579 | + should 'create a task for article approval if community is moderated' do | |
| 580 | + c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => true) | |
| 581 | + c.affiliate(profile, Profile::Roles.all_roles) | |
| 582 | + a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') | |
| 583 | + | |
| 584 | + assert_no_difference PublishedArticle, :count do | |
| 585 | + assert_difference ApproveArticle, :count do | |
| 586 | + assert_difference c.tasks, :count do | |
| 587 | + post :publish, :profile => profile.identifier, :id => a.id, :marked_groups => [{:name => 'bli', :group_id => c.id.to_s}] | |
| 588 | + assert_equal [{'group' => c, 'name' => 'bli'}], assigns(:marked_groups) | |
| 589 | + end | |
| 590 | + end | |
| 591 | + end | |
| 592 | + end | |
| 578 | 593 | |
| 579 | 594 | end | ... | ... |
| ... | ... | @@ -0,0 +1,26 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | + | |
| 3 | +class ApproveArticleTest < ActiveSupport::TestCase | |
| 4 | + | |
| 5 | + should 'have name, reference article and profile' do | |
| 6 | + profile = create_user('test_user').person | |
| 7 | + article = profile.articles.create!(:name => 'test article') | |
| 8 | + | |
| 9 | + a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile) | |
| 10 | + | |
| 11 | + assert_equal 'test name', a.name | |
| 12 | + assert_equal article, a.article | |
| 13 | + assert_equal profile, a.target | |
| 14 | + end | |
| 15 | + | |
| 16 | + should 'create published article when finished' do | |
| 17 | + profile = create_user('test_user').person | |
| 18 | + article = profile.articles.create!(:name => 'test article') | |
| 19 | + a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile) | |
| 20 | + | |
| 21 | + assert_difference PublishedArticle, :count do | |
| 22 | + a.finish | |
| 23 | + end | |
| 24 | + | |
| 25 | + end | |
| 26 | +end | ... | ... |