Skip to content

Commit 94b6841

Browse files
committedJun 10, 2013
Made notifications email address required unless notifications are made only internally - TRUNK-2498
1 parent d3bdfae commit 94b6841

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed
 

‎web/src/main/java/org/openmrs/web/controller/OptionsFormController.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse
201201
String notifyType = opts.getNotification();
202202
if (notifyType != null) {
203203
if (notifyType.equals("internal") || notifyType.equals("internalProtected") || notifyType.equals("email")) {
204-
if (StringUtils.isNotEmpty(opts.getNotificationAddress())) {
205-
if (!EmailValidator.getInstance().isValid(opts.getNotificationAddress())) {
206-
errors.reject("error.options.notificationAddress.invalid");
207-
}
204+
if (opts.getNotificationAddress().isEmpty()) {
205+
errors.reject("error.options.notificationAddress.empty");
206+
} else if (!EmailValidator.getInstance().isValid(opts.getNotificationAddress())) {
207+
errors.reject("error.options.notificationAddress.invalid");
208208
}
209209
}
210210
}

‎web/src/test/java/org/openmrs/web/controller/OptionsFormControllerTest.java

+14
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,18 @@ public void shouldAcceptValidNotificationAddress() throws Exception {
221221
assertEquals(correctAddress, optionsForm.getNotificationAddress());
222222
}
223223
}
224+
225+
@Test
226+
public void shouldRejectEmptyNotificationAddress() throws Exception {
227+
MockHttpServletRequest request = new MockHttpServletRequest("POST", "");
228+
request.setParameter("notification", "email");
229+
request.setParameter("notificationAddress", "");
230+
231+
HttpServletResponse response = new MockHttpServletResponse();
232+
ModelAndView modelAndView = controller.handleRequest(request, response);
233+
234+
BeanPropertyBindingResult bindingResult = (BeanPropertyBindingResult) modelAndView.getModel().get(
235+
"org.springframework.validation.BindingResult.opts");
236+
Assert.assertTrue(bindingResult.hasErrors());
237+
}
224238
}

‎webapp/src/main/webapp/WEB-INF/messages.properties

+2
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ error.username.invalid=Invalid username. Username must be alphanumeric and cann
373373
error.username.email=Invalid username. Username must be a valid e-mail.
374374
error.retired.requireMetadata=Who retired this and why?
375375
error.options.notificationAddress.invalid=Invalid notifications email address
376+
error.options.notificationAddress.empty=No notifications email address specified
377+
376378

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

0 commit comments

Comments
 (0)
Please sign in to comment.