%# Copyright (C) The Arvados Authors. All rights reserved. SPDX-License-Identifier: AGPL-3.0 %> <%= 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"}); <% if params[:direction] == "in" %> var user_a = ""+sessionStorage.getItem('link_account_email')+" ("+sessionStorage.getItem('link_account_username')+", "+sessionStorage.getItem('link_account_uuid')+")"; var user_b = "<%= Thread.current[:user].email %> (<%= Thread.current[:user].username%>, <%= Thread.current[:user].uuid%>)"; var user_a_is_active = (sessionStorage.getItem('link_account_is_active') == "true"); var user_a_is_admin = (sessionStorage.getItem('link_account_is_admin') == "true"); var user_b_is_admin = <%=if Thread.current[:user].is_admin then "true" else "false" end %>; <% else %> var user_a = "<%= Thread.current[:user].email %> (<%= Thread.current[:user].username%>, <%= Thread.current[:user].uuid%>)"; var user_b = ""+sessionStorage.getItem('link_account_email')+" ("+sessionStorage.getItem('link_account_username')+", "+sessionStorage.getItem('link_account_uuid')+")"; var user_a_is_active = <%= Thread.current[:user].is_active %>; var user_a_is_admin = <%=if Thread.current[:user].is_admin then "true" else "false" end %>; var user_b_is_admin = (sessionStorage.getItem('link_account_is_admin') == "true"); <% end %> $("#new-user-token-input").val(sessionStorage.getItem('link_account_api_token')); if (!user_a_is_active) { $("#will-link-to").html("
Cannot link "+user_b+" to inactive account "+user_a+".
"); $("#link-account-submit").prop("disabled", true); } else if (user_b_is_admin && !user_a_is_admin) { $("#will-link-to").html("Cannot link admin account "+user_b+" to non-admin account "+user_a+".
"); $("#link-account-submit").prop("disabled", true); } else { $("#will-link-to").html("Clicking 'Link accounts' will link "+user_b+" created on <%=Thread.current[:user].created_at%> to "+ user_a+" created at "+sessionStorage.getItem('link_account_created_at')+".
"+ "After linking, logging in as "+user_b+" will log you into the same account as "+user_a+ ".
Any objects owned by "+user_b+" will be transferred to "+user_a+".
"); } } 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_username'); sessionStorage.removeItem('link_account_created_at'); sessionStorage.removeItem('link_account_is_active'); sessionStorage.removeItem('link_account_is_admin'); }; $(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_username', '<%= Thread.current[:user].username %>'); 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 %>); sessionStorage.setItem('link_account_is_admin', <%= if Thread.current[:user].is_admin then "true" else "false" end %>); window.location.replace('<%=arvados_api_client.arvados_logout_url(return_to: arvados_api_client.arvados_login_url(return_to: "#{strip_token_from_path(request.url)}?direction="))%>'+dir); } $(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() { window.location.replace('/users/link_account?api_token='+$("#new-user-token-input").val()); }); <% end %>