diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb
index 1feb652..d916cd8 100644
--- a/app/controllers/my_profile/cms_controller.rb
+++ b/app/controllers/my_profile/cms_controller.rb
@@ -14,7 +14,8 @@ class CmsController < MyProfileController
end
end
- protect_if :except => [:set_home_page, :edit, :destroy, :publish] do |c, user, profile|
+ before_filter :login_required, :except => [:suggest_an_article]
+ protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish] do |c, user, profile|
user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile))
end
@@ -282,6 +283,18 @@ class CmsController < MyProfileController
end
end
+ def suggest_an_article
+ @back_to = params[:back_to] || request.referer || url_for(profile.public_profile_url)
+ @task = SuggestArticle.new(params[:task])
+ if request.post?
+ @task.target = profile
+ if @task.save
+ session[:notice] = _('You make your suggestion successfully. Please wait the article approval.')
+ redirect_to @back_to
+ 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/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 36aa1f7..3e3cea9 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1177,4 +1177,13 @@ module ApplicationHelper
concat(content_tag('div', wrapper + tag('br', :style => 'clear: both;'), { :class => 'comment-balloon ' + classes.to_s }.merge(options)), block.binding)
end
+ def display_source_info(page)
+ if !page.source.blank?
+ source_url = link_to(page.source_name.blank? ? page.source : page.source_name, page.source)
+ elsif page.reference_article
+ source_url = link_to(page.reference_article.profile.name, page.reference_article.url)
+ end
+ content_tag(:div, _('Source: %s') % source_url, :id => 'article-source') unless source_url.nil?
+ end
+
end
diff --git a/app/models/suggest_article.rb b/app/models/suggest_article.rb
new file mode 100644
index 0000000..586c199
--- /dev/null
+++ b/app/models/suggest_article.rb
@@ -0,0 +1,26 @@
+class SuggestArticle < Task
+
+ has_captcha
+
+ serialize :data, Hash
+ acts_as_having_settings :field => :data
+
+ validates_presence_of :target_id, :article_name, :email, :name, :article_body
+
+ def description
+ _('%{email} suggested to publish "%{article}" on %{community}') % { :email => email, :article => article_name, :community => target.name }
+ end
+
+ settings_items :email, :type => String
+ settings_items :name, :type => String
+ settings_items :article_name, :type => String
+ settings_items :article_body, :type => String
+ settings_items :article_abstract, :type => String
+ settings_items :article_parent_id, :type => String
+ settings_items :source, :type => String
+
+ def perform
+ TinyMceArticle.create!(:profile => target, :name => article_name, :body => article_body, :abstract => article_abstract, :parent_id => article_parent_id, :source => source, :source_name => name)
+ end
+
+end
diff --git a/app/views/cms/suggest_an_article.rhtml b/app/views/cms/suggest_an_article.rhtml
new file mode 100644
index 0000000..a5b6a8a
--- /dev/null
+++ b/app/views/cms/suggest_an_article.rhtml
@@ -0,0 +1,41 @@
+<%= error_messages_for 'task' %>
+
+<%= required_fields_message %>
+
+<%= render :file => 'shared/tiny_mce' %>
+
+<% labelled_form_for 'task', @task do |f| %>
+
+ <%= required labelled_form_field(_('Title'), text_field(:task, 'article_name')) %>
+
+ <%= labelled_form_field(_('Url Source'), text_field(:task, 'source')) %>
+
+ <%= required labelled_form_field(_('Name'), text_field(:task, 'name')) %>
+
+ <%= required labelled_form_field(_('Email'), text_field(:task, 'email')) %>
+
+
+ <%= button :add, _("Lead"), '#', :id => "lead-button", :style => "margin-left: 0px;" %>
+ <%= _('Used when a short version your text is needed.') %>
+
+
+ <%= labelled_form_field(_('Lead'), text_area(:task , 'article_abstract', :style => 'width: 100%; height: 300px;')) %>
+
+
+ <%= labelled_form_field(_('Text'), text_area(:task, 'article_body', :style => 'width:100%')) %>
+
+
+
+ <%= labelled_form_field(_("What is the result of '%s = ?'") % @task.captcha.task, text_field(:task, 'captcha_solution')) %>
+ <%= hidden_field :task, :captcha_secret %>
+
+
+
+ <%= hidden_field_tag('back_to', @back_to) %>
+ <% button_bar do %>
+ <%= submit_button :save, _('Save') %>
+ <%= button :cancel, _('Cancel'), @back_to %>
+ <% end %>
+<% end %>
+
+<%= javascript_include_tag 'article' %>
diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml
index 7b040b7..7f23a65 100644
--- a/app/views/content_viewer/view_page.rhtml
+++ b/app/views/content_viewer/view_page.rhtml
@@ -45,6 +45,8 @@
<%= button('upload-file', _('Upload files'), :controller => 'cms', :action => 'upload_files', :parent_id => (@page.folder? ? @page : @page.parent)) %>
<% end %>
+ <% else %>
+ <%= link_to content_tag( 'span', _('Suggest an article') ), profile.admin_url.merge({ :controller => 'cms', :action => 'suggest_an_article'}), :class => 'button with-text icon-new' %>
<% end %>
<%= link_to(image_tag('icons-mime/rss-feed.png'), @page.feed.url, :class => 'blog-feed-link') if @page.has_posts? && @page.feed %>
@@ -89,15 +91,7 @@
<% end %>
-<% if ! @page.source.nil? && ! @page.source.empty?%>
-
- <%= _('Source: %s') % link_to(@page.source, @page.source) %>
-
-<% elsif @page.reference_article %>
-
- <%= _('Source: %s') % link_to(@page.reference_article.profile.name, @page.reference_article.url) %>
-
-<% end %>
+<%= display_source_info(@page) %>
<%
# AddThis Button
diff --git a/app/views/tasks/_suggest_article.rhtml b/app/views/tasks/_suggest_article.rhtml
new file mode 100644
index 0000000..a716226
--- /dev/null
+++ b/app/views/tasks/_suggest_article.rhtml
@@ -0,0 +1,41 @@
+<%= _('Processing task: %s') % task.description %>
+
+<%= render :file => 'shared/tiny_mce' %>
+
+<% form_for('task', task, :url => { :action => 'close', :id => task.id}) do |f| %>
+
+ <%= label_tag(_("Sent by: %s") % task.name) %>
+ <%= label_tag(_("Email: %s") % task.email) %>
+ <%= label_tag(_("Source: %s") % task.source) %>
+
+ <%= required labelled_form_field(_('Title'), text_field_tag('task[article_name]', task.article_name)) %>
+
+ <%= select_folder(_('Select the folder where the article must be published'), 'task', 'article_parent_id', task.target.folders) %>
+
+
+
+ <%= button :add, _("Lead"), '#', :id => "lead-button", :style => "margin-left: 0px;" %>
+ <%= _('Used when a short version your text is needed.') %>
+
+
+ <%= labelled_form_field(_('Lead'), text_area_tag('task[article_abstract]', task.article_abstract, :style => 'width: 100%; height: 300px;')) %>
+
+
+ <%= labelled_form_field(_('Text'), text_area_tag('task[article_body]', task.article_body, :style => 'width:100%')) %>
+
+
+
+ <%= labelled_radio_button _('OK'), :decision, 'finish', true, :onclick => "if(this.checked) $('rejection-field-#{task.id}').style.display='none'" %>
+
+
+ <%= labelled_radio_button _('Cancel'), :decision, 'cancel', false, :onclick => "if(this.checked) $('rejection-field-#{task.id}').style.display='block'" %>
+
+
+ <% button_bar do %>
+ <%= submit_button(:ok, _('OK')) %>
+ <% end %>
+
+<% end %>
+
+<%= javascript_include_tag 'article' %>
+
diff --git a/db/migrate/20101209001631_add_source_name_to_articles.rb b/db/migrate/20101209001631_add_source_name_to_articles.rb
new file mode 100644
index 0000000..d88e181
--- /dev/null
+++ b/db/migrate/20101209001631_add_source_name_to_articles.rb
@@ -0,0 +1,11 @@
+class AddSourceNameToArticles < ActiveRecord::Migration
+ def self.up
+ add_column :articles, :source_name, :string, :null => true
+ add_column :article_versions, :source_name, :string, :null => true
+ end
+
+ def self.down
+ remove_column :articles, :source_name
+ remove_column :article_versions, :source_name
+ end
+end
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index bcba090..be83b6a 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -5237,3 +5237,17 @@ h1#agenda-title {
.forum-posts .pagination {
margin-top: 20px;
}
+
+#captcha input {
+ border: 1px solid #ccc;
+ margin: 4px 0px 2px 10px !important;
+ padding: 0px !important;
+ width: 150px !important;
+ font-size: 24px;
+ float: left;
+}
+
+#captcha label{
+ float: left;
+ font-size: 24px;
+}
diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb
index af51241..d55f3d0 100644
--- a/test/functional/cms_controller_test.rb
+++ b/test/functional/cms_controller_test.rb
@@ -1410,4 +1410,36 @@ class CmsControllerTest < Test::Unit::TestCase
assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/cms/upload_files?parent_id=#{profile.forum.id}"}
end
+ should 'not logged in to suggest an article' do
+ logout
+ get :suggest_an_article, :profile => profile.identifier, :back_to => 'action_view'
+
+ assert_template 'suggest_an_article'
+ end
+
+ should 'create a task suggest task to a profile' do
+ c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => true)
+
+ SuggestArticle.any_instance.stubs(:skip_captcha?).returns(true)
+ assert_difference SuggestArticle, :count do
+ post :suggest_an_article, :profile => c.identifier, :back_to => 'action_view', :task => {:article_name => 'some name', :article_body => 'some body', :email => 'some@localhost.com', :name => 'some name'}
+ end
+ end
+
+ should 'suggest an article from a profile' do
+ c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => true)
+ get :suggest_an_article, :profile => c.identifier, :back_to => c.identifier
+ assert_response :success
+ assert_template 'suggest_an_article'
+ assert_tag :tag => 'input', :attributes => { :value => c.identifier, :id => 'back_to' }
+ end
+
+ should 'suggest an article accessing the url directly' do
+ c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => true)
+ get :suggest_an_article, :profile => c.identifier
+ assert_response :success
+ assert_template 'suggest_an_article'
+ assert_tag :tag => 'input', :attributes => { :value => "https://colivre.net/profile/test_comm", :id => 'back_to' }
+ end
+
end
diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb
index ece454e..0b115b4 100644
--- a/test/functional/tasks_controller_test.rb
+++ b/test/functional/tasks_controller_test.rb
@@ -237,4 +237,29 @@ class TasksControllerTest < Test::Unit::TestCase
assert_equal Task::Status::CANCELLED, task.status
end
+ should 'create TinyMceArticle article after finish approve suggested article task' do
+ TinyMceArticle.destroy_all
+ c = fast_create(Community)
+ c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id))
+ @controller.stubs(:profile).returns(c)
+ SuggestArticle.skip_captcha!
+ t = SuggestArticle.create!(:article_name => 'test name', :article_body => 'test body', :name => 'some name', :email => 'test@localhost.com', :target => c)
+
+ post :close, :decision => 'finish', :id => t.id, :task => {}
+ assert_not_nil TinyMceArticle.find(:first)
+ end
+
+ should "change the article's attributes on suggested article task approval" do
+ TinyMceArticle.destroy_all
+ c = fast_create(Community)
+ c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id))
+ @controller.stubs(:profile).returns(c)
+ SuggestArticle.skip_captcha!
+ t = SuggestArticle.create!(:article_name => 'test name', :article_body => 'test body', :name => 'some name', :email => 'test@localhost.com', :target => c)
+
+ post :close, :decision => 'finish', :id => t.id, :task => {:article_name => 'new name', :article_body => 'new body'}
+ assert_equal 'new name', TinyMceArticle.find(:first).name
+ assert_equal 'new body', TinyMceArticle.find(:first).body
+ end
+
end
diff --git a/test/unit/suggest_article_test.rb b/test/unit/suggest_article_test.rb
new file mode 100644
index 0000000..dd47632
--- /dev/null
+++ b/test/unit/suggest_article_test.rb
@@ -0,0 +1,89 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class SuggestArticleTest < ActiveSupport::TestCase
+
+ def setup
+ ActionMailer::Base.delivery_method = :test
+ ActionMailer::Base.perform_deliveries = true
+ ActionMailer::Base.deliveries = []
+ @profile = create_user('test_user').person
+ end
+ attr_reader :profile
+
+ should 'have the article_name' do
+ t = SuggestArticle.new
+ assert !t.errors.invalid?(:article_name)
+ t.valid?
+ assert t.errors.invalid?(:article_name)
+ end
+
+ should 'have the article_body' do
+ t = SuggestArticle.new
+ assert !t.errors.invalid?(:article_body)
+ t.valid?
+ assert t.errors.invalid?(:article_body)
+ end
+
+ should 'have the email' do
+ t = SuggestArticle.new
+ assert !t.errors.invalid?(:email)
+ t.valid?
+ assert t.errors.invalid?(:email)
+ end
+
+ should 'have the name' do
+ t = SuggestArticle.new
+ assert !t.errors.invalid?(:name)
+ t.valid?
+ assert t.errors.invalid?(:name)
+ end
+
+ should 'have the target_id' do
+ t = SuggestArticle.new
+ assert !t.errors.invalid?(:target_id)
+ t.valid?
+ assert t.errors.invalid?(:target_id)
+ end
+
+ should 'have the captcha_solution be solved' do
+ t = SuggestArticle.new
+ assert !t.errors.invalid?(:captcha_solution)
+ t.valid?
+ assert t.errors.invalid?(:captcha_solution)
+
+ t.skip_captcha!
+ assert t.skip_captcha?
+ t.valid?
+ assert !t.errors.invalid?(:captcha_solution)
+ end
+
+ should 'have the article_abstract' do
+ t = SuggestArticle.new
+ assert t.respond_to?(:article_abstract)
+ end
+
+ should 'have the article_parent_id' do
+ t = SuggestArticle.new
+ assert t.respond_to?(:article_parent_id)
+ end
+
+ should 'source be defined' do
+ t = SuggestArticle.new
+ assert t.respond_to?(:source)
+ end
+
+ should 'create an article on with perfom method' do
+ t = SuggestArticle.new
+ name = 'some name'
+ body = 'some body'
+ abstract = 'some abstract'
+ t.article_name = name
+ t.article_body = body
+ t.article_abstract = abstract
+ t.target = @profile
+ count = TinyMceArticle.count
+ t.perform
+ assert_equal count + 1, TinyMceArticle.count
+ end
+
+end
--
libgit2 0.21.2