Add config to disable private changes
This commit adds a config option so that we can disable private changes. With this config enabled, users will not be able to create private changes through UI or Git push. Users can't set a change to be private through the PostPrivate REST endpoint, either. Change-Id: I2794c140f37bd3940b0a2fad68abbced1145c843
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
// Copyright (C) 2017 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.api.change;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.GerritConfig;
|
||||
import com.google.gerrit.acceptance.PushOneCommit;
|
||||
import com.google.gerrit.extensions.common.ChangeInput;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DisablePrivateChangesIT extends AbstractDaemonTest {
|
||||
|
||||
@Test
|
||||
@GerritConfig(name = "change.disablePrivateChanges", value = "true")
|
||||
public void createPrivateChangeWithDisablePrivateChangesTrue() throws Exception {
|
||||
ChangeInput input = new ChangeInput(project.get(), "master", "empty change");
|
||||
input.isPrivate = true;
|
||||
exception.expect(MethodNotAllowedException.class);
|
||||
exception.expectMessage("private changes are disabled");
|
||||
gApi.changes().create(input);
|
||||
}
|
||||
|
||||
@Test
|
||||
@GerritConfig(name = "change.disablePrivateChanges", value = "true")
|
||||
public void createNonPrivateChangeWithDisablePrivateChangesTrue() throws Exception {
|
||||
ChangeInput input = new ChangeInput(project.get(), "master", "empty change");
|
||||
assertThat(gApi.changes().create(input).get().isPrivate).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPrivateChangeWithDisablePrivateChangesFalse() throws Exception {
|
||||
ChangeInput input = new ChangeInput(project.get(), "master", "empty change");
|
||||
input.isPrivate = true;
|
||||
assertThat(gApi.changes().create(input).get().isPrivate).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@GerritConfig(name = "change.disablePrivateChanges", value = "true")
|
||||
public void pushPrivatesWithDisablePrivateChangesTrue() throws Exception {
|
||||
PushOneCommit.Result result =
|
||||
pushFactory.create(db, admin.getIdent(), testRepo).to("refs/for/master%private");
|
||||
result.assertErrorStatus();
|
||||
}
|
||||
|
||||
@Test
|
||||
@GerritConfig(name = "change.disablePrivateChanges", value = "true")
|
||||
public void pushDraftsWithDisablePrivateChangesTrue() throws Exception {
|
||||
RevCommit initialHead = getRemoteHead();
|
||||
PushOneCommit.Result result =
|
||||
pushFactory.create(db, admin.getIdent(), testRepo).to("refs/for/master%draft");
|
||||
result.assertErrorStatus();
|
||||
|
||||
testRepo.reset(initialHead);
|
||||
result = pushFactory.create(db, admin.getIdent(), testRepo).to("refs/drafts/master");
|
||||
result.assertErrorStatus();
|
||||
}
|
||||
|
||||
@Test
|
||||
@GerritConfig(name = "change.disablePrivateChanges", value = "true")
|
||||
public void pushWithDisablePrivateChangesTrue() throws Exception {
|
||||
PushOneCommit.Result result =
|
||||
pushFactory.create(db, admin.getIdent(), testRepo).to("refs/for/master");
|
||||
result.assertOkStatus();
|
||||
assertThat(result.getChange().change().isPrivate()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pushPrivatesWithDisablePrivateChangesFalse() throws Exception {
|
||||
PushOneCommit.Result result =
|
||||
pushFactory.create(db, admin.getIdent(), testRepo).to("refs/for/master%private");
|
||||
assertThat(result.getChange().change().isPrivate()).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pushDraftsWithDisablePrivateChangesFalse() throws Exception {
|
||||
RevCommit initialHead = getRemoteHead();
|
||||
PushOneCommit.Result result =
|
||||
pushFactory.create(db, admin.getIdent(), testRepo).to("refs/for/master%draft");
|
||||
assertThat(result.getChange().change().isPrivate()).isEqualTo(true);
|
||||
|
||||
testRepo.reset(initialHead);
|
||||
result = pushFactory.create(db, admin.getIdent(), testRepo).to("refs/drafts/master");
|
||||
assertThat(result.getChange().change().isPrivate()).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@GerritConfig(name = "change.disablePrivateChanges", value = "true")
|
||||
public void setPrivateWithDisablePrivateChangesTrue() throws Exception {
|
||||
PushOneCommit.Result result = createChange();
|
||||
|
||||
exception.expect(MethodNotAllowedException.class);
|
||||
exception.expectMessage("private changes are disabled");
|
||||
gApi.changes().id(result.getChangeId()).setPrivate(true, "set private");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPrivateWithDisablePrivateChangesFalse() throws Exception {
|
||||
PushOneCommit.Result result = createChange();
|
||||
gApi.changes().id(result.getChangeId()).setPrivate(true, "set private");
|
||||
assertThat(gApi.changes().id(result.getChangeId()).get().isPrivate).isTrue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user