diff --git a/plugins/send_email/controllers/send_email_plugin_base_controller.rb b/plugins/send_email/controllers/send_email_plugin_base_controller.rb index 61ba010..57b0bb4 100644 --- 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 diff --git a/plugins/send_email/lib/send_email_plugin.rb b/plugins/send_email/lib/send_email_plugin.rb index 5d40333..bd46df9 100644 --- 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 diff --git a/plugins/send_email/lib/send_email_plugin/mail.rb b/plugins/send_email/lib/send_email_plugin/mail.rb index 981fccf..2f6734e 100644 --- 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 diff --git a/plugins/send_email/lib/send_email_plugin/sender.rb b/plugins/send_email/lib/send_email_plugin/sender.rb index 6e0656f..cf927b2 100644 --- 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 diff --git 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 index 4f1d016..6b95ca5 100644 --- 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@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@example.com') + post :deliver, @extra_args.merge(:to => 'john@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 diff --git a/plugins/send_email/test/unit/send_email_plugin_sender_test.rb b/plugins/send_email/test/unit/send_email_plugin_sender_test.rb index a94957f..f4f6d24 100644 --- 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@localhost', response.from.join assert_equal "[Noosfero] #{@mail.subject}", response.subject end should 'deliver mail to john@example.com' do + @mail.expects(:params).returns({}) response = SendEmailPlugin::Sender.send_message("http://localhost/contact", 'http//profile', @mail) assert_equal ['john@example.com'], response.to end diff --git a/plugins/send_email/test/unit/send_email_plugin_test.rb b/plugins/send_email/test/unit/send_email_plugin_test.rb index 875f427..52fdd9a 100644 --- 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 => "
", :profile => profile) + + assert_match /profile\/#{profile.identifier}\/plugin\/send_email\/deliver/, @plugin.parse_content(article.to_html, nil).first + end + end diff --git a/plugins/send_email/views/send_email_plugin/sender/message.html.erb b/plugins/send_email/views/send_email_plugin/sender/message.html.erb deleted file mode 100644 index 251f4a8..0000000 --- a/plugins/send_email/views/send_email_plugin/sender/message.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -<%= _('Contact from %s') % @referer %> - -<%= word_wrap(@message || @mail.message) %> -<% (@params || @mail.params).each_pair do |key, value| %> -<%= key %>: <%= word_wrap(value) %> -<% end %> ---- -<%= url_for @context_url %> diff --git a/plugins/send_email/views/send_email_plugin/sender/send_message.html.erb b/plugins/send_email/views/send_email_plugin/sender/send_message.html.erb new file mode 100644 index 0000000..251f4a8 --- /dev/null +++ b/plugins/send_email/views/send_email_plugin/sender/send_message.html.erb @@ -0,0 +1,8 @@ +<%= _('Contact from %s') % @referer %> + +<%= word_wrap(@message || @mail.message) %> +<% (@params || @mail.params).each_pair do |key, value| %> +<%= key %>: <%= word_wrap(value) %> +<% end %> +--- +<%= url_for @context_url %> diff --git a/plugins/send_email/views/send_email_plugin/success.html.erb b/plugins/send_email/views/send_email_plugin/success.html.erb index 2cf8458..e7610bf 100644 --- 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 @@<%= button :back, c_('Back'), :back %>
-- libgit2 0.21.2