mirror of
https://github.com/google/nomulus.git
synced 2025-07-22 18:55:58 +02:00
This is an intermediate CL, part of the Registrar Console cleanup. TL;DR: - the current state: resource.js points to a resource TYPE on the server (only registrars can be resources right now), but the specific resource is selected based on the user (we select the "first resource of this type that the user has access to) - new state: resource.js points to a SPECIFIC resource (TYPE + ID). In this CL the server still chooses the resource like before (first one that user has access to) but we make sure the returned resource is the same one we requested. In a subsequent CL we will use the requested ID to load the resource, and then make sure the user has access to that resource. --------------------------- When loading the RegistrarConsole HTML page, the server determines which clientId belongs to the user ("guesses" it by looking for the first registrar that has this user as contact). It sends the relevant clientId back with the page load. However, this information isn't currently used in the JS requests to read / update the registrar. Instead, currently the client ID is guessed again for each JS access to the server. It is also saved again in the client's "session" cookie. As a result, it is theoretically possible to have the JS access a different clientID than the original page load (not likely, since it requires a single user registered for multiple registrars AND that the contacts change for the original registrar). So our goal is to only have a single clientID "value" instead of the 3 we currently have for JS requests (the one from the initial page load, the one saved in the session cookie, the one guessed on the JS request) As a first step, we send over the "initial page load" clientId on every JS request, and make sure the "session + guessed" value is equal to that one. Later we will remove the "session+guessed" values from the RegistrarSettings, using the "initial page load" clientID instead. In addition to the "nicer code" implications, having the clientID from the initial page load always used means it'll be easy to have a clientID selection option for users who have access to multiple clientIDs (such as admins) SECURITY NOTE:the choice of clientID has no security implication since we make sure the user has access to the clientID no matter how we actually choose the clientID on every single server request. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=214459506
174 lines
5.5 KiB
JavaScript
174 lines
5.5 KiB
JavaScript
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
goog.provide('registry.registrar.Console');
|
|
|
|
goog.require('goog.Uri');
|
|
goog.require('goog.dispose');
|
|
goog.require('goog.dom');
|
|
goog.require('goog.dom.classlist');
|
|
goog.require('goog.net.XhrIo');
|
|
goog.require('registry.Console');
|
|
goog.require('registry.Resource');
|
|
goog.require('registry.registrar.Contact');
|
|
goog.require('registry.registrar.ContactSettings');
|
|
goog.require('registry.registrar.ContactUs');
|
|
goog.require('registry.registrar.Dashboard');
|
|
goog.require('registry.registrar.Domain');
|
|
goog.require('registry.registrar.EppSession');
|
|
goog.require('registry.registrar.Host');
|
|
goog.require('registry.registrar.Resources');
|
|
goog.require('registry.registrar.SecuritySettings');
|
|
goog.require('registry.registrar.WhoisSettings');
|
|
goog.require('registry.util');
|
|
|
|
goog.forwardDeclare('registry.Component');
|
|
|
|
|
|
|
|
/**
|
|
* The Registrar Console.
|
|
* @param {!Object} params Parameters to be passed into templates. These are
|
|
* a combination of configurable parameters (e.g. phone number) and
|
|
* user/session/registrar specific parameters. See
|
|
* registrar/Console.soy#.main for expected contents.
|
|
* @constructor
|
|
* @extends {registry.Console}
|
|
* @final
|
|
*/
|
|
registry.registrar.Console = function(params) {
|
|
/**
|
|
* @type {!Object}
|
|
*/
|
|
// We have to define this before creating an EppSession because EppSession's
|
|
// constructor expects us to have it as an attribute.
|
|
this.params = params;
|
|
|
|
registry.registrar.Console.base(
|
|
this, 'constructor', new registry.registrar.EppSession(this));
|
|
|
|
/**
|
|
* Component that's currently embedded in the page.
|
|
* @type {?registry.Component}
|
|
* @private
|
|
*/
|
|
this.component_ = null;
|
|
|
|
// XXX: This was in parent ctor but was triggering event dispatching before
|
|
// ready here.
|
|
this.history.setEnabled(true);
|
|
|
|
/**
|
|
* Last active nav element.
|
|
* @type {Element}
|
|
*/
|
|
this.lastActiveNavElt;
|
|
|
|
/**
|
|
* @type {!Object.<string, function(new:registry.Component,
|
|
* !registry.registrar.Console,
|
|
* !registry.Resource)>}
|
|
*/
|
|
this.pageMap = {};
|
|
this.pageMap['security-settings'] = registry.registrar.SecuritySettings;
|
|
this.pageMap['contact-settings'] = registry.registrar.ContactSettings;
|
|
this.pageMap['whois-settings'] = registry.registrar.WhoisSettings;
|
|
this.pageMap['contact-us'] = registry.registrar.ContactUs;
|
|
this.pageMap['resources'] = registry.registrar.Resources;
|
|
this.pageMap['contact'] = registry.registrar.Contact;
|
|
this.pageMap['domain'] = registry.registrar.Domain;
|
|
this.pageMap['host'] = registry.registrar.Host;
|
|
this.pageMap[''] = registry.registrar.Dashboard;
|
|
};
|
|
goog.inherits(registry.registrar.Console, registry.Console);
|
|
|
|
|
|
/**
|
|
* Changes the content area depending on hash path.
|
|
*
|
|
* <p>Hash path is expected to be of the form:
|
|
*
|
|
* <pre>
|
|
* #type/id
|
|
* </pre>
|
|
*
|
|
* <p>The `id` part may be appended by `()` to specify that the target
|
|
* should be a resource create page.
|
|
*
|
|
* @override
|
|
*/
|
|
registry.registrar.Console.prototype.handleHashChange = function() {
|
|
var hashToken = this.history.getToken();
|
|
// On page reloads, opening a new tab, etc. it's possible that the
|
|
// session cookie for a logged-in session exists, but the
|
|
// this.session is not yet aware, so come back here after syncing.
|
|
//
|
|
// XXX: Method should be refactored to avoid this 2-stage behavior.
|
|
if (!this.session.isEppLoggedIn()) {
|
|
this.session.login(goog.bind(this.handleHashChange, this));
|
|
return;
|
|
}
|
|
|
|
// Otherwise, a resource operation.
|
|
var parts = hashToken.split('/');
|
|
var type = '';
|
|
var id = '';
|
|
if (parts.length >= 1) {
|
|
type = parts[0];
|
|
}
|
|
if (parts.length == 2) {
|
|
id = parts[1];
|
|
}
|
|
|
|
goog.net.XhrIo.cleanup();
|
|
|
|
var componentCtor = this.pageMap[type];
|
|
if (componentCtor == undefined) {
|
|
componentCtor = this.pageMap[''];
|
|
}
|
|
var oldComponent = this.component_;
|
|
const resource = new registry.Resource(
|
|
new goog.Uri('/registrar-settings'), this.params.clientId,
|
|
this.params.xsrfToken);
|
|
this.component_ = new componentCtor(this, resource);
|
|
this.registerDisposable(this.component_);
|
|
this.component_.basePath = type;
|
|
this.component_.bindToDom(id);
|
|
|
|
this.changeNavStyle();
|
|
|
|
goog.dispose(oldComponent);
|
|
};
|
|
|
|
|
|
/** Change nav style. */
|
|
registry.registrar.Console.prototype.changeNavStyle = function() {
|
|
var hashToken = this.history.getToken();
|
|
// Path except id
|
|
var slashNdx = hashToken.lastIndexOf('/');
|
|
slashNdx = slashNdx == -1 ? hashToken.length : slashNdx;
|
|
var regNavlist = goog.dom.getRequiredElement('reg-navlist');
|
|
var path = hashToken.substring(0, slashNdx);
|
|
var active = regNavlist.querySelector('a[href="/registrar#' + path + '"]');
|
|
if (goog.isNull(active)) {
|
|
registry.util.log('Unknown path or path form in changeNavStyle.');
|
|
return;
|
|
}
|
|
if (this.lastActiveNavElt) {
|
|
goog.dom.classlist.remove(
|
|
this.lastActiveNavElt, goog.getCssName('domain-active-nav'));
|
|
}
|
|
goog.dom.classlist.add(active, goog.getCssName('domain-active-nav'));
|
|
this.lastActiveNavElt = active;
|
|
};
|