[ARVADOS] updated: 1.1.4-274-g4aa2e93
Git user
git at public.curoverse.com
Thu May 17 17:43:16 EDT 2018
Summary of changes:
.../app/controllers/link_account_controller.rb | 19 -----
apps/workbench/app/controllers/users_controller.rb | 7 +-
apps/workbench/app/models/user.rb | 39 +++++++--
apps/workbench/app/views/layouts/body.html.erb | 2 +-
.../app/views/link_account/index.html.erb | 67 ---------------
apps/workbench/app/views/users/inactive.html.erb | 5 ++
.../app/views/users/link_account.html.erb | 99 ++++++++++++++++++++++
apps/workbench/config/routes.rb | 4 +-
services/api/app/models/user.rb | 2 +-
9 files changed, 147 insertions(+), 97 deletions(-)
delete mode 100644 apps/workbench/app/controllers/link_account_controller.rb
delete mode 100644 apps/workbench/app/views/link_account/index.html.erb
create mode 100644 apps/workbench/app/views/users/link_account.html.erb
via 4aa2e9342254971e92b5836a56728015e9cfc714 (commit)
via 7046a30e466536a2e8c515b3d15f4f528c68ef7f (commit)
from 95c1923ae79a29bb8b6b9b4565b90fb95dbea363 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 4aa2e9342254971e92b5836a56728015e9cfc714
Author: Peter Amstutz <pamstutz at veritasgenetics.com>
Date: Thu May 17 17:41:01 2018 -0400
12995: Can now merge with inactive accounts.
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 at veritasgenetics.com>
diff --git a/apps/workbench/app/controllers/link_account_controller.rb b/apps/workbench/app/controllers/link_account_controller.rb
deleted file mode 100644
index da6e99b..0000000
--- a/apps/workbench/app/controllers/link_account_controller.rb
+++ /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
diff --git a/apps/workbench/app/controllers/users_controller.rb b/apps/workbench/app/controllers/users_controller.rb
index 2e3ced6..d5325d4 100644
--- a/apps/workbench/app/controllers/users_controller.rb
+++ b/apps/workbench/app/controllers/users_controller.rb
@@ -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
diff --git a/apps/workbench/app/views/layouts/body.html.erb b/apps/workbench/app/views/layouts/body.html.erb
index 9f559f7..124a785 100644
--- a/apps/workbench/app/views/layouts/body.html.erb
+++ b/apps/workbench/app/views/layouts/body.html.erb
@@ -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 %>
diff --git a/apps/workbench/app/views/users/inactive.html.erb b/apps/workbench/app/views/users/inactive.html.erb
index 389044f..f3cb3cf 100644
--- a/apps/workbench/app/views/users/inactive.html.erb
+++ b/apps/workbench/app/views/users/inactive.html.erb
@@ -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>
diff --git a/apps/workbench/app/views/link_account/index.html.erb b/apps/workbench/app/views/users/link_account.html.erb
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 bdd4104..09ce588 100644
--- a/apps/workbench/app/views/link_account/index.html.erb
+++ b/apps/workbench/app/views/users/link_account.html.erb
@@ -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 %>
@@ -55,13 +66,14 @@
<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 %>
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index 3a41a9b..718adfd 100644
--- a/apps/workbench/config/routes.rb
+++ b/apps/workbench/config/routes.rb
@@ -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'
diff --git a/services/api/app/models/user.rb b/services/api/app/models/user.rb
index 831036f..9d4c20a 100644
--- a/services/api/app/models/user.rb
+++ b/services/api/app/models/user.rb
@@ -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
commit 7046a30e466536a2e8c515b3d15f4f528c68ef7f
Author: Peter Amstutz <pamstutz at veritasgenetics.com>
Date: Thu May 17 15:45:59 2018 -0400
12995: Can merge accounts in both directions.
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 03f8257..da6e99b 100644
--- a/apps/workbench/app/controllers/link_account_controller.rb
+++ b/apps/workbench/app/controllers/link_account_controller.rb
@@ -9,7 +9,7 @@ class LinkAccountController < ApplicationController
end
def merge
- User.merge params[:new_user_token]
+ User.merge params[:new_user_token], params[:direction]
redirect_to "/"
end
diff --git a/apps/workbench/app/models/user.rb b/apps/workbench/app/models/user.rb
index 449abe7..d30b472 100644
--- a/apps/workbench/app/models/user.rb
+++ b/apps/workbench/app/models/user.rb
@@ -14,16 +14,43 @@ class User < ArvadosBase
arvados_api_client.unpack_api_response(res)
end
- def self.merge new_user_token
+ def self.merge new_user_token, direction
+ # Merge user accounts.
+ #
+ # If the direction is "in", the current user is merged into the
+ # user represented by new_user_token
+ #
+ # If the direction is "out", the user represented by new_user_token
+ # is merged into the current user.
+
+ if direction == "in"
+ user_a = new_user_token
+ user_b = Thread.current[:arvados_api_token]
+ new_group_name = "Migrated from #{Thread.current[:user].email} (#{Thread.current[:user].uuid})"
+ elsif direction == "out"
+ user_a = Thread.current[:arvados_api_token]
+ user_b = new_user_token
+ res = arvados_api_client.api self, '/current', nil, {:arvados_api_token => user_b}, false
+ user_b_info = arvados_api_client.unpack_api_response(res)
+ new_group_name = "Migrated from #{user_b_info.email} (#{user_b_info.uuid})"
+ else
+ raise "Invalid merge direction, expected 'in' or 'out'"
+ end
+
+ # Create a project owned by user_a to accept everything owned by user_b
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
+ :name => new_group_name,
+ :group_class => "project"}},
+ {:arvados_api_token => user_a}, false
target = arvados_api_client.unpack_api_response(res)
- res = arvados_api_client.api self, '/merge', {:new_user_token => new_user_token,
+ # The merge API merges the "current" user (user_b) into the user
+ # represented by "new_user_token" (user_a).
+ # After merging, the user_b redirects to user_a.
+ res = arvados_api_client.api self, '/merge', {:new_user_token => user_a,
:new_owner_uuid => target[:uuid],
- :redirect_to_new_user => true}, {}, false
+ :redirect_to_new_user => true},
+ {:arvados_api_token => user_b}, false
arvados_api_client.unpack_api_response(res)
end
diff --git a/apps/workbench/app/views/link_account/index.html.erb b/apps/workbench/app/views/link_account/index.html.erb
index 320564c..bdd4104 100644
--- a/apps/workbench/app/views/link_account/index.html.erb
+++ b/apps/workbench/app/views/link_account/index.html.erb
@@ -1,52 +1,71 @@
<%= javascript_tag do %>
function update_visibility() {
- if (sessionStorage.getItem('link_account_api_token') &&
- sessionStorage.getItem('link_account_uuid') != '<%= Thread.current[:user].uuid %>')
- {
- $("#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%>)";
-
- $("#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>");
-
- $("#new-user-token-input").val(sessionStorage.getItem('link_account_api_token'));
- } else {
+ if (sessionStorage.getItem('link_account_api_token') &&
+ sessionStorage.getItem('link_account_uuid') != '<%= Thread.current[:user].uuid %>')
+ {
+ $("#ready-to-link").css({"display": "inherit"});
+ $("#need-login").css({"display": "none"});
+
+ <% 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%>)";
+ <% 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')+")";
+ <% 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>");
+
+ $("#new-user-token-input").val(sessionStorage.getItem('link_account_api_token'));
+ } else {
+ $("#ready-to-link").css({"display": "none"});
+ $("#need-login").css({"display": "inherit"});
+ }
+
+ sessionStorage.removeItem('link_account_api_token');
+ sessionStorage.removeItem('link_account_uuid');
+ sessionStorage.removeItem('link_account_email');
+ sessionStorage.removeItem('link_account_created_at');
+ };
+
+ $(window).on("load", function() {
+ update_visibility();
+ });
+
+ 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%>');
- $("#ready-to-link").css({"display": "none"});
- $("#need-login").css({"display": "inherit"});
+ window.location.replace('<%=arvados_api_client.arvados_login_url(return_to: "#{strip_token_from_path(request.url)}?direction=")%>'+dir);
}
- };
- $(window).on("load", function() {
- update_visibility();
- });
+ $(document).on("click", "#link-account-in", function(e) { do_login("in"); });
+ $(document).on("click", "#link-account-out", function(e) { do_login("out"); });
$(document).on("click", "#cancel-link-accounts", function() {
- sessionStorage.removeItem('link_account_api_token');
- sessionStorage.removeItem('link_account_uuid');
- sessionStorage.removeItem('link_account_email');
- sessionStorage.removeItem('link_account_created_at');
- open('<%= logout_path %>');
+ window.location.replace('<%=link_account_path%>?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>
-
<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>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>
-<%= 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 %>
+ <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>
+
+ <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>
+
</p>
</div>
@@ -54,10 +73,11 @@
<div id="will-link-to"></div>
- <%= button_tag "Cancel", class: "btn btn-cancel pull-left", id: "cancel-link-accounts", style: "margin-right: 5px" %>
+ <%= button_tag "Cancel", class: "btn btn-cancel pull-left", id: "cancel-link-accounts", style: "margin-right: 1em" %>
<%= 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 %>
<i class="fa fa-fw fa-link"></i> Link accounts
<% end %>
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list