Allow all users to use changes /index REST API
The /index changes REST API endpoint requires the user to be a member
of a group having the Administrate Server permission.
This is too restrictive. Users should be able to force indexing of
a change without being an administrator.
Allow /index to be used by any user that can see the change, i.e. has
read permission on the destination branch.
Change-Id: I3734e123a2859fcd0197895c42f9676a411d5716
diff --git a/Documentation/rest-api-changes.txt b/Documentation/rest-api-changes.txt
index 19ad9f6..e1978f3 100644
--- a/Documentation/rest-api-changes.txt
+++ b/Documentation/rest-api-changes.txt
@@ -1124,10 +1124,6 @@
Adds or updates the change in the secondary index.
-The caller must be a member of a group that is granted the
-link:access-control.html#capability_administrateServer[
-Administrate Server] capability.
-
.Request
----
POST /changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/index HTTP/1.0
diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change/IndexChangeIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change/IndexChangeIT.java
new file mode 100644
index 0000000..1b00c39
--- /dev/null
+++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change/IndexChangeIT.java
@@ -0,0 +1,40 @@
+// Copyright (C) 2014 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.rest.change;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.gerrit.acceptance.AbstractDaemonTest;
+import com.google.gerrit.acceptance.RestResponse;
+
+import org.apache.http.HttpStatus;
+import org.junit.Test;
+
+public class IndexChangeIT extends AbstractDaemonTest {
+ @Test
+ public void indexChange() throws Exception {
+ String changeId = createChange().getChangeId();
+ RestResponse r = userSession.post("/changes/" + changeId + "/index/");
+ assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
+ }
+
+ @Test
+ public void indexChangeOnNonVisibleBranch() throws Exception {
+ String changeId = createChange().getChangeId();
+ blockRead(project, "refs/heads/master");
+ RestResponse r = userSession.post("/changes/" + changeId + "/index/");
+ assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND);
+ }
+}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/Index.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/Index.java
index 6cf3e00..280d078 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/change/Index.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/Index.java
@@ -14,8 +14,6 @@
package com.google.gerrit.server.change;
-import com.google.gerrit.common.data.GlobalCapability;
-import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.reviewdb.server.ReviewDb;
@@ -27,7 +25,6 @@
import java.io.IOException;
-@RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER)
@Singleton
public class Index implements RestModifyView<ChangeResource, Input> {
public static class Input {