Merge changes Iddd04aa3,Ica535e34,I19d7c6f0,I79433c5e,I1566242d
* changes: RefPatternMatcher#getUsernames: Remove premature optimization RefPatternMatcher#getUsernames: Return ImmutableSet IdentifiedUser#getEmailAddresses: Return ImmutableSet Add IdentifiedUser#getLoggableName() AccountManager#update: Improve logging when username is not changed/set
This commit is contained in:
@@ -301,6 +301,11 @@ public class IdentifiedUser extends CurrentUser {
|
||||
return state().getUserName().orElse(null);
|
||||
}
|
||||
|
||||
/** @return unique name of the user for logging, never {@code null} */
|
||||
public String getLoggableName() {
|
||||
return getUserName() != null ? getUserName() : "a/" + getAccountId().get();
|
||||
}
|
||||
|
||||
public Account getAccount() {
|
||||
return state().getAccount();
|
||||
}
|
||||
@@ -320,12 +325,12 @@ public class IdentifiedUser extends CurrentUser {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Set<String> getEmailAddresses() {
|
||||
public ImmutableSet<String> getEmailAddresses() {
|
||||
if (!loadedAllEmails) {
|
||||
validEmails.addAll(realm.getEmailAddresses(this));
|
||||
loadedAllEmails = true;
|
||||
}
|
||||
return validEmails;
|
||||
return ImmutableSet.copyOf(validEmails);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
@@ -239,11 +239,14 @@ public class AccountManager {
|
||||
}
|
||||
|
||||
if (!realm.allowsEdit(AccountFieldName.USER_NAME)
|
||||
&& who.getUserName() != null
|
||||
&& !Objects.equals(user.getUserName(), Strings.emptyToNull(who.getUserName()))) {
|
||||
&& !Strings.isNullOrEmpty(who.getUserName())
|
||||
&& !who.getUserName().equals(user.getUserName())) {
|
||||
if (user.getUserName() != null) {
|
||||
log.warn(
|
||||
String.format(
|
||||
"Not changing already set username %s to %s", user.getUserName(), who.getUserName()));
|
||||
"Not changing already set username {} to {}", user.getUserName(), who.getUserName());
|
||||
} else {
|
||||
log.warn("Not setting username to {}", who.getUserName());
|
||||
}
|
||||
}
|
||||
|
||||
if (!accountUpdates.isEmpty()) {
|
||||
|
@@ -918,7 +918,7 @@ class ReceiveCommits {
|
||||
reject(cmd, "invalid project configuration");
|
||||
logError(
|
||||
"User "
|
||||
+ user.getUserName()
|
||||
+ user.getLoggableName()
|
||||
+ " tried to push invalid project configuration "
|
||||
+ cmd.getNewId().name()
|
||||
+ " for "
|
||||
@@ -994,7 +994,7 @@ class ReceiveCommits {
|
||||
reject(cmd, "invalid project configuration");
|
||||
logError(
|
||||
"User "
|
||||
+ user.getUserName()
|
||||
+ user.getLoggableName()
|
||||
+ " tried to push invalid project configuration "
|
||||
+ cmd.getNewId().name()
|
||||
+ " for "
|
||||
|
@@ -447,7 +447,7 @@ public class CommitValidators {
|
||||
} catch (ConfigInvalidException | IOException e) {
|
||||
log.error(
|
||||
"User "
|
||||
+ user.getUserName()
|
||||
+ user.getLoggableName()
|
||||
+ " tried to push an invalid project configuration "
|
||||
+ receiveEvent.command.getNewId().name()
|
||||
+ " for project "
|
||||
|
@@ -14,11 +14,12 @@
|
||||
|
||||
package com.google.gerrit.server.project;
|
||||
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static com.google.gerrit.server.project.RefPattern.isRE;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.google.gerrit.common.data.ParameterizedString;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
@@ -26,7 +27,6 @@ import com.google.gerrit.server.CurrentUser;
|
||||
import dk.brics.automaton.Automaton;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public abstract class RefPatternMatcher {
|
||||
@@ -132,15 +132,12 @@ public abstract class RefPatternMatcher {
|
||||
return false;
|
||||
}
|
||||
|
||||
private Iterable<String> getUsernames(CurrentUser user) {
|
||||
private ImmutableSet<String> getUsernames(CurrentUser user) {
|
||||
if (user.isIdentifiedUser()) {
|
||||
Set<String> emails = user.asIdentifiedUser().getEmailAddresses();
|
||||
if (user.getUserName() == null) {
|
||||
return emails;
|
||||
} else if (emails.isEmpty()) {
|
||||
return ImmutableSet.of(user.getUserName());
|
||||
}
|
||||
return Iterables.concat(emails, ImmutableSet.of(user.getUserName()));
|
||||
return Streams.concat(
|
||||
user.asIdentifiedUser().getEmailAddresses().stream(),
|
||||
ImmutableSet.of(user.getUserName()).stream())
|
||||
.collect(toImmutableSet());
|
||||
}
|
||||
if (user.getUserName() != null) {
|
||||
return ImmutableSet.of(user.getUserName());
|
||||
|
Reference in New Issue
Block a user