Merge branch '8784-dir-listings'
[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   def find_objects_for_index
7     search_what = Group
8     if params[:project_uuid]
9       # Special case for "search all things in project":
10       @filters = @filters.select do |attr, operator, operand|
11         not (attr == 'owner_uuid' and operator == '=')
12       end
13       # Special case for project_uuid is a user uuid:
14       if ArvadosBase::resource_class_for_uuid(params[:project_uuid]) == User
15         search_what = User.find params[:project_uuid]
16       else
17         search_what = Group.find params[:project_uuid]
18       end
19     end
20     @objects = search_what.contents(limit: @limit,
21                                     offset: @offset,
22                                     recursive: true,
23                                     count: 'none',
24                                     last_object_class: params["last_object_class"],
25                                     filters: @filters)
26     super
27   end
28
29   def next_page_href with_params={}
30     super with_params.merge(last_object_class: @objects.last.class.to_s,
31                             project_uuid: params[:project_uuid],
32                             recursive: true,
33                             count: 'none',
34                             filters: @filters.to_json)
35   end
36 end