12765: Add test for untrash on 404 page
[arvados.git] / apps / workbench / app / views / application / 404.html.erb
index 31462ef0333bc1cea093c536ff5cd81eb88621ab..94a6520873cc1a0cbc703aed52371a9b3be28ed6 100644 (file)
@@ -4,7 +4,7 @@ SPDX-License-Identifier: AGPL-3.0 %>
 
 <%
    if (controller.andand.action_name == 'show') and params[:uuid]
-     check_trash = controller.model_class.include_trash(true).where(uuid: params[:uuid], is_trashed: true)
+     check_trash = controller.model_class.include_trash(true).where(uuid: params[:uuid])
      class_name = controller.model_class.to_s.underscore
      class_name_h = class_name.humanize(capitalize: false)
      req_item = safe_join([class_name_h, " with UUID ",
@@ -16,23 +16,60 @@ SPDX-License-Identifier: AGPL-3.0 %>
    end
 %>
 
-  <% if check_trash.any? %>
-    <h2>Trashed</h2>
-
-    <p>The <%= req_item %> is in the trash.
+  <% untrash_object = nil %>
 
+  <% if check_trash.andand.any? %>
     <% object = check_trash.first %>
-    <% if object.editable? %>
-      <% msg = "Untrash '" + if !object.name.blank? then object.name else object.uuid end + "'?" %>
-      <%= link_to({action: 'untrash_items', selection: [object.uuid], controller: :trash_items}, remote: true, method: :post,
-        title: "Untrash", style: 'cursor: pointer;') do %>
+    <% if object.respond_to?(:is_trashed) && object.is_trashed %>
+      <% untrash_object = object %>
+    <% else %>
+      <% owner = Group.where(uuid: object.owner_uuid).include_trash(true).first %>
+      <% while !owner.nil? && !owner.is_trashed %>
+        <% if !owner.nil? and owner.is_trashed then %>
+          <% untrash_object = owner %>
+          <% break %>
+        <% end %>
+        <% owner = Group.where(uuid: owner.owner_uuid).include_trash(true).first %>
+      <% end %>
+    <% end %>
+  <% end %>
+
+  <% if !untrash_object.nil? %>
+    <h2>Trashed</h2>
 
+      <% untrash_name = if !untrash_object.name.blank? then
+                 "'#{untrash_object.name}'"
+                 else
+                 untrash_object.uuid
+               end %>
+
+    <p>The <%= req_item %> is
+      <% if untrash_object == object %>
+        in the trash.
+      <% else %>
+        owned by trashed project <%= untrash_name %> (<code><%= untrash_object.uuid %></code>).
       <% end %>
+    </p>
 
-      <%= form_tag url_for({action: 'untrash_items', controller: :trash_items}), {method: :post} %>
-      <%= hidden_field_tag :selection, [object.uuid] %>
-      <button type="submit">Click here to untrash this item <i class="fa fa-fw fa-recycle"></i></button>
+    <p>
+      It will be permanently deleted at <%= render_localized_date(untrash_object.delete_at) %>.
+    </p>
+
+  <p>
+    <% if untrash_object != object %>
+      You must untrash the owner project to access this <%= class_name_h %>.
     <% end %>
+      <% if untrash_object.is_trashed and untrash_object.editable? %>
+        <% msg = "Untrash '#{untrash_name}'?" %>
+        <%= link_to({action: 'untrash_items', selection: [untrash_object.uuid], controller: :trash_items}, remote: true, method: :post,
+        title: "Untrash", style: 'cursor: pointer;') do %>
+
+        <% end %>
+
+        <%= form_tag url_for({action: 'untrash_items', controller: :trash_items}), {method: :post} %>
+        <%= hidden_field_tag :selection, [untrash_object.uuid] %>
+        <button type="submit">Click here to untrash <%= untrash_name %> <i class="fa fa-fw fa-recycle"></i></button>
+      <% end %>
     </p>
 
   <% else %>