Commit 2ce4aa070dcad44cc73c1c435ac966629ee880c0
Committed by
Braulio Bhavamitra
1 parent
01e4652f
Exists in
master
and in
9 other branches
products-activities: Changes to insert notifications to network of products acti…
…ons (create, update and destroy)
Showing
11 changed files
with
109 additions
and
2 deletions
Show diff stats
app/helpers/action_tracker_helper.rb
... | ... | @@ -67,4 +67,22 @@ module ActionTrackerHelper |
67 | 67 | } |
68 | 68 | end |
69 | 69 | |
70 | + def create_product_description | |
71 | + _('created the product %{title}') % { | |
72 | + title: link_to(truncate(ta.get_name), ta.get_url), | |
73 | + } | |
74 | + end | |
75 | + | |
76 | + def update_product_description | |
77 | + _('updated the product %{title}') % { | |
78 | + title: link_to(truncate(ta.get_name), ta.get_url), | |
79 | + } | |
80 | + end | |
81 | + | |
82 | + def remove_product_description | |
83 | + _('removed the product %{title}') % { | |
84 | + title: truncate(ta.get_name), | |
85 | + } | |
86 | + end | |
87 | + | |
70 | 88 | end | ... | ... |
app/models/enterprise.rb
... | ... | @@ -15,7 +15,10 @@ class Enterprise < Organization |
15 | 15 | |
16 | 16 | N_('Enterprise') |
17 | 17 | |
18 | - has_many :products, :foreign_key => :profile_id, :dependent => :destroy, :order => 'name ASC' | |
18 | + acts_as_trackable after_add: proc{ |p, t| notify_activity t } | |
19 | + | |
20 | + has_many :products, :foreign_key => :profile_id, :dependent => :destroy | |
21 | + has_many :product_categories, :through => :products | |
19 | 22 | has_many :inputs, :through => :products |
20 | 23 | has_many :production_costs, :as => :owner |
21 | 24 | |
... | ... | @@ -202,4 +205,9 @@ class Enterprise < Organization |
202 | 205 | '' |
203 | 206 | end |
204 | 207 | |
208 | + def followed_by? person | |
209 | + super or self.fans.where(id: person.id).count > 0 | |
210 | + end | |
211 | + | |
212 | + | |
205 | 213 | end | ... | ... |
app/models/organization.rb
... | ... | @@ -35,6 +35,10 @@ class Organization < Profile |
35 | 35 | |
36 | 36 | validate :presence_of_required_fieds, :unless => :is_template |
37 | 37 | |
38 | + def self.notify_activity tracked_action | |
39 | + Delayed::Job.enqueue NotifyActivityToProfilesJob.new(tracked_action.id) | |
40 | + end | |
41 | + | |
38 | 42 | def presence_of_required_fieds |
39 | 43 | self.required_fields.each do |field| |
40 | 44 | if self.send(field).blank? | ... | ... |
app/models/product.rb
... | ... | @@ -38,6 +38,10 @@ class Product < ActiveRecord::Base |
38 | 38 | |
39 | 39 | acts_as_having_settings :field => :data |
40 | 40 | |
41 | + track_actions :create_product, :after_create, :keep_params => [:name, :url ], :if => Proc.new { |a| a.is_trackable? }, :custom_user => :action_tracker_user | |
42 | + track_actions :update_product, :before_update, :keep_params => [:name, :url], :if => Proc.new { |a| a.is_trackable? }, :custom_user => :action_tracker_user | |
43 | + track_actions :remove_product, :before_destroy, :keep_params => [:name], :if => Proc.new { |a| a.is_trackable? }, :custom_user => :action_tracker_user | |
44 | + | |
41 | 45 | validates_uniqueness_of :name, :scope => :profile_id, :allow_nil => true, :if => :validate_uniqueness_of_column_name? |
42 | 46 | |
43 | 47 | validates_presence_of :product_category_id |
... | ... | @@ -258,4 +262,13 @@ class Product < ActiveRecord::Base |
258 | 262 | true |
259 | 263 | end |
260 | 264 | |
265 | + def is_trackable? | |
266 | + # shopping_cart create products without profile | |
267 | + self.profile.present? | |
268 | + end | |
269 | + | |
270 | + def action_tracker_user | |
271 | + self.profile | |
272 | + end | |
273 | + | |
261 | 274 | end | ... | ... |
... | ... | @@ -0,0 +1,13 @@ |
1 | +<div class='profile-activity-image'> | |
2 | + <%= link_to image_tag(activity.target.default_image :minor), activity.target.url, class: 'product-pic' if activity.target.present? %> | |
3 | +</div> | |
4 | +<div class='profile-activity-description'> | |
5 | + <p class='profile-activity-text'><%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %></p> | |
6 | + <p class='profile-activity-time'><%= time_ago_as_sentence activity.created_at %></p> | |
7 | + | |
8 | + <div class='profile-wall-actions'> | |
9 | + <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> | |
10 | + </div> | |
11 | +</div> | |
12 | + | |
13 | +<div style="clear: both"></div> | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +<div class='profile-activity-image'> | |
2 | +</div> | |
3 | +<div class='profile-activity-description'> | |
4 | + <p class='profile-activity-text'><%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %></p> | |
5 | + <p class='profile-activity-time'><%= time_ago_as_sentence activity.created_at %></p> | |
6 | + | |
7 | + <div class='profile-wall-actions'> | |
8 | + <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> | |
9 | + </div> | |
10 | +</div> | |
11 | + | |
12 | +<div style="clear: both"></div> | ... | ... |
... | ... | @@ -0,0 +1,13 @@ |
1 | +<div class='profile-activity-image'> | |
2 | + <%= link_to image_tag(activity.target.default_image :minor), activity.target.url, class: 'product-pic' if activity.target.present? %> | |
3 | +</div> | |
4 | +<div class='profile-activity-description'> | |
5 | + <p class='profile-activity-text'><%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %></p> | |
6 | + <p class='profile-activity-time'><%= time_ago_as_sentence activity.created_at %></p> | |
7 | + | |
8 | + <div class='profile-wall-actions'> | |
9 | + <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> | |
10 | + </div> | |
11 | +</div> | |
12 | + | |
13 | +<div style="clear: both"></div> | ... | ... |
config/initializers/action_tracker.rb
lib/notify_activity_to_profiles_job.rb
... | ... | @@ -22,6 +22,12 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) |
22 | 22 | # Notify all friends |
23 | 23 | 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})") |
24 | 24 | |
25 | + if tracked_action.user.is_a? Organization | |
26 | + ActionTrackerNotification.connection.execute "insert into action_tracker_notifications(profile_id, action_tracker_id) " + | |
27 | + "select distinct accessor_id, #{tracked_action.id} from role_assignments where resource_id = #{tracked_action.user.id} and resource_type='Profile' " + | |
28 | + if tracked_action.user.is_a? Enterprise then "union select distinct person_id, #{tracked_action.id} from favorite_enteprises_people where enterprise_id = #{tracked_action.user.id}" else "" end | |
29 | + end | |
30 | + | |
25 | 31 | if target.is_a?(Community) |
26 | 32 | ActionTrackerNotification.create(:profile_id => target.id, :action_tracker_id => tracked_action.id) unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb) |
27 | 33 | ... | ... |
plugins/bsc/lib/bsc_plugin/ext/product.rb
... | ... | @@ -12,4 +12,14 @@ class Product |
12 | 12 | def display_supplier_on_search? |
13 | 13 | false |
14 | 14 | end |
15 | + | |
16 | + def action_tracker_user | |
17 | + return self.enterprise if self.enterprise.validated | |
18 | + | |
19 | + if self.enterprise.bsc | |
20 | + self.enterprise.bsc | |
21 | + else | |
22 | + self.enterprise | |
23 | + end | |
24 | + end | |
15 | 25 | end | ... | ... |
test/unit/product_test.rb
... | ... | @@ -117,7 +117,7 @@ class ProductTest < ActiveSupport::TestCase |
117 | 117 | enterprise.expects(:public_profile_url).returns({}) |
118 | 118 | |
119 | 119 | product.expects(:id).returns(999) |
120 | - product.expects(:enterprise).returns(enterprise) | |
120 | + product.expects(:profile).returns(enterprise) | |
121 | 121 | assert_equal({:controller => 'manage_products', :action => 'show', :id => 999}, product.url) |
122 | 122 | end |
123 | 123 | ... | ... |