Commit 097db7473c488e0765596ffe70ca71c91f3bd6af
1 parent
4aa9a336
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
api: return vote data for articles
Showing
21 changed files
with
98 additions
and
47 deletions
Show diff stats
app/views/features/manage_fields.html.erb
1 | <h1><%= _('Manage fields displayed for profiles') %></h1> | 1 | <h1><%= _('Manage fields displayed for profiles') %></h1> |
2 | 2 | ||
3 | +<%= javascript_include_tag "manage-fields.js" %> | ||
4 | + | ||
3 | <% tabs = [] %> | 5 | <% tabs = [] %> |
4 | <% tabs << {:title => _("Person's fields"), :id => 'person-fields', | 6 | <% tabs << {:title => _("Person's fields"), :id => 'person-fields', |
5 | :content => (render :partial => 'manage_person_fields')} %> | 7 | :content => (render :partial => 'manage_person_fields')} %> |
@@ -11,5 +13,3 @@ | @@ -11,5 +13,3 @@ | ||
11 | <% end %> | 13 | <% end %> |
12 | 14 | ||
13 | <%= render_tabs(tabs) %> | 15 | <%= render_tabs(tabs) %> |
14 | - | ||
15 | -<%= javascript_include_tag "manage-fields.js" %> |
lib/noosfero/api/entities.rb
@@ -64,6 +64,8 @@ module Noosfero | @@ -64,6 +64,8 @@ module Noosfero | ||
64 | expose :profile, :using => Profile | 64 | expose :profile, :using => Profile |
65 | expose :categories, :using => Category | 65 | expose :categories, :using => Category |
66 | expose :image, :using => Image | 66 | expose :image, :using => Image |
67 | + expose :votes_for | ||
68 | + expose :votes_against | ||
67 | end | 69 | end |
68 | 70 | ||
69 | class Article < ArticleBase | 71 | class Article < ArticleBase |
plugins/google_analytics/lib/ext/profile.rb
@@ -2,4 +2,9 @@ require_dependency 'profile' | @@ -2,4 +2,9 @@ require_dependency 'profile' | ||
2 | 2 | ||
3 | class Profile | 3 | class Profile |
4 | settings_items :google_analytics_profile_id | 4 | settings_items :google_analytics_profile_id |
5 | + attr_accessible :google_analytics_profile_id | ||
6 | + | ||
7 | + descendants.each do |descendant| | ||
8 | + descendant.attr_accessible :google_analytics_profile_id | ||
9 | + end | ||
5 | end | 10 | end |
plugins/google_analytics/lib/google_analytics_plugin.rb
@@ -19,12 +19,15 @@ class GoogleAnalyticsPlugin < Noosfero::Plugin | @@ -19,12 +19,15 @@ class GoogleAnalyticsPlugin < Noosfero::Plugin | ||
19 | 19 | ||
20 | def head_ending | 20 | def head_ending |
21 | unless profile_id.blank? | 21 | unless profile_id.blank? |
22 | - expanded_template('tracking-code.rhtml',{:profile_id => profile_id}) | 22 | + expanded_template('tracking-code.html.erb',{:profile_id => profile_id}) |
23 | end | 23 | end |
24 | end | 24 | end |
25 | 25 | ||
26 | def profile_editor_extras | 26 | def profile_editor_extras |
27 | - expanded_template('profile-editor-extras.rhtml',{:profile_id => profile_id}) | 27 | + analytics_id = profile_id |
28 | + lambda { | ||
29 | + render :file => 'profile-editor-extras', :locals => { :profile_id => analytics_id } | ||
30 | + } | ||
28 | end | 31 | end |
29 | 32 | ||
30 | end | 33 | end |
plugins/google_analytics/test/functional/profile_editor_controller_test.rb
0 → 100644
@@ -0,0 +1,31 @@ | @@ -0,0 +1,31 @@ | ||
1 | +require 'test_helper' | ||
2 | +require 'profile_editor_controller' | ||
3 | + | ||
4 | +# Re-raise errors caught by the controller. | ||
5 | +class ProfileEditorController; def rescue_action(e) raise e end; end | ||
6 | + | ||
7 | +class ProfileEditorControllerTest < ActionController::TestCase | ||
8 | + | ||
9 | + def setup | ||
10 | + @controller = ProfileEditorController.new | ||
11 | + @request = ActionController::TestRequest.new | ||
12 | + @response = ActionController::TestResponse.new | ||
13 | + @profile = create_user('default_user').person | ||
14 | + login_as(@profile.identifier) | ||
15 | + Environment.default.enable_plugin(GoogleAnalyticsPlugin.name) | ||
16 | + end | ||
17 | + | ||
18 | + attr_accessor :profile | ||
19 | + | ||
20 | + should 'add extra fields to profile editor info and settings' do | ||
21 | + get :edit, :profile => profile.identifier | ||
22 | + assert_tag_in_string @response.body, :tag => 'label', :content => /Google Analytics/, :attributes => { :for => 'profile_data_google_analytics_profile_id' } | ||
23 | + assert_tag_in_string @response.body, :tag => 'input', :attributes => { :id => 'profile_data_google_analytics_profile_id' } | ||
24 | + end | ||
25 | + | ||
26 | + should 'save code filled in on field' do | ||
27 | + post :edit, :profile => profile.identifier, :profile_data => {:google_analytics_profile_id => 12345678} | ||
28 | + assert_equal '12345678', Person.find(profile.id).google_analytics_profile_id | ||
29 | + end | ||
30 | + | ||
31 | +end |
plugins/google_analytics/test/unit/google_analytics_plugin_test.rb
@@ -27,11 +27,6 @@ class GoogleAnalyticsPluginTest < ActiveSupport::TestCase | @@ -27,11 +27,6 @@ class GoogleAnalyticsPluginTest < ActiveSupport::TestCase | ||
27 | assert_equal 'content', @plugin.head_ending | 27 | assert_equal 'content', @plugin.head_ending |
28 | end | 28 | end |
29 | 29 | ||
30 | - should 'add extra fields to profile editor info and settings' do | ||
31 | - assert_tag_in_string @plugin.profile_editor_extras, | ||
32 | - :tag => 'input', :attributes => {:id => 'profile_data_google_analytics_profile_id', :value => 10} | ||
33 | - end | ||
34 | - | ||
35 | should 'extends Profile with attr google_analytics_profile_id' do | 30 | should 'extends Profile with attr google_analytics_profile_id' do |
36 | assert_respond_to Profile.new, :google_analytics_profile_id | 31 | assert_respond_to Profile.new, :google_analytics_profile_id |
37 | end | 32 | end |
plugins/google_analytics/views/profile-editor-extras.html.erb
0 → 100644
@@ -0,0 +1,3 @@ | @@ -0,0 +1,3 @@ | ||
1 | +<h2><%= c_('Statistics') %></h2> | ||
2 | +<%= labelled_form_field(_('Google Analytics Profile ID'), text_field(:profile_data, :google_analytics_profile_id, :value => profile_id)) %> | ||
3 | +<%= link_to(_('See how to configure statistics for your profile'), '/doc/plugins/google_analytics', :target => '_blank') %> |
plugins/google_analytics/views/profile-editor-extras.rhtml
@@ -1,5 +0,0 @@ | @@ -1,5 +0,0 @@ | ||
1 | -<% extend ApplicationHelper %> | ||
2 | - | ||
3 | -<h2><%= c_('Statistics') %></h2> | ||
4 | -<%= labelled_form_field(_('Google Analytics Profile ID'), text_field(:profile_data, :google_analytics_profile_id, :value => profile_id)) %> | ||
5 | -<%= link_to(_('See how to configure statistics for your profile'), '/doc/plugins/google_analytics', :target => '_blank') %> |
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +<script> | ||
2 | + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | ||
3 | + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | ||
4 | + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | ||
5 | + })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); | ||
6 | + | ||
7 | + ga('create', '<%= escape_javascript locals[:profile_id] %>', 'auto'); | ||
8 | + ga('send', 'pageview'); | ||
9 | +</script> |
plugins/google_analytics/views/tracking-code.rhtml
@@ -1,10 +0,0 @@ | @@ -1,10 +0,0 @@ | ||
1 | -<script type="text/javascript"> | ||
2 | - var _gaq = _gaq || []; | ||
3 | - _gaq.push(['_setAccount', '<%= escape_javascript locals[:profile_id] %>']); | ||
4 | - _gaq.push(['_trackPageview']); | ||
5 | - (function() { | ||
6 | - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | ||
7 | - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | ||
8 | - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | ||
9 | - })(); | ||
10 | -</script> |
plugins/send_email/controllers/send_email_plugin_base_controller.rb
@@ -11,7 +11,8 @@ module SendEmailPluginBaseController | @@ -11,7 +11,8 @@ module SendEmailPluginBaseController | ||
11 | ) | 11 | ) |
12 | @mail.subject = params[:subject] unless params[:subject].blank? | 12 | @mail.subject = params[:subject] unless params[:subject].blank? |
13 | if @mail.valid? | 13 | if @mail.valid? |
14 | - SendEmailPlugin::Sender.send_message(request.referer, @context_url, @mail).deliver | 14 | + @referer = request.referer |
15 | + SendEmailPlugin::Sender.send_message(@referer, @context_url, @mail).deliver | ||
15 | if request.xhr? | 16 | if request.xhr? |
16 | render :text => _('Message sent') | 17 | render :text => _('Message sent') |
17 | else | 18 | else |
plugins/send_email/lib/send_email_plugin.rb
@@ -16,9 +16,9 @@ class SendEmailPlugin < Noosfero::Plugin | @@ -16,9 +16,9 @@ class SendEmailPlugin < Noosfero::Plugin | ||
16 | 16 | ||
17 | def parse_content(html, source) | 17 | def parse_content(html, source) |
18 | if context.profile | 18 | if context.profile |
19 | - html.gsub!(/\{sendemail\}/, "/profile/#{context.profile.identifier}/plugin/send_email/deliver") | 19 | + html.gsub!(/({|%7[Bb])sendemail(}|%7[Dd])/, "/profile/#{context.profile.identifier}/plugin/send_email/deliver") |
20 | else | 20 | else |
21 | - html.gsub!(/\{sendemail\}/, '/plugin/send_email/deliver') | 21 | + html.gsub!(/({|%7[Bb])sendemail(}|%7[Dd])/, '/plugin/send_email/deliver') |
22 | end | 22 | end |
23 | [html, source] | 23 | [html, source] |
24 | end | 24 | end |
plugins/send_email/lib/send_email_plugin/mail.rb
@@ -10,12 +10,11 @@ class SendEmailPlugin::Mail | @@ -10,12 +10,11 @@ class SendEmailPlugin::Mail | ||
10 | validate :recipients_format | 10 | validate :recipients_format |
11 | 11 | ||
12 | def initialize(attributes = {:subject => 'New mail'}) | 12 | def initialize(attributes = {:subject => 'New mail'}) |
13 | - @environment = attributes[:environment] | ||
14 | - @from = attributes[:from] | ||
15 | - @to = attributes[:to] | ||
16 | - @subject = attributes[:subject] | ||
17 | - @message = attributes[:message] | ||
18 | - @params = attributes[:params] | 13 | + if attributes |
14 | + attributes.each do |attr,value| | ||
15 | + self.send("#{attr}=", value) | ||
16 | + end | ||
17 | + end | ||
19 | end | 18 | end |
20 | 19 | ||
21 | def recipients_format | 20 | def recipients_format |
@@ -36,7 +35,7 @@ class SendEmailPlugin::Mail | @@ -36,7 +35,7 @@ class SendEmailPlugin::Mail | ||
36 | end | 35 | end |
37 | 36 | ||
38 | def params=(value = {}) | 37 | def params=(value = {}) |
39 | - [:action, :controller, :to, :message, :subject, :from].each{|k| value.delete(k)} | 38 | + [:profile, :action, :controller, :to, :message, :subject, :from, :commit].each{|k| value.delete(k)} |
40 | @params = value | 39 | @params = value |
41 | end | 40 | end |
42 | 41 |
plugins/send_email/lib/send_email_plugin/sender.rb
@@ -7,9 +7,9 @@ class SendEmailPlugin::Sender < Noosfero::Plugin::MailerBase | @@ -7,9 +7,9 @@ class SendEmailPlugin::Sender < Noosfero::Plugin::MailerBase | ||
7 | @params = mail.params | 7 | @params = mail.params |
8 | 8 | ||
9 | mail( | 9 | mail( |
10 | + content_type: 'text/plain', | ||
10 | to: mail.to, | 11 | to: mail.to, |
11 | from: mail.from, | 12 | from: mail.from, |
12 | - body: mail.params, | ||
13 | subject: "[#{mail.environment.name}] #{mail.subject}" | 13 | subject: "[#{mail.environment.name}] #{mail.subject}" |
14 | ) | 14 | ) |
15 | end | 15 | end |
plugins/send_email/test/functional/send_email_plugin_base_controller_test.rb
@@ -54,6 +54,13 @@ def run_common_tests | @@ -54,6 +54,13 @@ def run_common_tests | ||
54 | post :deliver, @extra_args.merge(:to => 'john@example.com', :message => 'Hi john', :subject => 'Hello john') | 54 | post :deliver, @extra_args.merge(:to => 'john@example.com', :message => 'Hi john', :subject => 'Hello john') |
55 | assert_equal '[Colivre.net] Hello john', ActionMailer::Base.deliveries.first.subject | 55 | assert_equal '[Colivre.net] Hello john', ActionMailer::Base.deliveries.first.subject |
56 | end | 56 | end |
57 | + | ||
58 | + should 'deliver mail with message from view' do | ||
59 | + Environment.any_instance.stubs(:send_email_plugin_allow_to).returns('john@example.com') | ||
60 | + post :deliver, @extra_args.merge(:to => 'john@example.com', :message => 'Hi john', :subject => 'Hello john') | ||
61 | + assert_match /Contact from/, ActionMailer::Base.deliveries.first.body.to_s | ||
62 | + end | ||
63 | + | ||
57 | end | 64 | end |
58 | 65 | ||
59 | class SendEmailPluginProfileControllerTest < ActionController::TestCase | 66 | class SendEmailPluginProfileControllerTest < ActionController::TestCase |
plugins/send_email/test/unit/send_email_plugin_sender_test.rb
@@ -15,12 +15,14 @@ class SendEmailPluginSenderTest < ActiveSupport::TestCase | @@ -15,12 +15,14 @@ class SendEmailPluginSenderTest < ActiveSupport::TestCase | ||
15 | end | 15 | end |
16 | 16 | ||
17 | should 'be able to deliver mail' do | 17 | should 'be able to deliver mail' do |
18 | + @mail.expects(:params).returns({}) | ||
18 | response = SendEmailPlugin::Sender.send_message("http://localhost/contact", 'http//profile', @mail) | 19 | response = SendEmailPlugin::Sender.send_message("http://localhost/contact", 'http//profile', @mail) |
19 | assert_equal 'noreply@localhost', response.from.join | 20 | assert_equal 'noreply@localhost', response.from.join |
20 | assert_equal "[Noosfero] #{@mail.subject}", response.subject | 21 | assert_equal "[Noosfero] #{@mail.subject}", response.subject |
21 | end | 22 | end |
22 | 23 | ||
23 | should 'deliver mail to john@example.com' do | 24 | should 'deliver mail to john@example.com' do |
25 | + @mail.expects(:params).returns({}) | ||
24 | response = SendEmailPlugin::Sender.send_message("http://localhost/contact", 'http//profile', @mail) | 26 | response = SendEmailPlugin::Sender.send_message("http://localhost/contact", 'http//profile', @mail) |
25 | assert_equal ['john@example.com'], response.to | 27 | assert_equal ['john@example.com'], response.to |
26 | end | 28 | end |
plugins/send_email/test/unit/send_email_plugin_test.rb
@@ -26,4 +26,12 @@ class SendEmailPluginTest < ActiveSupport::TestCase | @@ -26,4 +26,12 @@ class SendEmailPluginTest < ActiveSupport::TestCase | ||
26 | assert_match /profile\/#{@plugin.context.profile.identifier}\/plugin\/send_email\/deliver/, @plugin.parse_content("expand this macro {sendemail}", nil).first | 26 | assert_match /profile\/#{@plugin.context.profile.identifier}\/plugin\/send_email\/deliver/, @plugin.parse_content("expand this macro {sendemail}", nil).first |
27 | end | 27 | end |
28 | 28 | ||
29 | + should 'expand macro used on form on profile context' do | ||
30 | + profile = fast_create(Community) | ||
31 | + @plugin.context.stubs(:profile).returns(profile) | ||
32 | + article = RawHTMLArticle.create!(:name => 'Raw HTML', :body => "<form action='{sendemail}'></form>", :profile => profile) | ||
33 | + | ||
34 | + assert_match /profile\/#{profile.identifier}\/plugin\/send_email\/deliver/, @plugin.parse_content(article.to_html, nil).first | ||
35 | + end | ||
36 | + | ||
29 | end | 37 | end |
plugins/send_email/views/send_email_plugin/sender/message.html.erb
plugins/send_email/views/send_email_plugin/sender/send_message.html.erb
0 → 100644
plugins/send_email/views/send_email_plugin/success.html.erb
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | <table class='sendemail-plugin-message-sent'> | 3 | <table class='sendemail-plugin-message-sent'> |
4 | <tr><td class='label'><strong><%= c_('Subject') %>:</strong></td><td class='value'><em><%=h @mail.subject %></em></td></tr> | 4 | <tr><td class='label'><strong><%= c_('Subject') %>:</strong></td><td class='value'><em><%=h @mail.subject %></em></td></tr> |
5 | - <tr><td class='label'><strong><%= c_('Message') %>:</strong></td><td class='value'><pre><%=h render :file => 'send_email_plugin/sender/message' %></pre></td></tr> | 5 | + <tr><td class='label'><strong><%= c_('Message') %>:</strong></td><td class='value'><pre><%=h render :file => 'send_email_plugin/sender/send_message' %></pre></td></tr> |
6 | </table> | 6 | </table> |
7 | 7 | ||
8 | <p><%= button :back, c_('Back'), :back %></p> | 8 | <p><%= button :back, c_('Back'), :back %></p> |
public/javascripts/manage-fields.js
@@ -57,7 +57,7 @@ jQuery(document).ready(function(){ | @@ -57,7 +57,7 @@ jQuery(document).ready(function(){ | ||
57 | } | 57 | } |
58 | 58 | ||
59 | var checkbox = jQuery(checkboxes[i+3]).attr("id").split("_") | 59 | var checkbox = jQuery(checkboxes[i+3]).attr("id").split("_") |
60 | - jQuery("#" + checkbox.first() + "_" + checkbox.last()).attr("checked", allchecked) | 60 | + jQuery("#" + checkbox[0] + "_" + checkbox[checkbox.length-1]).attr("checked", allchecked) |
61 | } | 61 | } |
62 | } | 62 | } |
63 | 63 | ||
@@ -74,10 +74,10 @@ jQuery(document).ready(function(){ | @@ -74,10 +74,10 @@ jQuery(document).ready(function(){ | ||
74 | 74 | ||
75 | jQuery("input[type='checkbox']").click(function (){ | 75 | jQuery("input[type='checkbox']").click(function (){ |
76 | var checkbox = jQuery(this).attr("id").split("_") | 76 | var checkbox = jQuery(this).attr("id").split("_") |
77 | - verify_checked(checkbox.first()) | 77 | + verify_checked(checkbox[0]) |
78 | 78 | ||
79 | if(this.checked == false) { | 79 | if(this.checked == false) { |
80 | - jQuery("#" + checkbox.first() + "_" + checkbox.last()).attr("checked", false) | 80 | + jQuery("#" + checkbox[0] + "_" + checkbox[checkbox.length-1]).attr("checked", false) |
81 | } | 81 | } |
82 | }) | 82 | }) |
83 | }) | 83 | }) |