Make OutgoingEmailValidator a Singleton
Make the class a Singleton so that it can be used by classes that get it injected, rather than calling its methods statically. This is a preparatory step to allowing the validator to get the gerrit configuration injected, which will allow to disable validation using this validator. Change-Id: If5c7cc6d2c034b9ed16b1358b4d1d186d57daf98
This commit is contained in:
		| @@ -77,6 +77,7 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn | ||||
|   private final AuditService auditService; | ||||
|   private final ExternalIds externalIds; | ||||
|   private final ExternalIdsUpdate.User externalIdsUpdateFactory; | ||||
|   private final OutgoingEmailValidator validator; | ||||
|   private final String username; | ||||
|  | ||||
|   @Inject | ||||
| @@ -95,6 +96,7 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn | ||||
|       AuditService auditService, | ||||
|       ExternalIds externalIds, | ||||
|       ExternalIdsUpdate.User externalIdsUpdateFactory, | ||||
|       OutgoingEmailValidator validator, | ||||
|       @Assisted String username) { | ||||
|     this.db = db; | ||||
|     this.currentUser = currentUser; | ||||
| @@ -110,6 +112,7 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn | ||||
|     this.auditService = auditService; | ||||
|     this.externalIds = externalIds; | ||||
|     this.externalIdsUpdateFactory = externalIdsUpdateFactory; | ||||
|     this.validator = validator; | ||||
|     this.username = username; | ||||
|   } | ||||
|  | ||||
| @@ -141,7 +144,7 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn | ||||
|       if (externalIds.get(db, ExternalId.Key.create(SCHEME_MAILTO, input.email)) != null) { | ||||
|         throw new UnprocessableEntityException("email '" + input.email + "' already exists"); | ||||
|       } | ||||
|       if (!OutgoingEmailValidator.isValid(input.email)) { | ||||
|       if (!validator.isValid(input.email)) { | ||||
|         throw new BadRequestException("invalid email address"); | ||||
|       } | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 David Pursehouse
					David Pursehouse