Merge branch 'master' into 3193-manage-account
authorradhika <radhika@curoverse.com>
Thu, 24 Jul 2014 15:11:11 +0000 (11:11 -0400)
committerradhika <radhika@curoverse.com>
Thu, 24 Jul 2014 15:11:11 +0000 (11:11 -0400)
apps/workbench/app/controllers/users_controller.rb
apps/workbench/app/views/application/index.html.erb
apps/workbench/app/views/layouts/application.html.erb
apps/workbench/app/views/users/_manage_account.html.erb [new file with mode: 0644]
apps/workbench/app/views/users/_manage_current_token.html.erb [new file with mode: 0644]
apps/workbench/app/views/users/_manage_repositories.html.erb [new file with mode: 0644]
apps/workbench/app/views/users/_manage_ssh_keys.html.erb [new file with mode: 0644]
apps/workbench/app/views/users/_manage_virtual_machines.html.erb [new file with mode: 0644]
apps/workbench/app/views/users/manage_account.html.erb [new file with mode: 0644]
apps/workbench/config/routes.rb

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
index 0e72f7a2ddadf4f7947cb08b2afc0aa90a5cde50..3e2a608ed719cef61c52f17a07865bfdd6ca9dbd 100644 (file)
@@ -13,6 +13,8 @@
         <i class="fa fa-fw fa-plus"></i> Add a new user
       <% end %>
       <div id="user-setup-modal-window" class="modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
+    <% elsif controller.controller_name == 'manage_account' %>
+      <%# No add button is needed %>
     <% else %>
       <%= button_to({action: 'create'}, {class: 'btn btn-sm btn-primary'}) do %>
         <i class="fa fa-fw fa-plus"></i>
index ec2c98bdcb181d10f189c500e3e5972d96a6c773..5725f40de7409d87cce882420aadcacb4130b872 100644 (file)
@@ -81,8 +81,7 @@
             </a>
             <ul class="dropdown-menu" role="menu">
               <% if current_user.is_active %>
-              <li role="presentation"><a href="/authorized_keys" role="menuitem"><i class="fa fa-key fa-fw"></i> Manage ssh keys</a></li>
-              <li role="presentation"><a href="/api_client_authorizations" role="menuitem"><i class="fa fa-ticket fa-fw"></i> Manage API tokens</a></li>
+              <li role="presentation"><a href="/manage_account" role="menuitem"><i class="fa fa-key fa-fw"></i> Manage account</a></li>
               <li role="presentation" class="divider"></li>
               <% end %>
               <li role="presentation"><a href="<%= logout_path %>" role="menuitem"><i class="fa fa-sign-out fa-fw"></i> Log out</a></li>
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..76a0408
--- /dev/null
@@ -0,0 +1,51 @@
+<div class="col-sm-6">
+  <div class="panel-group" id="arv-adv-accordion">
+    <% ['Virtual Machines',
+       'Repositories',
+       'Current Token'].each do |section| %>
+      <% section_id = section.gsub(" ","_").downcase %>
+      <div class="panel panel-default">
+        <div class="panel-heading">
+          <h4 class="panel-title">
+            <a data-parent="#arv-adv-accordion" href="#manage_<%=section_id%>">
+              <%= section %>
+            </a>
+          </h4>
+        </div>
+        <div id="manage_<%=section_id%>">
+          <div class="panel-body">
+            <%= render partial: "manage_#{section_id}" %>
+          </div>
+        </div>
+      </div>
+    <% end %>
+  </div>
+</div>
+<div class="col-sm-6">
+  <div class="panel-group" id="arv-adv-accordion">
+    <% ['SSH Keys'].each do |section| %>
+      <% section_id = section.gsub(" ","_").downcase %>
+      <div class="panel panel-default">
+        <div class="panel-heading">
+          <div class="pull-right">
+            <%= button_to projects_path(method: 'post'), class: 'btn btn-xs btn-primary' do %>
+              <i class="fa fa-fw fa-plus"></i>
+              Add new SSH key
+            <% end %>
+
+          </div>
+          <h4 class="panel-title">
+            <a data-parent="#arv-adv-accordion" href="#manage_<%=section_id%>">
+              <%= section %>
+            </a>
+          </h4>
+        </div>
+        <div id="manage_<%=section_id%>">
+          <div class="panel-body">
+            <%= render partial: "manage_#{section_id}" %>
+          </div>
+        </div>
+      </div>
+    <% end %>
+  </div>
+</div>
diff --git a/apps/workbench/app/views/users/_manage_current_token.html.erb b/apps/workbench/app/views/users/_manage_current_token.html.erb
new file mode 100644 (file)
index 0000000..b87d80a
--- /dev/null
@@ -0,0 +1,11 @@
+### Pasting the following lines at a shell prompt will allow Arvados SDKs</br>
+### to authenticate to your account, <%= current_user.email %></br></br>
+read ARVADOS_API_TOKEN &lt;&lt;EOF</br>
+<%= Thread.current[:arvados_api_token] %></br>
+EOF</br>
+export ARVADOS_API_TOKEN ARVADOS_API_HOST=<%= current_api_host %></br>
+<% if Rails.configuration.arvados_insecure_https %>
+export ARVADOS_API_HOST_INSECURE=true</br>
+<% else %>
+unset ARVADOS_API_HOST_INSECURE</br>
+<% end %>
diff --git a/apps/workbench/app/views/users/_manage_repositories.html.erb b/apps/workbench/app/views/users/_manage_repositories.html.erb
new file mode 100644 (file)
index 0000000..9c6fb1e
--- /dev/null
@@ -0,0 +1,36 @@
+<div>
+  <p>
+    For more information see <%= link_to raw('setting up SSH access'),
+    "#{Rails.configuration.arvados_docsite}/user/getting_started/ssh-access-unix.html", target: "_blank"%>
+  </p>
+
+  <table class="table repositories-table">
+    <colgroup>
+      <col style="width: 30%" />
+      <col style="width: 15%" />
+      <col style="width: 55%" />
+    </colgroup>
+    <thead>
+      <tr>
+        <th> Name </th>
+        <th> Writable </th>
+        <th> URL </th>
+      </tr>
+    </thead>
+    <tbody>
+      <% @my_repositories.andand.each do |repo| %>
+        <tr>
+          <td>
+            <%= repo[:name] %>
+          </td>
+          <td>
+            <%= repo[:push_url] != nil %>
+          </td>
+          <td>
+            <%= repo[:fetch_url] %>
+          </td>
+        </tr>
+      <% end %>
+    </tbody>
+  </table>
+</div>
diff --git a/apps/workbench/app/views/users/_manage_ssh_keys.html.erb b/apps/workbench/app/views/users/_manage_ssh_keys.html.erb
new file mode 100644 (file)
index 0000000..f8eec71
--- /dev/null
@@ -0,0 +1,55 @@
+<div>
+<h4>Add / Delete SSH Keys</h4>
+  <table class="table virtual-machines-table">
+    <colgroup>
+      <col style="width: 95%" />
+      <col style="width: 5%" />
+    </colgroup>
+    <tbody>
+      <% @my_ssh_keys.andand.each do |key| %>
+        <tr>
+          <td>
+            <%= key[:uuid] %>
+          </td>
+          <td>
+    <%= link_to(authorized_key_path(id: key[:uuid]), method: 'delete', class: 'btn btn-sm', data: {confirm: "Really delete key"}) do %>
+      <i class="fa fa-fw fa-trash-o"></i>
+    <% end %>
+          </td>
+        </tr>
+      <% end %>
+    </tbody>
+  </table>
+</div>
+
+<hr>
+
+<div>
+<h4>Setting up SSH keys</h4>
+<p>
+Sample <code>~/.ssh/config</code>:
+</p>
+
+<pre>
+Host *.arvados
+  ProxyCommand ssh -p2222 turnout@switchyard.<%= current_api_host || 'xyzzy.arvadosapi.com' %> -x -a $SSH_PROXY_FLAGS %h
+<% if @my_vm_logins.andand.first %>
+  User <%= @my_vm_logins[@my_vm_logins.andand.keys.first].andand.first %>
+<% end %>
+</pre>
+
+<p>
+Sample login command:
+</p>
+
+<pre>
+ssh <%= @my_virtual_machines.first.andand.hostname.andand.sub('.'+current_api_host,'') or 'vm-hostname' %>.arvados
+</pre>
+
+<p>
+  See also:
+  <%= link_to raw('Arvados Docs &rarr; User Guide &rarr; SSH access'),
+  "#{Rails.configuration.arvados_docsite}/user/getting_started/ssh-access-unix.html",
+  target: "_blank"%>.
+</p>
+</div>
diff --git a/apps/workbench/app/views/users/_manage_virtual_machines.html.erb b/apps/workbench/app/views/users/_manage_virtual_machines.html.erb
new file mode 100644 (file)
index 0000000..46310d7
--- /dev/null
@@ -0,0 +1,35 @@
+<div>
+  <p>
+    For more information see <%= link_to raw('setting up SSH access'),
+    "#{Rails.configuration.arvados_docsite}/user/getting_started/ssh-access-unix.html", target: "_blank"%>
+  </p>
+
+  <table class="table virtual-machines-table">
+    <colgroup>
+      <col style="width: 35%" />
+      <col style="width: 35%" />
+      <col style="width: 30%" />
+    </colgroup>
+    <thead>
+      <tr>
+        <th> Host name </th>
+        <th> Login name </th>
+        <th> Last login </th>
+      </tr>
+    </thead>
+    <tbody>
+      <% @my_virtual_machines.andand.each do |vm| %>
+        <tr>
+          <td>
+            <%= vm[:hostname] %>
+          </td>
+          <td>
+            <%= @my_vm_logins[vm[:uuid]].andand.compact || [] %>
+          </td>
+          <td>
+          </td>
+        </tr>
+      <% end %>
+    </tbody>
+  </table>
+</div>
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 55e2fdae364465ef07958d728e9b992b26fffa5a..1f3d65f1a88a4fc70bc2e980da38cf0b8551f59d 100644 (file)
@@ -66,6 +66,7 @@ ArvadosWorkbench::Application.routes.draw do
     get 'choose', on: :collection
     post 'share_with', on: :member
   end
+  get '/manage_account' => 'users#manage_account'
 
   post 'actions' => 'actions#post'
   get 'websockets' => 'websocket#index'