From b74478a602b3cc5fcc18c2beb2962f98d1225ac4 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Thu, 14 Sep 2017 21:35:40 -0400 Subject: [PATCH] 12125: Can browse trashed projects & untrash them. Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- .../app/controllers/projects_controller.rb | 48 ++----------------- .../app/controllers/trash_items_controller.rb | 16 +++++-- apps/workbench/app/models/group.rb | 4 ++ ...=> _show_trashed_collection_rows.html.erb} | 0 .../_show_trashed_collections.html.erb | 6 +-- .../_show_trashed_projects.html.erb | 8 ++-- 6 files changed, 26 insertions(+), 56 deletions(-) rename apps/workbench/app/views/trash_items/{_show_trash_rows.html.erb => _show_trashed_collection_rows.html.erb} (100%) diff --git a/apps/workbench/app/controllers/projects_controller.rb b/apps/workbench/app/controllers/projects_controller.rb index c010123ea0..a2ed89bb92 100644 --- a/apps/workbench/app/controllers/projects_controller.rb +++ b/apps/workbench/app/controllers/projects_controller.rb @@ -134,50 +134,8 @@ class ProjectsController < ApplicationController @removed_uuids = [] links = [] params[:item_uuids].collect { |uuid| ArvadosBase.find uuid }.each do |item| - if (item.class == Link and - item.link_class == 'name' and - item.tail_uuid == @object.uuid) - # Given uuid is a name link, linking an object to this - # project. First follow the link to find the item we're removing, - # then delete the link. - links << item - item = ArvadosBase.find item.head_uuid - else - # Given uuid is an object. Delete all names. - links += Link.where(tail_uuid: @object.uuid, - head_uuid: item.uuid, - link_class: 'name') - end - links.each do |link| - @removed_uuids << link.uuid - link.destroy - end - - if item.class == Collection - # Use delete API on collections - item.destroy - @removed_uuids << item.uuid - elsif item.owner_uuid == @object.uuid - # Object is owned by this project. Remove it from the project by - # changing owner to the current user. - begin - item.update_attributes owner_uuid: current_user.uuid - @removed_uuids << item.uuid - rescue ArvadosApiClient::ApiErrorResponseException => e - if e.message.include? '_owner_uuid_' - rename_to = item.name + ' removed from ' + - (@object.name ? @object.name : @object.uuid) + - ' at ' + Time.now.to_s - updates = {} - updates[:name] = rename_to - updates[:owner_uuid] = current_user.uuid - item.update_attributes updates - @removed_uuids << item.uuid - else - raise - end - end - end + item.destroy + @removed_uuids << item.uuid end end @@ -337,7 +295,7 @@ class ProjectsController < ApplicationController def public # Yes 'public' is the name of the action for public projects return render_not_found if not Rails.configuration.anonymous_user_token or not Rails.configuration.enable_public_projects_page @objects = using_specific_api_token Rails.configuration.anonymous_user_token do - Group.where(group_class: 'project').order("updated_at DESC") + Group.where(group_class: 'project').order("modified_at DESC") end end end diff --git a/apps/workbench/app/controllers/trash_items_controller.rb b/apps/workbench/app/controllers/trash_items_controller.rb index b957798459..27cbb327f1 100644 --- a/apps/workbench/app/controllers/trash_items_controller.rb +++ b/apps/workbench/app/controllers/trash_items_controller.rb @@ -22,7 +22,7 @@ class TrashItemsController < ApplicationController if @objects.any? @objects = @objects.sort_by { |obj| obj.trash_at }.reverse @next_page_filters = next_page_filters('<=') - @next_page_href = url_for(partial: :trash_rows, + @next_page_href = url_for(partial: params[:partial], filters: @next_page_filters.to_json) else @next_page_href = nil @@ -55,13 +55,19 @@ class TrashItemsController < ApplicationController end def trashed_items + if params[:partial] == "trashed_collection_rows" + query_on = Collection + elsif params[:partial] == "trashed_project_rows" + query_on = Group + end + # API server index doesn't return manifest_text by default, but our # callers want it unless otherwise specified. - @select ||= Collection.columns.map(&:name) + @select ||= query_on.columns.map(&:name) - %w(id updated_at) limit = if params[:limit] then params[:limit].to_i else 100 end offset = if params[:offset] then params[:offset].to_i else 0 end - base_search = Collection.select(@select).include_trash(true).where(is_trashed: true) + base_search = query_on.select(@select).include_trash(true).where(is_trashed: true) base_search = base_search.filter(params[:filters]) if params[:filters] if params[:search].andand.length.andand > 0 @@ -80,7 +86,9 @@ class TrashItemsController < ApplicationController updates = {trash_at: nil} - Collection.include_trash(1).where(uuid: params[:selection]).each do |c| + klass = resource_class_for_uuid(params[:selection][0]) + + klass.include_trash(1).where(uuid: params[:selection]).each do |c| c.untrash @untrashed_uuids << c.uuid end diff --git a/apps/workbench/app/models/group.rb b/apps/workbench/app/models/group.rb index 523e5e94f6..08b13bf34b 100644 --- a/apps/workbench/app/models/group.rb +++ b/apps/workbench/app/models/group.rb @@ -40,4 +40,8 @@ class Group < ArvadosBase def self.creatable? false end + + def untrash + arvados_api_client.api(self.class, "/#{self.uuid}/untrash", {"ensure_unique_name" => true}) + end end diff --git a/apps/workbench/app/views/trash_items/_show_trash_rows.html.erb b/apps/workbench/app/views/trash_items/_show_trashed_collection_rows.html.erb similarity index 100% rename from apps/workbench/app/views/trash_items/_show_trash_rows.html.erb rename to apps/workbench/app/views/trash_items/_show_trashed_collection_rows.html.erb diff --git a/apps/workbench/app/views/trash_items/_show_trashed_collections.html.erb b/apps/workbench/app/views/trash_items/_show_trashed_collections.html.erb index c534e5256d..aaa29360f5 100644 --- a/apps/workbench/app/views/trash_items/_show_trashed_collections.html.erb +++ b/apps/workbench/app/views/trash_items/_show_trashed_collections.html.erb @@ -22,7 +22,7 @@ SPDX-License-Identifier: AGPL-3.0 %>
@@ -50,8 +50,8 @@ SPDX-License-Identifier: AGPL-3.0 %> - + diff --git a/apps/workbench/app/views/trash_items/_show_trashed_projects.html.erb b/apps/workbench/app/views/trash_items/_show_trashed_projects.html.erb index a78b02fcb1..ef782d6158 100644 --- a/apps/workbench/app/views/trash_items/_show_trashed_projects.html.erb +++ b/apps/workbench/app/views/trash_items/_show_trashed_projects.html.erb @@ -22,7 +22,7 @@ SPDX-License-Identifier: AGPL-3.0 %>
@@ -45,13 +45,13 @@ SPDX-License-Identifier: AGPL-3.0 %> Trashed at Permanently
Deleted At Owner - Contents + - + -- 2.30.2