Add hasEmailAddress to IdentifiedUser
This allows validation code to pass in an email address for checking, and lets IdentifiedUser worry about how that occurs. This refactoring opens the door to delegating the check to backend systems that are not able to supply the entire valid email list for a user. Change-Id: I3db2b34d311d0c8f6f5c0cfdaa109d44fd79e264
This commit is contained in:
@@ -144,7 +144,7 @@ class AccountSecurityImpl extends BaseServiceImplementation implements
|
|||||||
me.setFullName(Strings.emptyToNull(name));
|
me.setFullName(Strings.emptyToNull(name));
|
||||||
}
|
}
|
||||||
if (!Strings.isNullOrEmpty(emailAddr)
|
if (!Strings.isNullOrEmpty(emailAddr)
|
||||||
&& !self.getEmailAddresses().contains(emailAddr)) {
|
&& !self.hasEmailAddress(emailAddr)) {
|
||||||
throw new Failure(new PermissionDeniedException("Email address must be verified"));
|
throw new Failure(new PermissionDeniedException("Email address must be verified"));
|
||||||
}
|
}
|
||||||
me.setPreferredEmail(Strings.emptyToNull(emailAddr));
|
me.setPreferredEmail(Strings.emptyToNull(emailAddr));
|
||||||
|
@@ -270,6 +270,10 @@ public class IdentifiedUser extends CurrentUser {
|
|||||||
return diffPref;
|
return diffPref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasEmailAddress(String email) {
|
||||||
|
return getEmailAddresses().contains(email);
|
||||||
|
}
|
||||||
|
|
||||||
public Set<String> getEmailAddresses() {
|
public Set<String> getEmailAddresses() {
|
||||||
if (emailAddresses == null) {
|
if (emailAddresses == null) {
|
||||||
emailAddresses = state().getEmailAddresses();
|
emailAddresses = state().getEmailAddresses();
|
||||||
|
@@ -66,7 +66,7 @@ public class Emails implements
|
|||||||
throw new ResourceNotFoundException();
|
throw new ResourceNotFoundException();
|
||||||
}
|
}
|
||||||
return new AccountResource.Email(rsrc.getUser(), email);
|
return new AccountResource.Email(rsrc.getUser(), email);
|
||||||
} else if (rsrc.getUser().getEmailAddresses().contains(id.get())) {
|
} else if (rsrc.getUser().hasEmailAddress(id.get())) {
|
||||||
return new AccountResource.Email(rsrc.getUser(), id.get());
|
return new AccountResource.Email(rsrc.getUser(), id.get());
|
||||||
} else {
|
} else {
|
||||||
throw new ResourceNotFoundException();
|
throw new ResourceNotFoundException();
|
||||||
|
@@ -379,8 +379,7 @@ public class MergeUtil {
|
|||||||
|
|
||||||
final Timestamp dt = submitter.getGranted();
|
final Timestamp dt = submitter.getGranted();
|
||||||
final TimeZone tz = myIdent.getTimeZone();
|
final TimeZone tz = myIdent.getTimeZone();
|
||||||
if (emails.size() == 1
|
if (emails.size() == 1 && who.hasEmailAddress(emails.iterator().next())) {
|
||||||
&& who.getEmailAddresses().contains(emails.iterator().next())) {
|
|
||||||
authorIdent =
|
authorIdent =
|
||||||
new PersonIdent(codeReviewCommits.get(0).getAuthorIdent(), dt, tz);
|
new PersonIdent(codeReviewCommits.get(0).getAuthorIdent(), dt, tz);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -2279,7 +2279,7 @@ public class ReceiveCommits {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defaultName && currentUser.getEmailAddresses().contains(
|
if (defaultName && currentUser.hasEmailAddress(
|
||||||
c.getCommitterIdent().getEmailAddress())) {
|
c.getCommitterIdent().getEmailAddress())) {
|
||||||
try {
|
try {
|
||||||
Account a = db.accounts().get(currentUser.getAccountId());
|
Account a = db.accounts().get(currentUser.getAccountId());
|
||||||
|
@@ -394,7 +394,7 @@ public class CommitValidators {
|
|||||||
if (e != null) {
|
if (e != null) {
|
||||||
sboAuthor |= author.getEmailAddress().equals(e);
|
sboAuthor |= author.getEmailAddress().equals(e);
|
||||||
sboCommitter |= committer.getEmailAddress().equals(e);
|
sboCommitter |= committer.getEmailAddress().equals(e);
|
||||||
sboMe |= currentUser.getEmailAddresses().contains(e);
|
sboMe |= currentUser.hasEmailAddress(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -425,7 +425,7 @@ public class CommitValidators {
|
|||||||
IdentifiedUser currentUser = (IdentifiedUser) refControl.getCurrentUser();
|
IdentifiedUser currentUser = (IdentifiedUser) refControl.getCurrentUser();
|
||||||
final PersonIdent author = receiveEvent.commit.getAuthorIdent();
|
final PersonIdent author = receiveEvent.commit.getAuthorIdent();
|
||||||
|
|
||||||
if (!currentUser.getEmailAddresses().contains(author.getEmailAddress())
|
if (!currentUser.hasEmailAddress(author.getEmailAddress())
|
||||||
&& !refControl.canForgeAuthor()) {
|
&& !refControl.canForgeAuthor()) {
|
||||||
List<CommitValidationMessage> messages = new LinkedList<>();
|
List<CommitValidationMessage> messages = new LinkedList<>();
|
||||||
|
|
||||||
@@ -454,8 +454,7 @@ public class CommitValidators {
|
|||||||
CommitReceivedEvent receiveEvent) throws CommitValidationException {
|
CommitReceivedEvent receiveEvent) throws CommitValidationException {
|
||||||
IdentifiedUser currentUser = (IdentifiedUser) refControl.getCurrentUser();
|
IdentifiedUser currentUser = (IdentifiedUser) refControl.getCurrentUser();
|
||||||
final PersonIdent committer = receiveEvent.commit.getCommitterIdent();
|
final PersonIdent committer = receiveEvent.commit.getCommitterIdent();
|
||||||
if (!currentUser.getEmailAddresses()
|
if (!currentUser.hasEmailAddress(committer.getEmailAddress())
|
||||||
.contains(committer.getEmailAddress())
|
|
||||||
&& !refControl.canForgeCommitter()) {
|
&& !refControl.canForgeCommitter()) {
|
||||||
List<CommitValidationMessage> messages = new LinkedList<>();
|
List<CommitValidationMessage> messages = new LinkedList<>();
|
||||||
messages.add(getInvalidEmailError(receiveEvent.commit, "committer", committer,
|
messages.add(getInvalidEmailError(receiveEvent.commit, "committer", committer,
|
||||||
|
@@ -297,7 +297,7 @@ public class RefControl {
|
|||||||
if (getCurrentUser().isIdentifiedUser()) {
|
if (getCurrentUser().isIdentifiedUser()) {
|
||||||
final IdentifiedUser user = (IdentifiedUser) getCurrentUser();
|
final IdentifiedUser user = (IdentifiedUser) getCurrentUser();
|
||||||
final String addr = tagger.getEmailAddress();
|
final String addr = tagger.getEmailAddress();
|
||||||
valid = user.getEmailAddresses().contains(addr);
|
valid = user.hasEmailAddress(addr);
|
||||||
} else {
|
} else {
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user