Commit a1459c79bfe2f67f9eee286fd8e054cf87e2c7cf
Exists in
staging
and in
42 other branches
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
Showing
10 changed files
with
36 additions
and
20 deletions
Show diff stats
plugins/send_email/controllers/send_email_plugin_base_controller.rb
| ... | ... | @@ -11,7 +11,8 @@ module SendEmailPluginBaseController |
| 11 | 11 | ) |
| 12 | 12 | @mail.subject = params[:subject] unless params[:subject].blank? |
| 13 | 13 | if @mail.valid? |
| 14 | - SendEmailPlugin::Sender.send_message(request.referer, @context_url, @mail).deliver | |
| 14 | + @referer = request.referer | |
| 15 | + SendEmailPlugin::Sender.send_message(@referer, @context_url, @mail).deliver | |
| 15 | 16 | if request.xhr? |
| 16 | 17 | render :text => _('Message sent') |
| 17 | 18 | else | ... | ... |
plugins/send_email/lib/send_email_plugin.rb
| ... | ... | @@ -16,9 +16,9 @@ class SendEmailPlugin < Noosfero::Plugin |
| 16 | 16 | |
| 17 | 17 | def parse_content(html, source) |
| 18 | 18 | if context.profile |
| 19 | - html.gsub!(/\{sendemail\}/, "/profile/#{context.profile.identifier}/plugin/send_email/deliver") | |
| 19 | + html.gsub!(/({|%7[Bb])sendemail(}|%7[Dd])/, "/profile/#{context.profile.identifier}/plugin/send_email/deliver") | |
| 20 | 20 | else |
| 21 | - html.gsub!(/\{sendemail\}/, '/plugin/send_email/deliver') | |
| 21 | + html.gsub!(/({|%7[Bb])sendemail(}|%7[Dd])/, '/plugin/send_email/deliver') | |
| 22 | 22 | end |
| 23 | 23 | [html, source] |
| 24 | 24 | end | ... | ... |
plugins/send_email/lib/send_email_plugin/mail.rb
| ... | ... | @@ -10,12 +10,11 @@ class SendEmailPlugin::Mail |
| 10 | 10 | validate :recipients_format |
| 11 | 11 | |
| 12 | 12 | def initialize(attributes = {:subject => 'New mail'}) |
| 13 | - @environment = attributes[:environment] | |
| 14 | - @from = attributes[:from] | |
| 15 | - @to = attributes[:to] | |
| 16 | - @subject = attributes[:subject] | |
| 17 | - @message = attributes[:message] | |
| 18 | - @params = attributes[:params] | |
| 13 | + if attributes | |
| 14 | + attributes.each do |attr,value| | |
| 15 | + self.send("#{attr}=", value) | |
| 16 | + end | |
| 17 | + end | |
| 19 | 18 | end |
| 20 | 19 | |
| 21 | 20 | def recipients_format |
| ... | ... | @@ -36,7 +35,7 @@ class SendEmailPlugin::Mail |
| 36 | 35 | end |
| 37 | 36 | |
| 38 | 37 | def params=(value = {}) |
| 39 | - [:action, :controller, :to, :message, :subject, :from].each{|k| value.delete(k)} | |
| 38 | + [:action, :controller, :to, :message, :subject, :from, :commit].each{|k| value.delete(k)} | |
| 40 | 39 | @params = value |
| 41 | 40 | end |
| 42 | 41 | ... | ... |
plugins/send_email/lib/send_email_plugin/sender.rb
plugins/send_email/test/functional/send_email_plugin_base_controller_test.rb
| ... | ... | @@ -54,6 +54,13 @@ def run_common_tests |
| 54 | 54 | post :deliver, @extra_args.merge(:to => 'john@example.com', :message => 'Hi john', :subject => 'Hello john') |
| 55 | 55 | assert_equal '[Colivre.net] Hello john', ActionMailer::Base.deliveries.first.subject |
| 56 | 56 | end |
| 57 | + | |
| 58 | + should 'deliver mail with message from view' do | |
| 59 | + Environment.any_instance.stubs(:send_email_plugin_allow_to).returns('john@example.com') | |
| 60 | + post :deliver, @extra_args.merge(:to => 'john@example.com', :message => 'Hi john', :subject => 'Hello john') | |
| 61 | + assert_match /Contact from/, ActionMailer::Base.deliveries.first.body.to_s | |
| 62 | + end | |
| 63 | + | |
| 57 | 64 | end |
| 58 | 65 | |
| 59 | 66 | class SendEmailPluginProfileControllerTest < ActionController::TestCase | ... | ... |
plugins/send_email/test/unit/send_email_plugin_sender_test.rb
| ... | ... | @@ -15,12 +15,14 @@ class SendEmailPluginSenderTest < ActiveSupport::TestCase |
| 15 | 15 | end |
| 16 | 16 | |
| 17 | 17 | should 'be able to deliver mail' do |
| 18 | + @mail.expects(:params).returns({}) | |
| 18 | 19 | response = SendEmailPlugin::Sender.send_message("http://localhost/contact", 'http//profile', @mail) |
| 19 | 20 | assert_equal 'noreply@localhost', response.from.join |
| 20 | 21 | assert_equal "[Noosfero] #{@mail.subject}", response.subject |
| 21 | 22 | end |
| 22 | 23 | |
| 23 | 24 | should 'deliver mail to john@example.com' do |
| 25 | + @mail.expects(:params).returns({}) | |
| 24 | 26 | response = SendEmailPlugin::Sender.send_message("http://localhost/contact", 'http//profile', @mail) |
| 25 | 27 | assert_equal ['john@example.com'], response.to |
| 26 | 28 | end | ... | ... |
plugins/send_email/test/unit/send_email_plugin_test.rb
| ... | ... | @@ -26,4 +26,12 @@ class SendEmailPluginTest < ActiveSupport::TestCase |
| 26 | 26 | assert_match /profile\/#{@plugin.context.profile.identifier}\/plugin\/send_email\/deliver/, @plugin.parse_content("expand this macro {sendemail}", nil).first |
| 27 | 27 | end |
| 28 | 28 | |
| 29 | + should 'expand macro used on form on profile context' do | |
| 30 | + profile = fast_create(Community) | |
| 31 | + @plugin.context.stubs(:profile).returns(profile) | |
| 32 | + article = RawHTMLArticle.create!(:name => 'Raw HTML', :body => "<form action='{sendemail}'></form>", :profile => profile) | |
| 33 | + | |
| 34 | + assert_match /profile\/#{profile.identifier}\/plugin\/send_email\/deliver/, @plugin.parse_content(article.to_html, nil).first | |
| 35 | + end | |
| 36 | + | |
| 29 | 37 | end | ... | ... |
plugins/send_email/views/send_email_plugin/sender/message.html.erb
plugins/send_email/views/send_email_plugin/sender/send_message.html.erb
0 → 100644
plugins/send_email/views/send_email_plugin/success.html.erb
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | <table class='sendemail-plugin-message-sent'> |
| 4 | 4 | <tr><td class='label'><strong><%= c_('Subject') %>:</strong></td><td class='value'><em><%=h @mail.subject %></em></td></tr> |
| 5 | - <tr><td class='label'><strong><%= c_('Message') %>:</strong></td><td class='value'><pre><%=h render :file => 'send_email_plugin/sender/message' %></pre></td></tr> | |
| 5 | + <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> | |
| 6 | 6 | </table> |
| 7 | 7 | |
| 8 | 8 | <p><%= button :back, c_('Back'), :back %></p> | ... | ... |