Modified: branches/event_logging/app/controllers/application.rb (1866 => 1867)
--- branches/event_logging/app/controllers/application.rb 2008-10-16 14:59:00 UTC (rev 1866)
+++ branches/event_logging/app/controllers/application.rb 2008-10-16 16:59:17 UTC (rev 1867)
@@ -334,6 +334,7 @@
# First delete old creditations:
creditable.creditors.each do |c|
+ c.userid_initiating_action = current_user.id
c.destroy
end
@@ -341,21 +342,21 @@
# Current user
if (params[:credits_me].downcase == 'true')
- c = Creditation.new(:creditor_type => 'User', :creditor_id => current_user.id, :creditable_type => creditable.class.to_s, :creditable_id => creditable.id)
+ c = Creditation.new(:creditor_type => 'User', :creditor_id => current_user.id, :creditable_type => creditable.class.to_s, :creditable_id => creditable.id, :userid_initiating_action => current_user.id)
c.save
end
# Friends + other users
user_ids = parse_comma_seperated_string(params[:credits_users])
user_ids.each do |id|
- c = Creditation.new(:creditor_type => 'User', :creditor_id => id, :creditable_type => creditable.class.to_s, :creditable_id => creditable.id)
+ c = Creditation.new(:creditor_type => 'User', :creditor_id => id, :creditable_type => creditable.class.to_s, :creditable_id => creditable.id, :userid_initiating_action => current_user.id)
c.save
end
# Networks (aka Groups)
network_ids = parse_comma_seperated_string(params[:credits_groups])
network_ids.each do |id|
- c = Creditation.new(:creditor_type => 'Network', :creditor_id => id, :creditable_type => creditable.class.to_s, :creditable_id => creditable.id)
+ c = Creditation.new(:creditor_type => 'Network', :creditor_id => id, :creditable_type => creditable.class.to_s, :creditable_id => creditable.id, :userid_initiating_action => current_user.id)
c.save
end
@@ -365,6 +366,7 @@
# First delete old attributions:
attributable.attributors.each do |a|
+ a.userid_initiating_action = current_user.id
a.destroy
end
@@ -374,7 +376,7 @@
attributor_workflow_ids = parse_comma_seperated_string(params[:attributions_workflows])
attributor_type = 'Workflow'
attributor_workflow_ids.each do |id|
- a = Attribution.new(:attributor_type => attributor_type, :attributor_id => id, :attributable_type => attributable.class.to_s, :attributable_id => attributable.id)
+ a = Attribution.new(:attributor_type => attributor_type, :attributor_id => id, :attributable_type => attributable.class.to_s, :attributable_id => attributable.id, :userid_initiating_action => current_user.id)
a.save
end
@@ -382,7 +384,7 @@
attributor_file_ids = parse_comma_seperated_string(params[:attributions_files])
attributor_type = 'Blob'
attributor_file_ids.each do |id|
- a = Attribution.new(:attributor_type => attributor_type, :attributor_id => id, :attributable_type => attributable.class.to_s, :attributable_id => attributable.id)
+ a = Attribution.new(:attributor_type => attributor_type, :attributor_id => id, :attributable_type => attributable.class.to_s, :attributable_id => attributable.id, :userid_initiating_action => current_user.id)
a.save
end
Modified: branches/event_logging/app/models/attribution.rb (1866 => 1867)
--- branches/event_logging/app/models/attribution.rb 2008-10-16 14:59:00 UTC (rev 1866)
+++ branches/event_logging/app/models/attribution.rb 2008-10-16 16:59:17 UTC (rev 1867)
@@ -7,6 +7,29 @@
belongs_to :attributor, :polymorphic => true
belongs_to :attributable, :polymorphic => true
- acts_as_activity_logged :models => { :culprit => { :model => :attributable },
- :referenced => { :model => :attributor } } if USE_EVENT_LOG
+
+ # a temporary virtual attribute - required for the "log_allowed()"
+ # callback method to work properly - for example, for "create"
+ # action with respect to permissions it is important who has done this
+ # action, so that it can be logged properly;
+ #
+ # this variable is set in the appropriate actions in the controller
+ attr_accessor :userid_initiating_action
+
+ if USE_EVENT_LOG
+ acts_as_activity_logged (:models => { :culprit => { :model => :attributable },
+ :referenced => { :model => :attributor } },
+ :check_log_allowed => true)
+ end
+
+ # callback for "acts_as_activity_loggable"
+ def log_allowed(action_name)
+ case action_name.downcase
+ when "create", "update", "destroy"
+ ActivityLog.create(:action ="" action_name, :activity_loggable => self,
+ :culprit_type => "User", :culprit_id => self.userid_initiating_action,
+ :referenced => self.attributor)
+ return false
+ end
+ end
end
Modified: branches/event_logging/app/models/creditation.rb (1866 => 1867)
--- branches/event_logging/app/models/creditation.rb 2008-10-16 14:59:00 UTC (rev 1866)
+++ branches/event_logging/app/models/creditation.rb 2008-10-16 16:59:17 UTC (rev 1867)
@@ -7,7 +7,30 @@
belongs_to :creditor, :polymorphic => true
belongs_to :creditable, :polymorphic => true
- acts_as_activity_logged :models => { :culprit => { :model => :creditable },
- :referenced => { :model => :creditor } } if USE_EVENT_LOG
+
+ # a temporary virtual attribute - required for the "log_allowed()"
+ # callback method to work properly - for example, for "create"
+ # action with respect to permissions it is important who has done this
+ # action, so that it can be logged properly;
+ #
+ # this variable is set in the appropriate actions in the controller
+ attr_accessor :userid_initiating_action
+
+ if USE_EVENT_LOG
+ acts_as_activity_logged (:models => { :culprit => { :model => :creditable },
+ :referenced => { :model => :creditor } },
+ :check_log_allowed => true)
+ end
+
+ # callback for "acts_as_activity_logged"
+ def log_allowed(action_name)
+ case action_name.downcase
+ when "create", "update", "destroy"
+ ActivityLog.create(:action ="" action_name, :activity_loggable => self,
+ :culprit_type => "User", :culprit_id => self.userid_initiating_action,
+ :referenced => self.creditor)
+ return false
+ end
+ end
end