Commit e2b501d83cf90cd34c07d455e242aea6d819f04e
Committed by
Victor Costa
1 parent
a5c0c0f3
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Send an article by email to members of a community
Showing
7 changed files
with
98 additions
and
0 deletions
Show diff stats
app/views/content_viewer/_article_toolbar.rhtml
| ... | ... | @@ -37,6 +37,11 @@ |
| 37 | 37 | <%= colorbox_button(:new, label_for_new_article(@page), profile.admin_url.merge(:controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)))) unless remove_content_button(:new) %> |
| 38 | 38 | <% end %> |
| 39 | 39 | |
| 40 | + <% | |
| 41 | + @plugins.dispatch(:article_toolbar_extra_buttons).each do |plugin_button| %> | |
| 42 | + <%= instance_eval(&plugin_button) %> | |
| 43 | + <% end %> | |
| 44 | + | |
| 40 | 45 | <% if @page.accept_uploads? && @page.allow_create?(user) %> |
| 41 | 46 | <%= button('upload-file', _('Upload files'), profile.admin_url.merge(:controller => 'cms', :action => 'upload_files', :parent_id => (@page.folder? ? @page : @page.parent))) unless remove_content_button(:upload)%> |
| 42 | 47 | <% end %> | ... | ... |
lib/noosfero/plugin.rb
| ... | ... | @@ -285,6 +285,17 @@ class Noosfero::Plugin |
| 285 | 285 | nil |
| 286 | 286 | end |
| 287 | 287 | |
| 288 | + | |
| 289 | + # -> Adds buttons to manage members page | |
| 290 | + # returns = { :title => title, :icon => icon, :url => url } | |
| 291 | + # title = name that will be displayed. | |
| 292 | + # icon = css class name (for customized icons include them in a css file). | |
| 293 | + # url = url or route to which the button will redirect. | |
| 294 | + def article_toolbar_extra_buttons | |
| 295 | + nil | |
| 296 | + end | |
| 297 | + | |
| 298 | + | |
| 288 | 299 | # This method will be called just before a comment is saved to the database. |
| 289 | 300 | # |
| 290 | 301 | # It can modify the comment in several ways. In special, a plugin can call | ... | ... |
plugins/email_article/controllers/email_article_plugin_myprofile_controller.rb
0 → 100644
| ... | ... | @@ -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 | ... | ... |
| ... | ... | @@ -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 | ... | ... |
| ... | ... | @@ -0,0 +1 @@ |
| 1 | +require File.dirname(__FILE__) + '/../../../test/test_helper' | ... | ... |
plugins/email_article/test/unit/email_article_plugin_test.rb
0 → 100644
| ... | ... | @@ -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 | ... | ... |