3193: add manage account action to users controller.
authorradhika <radhika@curoverse.com>
Thu, 24 Jul 2014 15:10:20 +0000 (11:10 -0400)
committerradhika <radhika@curoverse.com>
Thu, 24 Jul 2014 15:10:20 +0000 (11:10 -0400)
apps/workbench/app/controllers/manage_account_controller.rb [deleted file]
apps/workbench/app/controllers/users_controller.rb
apps/workbench/app/views/users/_manage_account.html.erb [moved from apps/workbench/app/views/manage_account/_show_manage_account.html.erb with 81% similarity]
apps/workbench/app/views/users/_manage_current_token.html.erb [moved from apps/workbench/app/views/manage_account/_show_manage_current_token.html.erb with 100% similarity]
apps/workbench/app/views/users/_manage_repositories.html.erb [moved from apps/workbench/app/views/manage_account/_show_manage_repositories.html.erb with 93% similarity]
apps/workbench/app/views/users/_manage_ssh_keys.html.erb [moved from apps/workbench/app/views/manage_account/_show_manage_ssh_keys.html.erb with 79% similarity]
apps/workbench/app/views/users/_manage_virtual_machines.html.erb [moved from apps/workbench/app/views/manage_account/_show_manage_virtual_machines.html.erb with 85% similarity]
apps/workbench/app/views/users/manage_account.html.erb [new file with mode: 0644]
apps/workbench/config/routes.rb

diff --git a/apps/workbench/app/controllers/manage_account_controller.rb b/apps/workbench/app/controllers/manage_account_controller.rb
deleted file mode 100644 (file)
index 679db1c..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-class ManageAccountController < ApplicationController
-
-  def model_class
-    AuthorizedKey
-  end
-
-  def index_pane_list
-    %w(Manage_account)
-  end
-
-  def index    
-    # repositories current user can read / write
-    @repo_links = []
-    Link.where(tail_uuid: current_user.uuid,
-               link_class: 'permission',
-               name: ['can_write', 'can_read']).
-          each do |perm_link|
-            @repo_links << perm_link[:head_uuid]
-          end
-    @repositories = Repository.where(uuid: @repo_links)
-
-    # virtual machines the current user can login into
-    @vm_logins = {}
-    Link.where(tail_uuid: current_user.uuid,
-               link_class: 'permission',
-               name: 'can_login').
-          each do |perm_link|
-            if perm_link.properties.andand[:username]
-              @vm_logins[perm_link.head_uuid] ||= []
-              @vm_logins[perm_link.head_uuid] << perm_link.properties[:username]
-            end
-          end
-    @virtual_machines = VirtualMachine.where(uuid: @vm_logins.keys)
-
-    # current user's ssh keys
-    filters=[["owner_uuid", "=", current_user.uuid]]
-    @ssh_keys = AuthorizedKey.where(key_type: 'SSH', filters: filters)
-    @objects = @ssh_keys
-
-    render_index
-  end
-
-end
index 0313de5aa2e7b9559146b9cfca7a6f31b166862d..8c2a68082b19de47398a53f85c325ac0368f752d 100644 (file)
@@ -210,6 +210,39 @@ class UsersController < ApplicationController
     end
   end
 
+  def manage_account
+    # repositories current user can read / write
+    repo_links = []
+    Link.where(tail_uuid: current_user.uuid,
+               link_class: 'permission',
+               name: ['can_write', 'can_read']).
+          each do |perm_link|
+            repo_links << perm_link[:head_uuid]
+          end
+    @my_repositories = Repository.where(uuid: repo_links)
+
+    # virtual machines the current user can login into
+    @my_vm_logins = {}
+    Link.where(tail_uuid: current_user.uuid,
+               link_class: 'permission',
+               name: 'can_login').
+          each do |perm_link|
+            if perm_link.properties.andand[:username]
+              @my_vm_logins[perm_link.head_uuid] ||= []
+              @my_vm_logins[perm_link.head_uuid] << perm_link.properties[:username]
+            end
+          end
+    @my_virtual_machines = VirtualMachine.where(uuid: @my_vm_logins.keys)
+
+    # current user's ssh keys
+    @my_ssh_keys = AuthorizedKey.where(key_type: 'SSH', owner_uuid: current_user.uuid)
+
+    respond_to do |f|
+#      f.js { render template: 'users/manage_account.js' }
+      f.html { render template: 'users/manage_account' }
+    end
+  end
+
   protected
 
   def find_current_links user
similarity index 81%
rename from apps/workbench/app/views/manage_account/_show_manage_account.html.erb
rename to apps/workbench/app/views/users/_manage_account.html.erb
index 06a3d447570b18be9e44625b0b98d5ed3cba863b..76a0408e0a3cf28db70d9a86951fd441ea644801 100644 (file)
@@ -14,7 +14,7 @@
         </div>
         <div id="manage_<%=section_id%>">
           <div class="panel-body">
-            <%= render partial: "show_manage_#{section_id}", locals: {repositories: @repositories, virtual_machines: @virtual_machines, vm_logins: @vm_logins, ssh_keys: @ssh_keys} %>
+            <%= render partial: "manage_#{section_id}" %>
           </div>
         </div>
       </div>
@@ -42,7 +42,7 @@
         </div>
         <div id="manage_<%=section_id%>">
           <div class="panel-body">
-            <%= render partial: "show_manage_#{section_id}", locals: {repositories: @repositories, virtual_machines: @virtual_machines, ssh_keys: @ssh_keys} %>
+            <%= render partial: "manage_#{section_id}" %>
           </div>
         </div>
       </div>
similarity index 93%
rename from apps/workbench/app/views/manage_account/_show_manage_repositories.html.erb
rename to apps/workbench/app/views/users/_manage_repositories.html.erb
index 0733b9835ab80b66fad0c0002426df3eec8d54fe..9c6fb1e82e060927464bc202c8c51f1213a6a5bd 100644 (file)
@@ -18,7 +18,7 @@
       </tr>
     </thead>
     <tbody>
-      <% @repositories.andand.each do |repo| %>
+      <% @my_repositories.andand.each do |repo| %>
         <tr>
           <td>
             <%= repo[:name] %>
similarity index 79%
rename from apps/workbench/app/views/manage_account/_show_manage_ssh_keys.html.erb
rename to apps/workbench/app/views/users/_manage_ssh_keys.html.erb
index c8245c175968bacbb43a40134eb0dbc23f6e9484..f8eec71666d08b1f17eb29a5a06527a63812e8e6 100644 (file)
@@ -6,7 +6,7 @@
       <col style="width: 5%" />
     </colgroup>
     <tbody>
-      <% @ssh_keys.andand.each do |key| %>
+      <% @my_ssh_keys.andand.each do |key| %>
         <tr>
           <td>
             <%= key[:uuid] %>
@@ -33,8 +33,8 @@ Sample <code>~/.ssh/config</code>:
 <pre>
 Host *.arvados
   ProxyCommand ssh -p2222 turnout@switchyard.<%= current_api_host || 'xyzzy.arvadosapi.com' %> -x -a $SSH_PROXY_FLAGS %h
-<% if @vm_logins.andand.first %>
-  User <%= @vm_logins[@vm_logins.andand.keys.first].andand.first %>
+<% if @my_vm_logins.andand.first %>
+  User <%= @my_vm_logins[@my_vm_logins.andand.keys.first].andand.first %>
 <% end %>
 </pre>
 
@@ -43,7 +43,7 @@ Sample login command:
 </p>
 
 <pre>
-ssh <%= @virtual_machines.first.andand.hostname.andand.sub('.'+current_api_host,'') or 'vm-hostname' %>.arvados
+ssh <%= @my_virtual_machines.first.andand.hostname.andand.sub('.'+current_api_host,'') or 'vm-hostname' %>.arvados
 </pre>
 
 <p>
similarity index 85%
rename from apps/workbench/app/views/manage_account/_show_manage_virtual_machines.html.erb
rename to apps/workbench/app/views/users/_manage_virtual_machines.html.erb
index 8eddb69da10c70504db97b5ff0ab468dd1e746a4..46310d7dcc7ac2e142a7453169a4163bf2667f0e 100644 (file)
       </tr>
     </thead>
     <tbody>
-      <% @virtual_machines.andand.each do |vm| %>
+      <% @my_virtual_machines.andand.each do |vm| %>
         <tr>
           <td>
             <%= vm[:hostname] %>
           </td>
           <td>
-            <%= @vm_logins[vm[:uuid]].andand.compact || [] %>
+            <%= @my_vm_logins[vm[:uuid]].andand.compact || [] %>
           </td>
           <td>
           </td>
diff --git a/apps/workbench/app/views/users/manage_account.html.erb b/apps/workbench/app/views/users/manage_account.html.erb
new file mode 100644 (file)
index 0000000..0751866
--- /dev/null
@@ -0,0 +1 @@
+<%= render :partial => 'manage_account' %>
index c7c564382958ba3e8246911954ea9123edf50306..1f3d65f1a88a4fc70bc2e980da38cf0b8551f59d 100644 (file)
@@ -66,7 +66,7 @@ ArvadosWorkbench::Application.routes.draw do
     get 'choose', on: :collection
     post 'share_with', on: :member
   end
-  get '/manage_account' => 'manage_account#index'
+  get '/manage_account' => 'users#manage_account'
 
   post 'actions' => 'actions#post'
   get 'websockets' => 'websocket#index'