noosfero | 2 new commits pushed to repository

Bráulio Bhavamitra gitlab at gitlab.com
Thu Jan 29 12:17:27 BRST 2015


Bráulio Bhavamitra pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>

Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/4fc0ac241f11148a19c2ee4ecfeb912f66cd3b0d">4fc0ac24</a> by Braulio Bhavamitra
contact: Send message for non logged users

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/2f02a818ce0a3378cb203941cec63a79d7ceaf3e">2f02a818</a> by Bráulio Bhavamitra
Merge branch 'contact-without-login' into 'master'

Contact without login

Currently, unlogged users cannot contact profiles

See merge request !437

- - - - -


Changes:

=====================================
app/controllers/public/contact_controller.rb
=====================================
--- a/app/controllers/public/contact_controller.rb
+++ b/app/controllers/public/contact_controller.rb
@@ -1,13 +1,10 @@
 class ContactController < PublicController
 
-  before_filter :login_required
-
   needs_profile
 
   def new
-    @contact
+    @contact = build_contact
     if request.post? && params[:confirm] == 'true'
-      @contact = user.build_contact(profile, params[:contact])
       @contact.city = (!params[:city].blank? && City.exists?(params[:city])) ? City.find(params[:city]).name : nil
       @contact.state = (!params[:state].blank? && State.exists?(params[:state])) ? State.find(params[:state]).name : nil
       if @contact.deliver
@@ -16,8 +13,17 @@ class ContactController < PublicController
       else
         session[:notice] = _('Contact not sent')
       end
+    end
+  end
+
+  protected
+
+  def build_contact
+    params[:contact] ||= {}
+    if logged_in?
+      user.build_contact profile, params[:contact]
     else
-      @contact = user.build_contact(profile)
+      Contact.new params[:contact].merge(dest: profile)
     end
   end
 

=====================================
app/views/contact/new.html.erb
=====================================
--- a/app/views/contact/new.html.erb
+++ b/app/views/contact/new.html.erb
@@ -13,11 +13,16 @@
 
   <%= required_fields_message %>
 
-  <% location_fields = select_city(true) %>
+  <% unless logged_in? %>
+    <%= required f.text_field(:name) %>
+    <%= required f.text_field(:email) %>
+  <% end %>
 
+  <% location_fields = select_city(true) %>
   <% unless environment.enabled?('disable_select_city_for_contact') || location_fields.blank? %>
     <%= labelled_form_field _('City and state'), location_fields %>
   <% end %>
+
   <%= required f.text_field(:subject) %>
 
   <%= render :file => 'shared/tiny_mce' %>
@@ -25,5 +30,9 @@
 
   <%= labelled_form_field check_box(:contact, :receive_a_copy) + _('I want to receive a copy of the message in my e-mail.'), '' %>
 
-  <%= submit_button(:send, _('Send'), :onclick => "$('confirm').value = 'true'") %>
+  <% unless logged_in? %>
+    <%= recaptcha_tags :ajax => true, :display => {:theme => 'clean'} %>
+  <% end %>
+
+  <%= submit_button(:send, _('Send'), :onclick => "jQuery('#confirm').val('true')") %>
 <% end %>

=====================================
test/functional/contact_controller_test.rb
=====================================
--- a/test/functional/contact_controller_test.rb
+++ b/test/functional/contact_controller_test.rb
@@ -90,11 +90,12 @@ class ContactControllerTest < ActionController::TestCase
     assert_no_tag :tag => 'select', :attributes => {:name => 'state'}
   end
 
-  should 'not allow if not logged' do
+  should 'show name, email and captcha if not logged' do
     logout
     get :new, :profile => profile.identifier
-    assert_response :redirect
-    assert_redirected_to :controller => 'account', :action => 'login'
+    assert_tag :tag => 'input', :attributes => {:name => 'contact[name]'}
+    assert_tag :tag => 'input', :attributes => {:name => 'contact[email]'}
+    assert_tag :attributes => {id: 'dynamic_recaptcha'}
   end
 
   should 'identify sender' do

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150129/19067516/attachment-0001.html>


More information about the Noosfero-dev mailing list