[noosfero/noosfero][master] 2 commits: Fixes for sendemail_plugin

Antonio Terceiro gitlab at gitlab.com
Tue Apr 14 15:45:51 BRT 2015


Antonio Terceiro pushed to master at Noosfero / noosfero


Commits:
125613f4 by Daniela Feitosa at 2015-04-14T14:31:22Z
Fixes for sendemail_plugin

- Fixed email sent to users
- Removed from params info that don't need to be displayed to users on screen
  and email
- Fixed replace of macro "{sendemail}"

- - - - -
a1459c79 by Antonio Terceiro at 2015-04-14T18:45:34Z
Merge branch 'sendemail_plugin' into 'master'

Fixes for sendemail_plugin

The plugin wasn't working

Fixes:
- Replaced macro "{sendemail}" by "sendemail"
  * The {} is escaped on forms
- Removed from params info that don't need to be displayed to users on screen and email
- Fixed email sent to users

See merge request !547

- - - - -


9 changed files:

- plugins/send_email/controllers/send_email_plugin_base_controller.rb
- plugins/send_email/lib/send_email_plugin.rb
- plugins/send_email/lib/send_email_plugin/mail.rb
- plugins/send_email/lib/send_email_plugin/sender.rb
- plugins/send_email/test/functional/send_email_plugin_base_controller_test.rb
- plugins/send_email/test/unit/send_email_plugin_sender_test.rb
- plugins/send_email/test/unit/send_email_plugin_test.rb
- plugins/send_email/views/send_email_plugin/sender/message.html.erb → plugins/send_email/views/send_email_plugin/sender/send_message.html.erb
- plugins/send_email/views/send_email_plugin/success.html.erb


Changes:

=====================================
plugins/send_email/controllers/send_email_plugin_base_controller.rb
=====================================
--- a/plugins/send_email/controllers/send_email_plugin_base_controller.rb
+++ b/plugins/send_email/controllers/send_email_plugin_base_controller.rb
@@ -11,7 +11,8 @@ module SendEmailPluginBaseController
       )
       @mail.subject = params[:subject] unless params[:subject].blank?
       if @mail.valid?
-        SendEmailPlugin::Sender.send_message(request.referer, @context_url, @mail).deliver
+        @referer = request.referer
+        SendEmailPlugin::Sender.send_message(@referer, @context_url, @mail).deliver
         if request.xhr?
           render :text => _('Message sent')
         else

=====================================
plugins/send_email/lib/send_email_plugin.rb
=====================================
--- a/plugins/send_email/lib/send_email_plugin.rb
+++ b/plugins/send_email/lib/send_email_plugin.rb
@@ -16,9 +16,9 @@ class SendEmailPlugin < Noosfero::Plugin
 
   def parse_content(html, source)
     if context.profile
-      html.gsub!(/\{sendemail\}/, "/profile/#{context.profile.identifier}/plugin/send_email/deliver")
+      html.gsub!(/({|%7[Bb])sendemail(}|%7[Dd])/, "/profile/#{context.profile.identifier}/plugin/send_email/deliver")
     else
-      html.gsub!(/\{sendemail\}/, '/plugin/send_email/deliver')
+      html.gsub!(/({|%7[Bb])sendemail(}|%7[Dd])/, '/plugin/send_email/deliver')
     end
     [html, source]
   end

=====================================
plugins/send_email/lib/send_email_plugin/mail.rb
=====================================
--- a/plugins/send_email/lib/send_email_plugin/mail.rb
+++ b/plugins/send_email/lib/send_email_plugin/mail.rb
@@ -10,12 +10,11 @@ class SendEmailPlugin::Mail
   validate :recipients_format
 
   def initialize(attributes = {:subject => 'New mail'})
-    @environment = attributes[:environment]
-    @from = attributes[:from]
-    @to = attributes[:to]
-    @subject = attributes[:subject]
-    @message = attributes[:message]
-    @params = attributes[:params]
+    if attributes
+      attributes.each do |attr,value|
+        self.send("#{attr}=", value)
+      end
+    end
   end
 
   def recipients_format
@@ -36,7 +35,7 @@ class SendEmailPlugin::Mail
   end
 
   def params=(value = {})
-    [:action, :controller, :to, :message, :subject, :from].each{|k| value.delete(k)}
+    [:action, :controller, :to, :message, :subject, :from, :commit].each{|k| value.delete(k)}
     @params = value
   end
 

=====================================
plugins/send_email/lib/send_email_plugin/sender.rb
=====================================
--- a/plugins/send_email/lib/send_email_plugin/sender.rb
+++ b/plugins/send_email/lib/send_email_plugin/sender.rb
@@ -9,7 +9,6 @@ class SendEmailPlugin::Sender < Noosfero::Plugin::MailerBase
     mail(
       to: mail.to,
       from: mail.from,
-      body: mail.params,
       subject: "[#{mail.environment.name}] #{mail.subject}"
     )
   end

=====================================
plugins/send_email/test/functional/send_email_plugin_base_controller_test.rb
=====================================
--- a/plugins/send_email/test/functional/send_email_plugin_base_controller_test.rb
+++ b/plugins/send_email/test/functional/send_email_plugin_base_controller_test.rb
@@ -54,6 +54,13 @@ def run_common_tests
     post :deliver, @extra_args.merge(:to => 'john at example.com', :message => 'Hi john', :subject => 'Hello john')
     assert_equal '[Colivre.net] Hello john', ActionMailer::Base.deliveries.first.subject
   end
+
+  should 'deliver mail with message from view' do
+    Environment.any_instance.stubs(:send_email_plugin_allow_to).returns('john at example.com')
+    post :deliver, @extra_args.merge(:to => 'john at example.com', :message => 'Hi john', :subject => 'Hello john')
+    assert_match /Contact from/, ActionMailer::Base.deliveries.first.body.to_s
+  end
+
 end
 
 class SendEmailPluginProfileControllerTest < ActionController::TestCase

=====================================
plugins/send_email/test/unit/send_email_plugin_sender_test.rb
=====================================
--- a/plugins/send_email/test/unit/send_email_plugin_sender_test.rb
+++ b/plugins/send_email/test/unit/send_email_plugin_sender_test.rb
@@ -15,12 +15,14 @@ class SendEmailPluginSenderTest < ActiveSupport::TestCase
   end
 
   should 'be able to deliver mail' do
+    @mail.expects(:params).returns({})
     response = SendEmailPlugin::Sender.send_message("http://localhost/contact", 'http//profile', @mail)
     assert_equal 'noreply at localhost', response.from.join
     assert_equal "[Noosfero] #{@mail.subject}", response.subject
   end
 
   should 'deliver mail to john at example.com' do
+    @mail.expects(:params).returns({})
     response = SendEmailPlugin::Sender.send_message("http://localhost/contact", 'http//profile', @mail)
     assert_equal ['john at example.com'], response.to
   end

=====================================
plugins/send_email/test/unit/send_email_plugin_test.rb
=====================================
--- a/plugins/send_email/test/unit/send_email_plugin_test.rb
+++ b/plugins/send_email/test/unit/send_email_plugin_test.rb
@@ -26,4 +26,12 @@ class SendEmailPluginTest < ActiveSupport::TestCase
     assert_match /profile\/#{@plugin.context.profile.identifier}\/plugin\/send_email\/deliver/, @plugin.parse_content("expand this macro {sendemail}", nil).first
   end
 
+  should 'expand macro used on form on profile context' do
+    profile = fast_create(Community)
+    @plugin.context.stubs(:profile).returns(profile)
+    article = RawHTMLArticle.create!(:name => 'Raw HTML', :body => "<form action='{sendemail}'></form>", :profile => profile)
+
+    assert_match /profile\/#{profile.identifier}\/plugin\/send_email\/deliver/, @plugin.parse_content(article.to_html, nil).first
+  end
+
 end

=====================================
plugins/send_email/views/send_email_plugin/sender/message.html.erb → plugins/send_email/views/send_email_plugin/sender/send_message.html.erb
=====================================
--- a/plugins/send_email/views/send_email_plugin/sender/message.html.erb
+++ b/plugins/send_email/views/send_email_plugin/sender/send_message.html.erb

=====================================
plugins/send_email/views/send_email_plugin/success.html.erb
=====================================
--- a/plugins/send_email/views/send_email_plugin/success.html.erb
+++ b/plugins/send_email/views/send_email_plugin/success.html.erb
@@ -2,7 +2,7 @@
 
 <table class='sendemail-plugin-message-sent'>
   <tr><td class='label'><strong><%= c_('Subject') %>:</strong></td><td class='value'><em><%=h @mail.subject %></em></td></tr>
-  <tr><td class='label'><strong><%= c_('Message') %>:</strong></td><td class='value'><pre><%=h render :file => 'send_email_plugin/sender/message' %></pre></td></tr>
+  <tr><td class='label'><strong><%= c_('Message') %>:</strong></td><td class='value'><pre><%=h render :file => 'send_email_plugin/sender/send_message' %></pre></td></tr>
 </table>
 
 <p><%= button :back, c_('Back'), :back %></p>


View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/b501e2ce38e027ef868d32ca448bc8baf6fef314...a1459c79bfe2f67f9eee286fd8e054cf87e2c7cf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150414/672f11db/attachment-0001.html>


More information about the Noosfero-dev mailing list