Merge branch '15795-sys-root-token'
[arvados.git] / apps / workbench / app / controllers / search_controller.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class SearchController < ApplicationController
6   skip_before_action :ensure_arvados_api_exists
7
8   def find_objects_for_index
9     search_what = Group
10     if params[:project_uuid]
11       # Special case for "search all things in project":
12       @filters = @filters.select do |attr, operator, operand|
13         not (attr == 'owner_uuid' and operator == '=')
14       end
15       # Special case for project_uuid is a user uuid:
16       if ArvadosBase::resource_class_for_uuid(params[:project_uuid]) == User
17         search_what = User.find params[:project_uuid]
18       else
19         search_what = Group.find params[:project_uuid]
20       end
21     end
22     @objects = search_what.contents(limit: @limit,
23                                     offset: @offset,
24                                     recursive: true,
25                                     count: 'none',
26                                     last_object_class: params["last_object_class"],
27                                     filters: @filters)
28     super
29   end
30
31   def next_page_href with_params={}
32     super with_params.merge(last_object_class: @objects.last.class.to_s,
33                             project_uuid: params[:project_uuid],
34                             recursive: true,
35                             count: 'none',
36                             filters: @filters.to_json)
37   end
38 end