Merge branch 'stable-2.15'
* stable-2.15: Fix "Group members can't be added as reviewers" after merging Set version to 2.15-SNAPSHOT ProjectLevelConfig: Import Collectors.toList static Merge parent config values with child values Set version to 2.14.8-SNAPSHOT Fix the missing DB entry in Gerrit DB Fix unit test "addGroupAsReviewersWhenANotPerfectMatchedUserExist" Change-Id: I18e635f55f69892b1c5c9f203030f4181973fa3c
This commit is contained in:
@@ -143,7 +143,21 @@ public class AccountManager {
|
||||
try (ReviewDb db = schema.open()) {
|
||||
ExternalId id = externalIds.get(who.getExternalIdKey());
|
||||
if (id == null) {
|
||||
if (who.getUserName().isPresent()) {
|
||||
ExternalId.Key key = ExternalId.Key.create(SCHEME_USERNAME, who.getUserName().get());
|
||||
ExternalId existingId = externalIds.get(key);
|
||||
if (existingId != null) {
|
||||
// An inconsistency is detected in the database, having a record for scheme "username:"
|
||||
// but no record for scheme "gerrit:". Try to recover by linking
|
||||
// "gerrit:" identity to the existing account.
|
||||
log.warn(
|
||||
"User {} already has an account; link new identity to the existing account.",
|
||||
who.getUserName());
|
||||
return link(existingId.accountId(), who);
|
||||
}
|
||||
}
|
||||
// New account, automatically create and return.
|
||||
log.info("External ID not found. Attempting to create new account.");
|
||||
return create(db, who);
|
||||
}
|
||||
|
||||
@@ -383,6 +397,7 @@ public class AccountManager {
|
||||
public AuthResult link(Account.Id to, AuthRequest who)
|
||||
throws AccountException, OrmException, IOException, ConfigInvalidException {
|
||||
ExternalId extId = externalIds.get(who.getExternalIdKey());
|
||||
log.info("Link another authentication identity to an existing account");
|
||||
if (extId != null) {
|
||||
if (!extId.accountId().equals(to)) {
|
||||
throw new AccountException(
|
||||
@@ -390,6 +405,7 @@ public class AccountManager {
|
||||
}
|
||||
update(who, extId);
|
||||
} else {
|
||||
log.info("Linking new external ID to the existing account");
|
||||
accountsUpdateProvider
|
||||
.get()
|
||||
.update(
|
||||
|
||||
@@ -288,7 +288,32 @@ public class PluginConfigFactory implements ReloadPluginListener {
|
||||
*/
|
||||
public Config getProjectPluginConfigWithInheritance(
|
||||
Project.NameKey projectName, String pluginName) throws NoSuchProjectException {
|
||||
return getPluginConfig(projectName, pluginName).getWithInheritance();
|
||||
return getPluginConfig(projectName, pluginName).getWithInheritance(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configuration for the specified plugin that is stored in the '{@code
|
||||
* <plugin-name>.config}' file in the 'refs/meta/config' branch of the specified project.
|
||||
* Parameters from the '{@code <plugin-name>.config}' of the parent project are appended to this
|
||||
* project's '{@code <plugin-name>.config}' files.
|
||||
*
|
||||
* <p>E.g.: child project: [mySection "mySubsection"] myKey = childValue
|
||||
*
|
||||
* <p>parent project: [mySection "mySubsection"] myKey = parentValue anotherKey = someValue
|
||||
*
|
||||
* <p>return: [mySection "mySubsection"] myKey = childValue myKey = parentValue anotherKey =
|
||||
* someValue
|
||||
*
|
||||
* @param projectName the name of the project for which the plugin configuration should be
|
||||
* returned
|
||||
* @param pluginName the name of the plugin for which the configuration should be returned
|
||||
* @return the plugin configuration from the '{@code <plugin-name>.config}' file of the specified
|
||||
* project with parameters from the parent projects appended to the project values
|
||||
* @throws NoSuchProjectException thrown if the specified project does not exist
|
||||
*/
|
||||
public Config getProjectPluginConfigWithMergedInheritance(
|
||||
Project.NameKey projectName, String pluginName) throws NoSuchProjectException {
|
||||
return getPluginConfig(projectName, pluginName).getWithInheritance(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -310,7 +335,30 @@ public class PluginConfigFactory implements ReloadPluginListener {
|
||||
*/
|
||||
public Config getProjectPluginConfigWithInheritance(
|
||||
ProjectState projectState, String pluginName) {
|
||||
return projectState.getConfig(pluginName + EXTENSION).getWithInheritance();
|
||||
return projectState.getConfig(pluginName + EXTENSION).getWithInheritance(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configuration for the specified plugin that is stored in the '{@code
|
||||
* <plugin-name>.config}' file in the 'refs/meta/config' branch of the specified project.
|
||||
* Parameters from the '{@code <plugin-name>.config}' of the parent project are appended to this
|
||||
* project's '{@code <plugin-name>.config}' files.
|
||||
*
|
||||
* <p>E.g.: child project: [mySection "mySubsection"] myKey = childValue
|
||||
*
|
||||
* <p>parent project: [mySection "mySubsection"] myKey = parentValue anotherKey = someValue
|
||||
*
|
||||
* <p>return: [mySection "mySubsection"] myKey = childValue myKey = parentValue anotherKey =
|
||||
* someValue
|
||||
*
|
||||
* @param projectState the project for which the plugin configuration should be returned
|
||||
* @param pluginName the name of the plugin for which the configuration should be returned
|
||||
* @return the plugin configuration from the '{@code <plugin-name>.config}' file of the specified
|
||||
* project with inheriting non-set parameters from the parent projects
|
||||
*/
|
||||
public Config getProjectPluginConfigWithMergedInheritance(
|
||||
ProjectState projectState, String pluginName) {
|
||||
return projectState.getConfig(pluginName + EXTENSION).getWithInheritance(true);
|
||||
}
|
||||
|
||||
private ProjectLevelConfig getPluginConfig(Project.NameKey projectName, String pluginName)
|
||||
|
||||
@@ -14,12 +14,16 @@
|
||||
|
||||
package com.google.gerrit.server.git;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.server.project.ProjectState;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.lib.CommitBuilder;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
@@ -53,6 +57,22 @@ public class ProjectLevelConfig extends VersionedMetaData {
|
||||
}
|
||||
|
||||
public Config getWithInheritance() {
|
||||
return getWithInheritance(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Config that includes the values from all parent projects.
|
||||
*
|
||||
* <p>Merging means that matching sections/subsection will be merged to include the values from
|
||||
* both parent and child config.
|
||||
*
|
||||
* <p>No merging means that matching sections/subsections in the child project will replace the
|
||||
* corresponding value from the parent.
|
||||
*
|
||||
* @param merge whether to merge parent values with child values or not.
|
||||
* @return a combined config.
|
||||
*/
|
||||
public Config getWithInheritance(boolean merge) {
|
||||
Config cfgWithInheritance = new Config();
|
||||
try {
|
||||
cfgWithInheritance.fromText(get().toText());
|
||||
@@ -65,21 +85,41 @@ public class ProjectLevelConfig extends VersionedMetaData {
|
||||
for (String section : parentCfg.getSections()) {
|
||||
Set<String> allNames = get().getNames(section);
|
||||
for (String name : parentCfg.getNames(section)) {
|
||||
String[] parentValues = parentCfg.getStringList(section, null, name);
|
||||
if (!allNames.contains(name)) {
|
||||
cfgWithInheritance.setStringList(section, null, name, Arrays.asList(parentValues));
|
||||
} else if (merge) {
|
||||
cfgWithInheritance.setStringList(
|
||||
section, null, name, Arrays.asList(parentCfg.getStringList(section, null, name)));
|
||||
section,
|
||||
null,
|
||||
name,
|
||||
Stream.concat(
|
||||
Arrays.stream(cfg.getStringList(section, null, name)),
|
||||
Arrays.stream(parentValues))
|
||||
.sorted()
|
||||
.distinct()
|
||||
.collect(toList()));
|
||||
}
|
||||
}
|
||||
|
||||
for (String subsection : parentCfg.getSubsections(section)) {
|
||||
allNames = get().getNames(section, subsection);
|
||||
for (String name : parentCfg.getNames(section, subsection)) {
|
||||
String[] parentValues = parentCfg.getStringList(section, subsection, name);
|
||||
if (!allNames.contains(name)) {
|
||||
cfgWithInheritance.setStringList(
|
||||
section, subsection, name, Arrays.asList(parentValues));
|
||||
} else if (merge) {
|
||||
cfgWithInheritance.setStringList(
|
||||
section,
|
||||
subsection,
|
||||
name,
|
||||
Arrays.asList(parentCfg.getStringList(section, subsection, name)));
|
||||
Streams.concat(
|
||||
Arrays.stream(cfg.getStringList(section, subsection, name)),
|
||||
Arrays.stream(parentValues))
|
||||
.sorted()
|
||||
.distinct()
|
||||
.collect(toList()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,13 +194,20 @@ public class PostReviewers
|
||||
|
||||
Addition byAccountId =
|
||||
addByAccountId(reviewer, rsrc, state, notify, accountsToNotify, allowGroup, allowByEmail);
|
||||
|
||||
Addition wholeGroup = null;
|
||||
if (byAccountId == null || !byAccountId.exactMatchFound) {
|
||||
wholeGroup =
|
||||
addWholeGroup(
|
||||
reviewer, rsrc, state, notify, accountsToNotify, confirmed, allowGroup, allowByEmail);
|
||||
if (wholeGroup != null && wholeGroup.exactMatchFound) {
|
||||
return wholeGroup;
|
||||
}
|
||||
}
|
||||
|
||||
if (byAccountId != null) {
|
||||
return byAccountId;
|
||||
}
|
||||
|
||||
Addition wholeGroup =
|
||||
addWholeGroup(
|
||||
reviewer, rsrc, state, notify, accountsToNotify, confirmed, allowGroup, allowByEmail);
|
||||
if (wholeGroup != null) {
|
||||
return wholeGroup;
|
||||
}
|
||||
@@ -216,7 +223,8 @@ public class PostReviewers
|
||||
null,
|
||||
CC,
|
||||
NotifyHandling.NONE,
|
||||
ImmutableListMultimap.of());
|
||||
ImmutableListMultimap.of(),
|
||||
true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -229,9 +237,14 @@ public class PostReviewers
|
||||
boolean allowGroup,
|
||||
boolean allowByEmail)
|
||||
throws OrmException, PermissionBackendException, IOException, ConfigInvalidException {
|
||||
Account.Id accountId = null;
|
||||
IdentifiedUser user = null;
|
||||
boolean exactMatchFound = false;
|
||||
try {
|
||||
accountId = accounts.parse(reviewer).getAccountId();
|
||||
user = accounts.parse(reviewer);
|
||||
if (reviewer.equalsIgnoreCase(user.getName())
|
||||
|| reviewer.equals(String.valueOf(user.getAccountId()))) {
|
||||
exactMatchFound = true;
|
||||
}
|
||||
} catch (UnprocessableEntityException | AuthException e) {
|
||||
// AuthException won't occur since the user is authenticated at this point.
|
||||
if (!allowGroup && !allowByEmail) {
|
||||
@@ -242,13 +255,20 @@ public class PostReviewers
|
||||
return null;
|
||||
}
|
||||
|
||||
ReviewerResource rrsrc = reviewerFactory.create(rsrc, accountId);
|
||||
ReviewerResource rrsrc = reviewerFactory.create(rsrc, user.getAccountId());
|
||||
Account member = rrsrc.getReviewerUser().getAccount();
|
||||
PermissionBackend.ForRef perm =
|
||||
permissionBackend.user(rrsrc.getReviewerUser()).ref(rrsrc.getChange().getDest());
|
||||
if (isValidReviewer(member, perm)) {
|
||||
return new Addition(
|
||||
reviewer, rsrc, ImmutableSet.of(member.getId()), null, state, notify, accountsToNotify);
|
||||
reviewer,
|
||||
rsrc,
|
||||
ImmutableSet.of(member.getId()),
|
||||
null,
|
||||
state,
|
||||
notify,
|
||||
accountsToNotify,
|
||||
exactMatchFound);
|
||||
}
|
||||
if (!member.isActive()) {
|
||||
if (allowByEmail && state == CC) {
|
||||
@@ -328,7 +348,7 @@ public class PostReviewers
|
||||
}
|
||||
}
|
||||
|
||||
return new Addition(reviewer, rsrc, reviewers, null, state, notify, accountsToNotify);
|
||||
return new Addition(reviewer, rsrc, reviewers, null, state, notify, accountsToNotify, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -357,7 +377,7 @@ public class PostReviewers
|
||||
return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerInvalid, reviewer));
|
||||
}
|
||||
return new Addition(
|
||||
reviewer, rsrc, null, ImmutableList.of(adr), state, notify, accountsToNotify);
|
||||
reviewer, rsrc, null, ImmutableList.of(adr), state, notify, accountsToNotify, true);
|
||||
}
|
||||
|
||||
private boolean isValidReviewer(Account member, PermissionBackend.ForRef perm)
|
||||
@@ -395,6 +415,7 @@ public class PostReviewers
|
||||
final ReviewerState state;
|
||||
final ChangeNotes notes;
|
||||
final IdentifiedUser caller;
|
||||
final boolean exactMatchFound;
|
||||
|
||||
Addition(String reviewer) {
|
||||
result = new AddReviewerResult(reviewer);
|
||||
@@ -404,6 +425,7 @@ public class PostReviewers
|
||||
state = REVIEWER;
|
||||
notes = null;
|
||||
caller = null;
|
||||
exactMatchFound = false;
|
||||
}
|
||||
|
||||
protected Addition(
|
||||
@@ -413,7 +435,8 @@ public class PostReviewers
|
||||
@Nullable Collection<Address> reviewersByEmail,
|
||||
ReviewerState state,
|
||||
@Nullable NotifyHandling notify,
|
||||
ListMultimap<RecipientType, Account.Id> accountsToNotify) {
|
||||
ListMultimap<RecipientType, Account.Id> accountsToNotify,
|
||||
boolean exactMatchFound) {
|
||||
checkArgument(
|
||||
reviewers != null || reviewersByEmail != null,
|
||||
"must have either reviewers or reviewersByEmail");
|
||||
@@ -427,6 +450,7 @@ public class PostReviewers
|
||||
op =
|
||||
postReviewersOpFactory.create(
|
||||
rsrc, this.reviewers, this.reviewersByEmail, state, notify, accountsToNotify);
|
||||
this.exactMatchFound = exactMatchFound;
|
||||
}
|
||||
|
||||
void gatherResults() throws OrmException, PermissionBackendException {
|
||||
|
||||
Reference in New Issue
Block a user