Commit cf863b86ed0df5a5e06c2f42984ec400fe5cb217
1 parent
6387c1cb
Exists in
master
Adding old myprofile controller
Showing
4 changed files
with
83 additions
and
5 deletions
Show diff stats
controllers/email_article_plugin_myprofile_controller.rb
| @@ -4,7 +4,7 @@ class EmailArticlePluginMyprofileController < MyProfileController | @@ -4,7 +4,7 @@ class EmailArticlePluginMyprofileController < MyProfileController | ||
| 4 | needs_profile | 4 | needs_profile |
| 5 | 5 | ||
| 6 | def send_email | 6 | def send_email |
| 7 | - unless user.is_admin?(profile) | 7 | + unless profile.is_admin?(user) || user.is_admin? |
| 8 | render :status => :forbidden, :text => "Forbidden user" | 8 | render :status => :forbidden, :text => "Forbidden user" |
| 9 | return | 9 | return |
| 10 | end | 10 | end |
controllers/email_article_plugin_myprofile_controller_old.rb
0 → 100644
| @@ -0,0 +1,80 @@ | @@ -0,0 +1,80 @@ | ||
| 1 | +require 'nokogiri' | ||
| 2 | + | ||
| 3 | +class EmailArticlePluginMyprofileController < MyProfileController | ||
| 4 | + | ||
| 5 | + needs_profile | ||
| 6 | + | ||
| 7 | + def send_email | ||
| 8 | + if user.is_admin?(profile) | ||
| 9 | + article = profile.articles.find(params[:id]) | ||
| 10 | + #EmailArticlePluginMyprofileController::Sender.content(article).deliver | ||
| 11 | + Sender.content(article) | ||
| 12 | + render :text => "Email sent to queue" | ||
| 13 | + else | ||
| 14 | + render :status => :forbidden, :text => "Forbidden user" | ||
| 15 | + end | ||
| 16 | + end | ||
| 17 | + | ||
| 18 | + class Sender | ||
| 19 | + def self.content(article) | ||
| 20 | + source = article.author.user.person | ||
| 21 | + mail = Mailing.new | ||
| 22 | + mail. | ||
| 23 | + # mailing = create(Mailing, :source => article.author.user.person, :subject => 'Hello', :body => 'We have some news', :person => article.author.user.person) | ||
| 24 | + end | ||
| 25 | + | ||
| 26 | + def absolute_url? url | ||
| 27 | + url.start_with?('http') || url.start_with?('ftp') | ||
| 28 | + end | ||
| 29 | + end | ||
| 30 | + | ||
| 31 | + | ||
| 32 | + class Sender < ActionMailer::Base | ||
| 33 | + def content(article) | ||
| 34 | + doc = Nokogiri::HTML(article.body) | ||
| 35 | + doc.css("a").each do |link| | ||
| 36 | + if !link.attribute("href").nil? and !absolute_url?(link.attribute("href").value) | ||
| 37 | + relative_path = link.attribute("href").value | ||
| 38 | + if relative_path.starts_with?('/') | ||
| 39 | + relative_path[0]='' | ||
| 40 | + end | ||
| 41 | + link.attribute("href").value = "http://#{article.environment.default_hostname}/#{relative_path}" | ||
| 42 | + end | ||
| 43 | + end | ||
| 44 | + | ||
| 45 | + doc.css("img").each do |link| | ||
| 46 | + unless link.attribute("src").nil? and absolute_url?(link.attribute("src").value) | ||
| 47 | + relative_path = link.attribute("src").value | ||
| 48 | + link.attribute("src").value = "http://#{article.environment.default_hostname}/#{relative_path}" | ||
| 49 | + end | ||
| 50 | + end | ||
| 51 | + | ||
| 52 | +# link.attributes["href"].value = "http://myproxy.com/?url=#{CGI.escape link.attributes["href"].value}" | ||
| 53 | +# http://#{environment.default_hostname}/#{relative_path[1]} | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + body = doc.to_html | ||
| 57 | + sender = Person.find(article.author_id) | ||
| 58 | + members = article.profile.members | ||
| 59 | + emails = [] | ||
| 60 | + members.each{ |m| | ||
| 61 | + emails.push(m.user.email) | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + # mailing = create(Mailing, :source => article.author.user.person, :subject => 'Hello', :body => 'We have some news', :person => article.author.user.person) | ||
| 65 | + | ||
| 66 | + mail( | ||
| 67 | + content_type: 'text/html', | ||
| 68 | + to: emails, | ||
| 69 | + from: "#{article.author_name} <#{sender.contact_email}>", | ||
| 70 | + reply_to: article.author.user.email, | ||
| 71 | + subject: "[Artigo] " + article.title, | ||
| 72 | + body: body | ||
| 73 | +# body: set_absolute_path(article.body, article.environment) | ||
| 74 | + ) | ||
| 75 | + end | ||
| 76 | +end | ||
| 77 | + | ||
| 78 | + | ||
| 79 | + | ||
| 80 | +end |
lib/email_article_plugin.rb
| @@ -9,8 +9,7 @@ class EmailArticlePlugin < Noosfero::Plugin | @@ -9,8 +9,7 @@ class EmailArticlePlugin < Noosfero::Plugin | ||
| 9 | end | 9 | end |
| 10 | 10 | ||
| 11 | def article_extra_toolbar_buttons(article) | 11 | def article_extra_toolbar_buttons(article) |
| 12 | -#raise current_person.identifier.inspect + " " + profile.identifier.inspect + ' ' + current_person.is_admin?.inspect + " " + article.kind_of?(TextArticle).inspect + " " + profile.admins.include?(current_person).inspect | ||
| 13 | - return [] if !(profile.admins.include?(current_person) || current_person.is_admin?) || !article.kind_of?(TextArticle) | 12 | + return [] if !(profile.is_admin?(current_person) || current_person.is_admin?) || !article.kind_of?(TextArticle) |
| 14 | { | 13 | { |
| 15 | :icon => 'icon-menu-mail', | 14 | :icon => 'icon-menu-mail', |
| 16 | :url => { :profile => profile.identifier, :controller => 'email_article_plugin_myprofile', :action => "send_email", :id => article}, | 15 | :url => { :profile => profile.identifier, :controller => 'email_article_plugin_myprofile', :action => "send_email", :id => article}, |
test/unit/email_article_plugin_test.rb
| @@ -5,7 +5,7 @@ class EmailArticlePluginTest < ActiveSupport::TestCase | @@ -5,7 +5,7 @@ class EmailArticlePluginTest < ActiveSupport::TestCase | ||
| 5 | def setup | 5 | def setup |
| 6 | @environment = Environment.default | 6 | @environment = Environment.default |
| 7 | @user = create_user('testuser').person | 7 | @user = create_user('testuser').person |
| 8 | - @profile = fast_create(Profile) | 8 | + @profile = fast_create(Organization) |
| 9 | context = mock() | 9 | context = mock() |
| 10 | context.stubs(:current_person).returns(@user) | 10 | context.stubs(:current_person).returns(@user) |
| 11 | context.stubs(:profile).returns(@profile) | 11 | context.stubs(:profile).returns(@profile) |
| @@ -33,7 +33,6 @@ class EmailArticlePluginTest < ActiveSupport::TestCase | @@ -33,7 +33,6 @@ class EmailArticlePluginTest < ActiveSupport::TestCase | ||
| 33 | end | 33 | end |
| 34 | 34 | ||
| 35 | should 'display button to send email for all members of a community if the user is an environment administrator' do | 35 | should 'display button to send email for all members of a community if the user is an environment administrator' do |
| 36 | -# profile.add_admin(user) | ||
| 37 | environment.add_admin(user) | 36 | environment.add_admin(user) |
| 38 | article = fast_create(TextArticle, :profile_id => profile.id) | 37 | article = fast_create(TextArticle, :profile_id => profile.id) |
| 39 | assert_not_equal [], plugin.article_extra_toolbar_buttons(article) | 38 | assert_not_equal [], plugin.article_extra_toolbar_buttons(article) |