[ARVADOS] created: 1.1.4-272-g95c1923

Git user git at public.curoverse.com
Thu May 17 13:00:52 EDT 2018


        at  95c1923ae79a29bb8b6b9b4565b90fb95dbea363 (commit)


commit 95c1923ae79a29bb8b6b9b4565b90fb95dbea363
Author: Peter Amstutz <pamstutz at veritasgenetics.com>
Date:   Thu May 17 13:00:36 2018 -0400

    12995: Linking alternate login works.
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz at veritasgenetics.com>

diff --git a/apps/workbench/app/controllers/link_account_controller.rb b/apps/workbench/app/controllers/link_account_controller.rb
index 183ba1b..03f8257 100644
--- a/apps/workbench/app/controllers/link_account_controller.rb
+++ b/apps/workbench/app/controllers/link_account_controller.rb
@@ -8,6 +8,11 @@ class LinkAccountController < ApplicationController
   def index
   end
 
+  def merge
+    User.merge params[:new_user_token]
+    redirect_to "/"
+  end
+
   def model_class
     "User"
   end
diff --git a/apps/workbench/app/models/user.rb b/apps/workbench/app/models/user.rb
index 1f102db..449abe7 100644
--- a/apps/workbench/app/models/user.rb
+++ b/apps/workbench/app/models/user.rb
@@ -14,6 +14,19 @@ class User < ArvadosBase
     arvados_api_client.unpack_api_response(res)
   end
 
+  def self.merge new_user_token
+    res = arvados_api_client.api Group, nil, {:group => {
+                                                     :name => "Migrated from #{Thread.current[:user].email} (#{Thread.current[:user].uuid})",
+                                                     :group_class => "project"}},
+                                 {:arvados_api_token => new_user_token}, false
+    target = arvados_api_client.unpack_api_response(res)
+
+    res = arvados_api_client.api self, '/merge', {:new_user_token => new_user_token,
+                                                  :new_owner_uuid => target[:uuid],
+                                                  :redirect_to_new_user => true}, {}, false
+    arvados_api_client.unpack_api_response(res)
+  end
+
   def self.system
     @@arvados_system_user ||= begin
                                 res = arvados_api_client.api self, '/system'
diff --git a/apps/workbench/app/views/link_account/index.html.erb b/apps/workbench/app/views/link_account/index.html.erb
index 444f965..320564c 100644
--- a/apps/workbench/app/views/link_account/index.html.erb
+++ b/apps/workbench/app/views/link_account/index.html.erb
@@ -1,10 +1,10 @@
 <%= javascript_tag do %>
   function update_visibility() {
   if (sessionStorage.getItem('link_account_api_token') &&
-    sessionStorage.getItem('link_account_api_token') != '<%= Thread.current[:arvados_api_token] %>')
+    sessionStorage.getItem('link_account_uuid') != '<%= Thread.current[:user].uuid %>')
   {
-    $("#ready-to-link").css({"height": "auto", "visibility": "visible"});
-  $("#need-login").css({"height": "0px", "visibility": "hidden"});
+    $("#ready-to-link").css({"display": "inherit"});
+    $("#need-login").css({"display": "none"});
 
   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%>)";
@@ -12,14 +12,16 @@
     $("#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>");
+    ".</p>  <p>Any objects owned by "+user_b+" will be transferred to "+user_a+".</p>");
+
+    $("#new-user-token-input").val(sessionStorage.getItem('link_account_api_token'));
   } 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"});
+    $("#ready-to-link").css({"display": "none"});
+    $("#need-login").css({"display": "inherit"});
   }
   };
 
@@ -29,13 +31,16 @@
 
   $(document).on("click", "#cancel-link-accounts", function() {
     sessionStorage.removeItem('link_account_api_token');
-    update_visibility();
+    sessionStorage.removeItem('link_account_uuid');
+    sessionStorage.removeItem('link_account_email');
+    sessionStorage.removeItem('link_account_created_at');
+    open('<%= logout_path %>');
   });
 <% 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">
+<div id="need-login" style="display: none">
 <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)),
@@ -45,10 +50,18 @@
 </p>
 </div>
 
-<div id="ready-to-link" style="height: 0px; visibility: hidden">
+<div id="ready-to-link" style="display: none">
 
   <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>
+  <%= button_tag "Cancel", class: "btn btn-cancel pull-left", id: "cancel-link-accounts", style: "margin-right: 5px" %>
+
+  <%= form_tag do |f| %>
+    <input type="hidden" id="new-user-token-input" name="new_user_token" value="" />
+    <%= button_tag class: "btn btn-primary" do %>
+      <i class="fa fa-fw fa-link"></i> Link accounts
+  <% end %>
+<% end %>
+
+</div>
 </div>
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index 691c222..3a41a9b 100644
--- a/apps/workbench/config/routes.rb
+++ b/apps/workbench/config/routes.rb
@@ -126,6 +126,7 @@ ArvadosWorkbench::Application.routes.draw do
   get 'websockets' => 'websocket#index'
   post "combine_selected" => 'actions#combine_selected_files_into_collection'
   get 'link_account' => 'link_account#index'
+  post 'link_account' => 'link_account#merge'
 
   root :to => 'projects#index'
 

commit cb913fbdfdf7a17fc01e28967281e03f371a4890
Author: Peter Amstutz <pamstutz at veritasgenetics.com>
Date:   Thu May 17 12:07:06 2018 -0400

    12995: Add link account page with confirmation.
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz at veritasgenetics.com>

diff --git a/apps/workbench/app/controllers/link_account_controller.rb b/apps/workbench/app/controllers/link_account_controller.rb
new file mode 100644
index 0000000..183ba1b
--- /dev/null
+++ b/apps/workbench/app/controllers/link_account_controller.rb
@@ -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
diff --git a/apps/workbench/app/views/layouts/body.html.erb b/apps/workbench/app/views/layouts/body.html.erb
index f4be7ca..9f559f7 100644
--- a/apps/workbench/app/views/layouts/body.html.erb
+++ b/apps/workbench/app/views/layouts/body.html.erb
@@ -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
index 0000000..444f965
--- /dev/null
+++ b/apps/workbench/app/views/link_account/index.html.erb
@@ -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>
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index d969abd..691c222 100644
--- a/apps/workbench/config/routes.rb
+++ b/apps/workbench/config/routes.rb
@@ -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]

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list