Removed head_kind and tail_kind from workbench.
[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_tag_links = {}
34
35     @my_jobs = Job.
36       limit(10).
37       order('created_at desc').
38       where(created_by: current_user.uuid)
39
40     @my_collections = Collection.
41       limit(10).
42       order('created_at desc').
43       where(created_by: current_user.uuid)
44
45     Link.limit(1000).where(head_uuid: @my_collections.collect(&:uuid),
46                            link_class: 'tag').each do |link|
47       (@my_tag_links[link.head_uuid] ||= []) << link
48     end
49
50     @my_pipelines = PipelineInstance.
51       limit(10).
52       order('created_at desc').
53       where(created_by: current_user.uuid)
54
55
56     # A Tutorial is a Link which has link_class "resources" and name
57     # "wants", and is owned by the Tutorials Group (i.e., named
58     # "Arvados Tutorials" and owned by the system user).
59     @tutorial_group = Group.where(owner_uuid: User.system.uuid,
60                                   name: 'Arvados Tutorials').first
61     if @tutorial_group
62       @tutorial_links = Link.where(tail_uuid: @tutorial_group.uuid,
63                                    link_class: 'resources',
64                                    name: 'wants')
65     else
66       @tutorial_links = []
67     end
68     @tutorial_complete = {
69       'Run a job' => @my_last_job
70     }
71     respond_to do |f|
72       f.js { render template: 'users/home.js' }
73       f.html { render template: 'users/home' }
74     end
75   end
76 end