Always return the same message when the draft workflow is disabled

Always return 'Draft workflow is disabled' as message when a draft
operation is rejected because the draft workflow is disabled by having
'change.allowDrafts' set to 'false'.

DeleteDraftChange and DeleteDraftPatchSet already returned this
message, but CreateChange and ReceiveCommits used another message.

Change-Id: I233e7ad1a2eadeab53f57b38a45b0cef8377d3b9
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2015-02-02 09:25:48 +01:00
parent a9692dc8a7
commit 2105d0b2f0
6 changed files with 16 additions and 12 deletions

View File

@@ -78,7 +78,7 @@ public class CreateChangeIT extends AbstractDaemonTest {
ChangeInfo ci = newChangeInfo(ChangeStatus.DRAFT);
RestResponse r = adminSession.post("/changes/", ci);
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_METHOD_NOT_ALLOWED);
assertThat(r.getEntityContent()).contains("cannot upload drafts");
assertThat(r.getEntityContent()).contains("draft workflow is disabled");
}
private ChangeInfo newChangeInfo(ChangeStatus status) {

View File

@@ -103,7 +103,7 @@ public class DraftChangeIT extends AbstractDaemonTest {
public void createDraftChangeWhenDraftsNotAllowed() throws Exception {
assume().that(isAllowDrafts()).isFalse();
PushOneCommit.Result r = createDraftChange();
r.assertErrorStatus("cannot upload drafts");
r.assertErrorStatus("draft workflow is disabled");
}
private PushOneCommit.Result createDraftChange() throws Exception {

View File

@@ -136,7 +136,7 @@ public class CreateChange implements
}
if (!allowDrafts && input.status == ChangeStatus.DRAFT) {
throw new MethodNotAllowedException("cannot upload drafts");
throw new MethodNotAllowedException("draft workflow is disabled");
}
}

View File

@@ -69,7 +69,7 @@ public class DeleteDraftChange implements
}
if (!allowDrafts) {
throw new MethodNotAllowedException("Draft workflow is disabled");
throw new MethodNotAllowedException("draft workflow is disabled");
}
try {

View File

@@ -81,7 +81,7 @@ public class DeleteDraftPatchSet implements RestModifyView<RevisionResource, Inp
}
if (!allowDrafts) {
throw new MethodNotAllowedException("Draft workflow is disabled");
throw new MethodNotAllowedException("draft workflow is disabled");
}
if (!rsrc.getControl().canDeleteDraft(dbProvider.get())) {

View File

@@ -1268,13 +1268,17 @@ public class ReceiveCommits {
return;
}
if (magicBranch.draft
&& (!receiveConfig.allowDrafts
|| projectControl.controlForRef("refs/drafts/" + ref)
.isBlocked(Permission.PUSH))) {
errors.put(Error.CODE_REVIEW, ref);
reject(cmd, "cannot upload drafts");
return;
if (magicBranch.draft) {
if (!receiveConfig.allowDrafts) {
errors.put(Error.CODE_REVIEW, ref);
reject(cmd, "draft workflow is disabled");
return;
} else if (projectControl.controlForRef("refs/drafts/" + ref)
.isBlocked(Permission.PUSH)) {
errors.put(Error.CODE_REVIEW, ref);
reject(cmd, "cannot upload drafts");
return;
}
}
if (!magicBranch.ctl.canUpload()) {