Commit 829f9bb7 authored by Greg Messner's avatar Greg Messner
Browse files

Added support for getting inherited member (#557)

parent 63d7192b
...@@ -778,9 +778,7 @@ public class GroupApi extends AbstractApi { ...@@ -778,9 +778,7 @@ public class GroupApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public Member getMember(Object groupIdOrPath, int userId) throws GitLabApiException { public Member getMember(Object groupIdOrPath, int userId) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(), return (getMember(groupIdOrPath, userId, false));
"groups", getGroupIdOrPath(groupIdOrPath), "members", userId);
return (response.readEntity(new GenericType<Member>() {}));
} }
/** /**
...@@ -794,7 +792,46 @@ public class GroupApi extends AbstractApi { ...@@ -794,7 +792,46 @@ public class GroupApi extends AbstractApi {
*/ */
public Optional<Member> getOptionalMember(Object groupIdOrPath, int userId) { public Optional<Member> getOptionalMember(Object groupIdOrPath, int userId) {
try { try {
return (Optional.ofNullable(getMember(groupIdOrPath, userId))); return (Optional.ofNullable(getMember(groupIdOrPath, userId, false)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/**
* Gets a group team member, optionally including inherited member.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/members/all/:user_id</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param userId the user ID of the member
* @param includeInherited if true will the member even if inherited thru an ancestor group
* @return the member specified by the project ID/user ID pair
* @throws GitLabApiException if any exception occurs
*/
public Member getMember(Object groupIdOrPath, Integer userId, Boolean includeInherited) throws GitLabApiException {
Response response;
if (includeInherited) {
response = get(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath), "members", "all", userId);
} else {
response = get(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath), "members", userId);
}
return (response.readEntity(Member.class));
}
/**
* Gets a group team member, optionally including inherited member.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/members/:user_id</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param userId the user ID of the member
* @param includeInherited if true will the member even if inherited thru an ancestor group
* @return the member specified by the group ID/user ID pair as the value of an Optional
*/
public Optional<Member> getOptionalMember(Object groupIdOrPath, Integer userId, Boolean includeInherited) {
try {
return (Optional.ofNullable(getMember(groupIdOrPath, userId, includeInherited)));
} catch (GitLabApiException glae) { } catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae)); return (GitLabApi.createOptionalFromException(glae));
} }
......
...@@ -1540,8 +1540,7 @@ public class ProjectApi extends AbstractApi implements Constants { ...@@ -1540,8 +1540,7 @@ public class ProjectApi extends AbstractApi implements Constants {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public Member getMember(Object projectIdOrPath, Integer userId) throws GitLabApiException { public Member getMember(Object projectIdOrPath, Integer userId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "members", userId); return (getMember(projectIdOrPath, userId, false));
return (response.readEntity(Member.class));
} }
/** /**
...@@ -1555,7 +1554,46 @@ public class ProjectApi extends AbstractApi implements Constants { ...@@ -1555,7 +1554,46 @@ public class ProjectApi extends AbstractApi implements Constants {
*/ */
public Optional<Member> getOptionalMember(Object projectIdOrPath, Integer userId) { public Optional<Member> getOptionalMember(Object projectIdOrPath, Integer userId) {
try { try {
return (Optional.ofNullable(getMember(projectIdOrPath, userId))); return (Optional.ofNullable(getMember(projectIdOrPath, userId, false)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/**
* Gets a project team member, optionally including inherited member.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/members/all/:user_id</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param userId the user ID of the member
* @param includeInherited if true will the member even if inherited thru an ancestor group
* @return the member specified by the project ID/user ID pair
* @throws GitLabApiException if any exception occurs
*/
public Member getMember(Object projectIdOrPath, Integer userId, Boolean includeInherited) throws GitLabApiException {
Response response;
if (includeInherited) {
response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "members", "all", userId);
} else {
response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "members", userId);
}
return (response.readEntity(Member.class));
}
/**
* Gets a project team member, optionally including inherited member.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/members/:user_id</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param userId the user ID of the member
* @param includeInherited if true will the member even if inherited thru an ancestor group
* @return the member specified by the project ID/user ID pair as the value of an Optional
*/
public Optional<Member> getOptionalMember(Object projectIdOrPath, Integer userId, Boolean includeInherited) {
try {
return (Optional.ofNullable(getMember(projectIdOrPath, userId, includeInherited)));
} catch (GitLabApiException glae) { } catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae)); return (GitLabApi.createOptionalFromException(glae));
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment