Enable configurable 'maxBatchChanges' limit

One use case is when a group is responsible for importing
large batches of changes delivered from external partners,
and those changes all require review. This group, and only
this group, should be allowed to bypass the limit that is
enforced for everyone else.

Allow site administrators to configure the 'maxBatchChanges'
limit for users from global capability UI of All-Projects
access. The min box does not make sense if its value is not 0,
so disable it after giving it the default value of 0.

The effective limit value will be the capability value if it
exists, or the value in gerrit.config if it exists, or else
no limit.

Change-Id: Ic929dc4a89cc8ccbd098035ce2ceac4f22fd54da
This commit is contained in:
Bruce Zu
2014-11-18 17:39:41 +08:00
committed by Dave Borowitz
parent 30c35c8398
commit 4512fe68ef
9 changed files with 61 additions and 6 deletions

View File

@@ -35,6 +35,9 @@ public class GlobalCapability {
*/
public static final String ADMINISTRATE_SERVER = "administrateServer";
/** Maximum number of changes that may be pushed in a batch. */
public static final String BATCH_CHANGES_LIMIT = "batchChangesLimit";
/** Can create any account on the server. */
public static final String CREATE_ACCOUNT = "createAccount";
@@ -97,6 +100,13 @@ public class GlobalCapability {
/** Can view all pending tasks in the queue (not just the filtered set). */
public static final String VIEW_QUEUE = "viewQueue";
/**
* Default maximum number of changes that may be pushed in a batch, 0 means no
* limit. This is just used as a suggestion for prepopulating the field in the
* access UI.
*/
private static final int DEFAULT_MAX_BATCH_CHANGES = 0;
private static final List<String> NAMES_ALL;
private static final List<String> NAMES_LC;
@@ -104,6 +114,7 @@ public class GlobalCapability {
NAMES_ALL = new ArrayList<>();
NAMES_ALL.add(ACCESS_DATABASE);
NAMES_ALL.add(ADMINISTRATE_SERVER);
NAMES_ALL.add(BATCH_CHANGES_LIMIT);
NAMES_ALL.add(CREATE_ACCOUNT);
NAMES_ALL.add(CREATE_GROUP);
NAMES_ALL.add(CREATE_PROJECT);
@@ -140,7 +151,8 @@ public class GlobalCapability {
/** @return true if the capability should have a range attached. */
public static boolean hasRange(String varName) {
return QUERY_LIMIT.equalsIgnoreCase(varName);
return QUERY_LIMIT.equalsIgnoreCase(varName)
|| BATCH_CHANGES_LIMIT.equalsIgnoreCase(varName);
}
/** @return the valid range for the capability if it has one, otherwise null. */
@@ -151,6 +163,12 @@ public class GlobalCapability {
0, Integer.MAX_VALUE,
0, DEFAULT_MAX_QUERY_LIMIT);
}
if (BATCH_CHANGES_LIMIT.equalsIgnoreCase(varName)) {
return new PermissionRange.WithDefaults(
varName,
0, Integer.MAX_VALUE,
0, DEFAULT_MAX_BATCH_CHANGES);
}
return null;
}