closes #11840
[arvados.git] / services / api / app / controllers / arvados / v1 / collections_controller.rb
index 6c3589736e91d8762d04e1202a80c588c4257387..b5dd07e064a71e003b66e81030134dce460e7d4f 100644 (file)
@@ -3,10 +3,16 @@ require "arvados/keep"
 class Arvados::V1::CollectionsController < ApplicationController
   include DbCurrentTime
 
-  def self.limit_index_columns_read
-    ["manifest_text"]
+  def self._index_requires_parameters
+    (super rescue {}).
+      merge({
+        include_trash: {
+          type: 'boolean', required: false, description: "Include collections whose is_trashed attribute is true."
+        },
+      })
   end
 
+
   def create
     if resource_attrs[:uuid] and (loc = Keep::Locator.parse(resource_attrs[:uuid]))
       resource_attrs[:portable_data_hash] = loc.to_s
@@ -16,7 +22,7 @@ class Arvados::V1::CollectionsController < ApplicationController
   end
 
   def find_objects_for_index
-    if params[:include_trash] || ['destroy', 'trash'].include?(action_name)
+    if params[:include_trash] || ['destroy', 'trash', 'untrash'].include?(action_name)
       @objects = Collection.unscoped.readable_by(*@read_users)
     end
     super
@@ -40,6 +46,8 @@ class Arvados::V1::CollectionsController < ApplicationController
 
   def show
     if @object.is_a? Collection
+      # Omit unsigned_manifest_text
+      @select ||= model_class.selectable_attributes - ["unsigned_manifest_text"]
       super
     else
       send_json @object
@@ -65,6 +73,21 @@ class Arvados::V1::CollectionsController < ApplicationController
     show
   end
 
+  def untrash
+    if @object.is_trashed
+      @object.trash_at = nil
+
+      if params[:ensure_unique_name]
+        @object.save_with_unique_name!
+      else
+        @object.save!
+      end
+    else
+      raise InvalidStateTransitionError
+    end
+    show
+  end
+
   def find_collections(visited, sp, &b)
     case sp
     when ArvadosModel
@@ -212,8 +235,8 @@ class Arvados::V1::CollectionsController < ApplicationController
   def load_limit_offset_order_params *args
     super
     if action_name == 'index'
-      # Omit manifest_text from index results unless expressly selected.
-      @select ||= model_class.selectable_attributes - ["manifest_text"]
+      # Omit manifest_text and unsigned_manifest_text from index results unless expressly selected.
+      @select ||= model_class.selectable_attributes - ["manifest_text", "unsigned_manifest_text"]
     end
   end
 end