List{Branches,Tags}: "can_delete" should not be set when false

The ListBranches implementation already does not set "can_delete"
when it's false.  Fix the example in the documentation.

Fix the TagInfo constructors to use Java's Boolean class, rather
than the primitive boolean, and explicitly set it to null when
false. Also update the documentation.

In DeleteBranchIT and DeleteTagIT, add assertions that canDelete
is true or null.

Change-Id: Ia139f0939f1ca6cb7bdd8b097d69e7a3f6543c25
This commit is contained in:
David Pursehouse
2017-11-10 15:57:41 +09:00
parent 98566debdd
commit d00515e898
6 changed files with 14 additions and 9 deletions

View File

@@ -1305,7 +1305,6 @@ Limit the number of branches to be included in the results.
{ {
"ref": "HEAD", "ref": "HEAD",
"revision": "master", "revision": "master",
"can_delete": false
} }
] ]
---- ----
@@ -1329,7 +1328,6 @@ Skip the given number of branches from the beginning of the list.
{ {
"ref": "HEAD", "ref": "HEAD",
"revision": "master", "revision": "master",
"can_delete": false
} }
] ]
---- ----
@@ -2661,7 +2659,7 @@ The `BranchInfo` entity contains information about a branch.
|Field Name ||Description |Field Name ||Description
|`ref` ||The ref of the branch. |`ref` ||The ref of the branch.
|`revision` ||The revision to which the branch points. |`revision` ||The revision to which the branch points.
|`can_delete`|`false` if not set| |`can_delete`|not set if `false`|
Whether the calling user can delete this branch. Whether the calling user can delete this branch.
|`web_links` |optional| |`web_links` |optional|
Links to the branch in external sites as a list of Links to the branch in external sites as a list of
@@ -3220,7 +3218,7 @@ tag points.
the signature. the signature.
|`tagger`|Only set for annotated tags, if present in the tag.|The tagger as a |`tagger`|Only set for annotated tags, if present in the tag.|The tagger as a
link:rest-api-changes.html#git-person-info[GitPersonInfo] entity. link:rest-api-changes.html#git-person-info[GitPersonInfo] entity.
|`can_delete`|`false` if not set| |`can_delete`|not set if `false`|
Whether the calling user can delete this tag. Whether the calling user can delete this tag.
|`web_links` |optional| |`web_links` |optional|
Links to the tag in external sites as a list of Links to the tag in external sites as a list of

View File

@@ -139,6 +139,7 @@ public class DeleteBranchIT extends AbstractDaemonTest {
} }
private void assertDeleteSucceeds() throws Exception { private void assertDeleteSucceeds() throws Exception {
assertThat(branch().get().canDelete).isTrue();
String branchRev = branch().get().revision; String branchRev = branch().get().revision;
branch().delete(); branch().delete();
eventRecorder.assertRefUpdatedEvents( eventRecorder.assertRefUpdatedEvents(
@@ -148,6 +149,7 @@ public class DeleteBranchIT extends AbstractDaemonTest {
} }
private void assertDeleteForbidden() throws Exception { private void assertDeleteForbidden() throws Exception {
assertThat(branch().get().canDelete).isNull();
exception.expect(AuthException.class); exception.expect(AuthException.class);
exception.expectMessage("delete not permitted"); exception.expectMessage("delete not permitted");
branch().delete(); branch().delete();

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.acceptance.rest.project; package com.google.gerrit.acceptance.rest.project;
import static com.google.common.truth.Truth.assertThat;
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS; import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS; import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
import static org.eclipse.jgit.lib.Constants.R_TAGS; import static org.eclipse.jgit.lib.Constants.R_TAGS;
@@ -22,6 +23,7 @@ import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.RestResponse; import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.common.data.Permission; import com.google.gerrit.common.data.Permission;
import com.google.gerrit.extensions.api.projects.TagApi; import com.google.gerrit.extensions.api.projects.TagApi;
import com.google.gerrit.extensions.api.projects.TagInfo;
import com.google.gerrit.extensions.api.projects.TagInput; import com.google.gerrit.extensions.api.projects.TagInput;
import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException; import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
@@ -111,7 +113,9 @@ public class DeleteTagIT extends AbstractDaemonTest {
} }
private void assertDeleteSucceeds() throws Exception { private void assertDeleteSucceeds() throws Exception {
String tagRev = tag().get().revision; TagInfo tagInfo = tag().get();
assertThat(tagInfo.canDelete).isTrue();
String tagRev = tagInfo.revision;
tag().delete(); tag().delete();
eventRecorder.assertRefUpdatedEvents(project.get(), TAG, null, tagRev, tagRev, null); eventRecorder.assertRefUpdatedEvents(project.get(), TAG, null, tagRev, tagRev, null);
exception.expect(ResourceNotFoundException.class); exception.expect(ResourceNotFoundException.class);
@@ -119,6 +123,7 @@ public class DeleteTagIT extends AbstractDaemonTest {
} }
private void assertDeleteForbidden() throws Exception { private void assertDeleteForbidden() throws Exception {
assertThat(tag().get().canDelete).isNull();
exception.expect(AuthException.class); exception.expect(AuthException.class);
exception.expectMessage("delete not permitted"); exception.expectMessage("delete not permitted");
tag().delete(); tag().delete();

View File

@@ -187,7 +187,7 @@ public class TagsIT extends AbstractDaemonTest {
setApiUser(user); setApiUser(user);
result = tag(input.ref).get(); result = tag(input.ref).get();
assertThat(result.canDelete).isFalse(); assertThat(result.canDelete).isNull();
eventRecorder.assertRefUpdatedEvents(project.get(), result.ref, null, result.revision); eventRecorder.assertRefUpdatedEvents(project.get(), result.ref, null, result.revision);
} }

View File

@@ -24,7 +24,7 @@ public class TagInfo extends RefInfo {
public GitPerson tagger; public GitPerson tagger;
public List<WebLinkInfo> webLinks; public List<WebLinkInfo> webLinks;
public TagInfo(String ref, String revision, boolean canDelete, List<WebLinkInfo> webLinks) { public TagInfo(String ref, String revision, Boolean canDelete, List<WebLinkInfo> webLinks) {
this.ref = ref; this.ref = ref;
this.revision = revision; this.revision = revision;
this.canDelete = canDelete; this.canDelete = canDelete;
@@ -37,7 +37,7 @@ public class TagInfo extends RefInfo {
String object, String object,
String message, String message,
GitPerson tagger, GitPerson tagger,
boolean canDelete, Boolean canDelete,
List<WebLinkInfo> webLinks) { List<WebLinkInfo> webLinks) {
this(ref, revision, canDelete, webLinks); this(ref, revision, canDelete, webLinks);
this.object = object; this.object = object;

View File

@@ -190,7 +190,7 @@ public class ListTags implements RestReadView<ProjectResource> {
WebLinks links) WebLinks links)
throws MissingObjectException, IOException { throws MissingObjectException, IOException {
RevObject object = rw.parseAny(ref.getObjectId()); RevObject object = rw.parseAny(ref.getObjectId());
boolean canDelete = perm.testOrFalse(RefPermission.DELETE); Boolean canDelete = perm.testOrFalse(RefPermission.DELETE) ? true : null;
List<WebLinkInfo> webLinks = links.getTagLinks(projectName.get(), ref.getName()); List<WebLinkInfo> webLinks = links.getTagLinks(projectName.get(), ref.getName());
if (object instanceof RevTag) { if (object instanceof RevTag) {
// Annotated or signed tag // Annotated or signed tag