Commit ba6034cc078159eb73b10ced800ec6c4fab8a626
1 parent
313d6915
Exists in
master
and in
22 other branches
Fixes on AI1826
Added back add_member_in_community activity Fixed creation of notifications for communities
Showing
7 changed files
with
12 additions
and
11 deletions
Show diff stats
app/models/community.rb
@@ -80,7 +80,7 @@ class Community < Organization | @@ -80,7 +80,7 @@ class Community < Organization | ||
80 | end | 80 | end |
81 | 81 | ||
82 | def activities | 82 | def activities |
83 | - Scrap.find_by_sql("SELECT id, updated_at, 'Scrap' AS klass FROM scraps WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, 'ActionTracker::Record' AS klass FROM action_tracker WHERE action_tracker.target_id = #{self.id} UNION SELECT action_tracker.id, action_tracker.updated_at, 'ActionTracker::Record' AS klass FROM action_tracker INNER JOIN articles ON action_tracker.target_id = articles.id WHERE articles.profile_id = #{self.id} AND action_tracker.target_type = 'Article' ORDER BY action_tracker.updated_at DESC") | 83 | + Scrap.find_by_sql("SELECT id, updated_at, '#{Scrap.to_s}' AS klass FROM #{Scrap.table_name} WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} WHERE action_tracker.target_id = #{self.id} UNION SELECT at.id, at.updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} at INNER JOIN articles a ON at.target_id = a.id WHERE a.profile_id = #{self.id} AND at.target_type = 'Article' ORDER BY updated_at DESC") |
84 | end | 84 | end |
85 | 85 | ||
86 | end | 86 | end |
app/views/profile/_create_article.rhtml
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | <div class='profile-activity-lead'> | 9 | <div class='profile-activity-lead'> |
10 | <div class='article-name'><%= link_to(activity.params['name'], activity.params['url']) %></div> | 10 | <div class='article-name'><%= link_to(activity.params['name'], activity.params['url']) %></div> |
11 | <span title='<%= activity.target.class.short_description %>' class='profile-activity-icon icon-new icon-new<%= activity.target.class.icon_name %>'></span> | 11 | <span title='<%= activity.target.class.short_description %>' class='profile-activity-icon icon-new icon-new<%= activity.target.class.icon_name %>'></span> |
12 | - <%= image_tag(activity.params['first_image']) unless activity.params['first_image'].blank? %><%= strip_tags(truncate(activity.params['lead'], 1000, '...')).gsub(/(\xA0|\xC2|\s)+/, ' ').gsub(/^\s+/, '') %> <small><%= link_to(_('See more'), activity.params['url']) unless activity.get_lead.blank? %></small> | 12 | + <%= image_tag(activity.params['first_image']) unless activity.params['first_image'].blank? %><%= strip_tags(truncate(activity.params['lead'], :length => 1000, :ommision => '...')).gsub(/(\xA0|\xC2|\s)+/, ' ').gsub(/^\s+/, '') %> <small><%= link_to(_('See more'), activity.params['url']) unless activity.get_lead.blank? %></small> |
13 | </div> | 13 | </div> |
14 | <%= content_tag(:p, link_to(_('See complete forum'), activity.get_url), :class => 'see-forum') if activity.target.is_a?(Forum) %> | 14 | <%= content_tag(:p, link_to(_('See complete forum'), activity.get_url), :class => 'see-forum') if activity.target.is_a?(Forum) %> |
15 | <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) %></p> | 15 | <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) %></p> |
lib/notify_activity_to_profiles_job.rb
@@ -15,21 +15,22 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) | @@ -15,21 +15,22 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) | ||
15 | return | 15 | return |
16 | end | 16 | end |
17 | 17 | ||
18 | + # Notify the user | ||
18 | ActionTrackerNotification.create(:profile_id => tracked_action.user.id, :action_tracker_id => tracked_action.id) | 19 | ActionTrackerNotification.create(:profile_id => tracked_action.user.id, :action_tracker_id => tracked_action.id) |
19 | 20 | ||
20 | - #Notify all friends | 21 | + # Notify all friends |
21 | ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select f.friend_id, #{tracked_action.id} from friendships as f where person_id=#{tracked_action.user.id} and f.friend_id not in (select atn.profile_id from action_tracker_notifications as atn where atn.action_tracker_id = #{tracked_action.id})") | 22 | ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select f.friend_id, #{tracked_action.id} from friendships as f where person_id=#{tracked_action.user.id} and f.friend_id not in (select atn.profile_id from action_tracker_notifications as atn where atn.action_tracker_id = #{tracked_action.id})") |
22 | 23 | ||
23 | if target.is_a?(Community) | 24 | if target.is_a?(Community) |
24 | - ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select distinct profiles.id, #{tracked_action.id} from role_assignments, profiles where profiles.type = 'Person' and profiles.id = role_assignments.accessor_id and profiles.id != #{tracked_action.user.id} and role_assignments.resource_type = 'Profile' and role_assignments.resource_id = #{target.id}") | ||
25 | - | ||
26 | ActionTrackerNotification.create(:profile_id => target.id, :action_tracker_id => tracked_action.id) unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb) | 25 | ActionTrackerNotification.create(:profile_id => target.id, :action_tracker_id => tracked_action.id) unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb) |
26 | + | ||
27 | + ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select distinct profiles.id, #{tracked_action.id} from role_assignments, profiles where profiles.type = 'Person' and profiles.id = role_assignments.accessor_id and profiles.id != #{tracked_action.user.id} and profiles.id not in (select atn.profile_id from action_tracker_notifications as atn where atn.action_tracker_id = #{tracked_action.id}) and role_assignments.resource_type = 'Profile' and role_assignments.resource_id = #{target.id}") | ||
27 | end | 28 | end |
28 | 29 | ||
29 | if target.is_a?(Article) && target.profile.is_a?(Community) | 30 | if target.is_a?(Article) && target.profile.is_a?(Community) |
30 | - ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select distinct profiles.id, #{tracked_action.id} from role_assignments, profiles where profiles.type = 'Person' and profiles.id = role_assignments.accessor_id and profiles.id != #{tracked_action.user.id} and role_assignments.resource_type = 'Profile' and role_assignments.resource_id = #{target.profile.id}") | ||
31 | - | ||
32 | ActionTrackerNotification.create(:profile_id => target.profile.id, :action_tracker_id => tracked_action.id) unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb) | 31 | ActionTrackerNotification.create(:profile_id => target.profile.id, :action_tracker_id => tracked_action.id) unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb) |
32 | + | ||
33 | + ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select distinct profiles.id, #{tracked_action.id} from role_assignments, profiles where profiles.type = 'Person' and profiles.id = role_assignments.accessor_id and profiles.id != #{tracked_action.user.id} and profiles.id not in (select atn.profile_id from action_tracker_notifications as atn where atn.action_tracker_id = #{tracked_action.id}) and role_assignments.resource_type = 'Profile' and role_assignments.resource_id = #{target.profile.id}") | ||
33 | end | 34 | end |
34 | 35 | ||
35 | end | 36 | end |
test/unit/person_test.rb
@@ -1218,6 +1218,6 @@ class PersonTest < ActiveSupport::TestCase | @@ -1218,6 +1218,6 @@ class PersonTest < ActiveSupport::TestCase | ||
1218 | TinyMceArticle.create!(:profile => person, :name => 'An article about free software') | 1218 | TinyMceArticle.create!(:profile => person, :name => 'An article about free software') |
1219 | person_activity = ActionTracker::Record.last | 1219 | person_activity = ActionTracker::Record.last |
1220 | 1220 | ||
1221 | - assert_equal [person_scrap,person_activity], person.activities.map { |a| a.klass.constantize.find(a.id) } | 1221 | + assert_equivalent [person_scrap,person_activity], person.activities.map { |a| a.klass.constantize.find(a.id) } |
1222 | end | 1222 | end |
1223 | end | 1223 | end |
test/unit/textile_article_test.rb
@@ -121,7 +121,7 @@ class TextileArticleTest < ActiveSupport::TestCase | @@ -121,7 +121,7 @@ class TextileArticleTest < ActiveSupport::TestCase | ||
121 | end | 121 | end |
122 | 122 | ||
123 | should "the common trackable conditions return the correct value" do | 123 | should "the common trackable conditions return the correct value" do |
124 | - a = TextileArticle.new | 124 | + a = TextileArticle.new(:profile => profile) |
125 | a.published = a.advertise = true | 125 | a.published = a.advertise = true |
126 | assert_equal true, a.published? | 126 | assert_equal true, a.published? |
127 | assert_equal true, a.notifiable? | 127 | assert_equal true, a.notifiable? |
test/unit/tiny_mce_article_test.rb
@@ -209,7 +209,7 @@ end | @@ -209,7 +209,7 @@ end | ||
209 | end | 209 | end |
210 | 210 | ||
211 | should "the common trackable conditions return the correct value" do | 211 | should "the common trackable conditions return the correct value" do |
212 | - a = TinyMceArticle.new | 212 | + a = TinyMceArticle.new(:profile => profile) |
213 | a.published = a.advertise = true | 213 | a.published = a.advertise = true |
214 | assert_equal true, a.published? | 214 | assert_equal true, a.published? |
215 | assert_equal true, a.notifiable? | 215 | assert_equal true, a.notifiable? |
vendor/plugins/access_control/lib/role_assignment.rb
@@ -7,7 +7,7 @@ class RoleAssignment < ActiveRecord::Base | @@ -7,7 +7,7 @@ class RoleAssignment < ActiveRecord::Base | ||
7 | 7 | ||
8 | track_actions :join_community, :after_create, :keep_params => ["resource.name", "resource.url", "resource.profile_custom_icon"], :if => Proc.new { |x| x.resource.is_a?(Community) && x.accessor.role_assignments.count(:conditions => { :resource_id => x.resource.id, :resource_type => 'Profile' }) == 1 }, :custom_user => :accessor, :custom_target => :resource | 8 | track_actions :join_community, :after_create, :keep_params => ["resource.name", "resource.url", "resource.profile_custom_icon"], :if => Proc.new { |x| x.resource.is_a?(Community) && x.accessor.role_assignments.count(:conditions => { :resource_id => x.resource.id, :resource_type => 'Profile' }) == 1 }, :custom_user => :accessor, :custom_target => :resource |
9 | 9 | ||
10 | -# track_actions :add_member_in_community, :after_create, :if => Proc.new { |x| x.resource.is_a?(Community) && x.accessor.role_assignments.count(:conditions => { :resource_id => x.resource.id, :resource_type => 'Profile' }) == 1 }, :custom_user => :accessor, :custom_target => :resource | 10 | + track_actions :add_member_in_community, :after_create, :if => Proc.new { |x| x.resource.is_a?(Community) && x.accessor.role_assignments.count(:conditions => { :resource_id => x.resource.id, :resource_type => 'Profile' }) == 1 }, :custom_user => :accessor, :custom_target => :resource |
11 | 11 | ||
12 | def has_permission?(perm, res) | 12 | def has_permission?(perm, res) |
13 | return false unless role.has_permission?(perm.to_s) && (resource || is_global) | 13 | return false unless role.has_permission?(perm.to_s) && (resource || is_global) |