diff --git a/app/views/features/manage_fields.html.erb b/app/views/features/manage_fields.html.erb
index f57e9ad..8ca86db 100644
--- a/app/views/features/manage_fields.html.erb
+++ b/app/views/features/manage_fields.html.erb
@@ -1,5 +1,7 @@
<%= _('Manage fields displayed for profiles') %>
+<%= javascript_include_tag "manage-fields.js" %>
+
<% tabs = [] %>
<% tabs << {:title => _("Person's fields"), :id => 'person-fields',
:content => (render :partial => 'manage_person_fields')} %>
@@ -11,5 +13,3 @@
<% end %>
<%= render_tabs(tabs) %>
-
-<%= javascript_include_tag "manage-fields.js" %>
diff --git a/lib/noosfero/api/entities.rb b/lib/noosfero/api/entities.rb
index f05139b..ef96403 100644
--- a/lib/noosfero/api/entities.rb
+++ b/lib/noosfero/api/entities.rb
@@ -64,6 +64,8 @@ module Noosfero
expose :profile, :using => Profile
expose :categories, :using => Category
expose :image, :using => Image
+ expose :votes_for
+ expose :votes_against
end
class Article < ArticleBase
diff --git a/plugins/google_analytics/lib/ext/profile.rb b/plugins/google_analytics/lib/ext/profile.rb
index 8c966a1..acf834c 100644
--- a/plugins/google_analytics/lib/ext/profile.rb
+++ b/plugins/google_analytics/lib/ext/profile.rb
@@ -2,4 +2,9 @@ require_dependency 'profile'
class Profile
settings_items :google_analytics_profile_id
+ attr_accessible :google_analytics_profile_id
+
+ descendants.each do |descendant|
+ descendant.attr_accessible :google_analytics_profile_id
+ end
end
diff --git a/plugins/google_analytics/lib/google_analytics_plugin.rb b/plugins/google_analytics/lib/google_analytics_plugin.rb
index 1008c59..dac51dc 100644
--- a/plugins/google_analytics/lib/google_analytics_plugin.rb
+++ b/plugins/google_analytics/lib/google_analytics_plugin.rb
@@ -19,12 +19,15 @@ class GoogleAnalyticsPlugin < Noosfero::Plugin
def head_ending
unless profile_id.blank?
- expanded_template('tracking-code.rhtml',{:profile_id => profile_id})
+ expanded_template('tracking-code.html.erb',{:profile_id => profile_id})
end
end
def profile_editor_extras
- expanded_template('profile-editor-extras.rhtml',{:profile_id => profile_id})
+ analytics_id = profile_id
+ lambda {
+ render :file => 'profile-editor-extras', :locals => { :profile_id => analytics_id }
+ }
end
end
diff --git a/plugins/google_analytics/test/functional/profile_editor_controller_test.rb b/plugins/google_analytics/test/functional/profile_editor_controller_test.rb
new file mode 100644
index 0000000..1be3bb4
--- /dev/null
+++ b/plugins/google_analytics/test/functional/profile_editor_controller_test.rb
@@ -0,0 +1,31 @@
+require 'test_helper'
+require 'profile_editor_controller'
+
+# Re-raise errors caught by the controller.
+class ProfileEditorController; def rescue_action(e) raise e end; end
+
+class ProfileEditorControllerTest < ActionController::TestCase
+
+ def setup
+ @controller = ProfileEditorController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ @profile = create_user('default_user').person
+ login_as(@profile.identifier)
+ Environment.default.enable_plugin(GoogleAnalyticsPlugin.name)
+ end
+
+ attr_accessor :profile
+
+ should 'add extra fields to profile editor info and settings' do
+ get :edit, :profile => profile.identifier
+ assert_tag_in_string @response.body, :tag => 'label', :content => /Google Analytics/, :attributes => { :for => 'profile_data_google_analytics_profile_id' }
+ assert_tag_in_string @response.body, :tag => 'input', :attributes => { :id => 'profile_data_google_analytics_profile_id' }
+ end
+
+ should 'save code filled in on field' do
+ post :edit, :profile => profile.identifier, :profile_data => {:google_analytics_profile_id => 12345678}
+ assert_equal '12345678', Person.find(profile.id).google_analytics_profile_id
+ end
+
+end
diff --git a/plugins/google_analytics/test/unit/google_analytics_plugin_test.rb b/plugins/google_analytics/test/unit/google_analytics_plugin_test.rb
index 10394b3..a46a5e2 100644
--- a/plugins/google_analytics/test/unit/google_analytics_plugin_test.rb
+++ b/plugins/google_analytics/test/unit/google_analytics_plugin_test.rb
@@ -27,11 +27,6 @@ class GoogleAnalyticsPluginTest < ActiveSupport::TestCase
assert_equal 'content', @plugin.head_ending
end
- should 'add extra fields to profile editor info and settings' do
- assert_tag_in_string @plugin.profile_editor_extras,
- :tag => 'input', :attributes => {:id => 'profile_data_google_analytics_profile_id', :value => 10}
- end
-
should 'extends Profile with attr google_analytics_profile_id' do
assert_respond_to Profile.new, :google_analytics_profile_id
end
diff --git a/plugins/google_analytics/views/profile-editor-extras.html.erb b/plugins/google_analytics/views/profile-editor-extras.html.erb
new file mode 100644
index 0000000..7dba5a2
--- /dev/null
+++ b/plugins/google_analytics/views/profile-editor-extras.html.erb
@@ -0,0 +1,3 @@
+<%= c_('Statistics') %>
+<%= labelled_form_field(_('Google Analytics Profile ID'), text_field(:profile_data, :google_analytics_profile_id, :value => profile_id)) %>
+<%= link_to(_('See how to configure statistics for your profile'), '/doc/plugins/google_analytics', :target => '_blank') %>
diff --git a/plugins/google_analytics/views/profile-editor-extras.rhtml b/plugins/google_analytics/views/profile-editor-extras.rhtml
deleted file mode 100644
index 4073c6d..0000000
--- a/plugins/google_analytics/views/profile-editor-extras.rhtml
+++ /dev/null
@@ -1,5 +0,0 @@
-<% extend ApplicationHelper %>
-
-<%= c_('Statistics') %>
-<%= labelled_form_field(_('Google Analytics Profile ID'), text_field(:profile_data, :google_analytics_profile_id, :value => profile_id)) %>
-<%= link_to(_('See how to configure statistics for your profile'), '/doc/plugins/google_analytics', :target => '_blank') %>
diff --git a/plugins/google_analytics/views/tracking-code.html.erb b/plugins/google_analytics/views/tracking-code.html.erb
new file mode 100644
index 0000000..c233ce9
--- /dev/null
+++ b/plugins/google_analytics/views/tracking-code.html.erb
@@ -0,0 +1,9 @@
+
diff --git a/plugins/google_analytics/views/tracking-code.rhtml b/plugins/google_analytics/views/tracking-code.rhtml
deleted file mode 100644
index 8b89062..0000000
--- a/plugins/google_analytics/views/tracking-code.rhtml
+++ /dev/null
@@ -1,10 +0,0 @@
-
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..82a01fb 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)}
+ [:profile, :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..d138516 100644
--- a/plugins/send_email/lib/send_email_plugin/sender.rb
+++ b/plugins/send_email/lib/send_email_plugin/sender.rb
@@ -7,9 +7,9 @@ class SendEmailPlugin::Sender < Noosfero::Plugin::MailerBase
@params = mail.params
mail(
+ content_type: 'text/plain',
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..f11367b
--- /dev/null
+++ b/plugins/send_email/views/send_email_plugin/sender/send_message.html.erb
@@ -0,0 +1,9 @@
+<%= _('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 @@
<%= c_('Subject') %>: | <%=h @mail.subject %> |
- <%= c_('Message') %>: | <%=h render :file => 'send_email_plugin/sender/message' %> |
+ <%= c_('Message') %>: | <%=h render :file => 'send_email_plugin/sender/send_message' %> |
<%= button :back, c_('Back'), :back %>
diff --git a/public/javascripts/manage-fields.js b/public/javascripts/manage-fields.js
index 95e254b..9c0b678 100644
--- a/public/javascripts/manage-fields.js
+++ b/public/javascripts/manage-fields.js
@@ -57,7 +57,7 @@ jQuery(document).ready(function(){
}
var checkbox = jQuery(checkboxes[i+3]).attr("id").split("_")
- jQuery("#" + checkbox.first() + "_" + checkbox.last()).attr("checked", allchecked)
+ jQuery("#" + checkbox[0] + "_" + checkbox[checkbox.length-1]).attr("checked", allchecked)
}
}
@@ -74,10 +74,10 @@ jQuery(document).ready(function(){
jQuery("input[type='checkbox']").click(function (){
var checkbox = jQuery(this).attr("id").split("_")
- verify_checked(checkbox.first())
+ verify_checked(checkbox[0])
if(this.checked == false) {
- jQuery("#" + checkbox.first() + "_" + checkbox.last()).attr("checked", false)
+ jQuery("#" + checkbox[0] + "_" + checkbox[checkbox.length-1]).attr("checked", false)
}
})
})
--
libgit2 0.21.2