Commit 725c7c993dfc40f7b6a466dd9084c6c7c2e157fe
Committed by
Victor Costa
0 parents
Exists in
master
Send an article by email to members of a community
Showing
4 changed files
with
81 additions
and
0 deletions
Show diff stats
controllers/email_article_plugin_myprofile_controller.rb
0 → 100644
1 | +++ a/controllers/email_article_plugin_myprofile_controller.rb | |
... | ... | @@ -0,0 +1,29 @@ |
1 | +class EmailArticlePluginMyprofileController < MyProfileController | |
2 | + | |
3 | + needs_profile | |
4 | +# before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add] | |
5 | +# before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail] | |
6 | +# 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] | |
7 | + | |
8 | + def send_email | |
9 | + article = Article.find(params[:id]) | |
10 | + EmailArticlePluginMyprofileController::Sender.deliver_mail(article) | |
11 | + render :text=>'ok' | |
12 | + end | |
13 | + | |
14 | + class Sender < ActionMailer::Base | |
15 | + def mail(article) | |
16 | + members = article.profile.members | |
17 | + emails = [] | |
18 | + members.each{ |m| | |
19 | + emails.push(m.user.email) | |
20 | + } | |
21 | + content_type 'text/html' | |
22 | + recipients emails | |
23 | + from "#{article.author.user.name} <#{article.author.user.email}>" | |
24 | + reply_to article.author.user.email | |
25 | + subject "[Artigo] " + article.title | |
26 | + body article.body | |
27 | + end | |
28 | + end | |
29 | +end | |
0 | 30 | \ No newline at end of file | ... | ... |
1 | +++ a/lib/email_article_plugin.rb | |
... | ... | @@ -0,0 +1,30 @@ |
1 | +class EmailArticlePlugin < Noosfero::Plugin | |
2 | + | |
3 | + def self.plugin_name | |
4 | + "Email Article to Community Members Plugin" | |
5 | + end | |
6 | + | |
7 | + def self.plugin_description | |
8 | + _("A plugin that emails an article to the members of the community.") | |
9 | + end | |
10 | + | |
11 | + def article_toolbar_extra_buttons | |
12 | + label = _("Send article to members") | |
13 | + htmlclass = _("button with-text icon-menu-mail") | |
14 | + title = _("Email article to all community members") | |
15 | + lambda { | |
16 | + link_to_remote( | |
17 | + label, | |
18 | + { | |
19 | + :url => { :controller => 'email_article_plugin_myprofile', :action => "send_email", :id => @page}, | |
20 | + :method => :get, | |
21 | + :success => "alert('Emails enviados')", | |
22 | + :failure => "alert('Erro ao enviar email')", | |
23 | + :confirm => _("Are you sure you want to email this article to the all community members?"), | |
24 | + }, | |
25 | + :class => htmlclass, | |
26 | + :title => title | |
27 | + ) | |
28 | + } | |
29 | + end | |
30 | +end | ... | ... |
1 | +++ a/test/unit/email_article_plugin_test.rb | |
... | ... | @@ -0,0 +1,21 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class EmailArticlePluginTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @plugin = EmailArticlePlugin.new | |
7 | + end | |
8 | + | |
9 | + should 'be a noosfero plugin' do | |
10 | + assert_kind_of Noosfero::Plugin, @plugin | |
11 | + end | |
12 | + | |
13 | + should 'have name' do | |
14 | + assert_equal 'Relevant Content Plugin', EmailArticlePlugin.plugin_name | |
15 | + end | |
16 | + | |
17 | + should 'have description' do | |
18 | + assert_equal _("A plugin that lists the most accessed, most commented, most liked and most disliked contents."), EmailArticlePlugin.plugin_description | |
19 | + end | |
20 | + | |
21 | +end | ... | ... |