3 class Log < ArvadosModel
6 include CommonApiTemplate
7 serialize :properties, Hash
8 before_validation :set_default_event_at
9 after_save :send_notify
10 after_commit { AuditLogs.tidy_in_background }
12 api_accessible :user, extend: :common do |t|
15 t.add :object_owner_uuid
24 if k = ArvadosModel::resource_class_for_uuid(object_uuid)
29 def fill_object(thing)
30 self.object_uuid ||= thing.uuid
31 if respond_to? :object_owner_uuid=
32 # Skip this if the object_owner_uuid migration hasn't happened
33 # yet, i.e., we're in the process of migrating an old database.
34 self.object_owner_uuid = thing.owner_uuid
36 self.summary ||= "#{self.event_type} of #{thing.uuid}"
40 def fill_properties(age, etag_prop, attrs_prop)
41 self.properties.merge!({"#{age}_etag" => etag_prop,
42 "#{age}_attributes" => attrs_prop})
46 fill_properties('new', thing.andand.etag, thing.andand.logged_attributes)
49 self.event_at = thing.created_at
51 self.event_at = thing.modified_at
53 self.event_at = db_current_time
58 def self.readable_by(*users_list)
59 if users_list.select { |u| u.is_admin }.any?
62 user_uuids = users_list.map { |u| u.uuid }
63 uuid_list = user_uuids + users_list.flat_map { |u| u.groups_i_can(:read) }
65 permitted = "(SELECT head_uuid FROM links WHERE link_class='permission' AND tail_uuid IN (:uuids))"
66 joins("LEFT JOIN container_requests ON container_requests.container_uuid=logs.object_uuid").
67 where("logs.object_uuid IN #{permitted} OR "+
68 "container_requests.uuid IN (:uuids) OR "+
69 "container_requests.owner_uuid IN (:uuids) OR "+
70 "logs.object_uuid IN (:uuids) OR "+
71 "logs.owner_uuid IN (:uuids) OR "+
72 "logs.object_owner_uuid IN (:uuids)",
78 def permission_to_create
82 def permission_to_update
83 current_user.andand.is_admin
86 alias_method :permission_to_delete, :permission_to_update
88 def set_default_event_at
89 self.event_at ||= db_current_time
93 # don't log start state on logs
96 def log_change(event_type)
97 # Don't log changes to logs.
100 def ensure_valid_uuids
101 # logs can have references to deleted objects
105 ActiveRecord::Base.connection.execute "NOTIFY logs, '#{self.id}'"