Only create new changes as draft if draft changes are allowed
In change I33a3cccb the behavior of the "Create Change" and "Follow Up" buttons was changed so that new changes are always created as drafts. The `change.allowDrafts` setting was not considered, which allowed a new draft change to be created even when disabled. It was then not possible to publish the draft change because the publish draft action checks the `change.allowDrafts` setting. Change it so that changes are only created as draft when draft changes are allowed. When not allowed, create regular new changes. Change-Id: Ie8bea86218d23d2efb30afee4500e4eb8c59e2c2
This commit is contained in:
@@ -5,12 +5,16 @@ browser.
|
||||
|
||||
|
||||
[[create-change]]
|
||||
== Creating a New Empty Change
|
||||
== Creating a New Change
|
||||
|
||||
A new change can be created directly in the browser, meaning it is not necessary
|
||||
to clone the whole repository to make trivial changes.
|
||||
|
||||
There are two different ways to create an empty change:
|
||||
The new change is created as a draft change, unless
|
||||
link:config-gerrit.html#change.allowDrafts[change.allowDrafts] is set to false,
|
||||
in which case the change is created as a normal new change.
|
||||
|
||||
There are two different ways to create a new change:
|
||||
|
||||
By clicking on the 'Create Change' button in the project screen:
|
||||
|
||||
@@ -22,8 +26,8 @@ The user can select the branch on which the new change should be created:
|
||||
|
||||
image::images/inline-edit-create-change-project-screen-dialog.png[width=800, link="images/inline-edit-create-change-project-screen-dialog.png"]
|
||||
|
||||
By clicking the 'Follow-Up' button on the change screen, to create an empty
|
||||
change based on the selected change.
|
||||
By clicking the 'Follow-Up' button on the change screen, to create a new change
|
||||
based on the selected change.
|
||||
|
||||
[[create-change-from-change-screen]]
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ public class GerritConfig implements Cloneable {
|
||||
protected int largeChangeSize;
|
||||
protected String replyLabel;
|
||||
protected String replyTitle;
|
||||
protected boolean allowDraftChanges;
|
||||
|
||||
public String getLoginUrl() {
|
||||
return loginUrl;
|
||||
@@ -307,4 +308,12 @@ public class GerritConfig implements Cloneable {
|
||||
public void setReplyLabel(String r) {
|
||||
replyLabel = r;
|
||||
}
|
||||
|
||||
public boolean isAllowDraftChanges() {
|
||||
return allowDraftChanges;
|
||||
}
|
||||
|
||||
public void setAllowDraftChanges(boolean b) {
|
||||
allowDraftChanges = b;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class CreateChangeAction {
|
||||
|
||||
@Override
|
||||
public void onSend() {
|
||||
ChangeApi.createDraftChange(project, getDestinationBranch(),
|
||||
ChangeApi.createChange(project, getDestinationBranch(),
|
||||
message.getText(), null,
|
||||
new GerritCallback<ChangeInfo>() {
|
||||
@Override
|
||||
|
||||
@@ -35,7 +35,7 @@ class FollowUpAction extends ActionMessageBox {
|
||||
|
||||
@Override
|
||||
void send(String message) {
|
||||
ChangeApi.createDraftChange(project, branch, message, base,
|
||||
ChangeApi.createChange(project, branch, message, base,
|
||||
new GerritCallback<ChangeInfo>() {
|
||||
@Override
|
||||
public void onSuccess(ChangeInfo result) {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.client.changes;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.changes.ChangeInfo.CommitInfo;
|
||||
import com.google.gerrit.client.changes.ChangeInfo.EditInfo;
|
||||
import com.google.gerrit.client.changes.ChangeInfo.IncludedInInfo;
|
||||
@@ -37,15 +38,24 @@ public class ChangeApi {
|
||||
call(id, "abandon").post(input, cb);
|
||||
}
|
||||
|
||||
/** Create a draft change. */
|
||||
public static void createDraftChange(String project, String branch,
|
||||
/** Create a new change.
|
||||
*
|
||||
* The new change is created as DRAFT unless the draft workflow is disabled
|
||||
* by `change.allowDrafts = false` in the configuration, in which case the
|
||||
* new change is created as NEW.
|
||||
*
|
||||
*/
|
||||
public static void createChange(String project, String branch,
|
||||
String subject, String base, AsyncCallback<ChangeInfo> cb) {
|
||||
CreateChangeInput input = CreateChangeInput.create();
|
||||
input.project(emptyToNull(project));
|
||||
input.branch(emptyToNull(branch));
|
||||
input.subject(emptyToNull(subject));
|
||||
input.base_change(emptyToNull(base));
|
||||
input.status(Change.Status.DRAFT.toString());
|
||||
|
||||
if (Gerrit.getConfig().isAllowDraftChanges()) {
|
||||
input.status(Change.Status.DRAFT.toString());
|
||||
}
|
||||
|
||||
new RestApi("/changes/").post(input, cb);
|
||||
}
|
||||
|
||||
@@ -177,6 +177,8 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
||||
config.setReplyTitle(replyTitle);
|
||||
config.setReplyLabel(replyLabel);
|
||||
|
||||
config.setAllowDraftChanges(cfg.getBoolean("change", "allowDrafts", true));
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user