12995: Can now merge with inactive accounts.
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Thu, 17 May 2018 21:41:01 +0000 (17:41 -0400)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Thu, 17 May 2018 21:41:01 +0000 (17:41 -0400)
Checks that the remaining account is active so users don't lock
themselves out by accident.

Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

apps/workbench/app/controllers/link_account_controller.rb [deleted file]
apps/workbench/app/controllers/users_controller.rb
apps/workbench/app/views/layouts/body.html.erb
apps/workbench/app/views/users/inactive.html.erb
apps/workbench/app/views/users/link_account.html.erb [moved from apps/workbench/app/views/link_account/index.html.erb with 69% similarity]
apps/workbench/config/routes.rb
services/api/app/models/user.rb

diff --git a/apps/workbench/app/controllers/link_account_controller.rb b/apps/workbench/app/controllers/link_account_controller.rb
deleted file mode 100644 (file)
index da6e99b..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-# 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 merge
-    User.merge params[:new_user_token], params[:direction]
-    redirect_to "/"
-  end
-
-  def model_class
-    "User"
-  end
-end
index 2e3ced69a534485ca5d18df22b19ac53abeea793..d5325d477de43eb9b2318c38434eda31ec6f7a3a 100644 (file)
@@ -4,7 +4,7 @@
 
 class UsersController < ApplicationController
   skip_around_filter :require_thread_api_token, only: :welcome
-  skip_before_filter :check_user_agreements, only: [:welcome, :inactive]
+  skip_before_filter :check_user_agreements, only: [:welcome, :inactive, :link_account, :merge]
   skip_before_filter :check_user_profile, only: [:welcome, :inactive, :profile]
   skip_before_filter :find_object_by_uuid, only: [:welcome, :activity, :storage]
   before_filter :ensure_current_user_is_admin, only: [:sudo, :unsetup, :setup]
@@ -317,6 +317,11 @@ class UsersController < ApplicationController
     RequestShellAccessReporter.send_request(current_user, params).deliver
   end
 
+  def merge
+    User.merge params[:new_user_token], params[:direction]
+    redirect_to "/"
+  end
+
   protected
 
   def find_current_links user
index 9f559f7e108e7e343542c2a9ce0f915b6d17b995..124a78577f3e5cac875569c8912217d65b8fc1ce 100644 (file)
@@ -94,7 +94,7 @@ SPDX-License-Identifier: AGPL-3.0 %>
                     <i class="fa fa-lg fa-key fa-fw"></i> SSH keys
                   <% end %>
 </li>
-                <li role="menuitem"><a href="/link_account" role="menuitem"><i class="fa fa-lg fa-link fa-fw"></i> Link account </a></li>
+                <li role="menuitem"><a href="/users/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 %>
index 389044f92fc2a3ab19337ae95a0f3815950c4314..f3cb3cf5cae7d25bde0ed590a0f81c45a37447f3 100644 (file)
@@ -25,6 +25,11 @@ SPDX-License-Identifier: AGPL-3.0 %>
         <%= link_to 'Retry', (params[:return_to] || '/'), class: 'btn btn-primary' %>
 
       </p>
+
+      <p>
+       Already have an account with a different login?  <a href="/users/link_account">Link this login to your existing account.</a>
+      </p>
+
     </div>
   </div>
 </div>
similarity index 69%
rename from apps/workbench/app/views/link_account/index.html.erb
rename to apps/workbench/app/views/users/link_account.html.erb
index bdd4104c3635ecd87809faf07ec77a594981b7f5..09ce588a2f14d45887a41d3b3edda9a6da53299d 100644 (file)
@@ -9,17 +9,26 @@
       <% if params[:direction] == "in" %>
       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%>)";
+      var user_a_is_active = sessionStorage.getItem('link_account_is_active');
       <% else %>
       var user_a = "<b><%= Thread.current[:user].email %></b> (<%= Thread.current[:user].uuid%>)";
       var user_b = "<b>"+sessionStorage.getItem('link_account_email')+"</b> ("+sessionStorage.getItem('link_account_uuid')+")";
+      var user_a_is_active = <%= Thread.current[:user].is_active %>
       <% end %>
 
-      $("#will-link-to").html("<p>Clicking 'Link accounts' will link "+user_b+" created on <%=Thread.current[:user].created_at%> to "+
-        user_a+" created at <b>"+sessionStorage.getItem('link_account_created_at')+"</b>.</p>"+
-        "<p>After linking, logging in as "+user_b+" will log you into the same account as "+user_a+
-        ".</p>  <p>Any objects owned by "+user_b+" will be transferred to "+user_a+".</p>");
+      console.log("User a "+user_a_is_active);
 
       $("#new-user-token-input").val(sessionStorage.getItem('link_account_api_token'));
+
+      if (user_a_is_active) {
+        $("#will-link-to").html("<p>Clicking 'Link accounts' will link "+user_b+" created on <%=Thread.current[:user].created_at%> to "+
+          user_a+" created at <b>"+sessionStorage.getItem('link_account_created_at')+"</b>.</p>"+
+          "<p>After linking, logging in as "+user_b+" will log you into the same account as "+user_a+
+          ".</p>  <p>Any objects owned by "+user_b+" will be transferred to "+user_a+".</p>");
+      } else {
+        $("#will-link-to").html("<p>Cannot link "+user_b+" to inactive account "+user_a+".</p>");
+        $("#link-account-submit").prop("disabled", true);
+      }
     } else {
       $("#ready-to-link").css({"display": "none"});
       $("#need-login").css({"display": "inherit"});
@@ -29,6 +38,7 @@
     sessionStorage.removeItem('link_account_uuid');
     sessionStorage.removeItem('link_account_email');
     sessionStorage.removeItem('link_account_created_at');
+    sessionStorage.removeItem('link_account_is_active');
   };
 
   $(window).on("load", function() {
@@ -38,8 +48,9 @@
   function do_login(dir) {
     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%>');
+    sessionStorage.setItem('link_account_uuid', '<%= Thread.current[:user].uuid %>');
+    sessionStorage.setItem('link_account_created_at', '<%= Thread.current[:user].created_at %>');
+    sessionStorage.setItem('link_account_is_active', <%= if Thread.current[:user].is_active then "true" else "false" end %>);
     window.location.replace('<%=arvados_api_client.arvados_login_url(return_to: "#{strip_token_from_path(request.url)}?direction=")%>'+dir);
   }
 
@@ -47,7 +58,7 @@
   $(document).on("click", "#link-account-out", function(e) { do_login("out"); });
 
   $(document).on("click", "#cancel-link-accounts", function() {
-    window.location.replace('<%=link_account_path%>?api_token='+$("#new-user-token-input").val());
+    window.location.replace('/users/link_account?api_token='+$("#new-user-token-input").val());
   });
 <% 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>
 
-<p>You can link two Arvados accounts.  After linking, either login will take you to the same account.  Please choose one of the options below:</p>
+<p>You can link Arvados accounts.  After linking, either login will take you to the same account.</p>
 
-<p>
+  <p>
+    <% if Thread.current[:user].is_active %>
   <button class="btn btn-primary" id="link-account-in" style="margin-right: 1em">
     <i class="fa fa-fw fa-sign-in"></i> Add another login to this account
   </button>
-
+  <% end %>
   <button class="btn btn-primary" id="link-account-out" style="margin-right: 1em">
     <i class="fa fa-fw fa-sign-in"></i> Use this login to access another account
   </button>
@@ -78,7 +90,7 @@
   <%= form_tag do |f| %>
     <input type="hidden" id="new-user-token-input" name="new_user_token" value="" />
     <input type="hidden" id="new-user-token-input" name="direction" value="<%=params[:direction]%>" />
-    <%= button_tag class: "btn btn-primary" do %>
+    <%= button_tag class: "btn btn-primary", id: "link-account-submit" do %>
       <i class="fa fa-fw fa-link"></i> Link accounts
   <% end %>
 <% end %>
index 3a41a9b40bfbd1e649665b5c9757c73457b86383..718adfd2ed0583a99f8eebb221b5eae0c7d012c3 100644 (file)
@@ -65,6 +65,8 @@ ArvadosWorkbench::Application.routes.draw do
     get 'virtual_machines', :on => :member
     get 'repositories', :on => :member
     get 'ssh_keys', :on => :member
+    get 'link_account', :on => :collection
+    post 'link_account', :on => :collection, :action => :merge
   end
   get '/current_token' => 'users#current_token'
   get "/add_ssh_key_popup" => 'users#add_ssh_key_popup', :as => :add_ssh_key_popup
@@ -125,8 +127,6 @@ 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'
-  post 'link_account' => 'link_account#merge'
 
   root :to => 'projects#index'
 
index 831036fd9d9cd722e7e84aa668bb75d5e111d6fc..9d4c20af9faaa1ff7076fdcd0bd8d0348324e4ef 100644 (file)
@@ -414,7 +414,7 @@ class User < ArvadosModel
     end
     if self.is_active_changed?
       if self.is_active != self.is_active_was
-        logger.warn "User #{current_user.uuid} tried to change is_active from #{self.is_admin_was} to #{self.is_admin} for #{self.uuid}"
+        logger.warn "User #{current_user.uuid} tried to change is_active from #{self.is_active_was} to #{self.is_active} for #{self.uuid}"
         self.is_active = self.is_active_was
       end
     end