From 829f9bb7f68bf3c8505523e688ab3476969e654a Mon Sep 17 00:00:00 2001 From: Greg Messner Date: Sat, 2 May 2020 22:11:46 -0700 Subject: [PATCH] Added support for getting inherited member (#557) --- src/main/java/org/gitlab4j/api/GroupApi.java | 45 +++++++++++++++++-- .../java/org/gitlab4j/api/ProjectApi.java | 44 ++++++++++++++++-- 2 files changed, 82 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/GroupApi.java b/src/main/java/org/gitlab4j/api/GroupApi.java index 82d05b90..5ef3c960 100644 --- a/src/main/java/org/gitlab4j/api/GroupApi.java +++ b/src/main/java/org/gitlab4j/api/GroupApi.java @@ -778,9 +778,7 @@ public class GroupApi extends AbstractApi { * @throws GitLabApiException if any exception occurs */ public Member getMember(Object groupIdOrPath, int userId) throws GitLabApiException { - Response response = get(Response.Status.OK, getDefaultPerPageParam(), - "groups", getGroupIdOrPath(groupIdOrPath), "members", userId); - return (response.readEntity(new GenericType() {})); + return (getMember(groupIdOrPath, userId, false)); } /** @@ -794,7 +792,46 @@ public class GroupApi extends AbstractApi { */ public Optional getOptionalMember(Object groupIdOrPath, int userId) { 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. + * + *
GitLab Endpoint: GET /projects/:id/members/all/:user_id
+ * + * @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. + * + *
GitLab Endpoint: GET /projects/:id/members/:user_id
+ * + * @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 getOptionalMember(Object groupIdOrPath, Integer userId, Boolean includeInherited) { + try { + return (Optional.ofNullable(getMember(groupIdOrPath, userId, includeInherited))); } catch (GitLabApiException glae) { return (GitLabApi.createOptionalFromException(glae)); } diff --git a/src/main/java/org/gitlab4j/api/ProjectApi.java b/src/main/java/org/gitlab4j/api/ProjectApi.java index 88ddab1e..a9ff3c20 100644 --- a/src/main/java/org/gitlab4j/api/ProjectApi.java +++ b/src/main/java/org/gitlab4j/api/ProjectApi.java @@ -1540,8 +1540,7 @@ public class ProjectApi extends AbstractApi implements Constants { * @throws GitLabApiException if any exception occurs */ public Member getMember(Object projectIdOrPath, Integer userId) throws GitLabApiException { - Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "members", userId); - return (response.readEntity(Member.class)); + return (getMember(projectIdOrPath, userId, false)); } /** @@ -1555,7 +1554,46 @@ public class ProjectApi extends AbstractApi implements Constants { */ public Optional getOptionalMember(Object projectIdOrPath, Integer userId) { 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. + * + *
GitLab Endpoint: GET /projects/:id/members/all/:user_id
+ * + * @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. + * + *
GitLab Endpoint: GET /projects/:id/members/:user_id
+ * + * @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 getOptionalMember(Object projectIdOrPath, Integer userId, Boolean includeInherited) { + try { + return (Optional.ofNullable(getMember(projectIdOrPath, userId, includeInherited))); } catch (GitLabApiException glae) { return (GitLabApi.createOptionalFromException(glae)); } -- GitLab