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
56 def self.readable_by(*users_list)
57 if users_list.select { |u| u.is_admin }.any?
60 user_uuids = users_list.map { |u| u.uuid }
61 uuid_list = user_uuids + users_list.flat_map { |u| u.groups_i_can(:read) }
63 permitted = "(SELECT head_uuid FROM links WHERE link_class='permission' AND tail_uuid IN (:uuids))"
64 joins("LEFT JOIN container_requests ON container_requests.container_uuid=logs.object_uuid").
65 where("logs.object_uuid IN #{permitted} OR "+
66 "container_requests.uuid IN (:uuids) OR "+
67 "container_requests.owner_uuid IN (:uuids) OR "+
68 "logs.object_uuid IN (:uuids) OR "+
69 "logs.owner_uuid IN (:uuids) OR "+
70 "logs.object_owner_uuid IN (:uuids)",
76 def permission_to_create
80 def permission_to_update
81 current_user.andand.is_admin
84 alias_method :permission_to_delete, :permission_to_update
86 def set_default_event_at
87 self.event_at ||= db_current_time
91 # don't log start state on logs
94 def log_change(event_type)
95 # Don't log changes to logs.
98 def ensure_valid_uuids
99 # logs can have references to deleted objects
103 connection.execute "NOTIFY logs, '#{self.id}'"