From 725c7c993dfc40f7b6a466dd9084c6c7c2e157fe Mon Sep 17 00:00:00 2001 From: Evandro Junior Date: Thu, 8 May 2014 21:16:36 +0000 Subject: [PATCH] Send an article by email to members of a community --- controllers/email_article_plugin_myprofile_controller.rb | 29 +++++++++++++++++++++++++++++ lib/email_article_plugin.rb | 30 ++++++++++++++++++++++++++++++ test/test_helper.rb | 1 + test/unit/email_article_plugin_test.rb | 21 +++++++++++++++++++++ 4 files changed, 81 insertions(+), 0 deletions(-) create mode 100644 controllers/email_article_plugin_myprofile_controller.rb create mode 100644 lib/email_article_plugin.rb create mode 100644 test/test_helper.rb create mode 100644 test/unit/email_article_plugin_test.rb diff --git a/controllers/email_article_plugin_myprofile_controller.rb b/controllers/email_article_plugin_myprofile_controller.rb new file mode 100644 index 0000000..c606668 --- /dev/null +++ b/controllers/email_article_plugin_myprofile_controller.rb @@ -0,0 +1,29 @@ +class EmailArticlePluginMyprofileController < MyProfileController + + needs_profile +# before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add] +# before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail] +# before_filter :login_required, :only => [:add, :join, :join_not_logged, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity, :send_mail] + + def send_email + article = Article.find(params[:id]) + EmailArticlePluginMyprofileController::Sender.deliver_mail(article) + render :text=>'ok' + end + + class Sender < ActionMailer::Base + def mail(article) + members = article.profile.members + emails = [] + members.each{ |m| + emails.push(m.user.email) + } + content_type 'text/html' + recipients emails + from "#{article.author.user.name} <#{article.author.user.email}>" + reply_to article.author.user.email + subject "[Artigo] " + article.title + body article.body + end + end +end \ No newline at end of file diff --git a/lib/email_article_plugin.rb b/lib/email_article_plugin.rb new file mode 100644 index 0000000..1548508 --- /dev/null +++ b/lib/email_article_plugin.rb @@ -0,0 +1,30 @@ +class EmailArticlePlugin < Noosfero::Plugin + + def self.plugin_name + "Email Article to Community Members Plugin" + end + + def self.plugin_description + _("A plugin that emails an article to the members of the community.") + end + + def article_toolbar_extra_buttons + label = _("Send article to members") + htmlclass = _("button with-text icon-menu-mail") + title = _("Email article to all community members") + lambda { + link_to_remote( + label, + { + :url => { :controller => 'email_article_plugin_myprofile', :action => "send_email", :id => @page}, + :method => :get, + :success => "alert('Emails enviados')", + :failure => "alert('Erro ao enviar email')", + :confirm => _("Are you sure you want to email this article to the all community members?"), + }, + :class => htmlclass, + :title => title + ) + } + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..cca1fd3 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1 @@ +require File.dirname(__FILE__) + '/../../../test/test_helper' diff --git a/test/unit/email_article_plugin_test.rb b/test/unit/email_article_plugin_test.rb new file mode 100644 index 0000000..f5d94eb --- /dev/null +++ b/test/unit/email_article_plugin_test.rb @@ -0,0 +1,21 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class EmailArticlePluginTest < ActiveSupport::TestCase + + def setup + @plugin = EmailArticlePlugin.new + end + + should 'be a noosfero plugin' do + assert_kind_of Noosfero::Plugin, @plugin + end + + should 'have name' do + assert_equal 'Relevant Content Plugin', EmailArticlePlugin.plugin_name + end + + should 'have description' do + assert_equal _("A plugin that lists the most accessed, most commented, most liked and most disliked contents."), EmailArticlePlugin.plugin_description + end + +end -- libgit2 0.21.2