Skip to content

Commit

Permalink
Made notifications email address required unless notifications are ma…
Browse files Browse the repository at this point in the history
…de only internally - TRUNK-2498
  • Loading branch information
wluyima committed Jun 10, 2013
1 parent d3bdfae commit 94b6841
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Expand Up @@ -201,10 +201,10 @@ protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse
String notifyType = opts.getNotification();
if (notifyType != null) {
if (notifyType.equals("internal") || notifyType.equals("internalProtected") || notifyType.equals("email")) {
if (StringUtils.isNotEmpty(opts.getNotificationAddress())) {
if (!EmailValidator.getInstance().isValid(opts.getNotificationAddress())) {
errors.reject("error.options.notificationAddress.invalid");
}
if (opts.getNotificationAddress().isEmpty()) {
errors.reject("error.options.notificationAddress.empty");
} else if (!EmailValidator.getInstance().isValid(opts.getNotificationAddress())) {
errors.reject("error.options.notificationAddress.invalid");
}
}
}
Expand Down
Expand Up @@ -221,4 +221,18 @@ public void shouldAcceptValidNotificationAddress() throws Exception {
assertEquals(correctAddress, optionsForm.getNotificationAddress());
}
}

@Test
public void shouldRejectEmptyNotificationAddress() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("POST", "");
request.setParameter("notification", "email");
request.setParameter("notificationAddress", "");

HttpServletResponse response = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(request, response);

BeanPropertyBindingResult bindingResult = (BeanPropertyBindingResult) modelAndView.getModel().get(
"org.springframework.validation.BindingResult.opts");
Assert.assertTrue(bindingResult.hasErrors());
}
}
2 changes: 2 additions & 0 deletions webapp/src/main/webapp/WEB-INF/messages.properties
Expand Up @@ -373,6 +373,8 @@ error.username.invalid=Invalid username. Username must be alphanumeric and cann
error.username.email=Invalid username. Username must be a valid e-mail.
error.retired.requireMetadata=Who retired this and why?
error.options.notificationAddress.invalid=Invalid notifications email address
error.options.notificationAddress.empty=No notifications email address specified


changePassword.hint.password.length=Password should have at least {0} characters
changePassword.hint.password.bothCasesRequired=both upper and lower case characters
Expand Down

0 comments on commit 94b6841

Please sign in to comment.