1 class Log < ArvadosModel
4 include CommonApiTemplate
5 serialize :properties, Hash
6 before_validation :set_default_event_at
7 attr_accessor :object, :object_kind
8 after_save :send_notify
10 api_accessible :user, extend: :common do |t|
13 t.add :object_owner_uuid
22 if k = ArvadosModel::resource_class_for_uuid(object_uuid)
27 def fill_object(thing)
28 self.object_uuid ||= thing.uuid
29 if respond_to? :object_owner_uuid=
30 # Skip this if the object_owner_uuid migration hasn't happened
31 # yet, i.e., we're in the process of migrating an old database.
32 self.object_owner_uuid = thing.owner_uuid
34 self.summary ||= "#{self.event_type} of #{thing.uuid}"
38 def fill_properties(age, etag_prop, attrs_prop)
39 self.properties.merge!({"#{age}_etag" => etag_prop,
40 "#{age}_attributes" => attrs_prop})
44 fill_properties('new', thing.andand.etag, thing.andand.logged_attributes)
47 self.event_at = thing.created_at
49 self.event_at = thing.modified_at
51 self.event_at = db_current_time
58 def permission_to_create
62 def permission_to_update
63 current_user.andand.is_admin
66 alias_method :permission_to_delete, :permission_to_update
68 def set_default_event_at
69 self.event_at ||= db_current_time
73 # don't log start state on logs
76 def log_change(event_type)
77 # Don't log changes to logs.
80 def ensure_valid_uuids
81 # logs can have references to deleted objects
85 connection.execute "NOTIFY logs, '#{self.id}'"