3 class Arvados::V1::CollectionsController < ApplicationController
6 def self.limit_index_columns_read
11 if resource_attrs[:uuid] and (loc = Keep::Locator.parse(resource_attrs[:uuid]))
12 resource_attrs[:portable_data_hash] = loc.to_s
13 resource_attrs.delete :uuid
18 def find_objects_for_index
19 if params[:include_trash] || ['destroy', 'trash'].include?(action_name)
20 @objects = Collection.unscoped.readable_by(*@read_users)
25 def find_object_by_uuid
26 if loc = Keep::Locator.parse(params[:id])
28 if c = Collection.readable_by(*@read_users).where({ portable_data_hash: loc.to_s }).limit(1).first
30 uuid: c.portable_data_hash,
31 portable_data_hash: c.portable_data_hash,
32 manifest_text: c.signed_manifest_text,
42 if @object.is_a? Collection
50 if !@object.is_trashed
51 @object.update_attributes!(trash_at: db_current_time)
53 earliest_delete = (@object.trash_at +
54 Rails.configuration.blob_signature_ttl.seconds)
55 if @object.delete_at > earliest_delete
56 @object.update_attributes!(delete_at: earliest_delete)
62 if !@object.is_trashed
63 @object.update_attributes!(trash_at: db_current_time)
68 def find_collections(visited, sp, &b)
71 sp.class.columns.each do |c|
72 find_collections(visited, sp[c.name.to_sym], &b) if c.name != "log"
76 find_collections(visited, v, &b)
80 find_collections(visited, v, &b)
83 if m = /[a-f0-9]{32}\+\d+/.match(sp)
85 elsif m = Collection.uuid_regex.match(sp)
91 def search_edges(visited, uuid, direction)
92 if uuid.nil? or uuid.empty? or visited[uuid]
96 if loc = Keep::Locator.parse(uuid)
98 return if visited[loc.to_s]
101 logger.debug "visiting #{uuid}"
104 # uuid is a portable_data_hash
105 collections = Collection.readable_by(*@read_users).where(portable_data_hash: loc.to_s)
106 c = collections.limit(2).all
108 visited[loc.to_s] = c[0]
110 name = collections.limit(1).where("name <> ''").first
112 visited[loc.to_s] = {
113 portable_data_hash: c[0].portable_data_hash,
114 name: "#{name.name} + #{collections.count-1} more"
117 visited[loc.to_s] = {
118 portable_data_hash: c[0].portable_data_hash,
124 if direction == :search_up
125 # Search upstream for jobs where this locator is the output of some job
126 Job.readable_by(*@read_users).where(output: loc.to_s).each do |job|
127 search_edges(visited, job.uuid, :search_up)
130 Job.readable_by(*@read_users).where(log: loc.to_s).each do |job|
131 search_edges(visited, job.uuid, :search_up)
133 elsif direction == :search_down
134 if loc.to_s == "d41d8cd98f00b204e9800998ecf8427e+0"
135 # Special case, don't follow the empty collection.
139 # Search downstream for jobs where this locator is in script_parameters
140 Job.readable_by(*@read_users).where(["jobs.script_parameters like ?", "%#{loc.to_s}%"]).each do |job|
141 search_edges(visited, job.uuid, :search_down)
144 Job.readable_by(*@read_users).where(["jobs.docker_image_locator = ?", "#{loc.to_s}"]).each do |job|
145 search_edges(visited, job.uuid, :search_down)
149 # uuid is a regular Arvados UUID
150 rsc = ArvadosModel::resource_class_for_uuid uuid
152 Job.readable_by(*@read_users).where(uuid: uuid).each do |job|
153 visited[uuid] = job.as_api_response
154 if direction == :search_up
155 # Follow upstream collections referenced in the script parameters
156 find_collections(visited, job) do |hash, col_uuid|
157 search_edges(visited, hash, :search_up) if hash
158 search_edges(visited, col_uuid, :search_up) if col_uuid
160 elsif direction == :search_down
161 # Follow downstream job output
162 search_edges(visited, job.output, direction)
165 elsif rsc == Collection
166 if c = Collection.readable_by(*@read_users).where(uuid: uuid).limit(1).first
167 search_edges(visited, c.portable_data_hash, direction)
168 visited[c.portable_data_hash] = c.as_api_response
171 rsc.where(uuid: uuid).each do |r|
172 visited[uuid] = r.as_api_response
177 if direction == :search_up
178 # Search for provenance links pointing to the current uuid
179 Link.readable_by(*@read_users).
180 where(head_uuid: uuid, link_class: "provenance").
182 visited[link.uuid] = link.as_api_response
183 search_edges(visited, link.tail_uuid, direction)
185 elsif direction == :search_down
186 # Search for provenance links emanating from the current uuid
187 Link.readable_by(current_user).
188 where(tail_uuid: uuid, link_class: "provenance").
190 visited[link.uuid] = link.as_api_response
191 search_edges(visited, link.head_uuid, direction)
198 search_edges(visited, @object[:portable_data_hash], :search_up)
199 search_edges(visited, @object[:uuid], :search_up)
205 search_edges(visited, @object[:uuid], :search_down)
206 search_edges(visited, @object[:portable_data_hash], :search_down)
212 def load_limit_offset_order_params *args
214 if action_name == 'index'
215 # Omit manifest_text from index results unless expressly selected.
216 @select ||= model_class.selectable_attributes - ["manifest_text"]