X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9fd58497a867ae3846a5c4761eb724d1d1b91fc7..d37d7308827b4cc64272b5cc71f2adc4faf895a3:/services/api/app/models/log.rb diff --git a/services/api/app/models/log.rb b/services/api/app/models/log.rb index af0b533c75..b10a491163 100644 --- a/services/api/app/models/log.rb +++ b/services/api/app/models/log.rb @@ -1,24 +1,36 @@ class Log < ArvadosModel - include AssignUuid + include HasUuid include KindAndEtag include CommonApiTemplate serialize :properties, Hash before_validation :set_default_event_at - attr_accessor :object + attr_accessor :object, :object_kind + after_save :send_notify api_accessible :user, extend: :common do |t| - t.add :object_kind + t.add :id t.add :object_uuid - t.add :object, :if => :object + t.add :object_owner_uuid + t.add :object_kind t.add :event_at t.add :event_type t.add :summary t.add :properties end + def object_kind + if k = ArvadosModel::resource_class_for_uuid(object_uuid) + k.kind + end + end + def fill_object(thing) - self.object_kind ||= thing.kind self.object_uuid ||= thing.uuid + if respond_to? :object_owner_uuid= + # Skip this if the object_owner_uuid migration hasn't happened + # yet, i.e., we're in the process of migrating an old database. + self.object_owner_uuid = thing.owner_uuid + end self.summary ||= "#{self.event_type} of #{thing.uuid}" self end @@ -36,7 +48,7 @@ class Log < ArvadosModel when "update" self.event_at = thing.modified_at when "destroy" - self.event_at = Time.now + self.event_at = db_current_time end self end @@ -54,10 +66,23 @@ class Log < ArvadosModel alias_method :permission_to_delete, :permission_to_update def set_default_event_at - self.event_at ||= Time.now + self.event_at ||= db_current_time + end + + def log_start_state + # don't log start state on logs end def log_change(event_type) # Don't log changes to logs. end + + def ensure_valid_uuids + # logs can have references to deleted objects + end + + def send_notify + connection.execute "NOTIFY logs, '#{self.id}'" + end + end