1 class Log < ArvadosModel
4 include CommonApiTemplate
5 serialize :properties, Hash
6 before_validation :set_default_event_at
7 after_save :send_notify
9 api_accessible :user, extend: :common do |t|
12 t.add :object_owner_uuid
21 if k = ArvadosModel::resource_class_for_uuid(object_uuid)
26 def fill_object(thing)
27 self.object_uuid ||= thing.uuid
28 if respond_to? :object_owner_uuid=
29 # Skip this if the object_owner_uuid migration hasn't happened
30 # yet, i.e., we're in the process of migrating an old database.
31 self.object_owner_uuid = thing.owner_uuid
33 self.summary ||= "#{self.event_type} of #{thing.uuid}"
37 def fill_properties(age, etag_prop, attrs_prop)
38 self.properties.merge!({"#{age}_etag" => etag_prop,
39 "#{age}_attributes" => attrs_prop})
43 fill_properties('new', thing.andand.etag, thing.andand.logged_attributes)
46 self.event_at = thing.created_at
48 self.event_at = thing.modified_at
50 self.event_at = db_current_time
55 def self.readable_by(*users_list)
56 if users_list.select { |u| u.is_admin }.any?
59 user_uuids = users_list.map { |u| u.uuid }
60 uuid_list = user_uuids + users_list.flat_map { |u| u.groups_i_can(:read) }
62 permitted = "(SELECT head_uuid FROM links WHERE link_class='permission' AND tail_uuid IN (:uuids))"
63 joins("LEFT JOIN container_requests ON container_requests.container_uuid=logs.object_uuid").
64 where("logs.object_uuid IN #{permitted} OR "+
65 "container_requests.uuid IN (:uuids) OR "+
66 "container_requests.owner_uuid IN (:uuids) OR "+
67 "logs.object_uuid IN (:uuids) OR "+
68 "logs.owner_uuid IN (:uuids) OR "+
69 "logs.object_owner_uuid IN (:uuids)",
75 def permission_to_create
79 def permission_to_update
80 current_user.andand.is_admin
83 alias_method :permission_to_delete, :permission_to_update
85 def set_default_event_at
86 self.event_at ||= db_current_time
90 # don't log start state on logs
93 def log_change(event_type)
94 # Don't log changes to logs.
97 def ensure_valid_uuids
98 # logs can have references to deleted objects
102 connection.execute "NOTIFY logs, '#{self.id}'"