12125: 404 page searches owners to find actual trashed object.
[arvados.git] / apps / workbench / app / views / application / 404.html.erb
1 <%# Copyright (C) The Arvados Authors. All rights reserved.
2
3 SPDX-License-Identifier: AGPL-3.0 %>
4
5 <%
6    if (controller.andand.action_name == 'show') and params[:uuid]
7      check_trash = controller.model_class.include_trash(true).where(uuid: params[:uuid])
8      class_name = controller.model_class.to_s.underscore
9      class_name_h = class_name.humanize(capitalize: false)
10      req_item = safe_join([class_name_h, " with UUID ",
11                              raw("<code>"), params[:uuid], raw("</code>")], "")
12      req_item_plain_text = safe_join([class_name_h, " with UUID ", params[:uuid]])
13    else
14      req_item = "page you requested"
15      req_item_plain_text = "page you requested"
16    end
17 %>
18
19   <% if check_trash.andand.any? %>
20     <h2>Trashed</h2>
21
22       <% object = check_trash.first %>
23
24       <% untrash_object = object %>
25       <% while !untrash_object.is_trashed %>
26         <% owner = Group.where(uuid: untrash_object.owner_uuid).include_trash(true).first %>
27         <% if owner.nil? then %>
28           <% break %>
29         <% else %>
30           <% untrash_object = owner %>
31         <% end %>
32       <% end %>
33
34       <% untrash_name = if !untrash_object.name.blank? then
35                  "'#{untrash_object.name}'"
36                  else
37                  untrash_object.uuid
38                end %>
39
40     <p>The <%= req_item %> is
41       <% if untrash_object == object %>
42         in the trash.
43       <% else %>
44         owned by trashed project <%= untrash_name %> (<code><%= untrash_object.uuid %></code>).
45       <% end %>
46     </p>
47
48
49     <p>
50       It will be permanently deleted at <%= render_localized_date(untrash_object.delete_at) %>.
51     </p>
52
53   <p>
54     <% if untrash_object != object %>
55       You must untrash the owner project to access this <%= class_name_h %>.
56     <% end %>
57       <% if untrash_object.editable? %>
58         <% msg = "Untrash '#{untrash_name}'?" %>
59         <%= link_to({action: 'untrash_items', selection: [untrash_object.uuid], controller: :trash_items}, remote: true, method: :post,
60         title: "Untrash", style: 'cursor: pointer;') do %>
61
62         <% end %>
63
64         <%= form_tag url_for({action: 'untrash_items', controller: :trash_items}), {method: :post} %>
65         <%= hidden_field_tag :selection, [untrash_object.uuid] %>
66         <button type="submit">Click here to untrash <%= untrash_name %> <i class="fa fa-fw fa-recycle"></i></button>
67       <% end %>
68     </p>
69
70   <% else %>
71
72 <h2>Not Found</h2>
73
74 <p>The <%= req_item %> was not found.</p>
75
76 <% if !current_user %>
77
78   <p>
79     <%= link_to(arvados_api_client.arvados_login_url(return_to: strip_token_from_path(request.url)),
80                 {class: "btn btn-primary report-issue-modal-window"}) do %>
81       <i class="fa fa-fw fa-sign-in"></i> Log in
82     <% end %>
83     to view private data.
84   </p>
85
86 <% elsif class_name %>
87
88   <p>
89     Perhaps you'd like to <%= link_to("browse all
90     #{class_name_h.pluralize}", action: :index, controller:
91     class_name.tableize) %>?
92   </p>
93
94 <% end %>
95
96 <% end %>
97
98 <% error_message = "The #{req_item_plain_text} was not found." %>
99 <%= render :partial => "report_error", :locals => {error_message: error_message, error_type: '404'} %>