Commit 530e66dde532ce3586b6f8bdce64703419918501
1 parent
f6dc326c
Exists in
staging
and in
42 other branches
html_safe: fix action tracker description mess
Showing
7 changed files
with
122 additions
and
76 deletions
Show diff stats
app/controllers/public/profile_controller.rb
| @@ -6,6 +6,7 @@ class ProfileController < PublicController | @@ -6,6 +6,7 @@ class ProfileController < PublicController | ||
| 6 | before_filter :login_required, :only => [:add, :join, :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] | 6 | before_filter :login_required, :only => [:add, :join, :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 | 7 | ||
| 8 | helper TagsHelper | 8 | helper TagsHelper |
| 9 | + helper ActionTrackerHelper | ||
| 9 | 10 | ||
| 10 | protect 'send_mail_to_members', :profile, :only => [:send_mail] | 11 | protect 'send_mail_to_members', :profile, :only => [:send_mail] |
| 11 | 12 |
| @@ -0,0 +1,70 @@ | @@ -0,0 +1,70 @@ | ||
| 1 | +module ActionTrackerHelper | ||
| 2 | + | ||
| 3 | + def create_article_description ta | ||
| 4 | + _('published an article: %{title}') % { title: link_to(truncate(ta.get_name), ta.get_url) } | ||
| 5 | + end | ||
| 6 | + | ||
| 7 | + def new_friendship_description ta | ||
| 8 | + n_('has made 1 new friend:<br />%{name}', 'has made %{num} new friends:<br />%{name}', ta.get_friend_name.size) % { | ||
| 9 | + num: ta.get_friend_name.size, | ||
| 10 | + name: ta.collect_group_with_index(:friend_name) do |n,i| | ||
| 11 | + link_to image_tag(ta.get_friend_profile_custom_icon[i] || default_or_themed_icon("/images/icons-app/person-icon.png")), | ||
| 12 | + ta.get_friend_url[i], title: n | ||
| 13 | + end.join | ||
| 14 | + } | ||
| 15 | + end | ||
| 16 | + | ||
| 17 | + def join_community_description ta | ||
| 18 | + n_('has joined 1 community:<br />%{name}', 'has joined %{num} communities:<br />%{name}', ta.get_resource_name.size) % { | ||
| 19 | + num: ta.get_resource_name.size, | ||
| 20 | + name: ta.collect_group_with_index(:resource_name) do |n,i| | ||
| 21 | + link_to image_tag(ta.get_resource_profile_custom_icon[i] || default_or_themed_icon("/images/icons-app/community-icon.png")), | ||
| 22 | + ta.get_resource_url[i], title: n | ||
| 23 | + end.join | ||
| 24 | + } | ||
| 25 | + end | ||
| 26 | + | ||
| 27 | + def add_member_in_community_description ta | ||
| 28 | + _('has joined the community.') | ||
| 29 | + end | ||
| 30 | + | ||
| 31 | + def upload_image_description ta | ||
| 32 | + total = ta.get_view_url.size | ||
| 33 | + (n_('uploaded 1 image', 'uploaded %d images', total) % total) + | ||
| 34 | + tag(:br) + | ||
| 35 | + ta.collect_group_with_index(:thumbnail_path) do |t,i| | ||
| 36 | + if total == 1 | ||
| 37 | + link_to image_tag(t), ta.get_view_url[i], class: 'upimg' | ||
| 38 | + else | ||
| 39 | + pos = total-i; | ||
| 40 | + morethen2 = pos>2 ? 'morethen2' : '' | ||
| 41 | + morethen5 = pos>5 ? 'morethen5' : '' | ||
| 42 | + t = t.gsub(/(.*)(display)(.*)/, '\\1thumb\\3') | ||
| 43 | + | ||
| 44 | + link_to ' '.html_safe, ta.get_view_url[i], | ||
| 45 | + style: "background-image:url(#{t})", | ||
| 46 | + class: "upimg pos#{pos} #{morethen2} #{morethen5}" | ||
| 47 | + end | ||
| 48 | + end.reverse.join + | ||
| 49 | + if total <= 5 then ''.html_safe else content_tag :span, '…'.html_safe, | ||
| 50 | + class: 'more', onclick: "this.parentNode.className+=' show-all'" end + | ||
| 51 | + tag(:br, style: 'clear: both') | ||
| 52 | + end | ||
| 53 | + | ||
| 54 | + def reply_scrap_description ta | ||
| 55 | + _('sent a message to %{receiver}: <br /> "%{message}"') % { | ||
| 56 | + receiver: link_to(ta.get_receiver_name, ta.get_receiver_url), | ||
| 57 | + message: auto_link_urls(ta.get_content) | ||
| 58 | + } | ||
| 59 | + end | ||
| 60 | + | ||
| 61 | + alias :leave_scrap_description :reply_scrap_description | ||
| 62 | + alias :reply_scrap_on_self_description :reply_scrap_description | ||
| 63 | + | ||
| 64 | + def leave_scrap_to_self_description ta | ||
| 65 | + _('wrote: <br /> "%{text}"') % { | ||
| 66 | + text: auto_link_urls(ta.get_content) | ||
| 67 | + } | ||
| 68 | + end | ||
| 69 | + | ||
| 70 | +end |
app/models/person_notifier.rb
| @@ -76,7 +76,8 @@ class PersonNotifier | @@ -76,7 +76,8 @@ class PersonNotifier | ||
| 76 | 76 | ||
| 77 | class Mailer < ActionMailer::Base | 77 | class Mailer < ActionMailer::Base |
| 78 | 78 | ||
| 79 | - add_template_helper(ApplicationHelper) | 79 | + helper ApplicationHelper |
| 80 | + helper ActionTrackerHelper | ||
| 80 | 81 | ||
| 81 | def session | 82 | def session |
| 82 | {:theme => nil} | 83 | {:theme => nil} |
app/views/person_notifier/mailer/_default_activity.html.erb
| @@ -4,7 +4,10 @@ | @@ -4,7 +4,10 @@ | ||
| 4 | </td> | 4 | </td> |
| 5 | <td> | 5 | <td> |
| 6 | <p> | 6 | <p> |
| 7 | - <span style="font-size: 14px;"><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></span> | 7 | + <span style="font-size: 14px;"> |
| 8 | + <%= link_to activity.user.name, activity.user.url %> | ||
| 9 | + <%= describe activity %> | ||
| 10 | + </span> | ||
| 8 | <span style="font-size: 10px; color: #929292; float: right;"><%= time_ago_in_words(activity.created_at) %></span> | 11 | <span style="font-size: 10px; color: #929292; float: right;"><%= time_ago_in_words(activity.created_at) %></span> |
| 9 | </p> | 12 | </p> |
| 10 | </td> | 13 | </td> |
config/initializers/action_tracker.rb
| @@ -2,64 +2,33 @@ require 'noosfero/i18n' | @@ -2,64 +2,33 @@ require 'noosfero/i18n' | ||
| 2 | 2 | ||
| 3 | # ActionTracker plugin stuff | 3 | # ActionTracker plugin stuff |
| 4 | 4 | ||
| 5 | -@reply_scrap_description = proc { _('sent a message to %{receiver}: <br /> "%{message}"') % { :receiver => "{{link_to(ta.get_receiver_name, ta.get_receiver_url)}}", :message => "{{auto_link_urls(ta.get_content)}}" } } | ||
| 6 | - | ||
| 7 | ActionTrackerConfig.verbs = { | 5 | ActionTrackerConfig.verbs = { |
| 8 | 6 | ||
| 9 | - :create_article => { | ||
| 10 | - :description => proc { _('published an article: %{title}') % { :title => '{{link_to(truncate(ta.get_name), ta.get_url)}}' } } | 7 | + create_article: { |
| 11 | }, | 8 | }, |
| 12 | 9 | ||
| 13 | - :new_friendship => { | ||
| 14 | - :description => proc { n_('has made 1 new friend:<br />%{name}', 'has made %{num} new friends:<br />%{name}', get_friend_name.size) % { :num => get_friend_name.size, :name => '{{ta.collect_group_with_index(:friend_name){ |n,i| link_to(image_tag(ta.get_friend_profile_custom_icon[i] || default_or_themed_icon("/images/icons-app/person-icon.png")), ta.get_friend_url[i], :title => n)}.join}}' } }, | ||
| 15 | - :type => :groupable | 10 | + new_friendship: { |
| 11 | + type: :groupable | ||
| 16 | }, | 12 | }, |
| 17 | 13 | ||
| 18 | - :join_community => { | ||
| 19 | - :description => proc { n_('has joined 1 community:<br />%{name}', 'has joined %{num} communities:<br />%{name}', get_resource_name.size) % { :num => get_resource_name.size, :name => '{{ta.collect_group_with_index(:resource_name){ |n,i| link_to(image_tag(ta.get_resource_profile_custom_icon[i] || default_or_themed_icon("/images/icons-app/community-icon.png")), ta.get_resource_url[i], :title => n)}.join}}' } }, | ||
| 20 | - :type => :groupable | 14 | + join_community: { |
| 15 | + type: :groupable | ||
| 21 | }, | 16 | }, |
| 22 | 17 | ||
| 23 | - :add_member_in_community => { | ||
| 24 | - :description => proc { _('has joined the community.') }, | 18 | + add_member_in_community: { |
| 25 | }, | 19 | }, |
| 26 | 20 | ||
| 27 | - :upload_image => { | ||
| 28 | - :description => proc do | ||
| 29 | - total = get_view_url.size | ||
| 30 | - n_('uploaded 1 image', 'uploaded %d images', total) % total + | ||
| 31 | - '<br />{{'+ | ||
| 32 | - 'ta.collect_group_with_index(:thumbnail_path) { |t,i|' + | ||
| 33 | - " if ( #{total} == 1 );" + | ||
| 34 | - ' link_to( image_tag(t), ta.get_view_url[i], :class => \'upimg\' );' + | ||
| 35 | - ' else;' + | ||
| 36 | - " pos = #{total}-i;" + | ||
| 37 | - ' morethen2 = pos>2 ? \'morethen2\' : \'\';' + | ||
| 38 | - ' morethen5 = pos>5 ? \'morethen5\' : \'\';' + | ||
| 39 | - ' t = t.gsub(/(.*)(display)(.*)/, \'\\1thumb\\3\');' + | ||
| 40 | - ' link_to( \' \', ta.get_view_url[i],' + | ||
| 41 | - ' :style => "background-image:url(#{t})",' + | ||
| 42 | - ' :class => "upimg pos#{pos} #{morethen2} #{morethen5}" );' + | ||
| 43 | - ' end' + | ||
| 44 | - '}.reverse.join}}' + | ||
| 45 | - ( total > 5 ? | ||
| 46 | - '<span class="more" onclick="this.parentNode.className+=\' show-all\'">' + | ||
| 47 | - '…</span>' : '' ) + | ||
| 48 | - '<br style="clear: both;" />' | ||
| 49 | - end, | ||
| 50 | - :type => :groupable | 21 | + upload_image: { |
| 22 | + type: :groupable | ||
| 51 | }, | 23 | }, |
| 52 | 24 | ||
| 53 | - :leave_scrap => { | ||
| 54 | - :description => @reply_scrap_description | 25 | + leave_scrap: { |
| 55 | }, | 26 | }, |
| 56 | 27 | ||
| 57 | - :leave_scrap_to_self => { | ||
| 58 | - :description => proc { _('wrote: <br /> "%{text}"') % { :text => "{{auto_link_urls(ta.get_content)}}" } } | 28 | + leave_scrap_to_self: { |
| 59 | }, | 29 | }, |
| 60 | 30 | ||
| 61 | - :reply_scrap_on_self => { | ||
| 62 | - :description => @reply_scrap_description | 31 | + reply_scrap_on_self: { |
| 63 | }, | 32 | }, |
| 64 | } | 33 | } |
| 65 | 34 |
test/unit/person_notifier_test.rb
| @@ -162,23 +162,31 @@ class PersonNotifierTest < ActiveSupport::TestCase | @@ -162,23 +162,31 @@ class PersonNotifierTest < ActiveSupport::TestCase | ||
| 162 | 162 | ||
| 163 | ActionTrackerConfig.verb_names.each do |verb| | 163 | ActionTrackerConfig.verb_names.each do |verb| |
| 164 | should "render notification for verb #{verb}" do | 164 | should "render notification for verb #{verb}" do |
| 165 | - action = mock() | ||
| 166 | - action.stubs(:verb).returns(verb) | ||
| 167 | - action.stubs(:user).returns(@member) | ||
| 168 | - action.stubs(:created_at).returns(DateTime.now) | ||
| 169 | - action.stubs(:target).returns(fast_create(Forum)) | ||
| 170 | - action.stubs(:comments_count).returns(0) | ||
| 171 | - action.stubs(:comments).returns([]) | ||
| 172 | - action.stubs(:params).returns({'name' => 'home', 'url' => '/', 'lead' => ''}) | ||
| 173 | - action.stubs(:get_url).returns('') | ||
| 174 | - | ||
| 175 | - notifications = [] | ||
| 176 | - notifications.stubs(:find).returns([action]) | ||
| 177 | - Person.any_instance.stubs(:tracked_notifications).returns(notifications) | ||
| 178 | - | ||
| 179 | - notify | ||
| 180 | - sent = ActionMailer::Base.deliveries.last | ||
| 181 | - assert_no_match /cannot render notification for #{verb}/, sent.body.to_s | 165 | + @member.tracked_notifications = [] |
| 166 | + | ||
| 167 | + a = @member.tracked_notifications.build | ||
| 168 | + a.verb = verb | ||
| 169 | + a.user = @member | ||
| 170 | + a.created_at = @member.notifier.notify_from + 1.day | ||
| 171 | + a.target = fast_create(Forum) | ||
| 172 | + a.comments_count = 0 | ||
| 173 | + a.params = { | ||
| 174 | + 'name' => 'home', 'url' => '/', 'lead' => '', | ||
| 175 | + 'receiver_url' => '/', 'content' => 'nothing', | ||
| 176 | + 'friend_url' => '/', 'friend_profile_custom_icon' => [], 'friend_name' => ['joe'], | ||
| 177 | + 'resource_name' => ['resource'], 'resource_profile_custom_icon' => [], 'resource_url' => ['/'], | ||
| 178 | + 'view_url'=> ['/'], 'thumbnail_path' => ['1'], | ||
| 179 | + } | ||
| 180 | + a.get_url = '' | ||
| 181 | + a.save! | ||
| 182 | + n = @member.action_tracker_notifications.build | ||
| 183 | + n.action_tracker = a | ||
| 184 | + n.profile = @member | ||
| 185 | + n.save! | ||
| 186 | + | ||
| 187 | + assert_nothing_raised do | ||
| 188 | + notify | ||
| 189 | + end | ||
| 182 | end | 190 | end |
| 183 | end | 191 | end |
| 184 | 192 |
vendor/plugins/action_tracker/lib/action_tracker.rb
| @@ -8,21 +8,21 @@ module ActionTracker | @@ -8,21 +8,21 @@ module ActionTracker | ||
| 8 | base.send :user_stamp, ActionTracker::Record | 8 | base.send :user_stamp, ActionTracker::Record |
| 9 | base.send :extend, ClassMethods | 9 | base.send :extend, ClassMethods |
| 10 | end | 10 | end |
| 11 | - | 11 | + |
| 12 | module ClassMethods | 12 | module ClassMethods |
| 13 | 13 | ||
| 14 | def track_actions_after(verb, options = {}, &block) | 14 | def track_actions_after(verb, options = {}, &block) |
| 15 | track_actions_by_time(verb, :after, options, &block) | 15 | track_actions_by_time(verb, :after, options, &block) |
| 16 | end | 16 | end |
| 17 | - | 17 | + |
| 18 | def track_actions_before(verb, options = {}, &block) | 18 | def track_actions_before(verb, options = {}, &block) |
| 19 | track_actions_by_time(verb, :before, options, &block) | 19 | track_actions_by_time(verb, :before, options, &block) |
| 20 | end | 20 | end |
| 21 | - | 21 | + |
| 22 | def track_actions(verb, options = {}, &block) | 22 | def track_actions(verb, options = {}, &block) |
| 23 | track_actions_by_time(verb, ActionTrackerConfig.default_filter_time, options, &block) | 23 | track_actions_by_time(verb, ActionTrackerConfig.default_filter_time, options, &block) |
| 24 | end | 24 | end |
| 25 | - | 25 | + |
| 26 | def track_actions_by_time(verb, time, options = {}, &block) | 26 | def track_actions_by_time(verb, time, options = {}, &block) |
| 27 | keep_params = options.delete(:keep_params) || options.delete('keep_params') || :all | 27 | keep_params = options.delete(:keep_params) || options.delete('keep_params') || :all |
| 28 | send("#{time}_filter", options) do |x| | 28 | send("#{time}_filter", options) do |x| |
| @@ -32,7 +32,7 @@ module ActionTracker | @@ -32,7 +32,7 @@ module ActionTracker | ||
| 32 | send :include, InstanceMethods | 32 | send :include, InstanceMethods |
| 33 | end | 33 | end |
| 34 | end | 34 | end |
| 35 | - | 35 | + |
| 36 | module InstanceMethods | 36 | module InstanceMethods |
| 37 | def save_action_for_verb(verb, keep_params = :all) | 37 | def save_action_for_verb(verb, keep_params = :all) |
| 38 | if keep_params.is_a? Array | 38 | if keep_params.is_a? Array |
| @@ -62,7 +62,7 @@ module ActionTracker | @@ -62,7 +62,7 @@ module ActionTracker | ||
| 62 | def self.included(base) | 62 | def self.included(base) |
| 63 | base.send :extend, ClassMethods | 63 | base.send :extend, ClassMethods |
| 64 | end | 64 | end |
| 65 | - | 65 | + |
| 66 | module ClassMethods | 66 | module ClassMethods |
| 67 | def track_actions(verb, callback, options = {}, &block) | 67 | def track_actions(verb, callback, options = {}, &block) |
| 68 | keep_params = options.delete(:keep_params) || options.delete('keep_params') || :all | 68 | keep_params = options.delete(:keep_params) || options.delete('keep_params') || :all |
| @@ -78,11 +78,11 @@ module ActionTracker | @@ -78,11 +78,11 @@ module ActionTracker | ||
| 78 | send :include, InstanceMethods | 78 | send :include, InstanceMethods |
| 79 | end | 79 | end |
| 80 | end | 80 | end |
| 81 | - | 81 | + |
| 82 | module InstanceMethods | 82 | module InstanceMethods |
| 83 | def time_spent_doing(verb, conditions = {}) | 83 | def time_spent_doing(verb, conditions = {}) |
| 84 | time = 0 | 84 | time = 0 |
| 85 | - tracked_actions.all(:conditions => conditions.merge({ :verb => verb.to_s })).each do |t| | 85 | + tracked_actions.all(:conditions => conditions.merge({ :verb => verb.to_s })).each do |t| |
| 86 | time += t.updated_at - t.created_at | 86 | time += t.updated_at - t.created_at |
| 87 | end | 87 | end |
| 88 | time.to_f | 88 | time.to_f |
| @@ -124,13 +124,7 @@ module ActionTracker | @@ -124,13 +124,7 @@ module ActionTracker | ||
| 124 | 124 | ||
| 125 | module ViewHelper | 125 | module ViewHelper |
| 126 | def describe(ta) | 126 | def describe(ta) |
| 127 | - "".tap do |result| | ||
| 128 | - if ta.is_a?(ActionTracker::Record) | ||
| 129 | - result << ta.description.gsub(/\{\{(.*?)\}\}/) { eval $1 } | ||
| 130 | - else | ||
| 131 | - result << "" | ||
| 132 | - end | ||
| 133 | - end | 127 | + send "#{ta.verb}_description", ta if ta.is_a? ActionTracker::Record |
| 134 | end | 128 | end |
| 135 | end | 129 | end |
| 136 | 130 |