app/models/action.rb in artfully_ose-1.2.0 vs app/models/action.rb in artfully_ose-1.3.0.pre1

- old
+ new

@@ -1,49 +1,71 @@ class Action < ActiveRecord::Base include OhNoes::Destroy - + belongs_to :person, touch: true belongs_to :creator, :class_name => "User", :foreign_key => "creator_id" belongs_to :organization belongs_to :subject, :polymorphic => true belongs_to :import validates_presence_of :occurred_at - validates_presence_of :person_id before_save :default_starred_to_false + after_create :add_to_feed + after_update :rebuild_feed + after_destroy :rebuild_feed set_watch_for :occurred_at, :local_to => :organization + searchable do + text :details + text :verb + integer :person_id, stored: true + string :organization_id + string :type + date :created_at + end + include Ext::DelayedIndexing + def self.for_organization(organization) #Skipping whitelisting because we're playing on our home field Kernel.const_get(self.name.camelize).new({:occurred_at => DateTime.now.in_time_zone(organization.time_zone), :organization => organization}, :without_protection => true) end + def add_to_feed + ActionFeed.for(self.organization_id).add(self) + end + + def rebuild_feed + ActionFeed.for(self.organization_id).rebuild_if_necessary(self, true) + end + # # Action types: give, go, do, get, join, hear # def self.create_of_type(type) case type when "hear" then HearAction.new when "say" then SayAction.new when "go" then GoAction.new when "give" then GiveAction.new when "do" then DoAction.new + when "pledge" then PledgeAction.new end end def self.subtypes_by_type { "hear" => HearAction.subtypes, "say" => SayAction.subtypes, "go" => GoAction.subtypes, "give" => GiveAction.subtypes, "do" => DoAction.subtypes, - "get" => GetAction.subtypes + "get" => GetAction.subtypes, + "pledge" => PledgeAction.subtypes, } end # destroyable? is mixed-in from ohnoes.rb def editable? @@ -89,19 +111,26 @@ details end #This returnes an ARel, so you can chain def self.recent(organization) - Action.includes(:person, :subject).where(:organization_id => organization).order('occurred_at DESC') + Action.includes(:person, :subject). + where(:organization_id => organization). + where(:hide_on_recent_activity => false). + order('occurred_at DESC') end def self.subtypes [] end def default_starred_to_false self.starred = false if self.starred.blank? true + end + + def can_wait? + import_id.present? end # # This exists solely so that DJ can serialize an unsaved action so that ActionJob can run # There's nothing inherent to Action in this method so it looks like a good candidate to