Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List user permission for repo #63

Merged
merged 6 commits into from
May 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ RepositoryPage list(@PathParam("project") String project,
@Nullable @QueryParam("start") Integer start,
@Nullable @QueryParam("limit") Integer limit);

@Named("repository:list-Permissions-User")
@Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/5.0.0/bitbucket-rest.html#idm45659054938032"})
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{project}/repos/{repo}/permissions/users")
@Fallback(BitbucketFallbacks.PermissionsPageOnError.class)
@GET
PermissionsPage listPermissionsByUser(@PathParam("project") String project,
@PathParam("repo") String repo,
@Nullable @QueryParam("start") Integer start,
@Nullable @QueryParam("limit") Integer limit);

@Named("repository:create-Permissions-Group")
@Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/5.0.0/bitbucket-rest.html#idm45659054969200"})
@Consumes(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ public void testCreateRepositoryWithIllegalName() {
assertThat(repository.errors().isEmpty()).isFalse();
}

@Test(dependsOnMethods = "testGetRepository")
public void testListPermissionByUser() {
PermissionsPage permissionsPage = api().listPermissionsByUser(projectKey, repoKey, 0, 100);
assertThat(permissionsPage.values()).isEmpty();
}

@Test(dependsOnMethods = "testGetRepository")
public void testListPermissionByGroup() {
PermissionsPage permissionsPage = api().listPermissionsByGroup(projectKey, repoKey, 0, 100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,32 @@ public void testGetRepositoryListNonExistent() throws Exception {
}
}

public void testListPermissionByUser() throws Exception {
MockWebServer server = mockEtcdJavaWebServer();

server.enqueue(new MockResponse().setBody(payloadFromResource("/repository-permission-users.json")).setResponseCode(200));
BitbucketApi baseApi = api(server.getUrl("/"));
RepositoryApi api = baseApi.repositoryApi();
try {
String projectKey = "PRJ1";
String repoKey = "1234";

PermissionsPage permissionsPage = api.listPermissionsByUser(projectKey, repoKey, 0, 100);
assertThat(permissionsPage).isNotNull();
assertThat(permissionsPage.errors()).isEmpty();
assertThat(permissionsPage.size() == 1).isTrue();
assertThat(permissionsPage.values().get(0).group() == null).isTrue();
assertThat(permissionsPage.values().get(0).user().name().equals("test")).isTrue();

Map<String, ?> queryParams = ImmutableMap.of("limit", 100, "start", 0);
assertSent(server, "GET", "/rest/api/" + BitbucketApiMetadata.API_VERSION
+ "/projects/" + projectKey + "/repos/" + repoKey + "/permissions/users", queryParams);
} finally {
baseApi.close();
server.shutdown();
}
}

public void testCreatePermissionByGroup() throws Exception {
MockWebServer server = mockEtcdJavaWebServer();

Expand Down Expand Up @@ -268,6 +294,7 @@ public void testListPermissionByGroup() throws Exception {
try {
String projectKey = "PRJ1";
String repoKey = "1234";

PermissionsPage permissionsPage = api.listPermissionsByGroup(projectKey, repoKey, 0, 100);
assertThat(permissionsPage).isNotNull();
assertThat(permissionsPage.errors()).isEmpty();
Expand All @@ -284,6 +311,29 @@ public void testListPermissionByGroup() throws Exception {
}
}

public void testListPermissionByUserOnError() throws Exception {
MockWebServer server = mockEtcdJavaWebServer();

server.enqueue(new MockResponse().setBody(payloadFromResource("/repository-permission-users-error.json")).setResponseCode(404));
BitbucketApi baseApi = api(server.getUrl("/"));
RepositoryApi api = baseApi.repositoryApi();
try {
String projectKey = "PRJ1";
String repoKey = "1234";
PermissionsPage permissionsPage = api.listPermissionsByUser(projectKey, repoKey, 0, 100);
assertThat(permissionsPage).isNotNull();
assertThat(permissionsPage.values()).isEmpty();
assertThat(permissionsPage.errors()).isNotEmpty();

Map<String, ?> queryParams = ImmutableMap.of("limit", 100, "start", 0);
assertSent(server, "GET", "/rest/api/" + BitbucketApiMetadata.API_VERSION
+ "/projects/" + projectKey + "/repos/" + repoKey + "/permissions/users", queryParams);
} finally {
baseApi.close();
server.shutdown();
}
}

public void testCreatePermissionByGroupOnError() throws Exception {
MockWebServer server = mockEtcdJavaWebServer();

Expand Down
9 changes: 9 additions & 0 deletions src/test/resources/repository-permission-users-error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"errors": [
{
"context": null,
"exceptionName": "com.atlassian.bitbucket.project.NoSuchProjectException",
"message": "Project test123 does not exist."
}
]
}
27 changes: 27 additions & 0 deletions src/test/resources/repository-permission-users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"isLastPage": true,
"limit": 25,
"size": 1,
"start": 0,
"values": [
{
"permission": "REPO_READ",
"user": {
"active": true,
"displayName": "test123 123",
"emailAddress": "[email protected]",
"id": 339,
"links": {
"self": [
{
"href": "https://bitbucket.amce.com/users/test"
}
]
},
"name": "test",
"slug": "test",
"type": "NORMAL"
}
}
]
}