diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb
index 352fc37..bc89ea1 100644
--- a/app/controllers/my_profile/cms_controller.rb
+++ b/app/controllers/my_profile/cms_controller.rb
@@ -222,11 +222,18 @@ class CmsController < MyProfileController
end
end.compact unless params[:marked_groups].nil?
if request.post?
+ @failed = {}
@marked_groups.each do |item|
task = ApproveArticle.create!(:article => @article, :name => item[:name], :target => item[:group], :requestor => profile)
- task.finish unless item[:group].moderated_articles?
+ begin
+ task.finish unless item[:group].moderated_articles?
+ rescue Exception => ex
+ @failed[ex.clean_message] ? @failed[ex.clean_message] << item[:group].name : @failed[ex.clean_message] = [item[:group].name]
+ end
+ end
+ if @failed.blank?
+ redirect_back
end
- redirect_back
end
end
diff --git a/app/controllers/my_profile/tasks_controller.rb b/app/controllers/my_profile/tasks_controller.rb
index ed1bba9..fcb4b4a 100644
--- a/app/controllers/my_profile/tasks_controller.rb
+++ b/app/controllers/my_profile/tasks_controller.rb
@@ -17,7 +17,11 @@ class TasksController < MyProfileController
if request.post? && VALID_DECISIONS.include?(decision) && params[:id]
task = profile.find_in_all_tasks(params[:id])
task.update_attributes!(params[:task])
- task.send(decision)
+ begin
+ task.send(decision)
+ rescue Exception => ex
+ flash[:notice] = ex.clean_message
+ end
end
redirect_to :action => 'index'
end
diff --git a/app/models/approve_article.rb b/app/models/approve_article.rb
index a32a29f..853c523 100644
--- a/app/models/approve_article.rb
+++ b/app/models/approve_article.rb
@@ -64,7 +64,7 @@ class ApproveArticle < Task
end
def perform
- PublishedArticle.create(:name => name, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted)
+ PublishedArticle.create!(:name => name, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted)
end
def target_notification_message
diff --git a/app/views/cms/publish.rhtml b/app/views/cms/publish.rhtml
index 3a36da4..0f2d6cc 100644
--- a/app/views/cms/publish.rhtml
+++ b/app/views/cms/publish.rhtml
@@ -1,5 +1,19 @@
<%= _('Select the groups where you want to publish your article') %>
+<% if !@failed.blank? %>
+
+
<%=_("There were errors with the following communities: ")%>
+ <% @failed.each do |error, communities|%>
+
<%= error %>:
+
+ <% communities.each do |community| %>
+ - <%= community %>
+ <% end %>
+
+ <% end %>
+
+<% end %>
+
<% form_tag do%>
<%= hidden_field_tag :back_to, @back_to %>
<% @groups.each do |group| %>
diff --git a/features/publish_article.feature b/features/publish_article.feature
new file mode 100644
index 0000000..5f4f13b
--- /dev/null
+++ b/features/publish_article.feature
@@ -0,0 +1,125 @@
+Feature: publish article
+ As a user
+ I want to publish an article
+ In order to share it with other users
+
+ Background:
+ Given the following users
+ | login | name |
+ | joaosilva | Joao Silva |
+ | mariasilva | Maria Silva |
+ And the following communities
+ | identifier | name |
+ | sample-community | Sample Community |
+ And the following articles
+ | owner | name | body |
+ | joaosilva | Sample Article | This is the first published article |
+
+ Scenario: publishing an article that doesn't exists in the community
+ Given I am logged in as "joaosilva"
+ And "Joao Silva" is a member of "Sample Community"
+ And I am on Joao Silva's control panel
+ And I follow "Manage Content"
+ #These "deletes" are to remove default articles and spread the correct created one
+ And I follow "Delete"
+ And I follow "Delete"
+ And I follow "Delete"
+ And I follow "Spread"
+ And I check "Sample Community"
+ And I press "Publish"
+ And I am on Sample Community's homepage
+ And I follow "View profile"
+ And I follow "Site map"
+ When I follow "Sample Article"
+ Then I should see "This is the first published article"
+
+
+ Scenario: getting an error message when publishing article with same name
+ Given I am logged in as "joaosilva"
+ And "Joao Silva" is a member of "Sample Community"
+ And I am on Joao Silva's control panel
+ And I follow "Manage Content"
+ And I follow "Delete"
+ And I follow "Delete"
+ And I follow "Delete"
+ And I follow "Spread"
+ And I check "Sample Community"
+ And I press "Publish"
+ And I am logged in as "mariasilva"
+ And "Maria Silva" is a member of "Sample Community"
+ And I am on Maria Silva's control panel
+ And I follow "Manage Content"
+ And I follow "New article"
+ And I follow "Text article with Textile markup language"
+ And I fill in the following:
+ | Title | Sample Article |
+ | Text | this is Maria's first published article |
+ And I press "Save"
+ And I follow "Delete"
+ And I follow "Delete"
+ And I follow "Delete"
+ And I follow "Spread"
+ And I check "Sample Community"
+ When I press "Publish"
+ Then I should see "Validation failed: Slug (the code generated from the article name) is already being used by another article.:"
+
+ Scenario: publishing an article in many communities and listing the communities that couldn't publish the article again,
+ stills publishing the article in the other communities.
+ Given the following communities
+ | identifier | name |
+ | another-community1 | Another Community1 |
+ | another-community2 | Another Community2 |
+ And I am logged in as "joaosilva"
+ And "Joao Silva" is a member of "Sample Community"
+ And "Joao Silva" is a member of "Another Community1"
+ And "Joao Silva" is a member of "Another Community2"
+ And I am on Joao Silva's control panel
+ And I follow "Manage Content"
+ And I follow "Delete"
+ And I follow "Delete"
+ And I follow "Delete"
+ And I follow "Spread"
+ And I check "Sample Community"
+ And I press "Publish"
+ And I should not see "This article name is already in use in the following community(ies):"
+ And I follow "Spread"
+ And I check "Sample Community"
+ And I check "Another Community1"
+ And I check "Another Community2"
+ When I press "Publish"
+ Then I should see "Validation failed: Slug (the code generated from the article name) is already being used by another article.:"
+ And I am on Another Community1's homepage
+ And I follow "View profile"
+ When I follow "Site map"
+ Then I should see "Sample Article"
+ And I am on Another Community2's homepage
+ And I follow "View profile"
+ When I follow "Site map"
+ Then I should see "Sample Article"
+
+ Scenario: publishing articles with the same name in a moderated community
+ Given I am logged in as "joaosilva"
+ And "Joao Silva" is a member of "Sample Community"
+ And "Joao Silva" is admin of "Sample Community"
+ And I am on Sample Community's control panel
+ And I follow "Community Info and settings"
+ And I choose "profile_data_moderated_articles_true"
+ And I press "Save"
+ And I am on Joao Silva's control panel
+ And I follow "Manage Content"
+ And I follow "Delete"
+ And I follow "Delete"
+ And I follow "Delete"
+ And I follow "Spread"
+ And I check "Sample Community"
+ And I press "Publish"
+ And I follow "Spread"
+ And I check "Sample Community"
+ And I press "Publish"
+ And I am on Sample Community's control panel
+ And I follow "Tasks"
+ And I press "Ok!"
+ And I should not see "Validation failed: Slug (the code generated from the article name) is already being used by another article.:"
+ When I press "Ok!"
+ Then I should see "Validation failed: Slug (the code generated from the article name) is already being used by another article."
+
diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb
index f28245f..f7366a6 100644
--- a/features/step_definitions/noosfero_steps.rb
+++ b/features/step_definitions/noosfero_steps.rb
@@ -94,6 +94,10 @@ Given /^feature "(.+)" is disabled on environment$/ do |feature|
e.save
end
+Given /^"(.+)" is a member of "(.+)"$/ do |person,profile|
+ Profile.find_by_name(profile).add_member(Profile.find_by_name(person))
+end
+
Given /^"(.+)" should be a member of "(.+)"$/ do |person,profile|
Profile.find_by_name(profile).members.should include(Person.find_by_name(person))
end
--
libgit2 0.21.2