Make integer attributes searchable, add test cases.
[arvados.git] / apps / workbench / app / controllers / users_controller.rb
1 class UsersController < ApplicationController
2   skip_before_filter :find_object_by_uuid, :only => :welcome
3   skip_around_filter :thread_with_mandatory_api_token, :only => :welcome
4   before_filter :ensure_current_user_is_admin, only: :sudo
5
6   def welcome
7     if current_user
8       params[:action] = 'home'
9       home
10     end
11   end
12
13   def show_pane_list
14     if current_user.andand.is_admin
15       super | %w(Admin)
16     else
17       super
18     end
19   end
20
21   def sudo
22     resp = $arvados_api_client.api(ApiClientAuthorization, '', {
23                                      api_client_authorization: {
24                                        owner_uuid: @object.uuid
25                                      }
26                                    })
27     redirect_to root_url(api_token: resp[:api_token])
28   end
29
30   def home
31     @showallalerts = false
32     @my_ssh_keys = AuthorizedKey.where(authorized_user_uuid: current_user.uuid)
33     # @my_vm_perms = Link.where(tail_uuid: current_user.uuid, head_kind: 'arvados#virtual_machine', link_class: 'permission', name: 'can_login')
34     # @my_repo_perms = Link.where(tail_uuid: current_user.uuid, head_kind: 'arvados#repository', link_class: 'permission', name: 'can_write')
35
36     @my_tag_links = {}
37
38     @my_jobs = Job.
39       limit(10).
40       order('created_at desc').
41       where(created_by: current_user.uuid)
42
43     @my_collections = Collection.
44       limit(10).
45       order('created_at desc').
46       where(created_by: current_user.uuid)
47
48     Link.limit(1000).where(head_uuid: @my_collections.collect(&:uuid),
49                            link_class: 'tag').each do |link|
50       (@my_tag_links[link.head_uuid] ||= []) << link
51     end
52
53     @my_pipelines = PipelineInstance.
54       limit(10).
55       order('created_at desc').
56       where(created_by: current_user.uuid)
57
58
59     # A Tutorial is a Link which has link_class "resources" and name
60     # "wants", and is owned by the Tutorials Group (i.e., named
61     # "Arvados Tutorials" and owned by the system user).
62     @tutorial_group = Group.where(owner_uuid: User.system.uuid,
63                                   name: 'Arvados Tutorials').first
64     if @tutorial_group
65       @tutorial_links = Link.where(tail_uuid: @tutorial_group.uuid,
66                                    link_class: 'resources',
67                                    name: 'wants')
68     else
69       @tutorial_links = []
70     end
71     @tutorial_complete = {
72       'Run a job' => @my_last_job
73     }
74     respond_to do |f|
75       f.js { render template: 'users/home.js' }
76       f.html { render template: 'users/home' }
77     end
78   end
79 end