Commit 30f292618062711dcf5beae6e508b754a085053c
1 parent
b3756e14
Exists in
master
and in
29 other branches
Accept article suggestion from logged in users
Showing
7 changed files
with
74 additions
and
11 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
... | ... | @@ -357,6 +357,7 @@ class CmsController < MyProfileController |
357 | 357 | @task.ip_address = request.remote_ip |
358 | 358 | @task.user_agent = request.user_agent |
359 | 359 | @task.referrer = request.referrer |
360 | + @task.requestor = current_person if logged_in? | |
360 | 361 | if verify_recaptcha(:model => @task, :message => _('Please type the words correctly')) && @task.save |
361 | 362 | session[:notice] = _('Thanks for your suggestion. The community administrators were notified.') |
362 | 363 | redirect_to @back_to | ... | ... |
app/models/suggest_article.rb
1 | 1 | class SuggestArticle < Task |
2 | 2 | |
3 | - validates_presence_of :target_id, :article_name, :email, :name, :article_body | |
3 | + validates_presence_of :target_id, :article_name, :article_body | |
4 | + validates_presence_of :email, :name, :if => Proc.new { |task| task.requestor.blank? } | |
4 | 5 | |
5 | 6 | settings_items :email, :type => String |
6 | 7 | settings_items :name, :type => String |
... | ... | @@ -24,7 +25,7 @@ class SuggestArticle < Task |
24 | 25 | include Noosfero::Plugin::HotSpot |
25 | 26 | |
26 | 27 | def sender |
27 | - "#{name} (#{email})" | |
28 | + requestor ? "#{requestor.name}" : "#{name} (#{email})" | |
28 | 29 | end |
29 | 30 | |
30 | 31 | def perform |
... | ... | @@ -50,8 +51,9 @@ class SuggestArticle < Task |
50 | 51 | end |
51 | 52 | |
52 | 53 | def information |
53 | - { :message => _('%{sender} suggested the publication of the article: %{subject}.'), | |
54 | - :variables => {:sender => sender} } | |
54 | + variables = requestor.blank? ? {:requestor => sender} : {} | |
55 | + { :message => _('%{requestor} suggested the publication of the article: %{subject}.'), | |
56 | + :variables => variables } | |
55 | 57 | end |
56 | 58 | |
57 | 59 | def accept_details |
... | ... | @@ -63,8 +65,8 @@ class SuggestArticle < Task |
63 | 65 | end |
64 | 66 | |
65 | 67 | def target_notification_description |
66 | - _('%{sender} suggested the publication of the article: %{article}.') % | |
67 | - {:sender => sender, :article => article_name} | |
68 | + _('%{requestor} suggested the publication of the article: %{article}.') % | |
69 | + {:requestor => sender, :article => article_name} | |
68 | 70 | end |
69 | 71 | |
70 | 72 | def target_notification_message | ... | ... |
app/views/cms/suggest_an_article.html.erb
... | ... | @@ -12,9 +12,10 @@ |
12 | 12 | |
13 | 13 | <%= labelled_form_field(_('Source URL'), text_field(:task, 'source')) %> |
14 | 14 | |
15 | - <%= required labelled_form_field(_('Your name'), text_field(:task, 'name')) %> | |
16 | - | |
17 | - <%= required labelled_form_field(_('Email'), text_field(:task, 'email')) %> | |
15 | + <% unless logged_in? %> | |
16 | + <%= required labelled_form_field(_('Your name'), text_field(:task, 'name')) %> | |
17 | + <%= required labelled_form_field(_('Email'), text_field(:task, 'email')) %> | |
18 | + <% end %> | |
18 | 19 | |
19 | 20 | <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :object => :task, :abstract_method => 'article_abstract', :body_method => 'article_body'} %> |
20 | 21 | ... | ... |
app/views/tasks/_suggest_article_accept_details.html.erb
1 | 1 | <%= render :file => 'shared/tiny_mce' %> |
2 | 2 | |
3 | -<%= labelled_form_field(_("Sent by: "), f.text_field(:name)) %> | |
4 | -<p><%= label_tag(_("Email: %s") % task.email) %> </p> | |
3 | +<% unless task.requestor %> | |
4 | + <%= labelled_form_field(_("Sent by: "), f.text_field(:name)) %> | |
5 | + <p><%= label_tag(_("Email: %s") % task.email) %> </p> | |
6 | +<% end %> | |
5 | 7 | <%= required labelled_form_field(_('Title'), f.text_field(:article_name, :size => 50)) %> |
6 | 8 | <%= labelled_form_field(_('Source'), f.text_field(:source_name)) %> |
7 | 9 | <%= labelled_form_field(_("Source URL"), f.text_field(:source)) %> | ... | ... |
test/functional/cms_controller_test.rb
... | ... | @@ -1407,6 +1407,21 @@ class CmsControllerTest < ActionController::TestCase |
1407 | 1407 | assert_template 'suggest_an_article' |
1408 | 1408 | end |
1409 | 1409 | |
1410 | + should 'display name and email when a not logged in user suggest an article' do | |
1411 | + logout | |
1412 | + get :suggest_an_article, :profile => profile.identifier, :back_to => 'action_view' | |
1413 | + | |
1414 | + assert_select '#task_name' | |
1415 | + assert_select '#task_email' | |
1416 | + end | |
1417 | + | |
1418 | + should 'do not display name and email when a logged in user suggest an article' do | |
1419 | + get :suggest_an_article, :profile => profile.identifier, :back_to => 'action_view' | |
1420 | + | |
1421 | + assert_select '#task_name', 0 | |
1422 | + assert_select '#task_email', 0 | |
1423 | + end | |
1424 | + | |
1410 | 1425 | should 'render TinyMce Editor on suggestion of article' do |
1411 | 1426 | logout |
1412 | 1427 | get :suggest_an_article, :profile => profile.identifier |
... | ... | @@ -1423,6 +1438,13 @@ class CmsControllerTest < ActionController::TestCase |
1423 | 1438 | end |
1424 | 1439 | end |
1425 | 1440 | |
1441 | + should 'create suggest task with logged in user as the article author' do | |
1442 | + c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => true) | |
1443 | + | |
1444 | + post :suggest_an_article, :profile => c.identifier, :back_to => 'action_view', :task => {:article_name => 'some name', :article_body => 'some body'} | |
1445 | + assert_equal profile, SuggestArticle.last.requestor | |
1446 | + end | |
1447 | + | |
1426 | 1448 | should 'suggest an article from a profile' do |
1427 | 1449 | c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => true) |
1428 | 1450 | get :suggest_an_article, :profile => c.identifier, :back_to => c.identifier | ... | ... |
test/functional/tasks_controller_test.rb
... | ... | @@ -305,6 +305,28 @@ class TasksControllerTest < ActionController::TestCase |
305 | 305 | assert_equal 'new source', TinyMceArticle.find(:first).source_name |
306 | 306 | end |
307 | 307 | |
308 | + should "display name from article suggestion when requestor was not setted" do | |
309 | + Task.destroy_all | |
310 | + c = fast_create(Community) | |
311 | + c.add_admin profile | |
312 | + @controller.stubs(:profile).returns(c) | |
313 | + t = SuggestArticle.create!(:article_name => 'test name', :article_abstract => 'test abstract', :article_body => 'test body', :name => 'some name', :email => 'test@localhost.com', :target => c) | |
314 | + | |
315 | + get :index | |
316 | + assert_select "#tasks_#{t.id}_task_name" | |
317 | + end | |
318 | + | |
319 | + should "not display name from article suggestion when requestor was setted" do | |
320 | + Task.destroy_all | |
321 | + c = fast_create(Community) | |
322 | + c.add_admin profile | |
323 | + @controller.stubs(:profile).returns(c) | |
324 | + t = SuggestArticle.create!(:article_name => 'test name', :article_abstract => 'test abstract', :article_body => 'test body', :requestor => fast_create(Person), :target => c) | |
325 | + | |
326 | + get :index | |
327 | + assert_select "#tasks_#{t.id}_task_name", 0 | |
328 | + end | |
329 | + | |
308 | 330 | should "not crash if accessing close without tasks parameter" do |
309 | 331 | assert_nothing_raised do |
310 | 332 | post :close | ... | ... |
test/unit/suggest_article_test.rb
... | ... | @@ -225,4 +225,17 @@ class SuggestArticleTest < ActiveSupport::TestCase |
225 | 225 | assert_match "SuggestArticle-id: #{t.id} IP: 192.168.0.1", log.read |
226 | 226 | end |
227 | 227 | |
228 | + should 'not require name and email when requestor is present' do | |
229 | + t = SuggestArticle.new(:requestor => fast_create(Person)) | |
230 | + t.valid? | |
231 | + assert t.errors[:email].blank? | |
232 | + assert t.errors[:name].blank? | |
233 | + end | |
234 | + | |
235 | + should 'return name as sender when requestor is setted' do | |
236 | + person = fast_create(Person) | |
237 | + t = SuggestArticle.new(:requestor => person) | |
238 | + assert_equal person.name, t.sender | |
239 | + end | |
240 | + | |
228 | 241 | end | ... | ... |