Enable create-project for non-Administrators

Allow other than 'Administrators' to use the create-project command.

Added configuration parameters in gerrit.config to denote which
group(s) are allowed to create projects, and which group(s) should
be new projects' owner(s) by default.

repository.*.createGroup specifies which group(s) are allowed to
create projects. Default is 'Administrators'.

repository.*.ownerGroup specifies which group(s) become the
owner(s) of new projects. Default is whatever is specified
by repository.*.createGroup, or 'Administrators' if no such
configuration exists. Can be overridden by create-project's
parameter --owner.

Bug: issue 269
Change-Id: Ieeb694508dd4c12578877335a63944bc90d6b553
This commit is contained in:
Hugo Josefson
2010-04-21 19:27:11 +02:00
committed by Shawn O. Pearce
parent c025627422
commit 072b470570
11 changed files with 378 additions and 54 deletions

View File

@@ -16,9 +16,18 @@ package com.google.gerrit.server.config;
import static org.eclipse.jgit.util.StringUtils.equalsIgnoreCase;
import com.google.gerrit.reviewdb.AccountGroup;
import com.google.gerrit.reviewdb.AccountGroupName;
import com.google.gerrit.reviewdb.ReviewDb;
import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import org.eclipse.jgit.lib.Config;
import org.slf4j.Logger;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
public class ConfigUtil {
@@ -199,6 +208,60 @@ public class ConfigUtil {
}
}
/**
* Resolve groups from group names, via the database. Group names not found in
* the database will be skipped.
*
* @param dbfactory database to resolve from.
* @param groupNames group names to resolve.
* @param log log for any warnings and errors.
* @param groupNotFoundWarning formatted message to output to the log for each
* group name which is not found in the database. <code>{0}</code> will
* be replaced with the group name.
* @return the actual groups resolved from the database. If no groups are
* found, returns an empty {@code Set}, never {@code null}.
*/
public static Set<AccountGroup.Id> groupsFor(
SchemaFactory<ReviewDb> dbfactory, String[] groupNames, Logger log,
String groupNotFoundWarning) {
final Set<AccountGroup.Id> result = new HashSet<AccountGroup.Id>();
try {
final ReviewDb db = dbfactory.open();
try {
for (String name : groupNames) {
AccountGroupName group =
db.accountGroupNames().get(new AccountGroup.NameKey(name));
if (group == null) {
log.warn(MessageFormat.format(groupNotFoundWarning, name));
} else {
result.add(group.getId());
}
}
} finally {
db.close();
}
} catch (OrmException e) {
log.error("Database error, cannot load groups", e);
}
return result;
}
/**
* Resolve groups from group names, via the database. Group names not found in
* the database will be skipped.
*
* @param dbfactory database to resolve from.
* @param groupNames group names to resolve.
* @param log log for any warnings and errors.
* @return the actual groups resolved from the database. If no groups are
* found, returns an empty {@code Set}, never {@code null}.
*/
public static Set<AccountGroup.Id> groupsFor(
SchemaFactory<ReviewDb> dbfactory, String[] groupNames, Logger log) {
return groupsFor(dbfactory, groupNames, log,
"Group \"{0}\" not in database, skipping.");
}
private static boolean match(final String a, final String... cases) {
for (final String b : cases) {
if (equalsIgnoreCase(a, b)) {