Commit ba6034cc078159eb73b10ced800ec6c4fab8a626

Authored by Daniela Feitosa
1 parent 313d6915

Fixes on AI1826

Added back add_member_in_community activity
Fixed creation of notifications for communities
app/models/community.rb
... ... @@ -80,7 +80,7 @@ class Community < Organization
80 80 end
81 81  
82 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 84 end
85 85  
86 86 end
... ...
app/views/profile/_create_article.rhtml
... ... @@ -9,7 +9,7 @@
9 9 <div class='profile-activity-lead'>
10 10 <div class='article-name'><%= link_to(activity.params['name'], activity.params['url']) %></div>
11 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 13 </div>
14 14 <%= content_tag(:p, link_to(_('See complete forum'), activity.get_url), :class => 'see-forum') if activity.target.is_a?(Forum) %>
15 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 &lt; Struct.new(:tracked_action_id)
15 15 return
16 16 end
17 17  
  18 + # Notify the user
18 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 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 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 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 28 end
28 29  
29 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 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 34 end
34 35  
35 36 end
... ...
test/unit/person_test.rb
... ... @@ -1218,6 +1218,6 @@ class PersonTest &lt; ActiveSupport::TestCase
1218 1218 TinyMceArticle.create!(:profile => person, :name => 'An article about free software')
1219 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 1222 end
1223 1223 end
... ...
test/unit/textile_article_test.rb
... ... @@ -121,7 +121,7 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
121 121 end
122 122  
123 123 should "the common trackable conditions return the correct value" do
124   - a = TextileArticle.new
  124 + a = TextileArticle.new(:profile => profile)
125 125 a.published = a.advertise = true
126 126 assert_equal true, a.published?
127 127 assert_equal true, a.notifiable?
... ...
test/unit/tiny_mce_article_test.rb
... ... @@ -209,7 +209,7 @@ end
209 209 end
210 210  
211 211 should "the common trackable conditions return the correct value" do
212   - a = TinyMceArticle.new
  212 + a = TinyMceArticle.new(:profile => profile)
213 213 a.published = a.advertise = true
214 214 assert_equal true, a.published?
215 215 assert_equal true, a.notifiable?
... ...
vendor/plugins/access_control/lib/role_assignment.rb
... ... @@ -7,7 +7,7 @@ class RoleAssignment &lt; ActiveRecord::Base
7 7  
8 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 12 def has_permission?(perm, res)
13 13 return false unless role.has_permission?(perm.to_s) && (resource || is_global)
... ...