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]
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
<% 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"});
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() {
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);
}
$(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>
<%= 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 %>
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
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'