12995: Add link account page with confirmation.
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Thu, 17 May 2018 16:07:06 +0000 (12:07 -0400)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Thu, 17 May 2018 16:07:06 +0000 (12:07 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

apps/workbench/app/controllers/link_account_controller.rb [new file with mode: 0644]
apps/workbench/app/views/layouts/body.html.erb
apps/workbench/app/views/link_account/index.html.erb [new file with mode: 0644]
apps/workbench/config/routes.rb

diff --git a/apps/workbench/app/controllers/link_account_controller.rb b/apps/workbench/app/controllers/link_account_controller.rb
new file mode 100644 (file)
index 0000000..183ba1b
--- /dev/null
@@ -0,0 +1,14 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+class LinkAccountController < ApplicationController
+  skip_before_filter :find_objects_for_index
+
+  def index
+  end
+
+  def model_class
+    "User"
+  end
+end
index f4be7cad63ab282f2332235e89cd848d6bfb1771..9f559f7e108e7e343542c2a9ce0f915b6d17b995 100644 (file)
@@ -93,7 +93,8 @@ SPDX-License-Identifier: AGPL-3.0 %>
                   <%= link_to ssh_keys_user_path(current_user), role: 'menu-item' do %>
                     <i class="fa fa-lg fa-key fa-fw"></i> SSH keys
                   <% end %>
-                </li>
+</li>
+                <li role="menuitem"><a href="/link_account" role="menuitem"><i class="fa fa-lg fa-link fa-fw"></i> Link account </a></li>
                 <% if Rails.configuration.user_profile_form_fields %>
                   <li role="menuitem"><a href="/users/<%=current_user.uuid%>/profile" role="menuitem"><i class="fa fa-lg fa-user fa-fw"></i> Manage profile</a></li>
                 <% end %>
diff --git a/apps/workbench/app/views/link_account/index.html.erb b/apps/workbench/app/views/link_account/index.html.erb
new file mode 100644 (file)
index 0000000..444f965
--- /dev/null
@@ -0,0 +1,54 @@
+<%= javascript_tag do %>
+  function update_visibility() {
+  if (sessionStorage.getItem('link_account_api_token') &&
+    sessionStorage.getItem('link_account_api_token') != '<%= Thread.current[:arvados_api_token] %>')
+  {
+    $("#ready-to-link").css({"height": "auto", "visibility": "visible"});
+  $("#need-login").css({"height": "0px", "visibility": "hidden"});
+
+  var user_a = "<b>"+sessionStorage.getItem('link_account_email')+"</b> ("+sessionStorage.getItem('link_account_uuid')+")";
+  var user_b = "<b><%= Thread.current[:user].email %></b> (<%= Thread.current[:user].uuid%>)";
+
+    $("#will-link-to").html("<p>Clicking 'Link accounts' will link this account to "+
+      user_a+" created at <b>"+sessionStorage.getItem('link_account_created_at')+"</b>.</p>"+
+      "<p>After linking, logging in as "+user_b+" will put you in the account "+user_a+
+      ".</p>  <p>Any objects owned by "+user_b+" will be transferred to "+user_a+".</p>");
+  } else {
+    sessionStorage.setItem('link_account_api_token', '<%= Thread.current[:arvados_api_token] %>');
+    sessionStorage.setItem('link_account_email', '<%= Thread.current[:user].email %>');
+    sessionStorage.setItem('link_account_uuid', '<%= Thread.current[:user].uuid%>');
+    sessionStorage.setItem('link_account_created_at', '<%= Thread.current[:user].created_at%>');
+    $("#ready-to-link").css({"height": "0px", "visibility": "hidden"});
+    $("#need-login").css({"height": "auto", "visibility": "visible"});
+  }
+  };
+
+  $(window).on("load", function() {
+    update_visibility();
+  });
+
+  $(document).on("click", "#cancel-link-accounts", function() {
+    sessionStorage.removeItem('link_account_api_token');
+    update_visibility();
+  });
+<% end %>
+
+<p>You are currently logged in as <b><%= Thread.current[:user].email %></b> (<%= Thread.current[:user].uuid%>) created at <b><%= Thread.current[:user].created_at%></b></p>
+
+<div id="need-login" style="height: 0px; visibility: hidden">
+<p>If you would like to link another login to this Arvados account, please click the button below.</p>
+<p>
+<%= link_to(arvados_api_client.arvados_login_url(return_to: strip_token_from_path(request.url)),
+        {class: "btn btn-primary", id: "#link_account_button"}) do %>
+  <i class="fa fa-fw fa-sign-in"></i> Login with alternate account
+<% end %>
+</p>
+</div>
+
+<div id="ready-to-link" style="height: 0px; visibility: hidden">
+
+  <div id="will-link-to"></div>
+
+  <button class="btn btn-cancel" id="cancel-link-accounts">Cancel</button>
+  <button class="btn btn-primary">Link accounts</button>
+</div>
index d969abd78c2b69d8de936e2a00df0c0d1f1ef0f1..691c222b6fcf3df9d84134f913a50691dcb074c0 100644 (file)
@@ -109,7 +109,7 @@ ArvadosWorkbench::Application.routes.draw do
     get 'tab_counts', on: :member
     get 'public', on: :collection
   end
-  
+
   resources :search do
     get 'choose', :on => :collection
   end
@@ -125,15 +125,16 @@ ArvadosWorkbench::Application.routes.draw do
   get 'actions' => 'actions#show'
   get 'websockets' => 'websocket#index'
   post "combine_selected" => 'actions#combine_selected_files_into_collection'
+  get 'link_account' => 'link_account#index'
 
   root :to => 'projects#index'
 
   match '/_health/ping', to: 'healthcheck#ping', via: [:get]
 
   get '/tests/mithril', to: 'tests#mithril'
-  
+
   get '/status', to: 'status#status'
-  
+
   # Send unroutable requests to an arbitrary controller
   # (ends up at ApplicationController#render_not_found)
   match '*a', to: 'links#render_not_found', via: [:get, :post]