mirror of
https://github.com/google/nomulus.git
synced 2025-07-12 14:08:18 +02:00
Implement "premium price ack required" checkbox
Implement a checkbox in the "Resources" tab to allow registrars to toggle their "premium price ack required" flag. Tested: Verfied the console functionality by hand. I've started work on an automated test, but we can't actually test those from blaze and the kokoro tests are way too time-consuming to be practical for development, so we're going to have to either find a way to run those locally outside of the normal process or make do without a test. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=190212177
This commit is contained in:
parent
f47965d5f6
commit
785225fc28
22 changed files with 423 additions and 50 deletions
|
@ -49,6 +49,18 @@
|
|||
<url-pattern>/registrar-settings</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!--
|
||||
Registrar Self-serve console to support updating the premium price ack
|
||||
flag. Ideally, this should be handled by /registrar-settings (above), but
|
||||
unfortunately the console is broken and registrar-settings doesn't support
|
||||
this use-case as it requires fields that are not universally sent during
|
||||
updates.
|
||||
-->
|
||||
<servlet-mapping>
|
||||
<servlet-name>frontend-servlet</servlet-name>
|
||||
<url-pattern>/registrar-premium-price-ack</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- HTTP WHOIS. -->
|
||||
<servlet-mapping>
|
||||
<servlet-name>frontend-servlet</servlet-name>
|
||||
|
|
|
@ -615,6 +615,7 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
|
|||
.put("emailAddress", emailAddress)
|
||||
.put("whoisServer", getWhoisServer())
|
||||
.put("blockPremiumNames", blockPremiumNames)
|
||||
.put("premiumPriceAckRequired", premiumPriceAckRequired)
|
||||
.put("url", url)
|
||||
.put("referralUrl", getReferralUrl())
|
||||
.put("icannReferralEmail", getIcannReferralEmail())
|
||||
|
|
|
@ -40,6 +40,7 @@ import google.registry.request.RequestScope;
|
|||
import google.registry.ui.server.registrar.ConsoleUiAction;
|
||||
import google.registry.ui.server.registrar.RegistrarPaymentAction;
|
||||
import google.registry.ui.server.registrar.RegistrarPaymentSetupAction;
|
||||
import google.registry.ui.server.registrar.RegistrarPremiumPriceAckAction;
|
||||
import google.registry.ui.server.registrar.RegistrarSettingsAction;
|
||||
import google.registry.whois.WhoisHttpServer;
|
||||
import google.registry.whois.WhoisModule;
|
||||
|
@ -66,6 +67,7 @@ interface FrontendRequestComponent {
|
|||
RdapAutnumAction rdapAutnumAction();
|
||||
RegistrarPaymentAction registrarPaymentAction();
|
||||
RegistrarPaymentSetupAction registrarPaymentSetupAction();
|
||||
RegistrarPremiumPriceAckAction registrarPremiumPriceAckAction();
|
||||
RegistrarSettingsAction registrarSettingsAction();
|
||||
RdapDomainAction rdapDomainAction();
|
||||
RdapDomainSearchAction rdapDomainSearchAction();
|
||||
|
|
|
@ -84,7 +84,8 @@ registry.json.Response.prototype.results;
|
|||
* localizedAddress: registry.json.RegistrarAddress,
|
||||
* whoisServer: (string?|undefined),
|
||||
* referralUrl: (string?|undefined),
|
||||
* contacts: !Array.<registry.json.RegistrarContact>
|
||||
* contacts: !Array.<registry.json.RegistrarContact>,
|
||||
* premiumPriceAckRequired: boolean
|
||||
* }}
|
||||
*/
|
||||
registry.json.Registrar;
|
||||
|
|
|
@ -37,7 +37,7 @@ registry.registrar.Resources = function(console, xsrfToken) {
|
|||
this,
|
||||
'constructor',
|
||||
console,
|
||||
new registry.Resource(new goog.Uri('/registrar-settings'), xsrfToken),
|
||||
new registry.Resource(new goog.Uri('/registrar-premium-price-ack'), xsrfToken),
|
||||
registry.soy.registrar.console.resources,
|
||||
null);
|
||||
};
|
||||
|
@ -47,6 +47,6 @@ goog.inherits(registry.registrar.Resources,
|
|||
|
||||
/** @override */
|
||||
registry.registrar.Resources.prototype.bindToDom = function(id) {
|
||||
registry.registrar.Resources.base(this, 'bindToDom', '');
|
||||
goog.dom.removeChildren(goog.dom.getRequiredElement('reg-app-buttons'));
|
||||
registry.registrar.Resources.base(this, 'bindToDom', 'fake');
|
||||
goog.dom.removeNode(goog.dom.getRequiredElement('reg-app-btn-back'));
|
||||
};
|
||||
|
|
|
@ -315,6 +315,9 @@ public final class RegistrarFormFields {
|
|||
L10N_STREET_FIELD, L10N_CITY_FIELD, L10N_STATE_FIELD, L10N_ZIP_FIELD))
|
||||
.build();
|
||||
|
||||
public static final FormField<Boolean, Boolean> PREMIUM_PRICE_ACK_REQUIRED =
|
||||
FormField.named("premiumPriceAckRequired", Boolean.class).build();
|
||||
|
||||
private static Function<Map<String, ?>, RegistrarAddress> newAddressTransform(
|
||||
final FormField<List<String>, List<String>> streetField,
|
||||
final FormField<String, String> cityField,
|
||||
|
|
|
@ -138,6 +138,7 @@ public final class ConsoleUiAction implements Runnable {
|
|||
data.put("xsrfToken", xsrfTokenManager.generateToken(userAuthInfo.user().getEmail()));
|
||||
data.put("clientId", clientId);
|
||||
data.put("showPaymentLink", registrar.getBillingMethod() == Registrar.BillingMethod.BRAINTREE);
|
||||
data.put("requireFeeExtension", registrar.getPremiumPriceAckRequired());
|
||||
|
||||
String payload = TOFU_SUPPLIER.get()
|
||||
.newRenderer(ConsoleSoyInfo.MAIN)
|
||||
|
|
|
@ -157,7 +157,7 @@ public final class RegistrarPaymentAction implements Runnable, JsonAction {
|
|||
|
||||
@Override
|
||||
public Map<String, Object> handleJsonRequest(Map<String, ?> json) {
|
||||
Registrar registrar = sessionUtils.getRegistrarForAuthResult(request, authResult);
|
||||
Registrar registrar = sessionUtils.getRegistrarForAuthResult(request, authResult, false);
|
||||
logger.infofmt("Processing payment: %s", json);
|
||||
String paymentMethodNonce;
|
||||
Money amount;
|
||||
|
|
|
@ -91,7 +91,7 @@ public final class RegistrarPaymentSetupAction implements Runnable, JsonAction {
|
|||
|
||||
@Override
|
||||
public Map<String, Object> handleJsonRequest(Map<String, ?> json) {
|
||||
Registrar registrar = sessionUtils.getRegistrarForAuthResult(request, authResult);
|
||||
Registrar registrar = sessionUtils.getRegistrarForAuthResult(request, authResult, false);
|
||||
|
||||
if (!json.isEmpty()) {
|
||||
return JsonResponseHelper.create(ERROR, "JSON request object must be empty");
|
||||
|
|
|
@ -0,0 +1,170 @@
|
|||
// 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.
|
||||
|
||||
package google.registry.ui.server.registrar;
|
||||
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.security.JsonResponseHelper.Status.ERROR;
|
||||
import static google.registry.security.JsonResponseHelper.Status.SUCCESS;
|
||||
import static google.registry.ui.server.registrar.RegistrarSettingsAction.ARGS_PARAM;
|
||||
import static google.registry.ui.server.registrar.RegistrarSettingsAction.OP_PARAM;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.export.sheet.SyncRegistrarsSheetAction;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.request.Action;
|
||||
import google.registry.request.HttpException.BadRequestException;
|
||||
import google.registry.request.JsonActionRunner;
|
||||
import google.registry.request.auth.Auth;
|
||||
import google.registry.request.auth.AuthResult;
|
||||
import google.registry.security.JsonResponseHelper;
|
||||
import google.registry.ui.forms.FormException;
|
||||
import google.registry.ui.forms.FormFieldException;
|
||||
import google.registry.ui.server.RegistrarFormFields;
|
||||
import google.registry.util.CollectionUtils;
|
||||
import google.registry.util.DiffUtils;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* Action handler for toggling the "Premium Price Ack Required" flag.
|
||||
*
|
||||
* <p>This class exists to supplement RegistrarSettings, which is supposed to take care of
|
||||
* everything but mostly doesn't work.
|
||||
*/
|
||||
@Action(
|
||||
path = RegistrarPremiumPriceAckAction.PATH,
|
||||
method = Action.Method.POST,
|
||||
auth = Auth.AUTH_PUBLIC_LOGGED_IN
|
||||
)
|
||||
public class RegistrarPremiumPriceAckAction implements Runnable, JsonActionRunner.JsonAction {
|
||||
public static final String PATH = "/registrar-premium-price-ack";
|
||||
|
||||
@Inject AuthResult authResult;
|
||||
@Inject HttpServletRequest request;
|
||||
@Inject JsonActionRunner jsonActionRunner;
|
||||
@Inject SendEmailUtils sendEmailUtils;
|
||||
@Inject SessionUtils sessionUtils;
|
||||
|
||||
@Inject
|
||||
@Config("registrarChangesNotificationEmailAddresses")
|
||||
ImmutableList<String> registrarChangesNotificationEmailAddresses;
|
||||
|
||||
@Inject
|
||||
RegistrarPremiumPriceAckAction() {}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
jsonActionRunner.run(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> handleJsonRequest(Map<String, ?> input) {
|
||||
if (input == null) {
|
||||
throw new BadRequestException("Malformed JSON");
|
||||
}
|
||||
|
||||
// Get the registrar
|
||||
Registrar initialRegistrar = sessionUtils.getRegistrarForAuthResult(request, authResult, true);
|
||||
|
||||
// Process the operation. Though originally derived from a CRUD handler, registrar-settings
|
||||
// and registrar-premium-price-action really only support read and update.
|
||||
String op = Optional.ofNullable((String) input.get(OP_PARAM)).orElse("read");
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> args =
|
||||
(Map<String, Object>)
|
||||
Optional.<Object>ofNullable(input.get(ARGS_PARAM)).orElse(ImmutableMap.of());
|
||||
try {
|
||||
switch (op) {
|
||||
case "update":
|
||||
return update(args, initialRegistrar);
|
||||
case "read":
|
||||
// Though this class only exists to support update of the premiumPriceAckRequired flag,
|
||||
// "read" gives back a javascript representation of the entire registrar object to support
|
||||
// the architecture of the console.
|
||||
return JsonResponseHelper.create(SUCCESS, "Success", initialRegistrar.toJsonMap());
|
||||
default:
|
||||
return JsonResponseHelper.create(ERROR, "Unknown or unsupported operation: " + op);
|
||||
}
|
||||
} catch (FormFieldException e) {
|
||||
return JsonResponseHelper.createFormFieldError(e.getMessage(), e.getFieldName());
|
||||
} catch (FormException e) {
|
||||
return JsonResponseHelper.create(ERROR, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> update(final Map<String, ?> args, final Registrar registrar) {
|
||||
final String clientId = sessionUtils.getRegistrarClientId(request);
|
||||
return ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
// Verify that the registrar hasn't been changed.
|
||||
Optional<Registrar> latest = Registrar.loadByClientId(registrar.getClientId());
|
||||
if (!latest.isPresent()
|
||||
|| latest.get().getPremiumPriceAckRequired()
|
||||
!= registrar.getPremiumPriceAckRequired()) {
|
||||
return JsonResponseHelper.create(
|
||||
ERROR,
|
||||
"Premium price ack has changed (or registrar no longer exists). "
|
||||
+ "Please reload.");
|
||||
}
|
||||
Registrar reg = latest.get();
|
||||
|
||||
Optional<Boolean> premiumPriceAckRequired =
|
||||
RegistrarFormFields.PREMIUM_PRICE_ACK_REQUIRED.extractUntyped(args);
|
||||
if (premiumPriceAckRequired.isPresent()
|
||||
&& premiumPriceAckRequired.get() != reg.getPremiumPriceAckRequired()) {
|
||||
Registrar updatedRegistrar =
|
||||
reg.asBuilder()
|
||||
.setPremiumPriceAckRequired(premiumPriceAckRequired.get())
|
||||
.build();
|
||||
ofy().save().entity(updatedRegistrar);
|
||||
sendExternalUpdatesIfNecessary(reg, updatedRegistrar);
|
||||
return JsonResponseHelper.create(
|
||||
SUCCESS, "Saved " + clientId, updatedRegistrar.toJsonMap());
|
||||
} else {
|
||||
return JsonResponseHelper.create(SUCCESS, "Unchanged " + clientId, reg.toJsonMap());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void sendExternalUpdatesIfNecessary(
|
||||
Registrar existingRegistrar, Registrar updatedRegistrar) {
|
||||
if (registrarChangesNotificationEmailAddresses.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<?, ?> diffs =
|
||||
DiffUtils.deepDiff(
|
||||
existingRegistrar.toDiffableFieldMap(), updatedRegistrar.toDiffableFieldMap(), true);
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<String> changedKeys = (Set<String>) diffs.keySet();
|
||||
if (CollectionUtils.difference(changedKeys, "lastUpdateTime").isEmpty()) {
|
||||
return;
|
||||
}
|
||||
SyncRegistrarsSheetAction.enqueueBackendTask();
|
||||
if (!registrarChangesNotificationEmailAddresses.isEmpty()) {
|
||||
sendEmailUtils.sendEmail(
|
||||
registrarChangesNotificationEmailAddresses,
|
||||
String.format("Registrar %s updated", existingRegistrar.getRegistrarName()),
|
||||
"The following changes were made to the registrar:\n"
|
||||
+ DiffUtils.prettyPrintDiffedMap(diffs, null));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -67,8 +67,8 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
|
|||
|
||||
public static final String PATH = "/registrar-settings";
|
||||
|
||||
private static final String OP_PARAM = "op";
|
||||
private static final String ARGS_PARAM = "args";
|
||||
static final String OP_PARAM = "op";
|
||||
static final String ARGS_PARAM = "args";
|
||||
|
||||
@Inject HttpServletRequest request;
|
||||
@Inject JsonActionRunner jsonActionRunner;
|
||||
|
@ -93,7 +93,7 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
|
|||
throw new BadRequestException("Malformed JSON");
|
||||
}
|
||||
|
||||
Registrar initialRegistrar = sessionUtils.getRegistrarForAuthResult(request, authResult);
|
||||
Registrar initialRegistrar = sessionUtils.getRegistrarForAuthResult(request, authResult, false);
|
||||
// Process the operation. Though originally derived from a CRUD
|
||||
// handler, registrar-settings really only supports read and update.
|
||||
String op = Optional.ofNullable((String) input.get(OP_PARAM)).orElse("read");
|
||||
|
|
|
@ -48,7 +48,8 @@ public class SessionUtils {
|
|||
@Config("registryAdminClientId")
|
||||
String registryAdminClientId;
|
||||
|
||||
@Inject public SessionUtils() {}
|
||||
@Inject
|
||||
public SessionUtils() {}
|
||||
|
||||
/**
|
||||
* Checks that the authentication result indicates a user that has access to the registrar
|
||||
|
@ -58,7 +59,8 @@ public class SessionUtils {
|
|||
* the registrar console.
|
||||
*/
|
||||
@CheckReturnValue
|
||||
Registrar getRegistrarForAuthResult(HttpServletRequest request, AuthResult authResult) {
|
||||
Registrar getRegistrarForAuthResult(
|
||||
HttpServletRequest request, AuthResult authResult, boolean bypassCache) {
|
||||
if (!authResult.userAuthInfo().isPresent()) {
|
||||
throw new ForbiddenException("Not logged in");
|
||||
}
|
||||
|
@ -67,7 +69,11 @@ public class SessionUtils {
|
|||
}
|
||||
String clientId = getRegistrarClientId(request);
|
||||
return checkArgumentPresent(
|
||||
Registrar.loadByClientIdCached(clientId), "Registrar %s not found", clientId);
|
||||
bypassCache
|
||||
? Registrar.loadByClientId(clientId)
|
||||
: Registrar.loadByClientIdCached(clientId),
|
||||
"Registrar %s not found",
|
||||
clientId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,11 +83,11 @@ public class SessionUtils {
|
|||
* {@code clientId} attribute:
|
||||
*
|
||||
* <ul>
|
||||
* <li>If it does not exist, then we will attempt to guess the {@link Registrar} with which the
|
||||
* user is associated. The {@code clientId} of the first matching {@code Registrar} will then
|
||||
* be stored to the HTTP session.
|
||||
* <li>If it does exist, then we'll fetch the Registrar from Datastore to make sure access
|
||||
* wasn't revoked.
|
||||
* <li>If it does not exist, then we will attempt to guess the {@link Registrar} with which the
|
||||
* user is associated. The {@code clientId} of the first matching {@code Registrar} will
|
||||
* then be stored to the HTTP session.
|
||||
* <li>If it does exist, then we'll fetch the Registrar from Datastore to make sure access
|
||||
* wasn't revoked.
|
||||
* </ul>
|
||||
*
|
||||
* <p><b>Note:</b> You must ensure the user has logged in before calling this method.
|
||||
|
@ -162,10 +168,8 @@ public class SessionUtils {
|
|||
|
||||
/** Returns first {@link Registrar} that {@code gaeUserId} is authorized to administer. */
|
||||
private static Optional<Registrar> findRegistrarForUser(String gaeUserId) {
|
||||
RegistrarContact contact = ofy().load()
|
||||
.type(RegistrarContact.class)
|
||||
.filter("gaeUserId", gaeUserId)
|
||||
.first().now();
|
||||
RegistrarContact contact =
|
||||
ofy().load().type(RegistrarContact.class).filter("gaeUserId", gaeUserId).first().now();
|
||||
if (contact == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
|
|
@ -266,6 +266,8 @@
|
|||
{template .resources}
|
||||
{@param? driveFolderId: string}
|
||||
{@param technicalDocsUrl: string}
|
||||
{@param premiumPriceAckRequired: bool}
|
||||
{@param readonly: bool}
|
||||
<div id="domain-registrar-resources">
|
||||
<h1>Resources & billing</h1>
|
||||
<p>
|
||||
|
@ -290,6 +292,15 @@
|
|||
{else}
|
||||
<em>Your billing folder is pending allocation.</em>
|
||||
{/if}
|
||||
<h2><img src="/assets/images/folder.png">EPP Settings</h2>
|
||||
<p>Use the 'Edit' button above to switch to enable editing the information
|
||||
below. <i>Updates may require up to 10 minutes to take effect.</i>
|
||||
<form name="item" class="{css('item')} {css('registrar')}">
|
||||
<input type="checkbox" id="premiumPriceAckRequired" name="premiumPriceAckRequired"
|
||||
{if $premiumPriceAckRequired} checked{/if}
|
||||
{if $readonly} disabled{/if}>
|
||||
Require use of fee extension to acknowledge all premium domain prices.
|
||||
</form>
|
||||
</div>
|
||||
{/template}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue