Make project state check in ADD_PATCH_SET explicit

The majority of code in {Project,Ref,Change}Control is now about
permissions, but not all. Exceptions include checks for a project's
state. This is confusing, because users are presented with an exception
telling them that they lack some kind of permission while the real
reason for the failed operation is that the project's current state
doesn't permit the operation.

This is part of a series of commits to remove all project state checks
from *Control classes and make explicit checks instead.

This commit also adds more documentation to the individual states and
adds a convenience method for validating that a project is writeable.

Change-Id: I3edfe80e745657a1fd41e7ddaf019c9dee4fa8f6
This commit is contained in:
Patrick Hiesel
2018-01-11 15:00:56 +01:00
parent 0a997939ab
commit f83a4e9cbb
9 changed files with 60 additions and 21 deletions

View File

@@ -1037,7 +1037,7 @@ class ReceiveCommits {
// Must pass explicit user instead of injecting a provider into CreateRefControl, since
// Provider<CurrentUser> within ReceiveCommits will always return anonymous.
createRefControl.checkCreateRef(Providers.of(user), rp.getRepository(), branch, obj);
} catch (AuthException denied) {
} catch (AuthException | ResourceConflictException denied) {
reject(cmd, "prohibited by Gerrit: " + denied.getMessage());
return;
}
@@ -2391,6 +2391,10 @@ class ReceiveCommits {
return false;
}
if (!projectState.statePermitsWrite()) {
reject(inputCommand, "cannot add patch set to " + ontoChange + ".");
return false;
}
if (change.getStatus().isClosed()) {
reject(inputCommand, "change " + ontoChange + " closed");
return false;