From 27355f62088566a9388972e128bfb8ba77790e9a Mon Sep 17 00:00:00 2001 From: radhika Date: Wed, 31 May 2017 15:03:53 -0400 Subject: [PATCH] 9587: expose untrash api --- .../app/controllers/trash_items_controller.rb | 6 +++--- apps/workbench/app/models/collection.rb | 3 +++ .../controllers/arvados/v1/collections_controller.rb | 11 ++++++++++- services/api/config/routes.rb | 1 + 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/workbench/app/controllers/trash_items_controller.rb b/apps/workbench/app/controllers/trash_items_controller.rb index 5190474e90..7271fc1798 100644 --- a/apps/workbench/app/controllers/trash_items_controller.rb +++ b/apps/workbench/app/controllers/trash_items_controller.rb @@ -77,9 +77,9 @@ class TrashItemsController < ApplicationController updates = {trash_at: nil} - params[:selection].collect { |uuid| ArvadosBase.find uuid }.each do |item| - item.update_attributes updates - @untrashed_uuids << item.uuid + Collection.include_trash(1).where(uuid: params[:selection]).each do |c| + c.untrash + @untrashed_uuids << c.uuid end respond_to do |format| diff --git a/apps/workbench/app/models/collection.rb b/apps/workbench/app/models/collection.rb index ea81ad8c0a..305ea01530 100644 --- a/apps/workbench/app/models/collection.rb +++ b/apps/workbench/app/models/collection.rb @@ -98,4 +98,7 @@ class Collection < ArvadosBase [ 'description' ] end + def untrash + arvados_api_client.api(self.class, "/#{self.uuid}/untrash", {}) + end end diff --git a/services/api/app/controllers/arvados/v1/collections_controller.rb b/services/api/app/controllers/arvados/v1/collections_controller.rb index 8ba7925b28..73a7e09c5e 100644 --- a/services/api/app/controllers/arvados/v1/collections_controller.rb +++ b/services/api/app/controllers/arvados/v1/collections_controller.rb @@ -12,7 +12,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.readable_by(*@read_users).unscoped end super @@ -63,6 +63,15 @@ class Arvados::V1::CollectionsController < ApplicationController show end + def untrash + if @object.is_trashed + @object.update_attributes!(trash_at: nil) + else + raise InvalidStateTransitionError + end + show + end + def find_collections(visited, sp, &b) case sp when ArvadosModel diff --git a/services/api/config/routes.rb b/services/api/config/routes.rb index 77e5372a15..87c4d91757 100644 --- a/services/api/config/routes.rb +++ b/services/api/config/routes.rb @@ -21,6 +21,7 @@ Server::Application.routes.draw do get 'provenance', on: :member get 'used_by', on: :member post 'trash', on: :member + post 'untrash', on: :member end resources :groups do get 'contents', on: :collection -- 2.30.2