From 036fa56da3d4ed6d1cf18819d22424beb5718c15 Mon Sep 17 00:00:00 2001 From: Greg Messner Date: Wed, 3 Jan 2018 01:23:32 -0800 Subject: [PATCH] Added hard_delete support to deleteUser() (#123). --- src/main/java/org/gitlab4j/api/UserApi.java | 33 +++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/UserApi.java b/src/main/java/org/gitlab4j/api/UserApi.java index f4ef282f..7f19d0a9 100644 --- a/src/main/java/org/gitlab4j/api/UserApi.java +++ b/src/main/java/org/gitlab4j/api/UserApi.java @@ -351,13 +351,28 @@ public class UserApi extends AbstractApi { * @throws GitLabApiException if any exception occurs */ public void deleteUser(Integer userId) throws GitLabApiException { + deleteUser(userId, null); + } + + /** + * Deletes a user. Available only for administrators. + * + * DELETE /users/:id + * + * @param userId the user ID to delete + * @param hardDelete If true, contributions that would usually be moved to the + * ghost user will be deleted instead, as well as groups owned solely by this user + * @throws GitLabApiException if any exception occurs + */ + public void deleteUser(Integer userId, Boolean hardDelete) throws GitLabApiException { if (userId == null) { throw new RuntimeException("userId cannot be null"); } + GitLabApiForm formData = new GitLabApiForm().withParam("hard_delete ", hardDelete); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); - delete(expectedStatus, null, "users", userId); + delete(expectedStatus, formData.asMap(), "users", userId); } /** @@ -369,7 +384,21 @@ public class UserApi extends AbstractApi { * @throws GitLabApiException if any exception occurs */ public void deleteUser(User user) throws GitLabApiException { - deleteUser(user.getId()); + deleteUser(user.getId(), null); + } + + /** + * Deletes a user. Available only for administrators. + * + * DELETE /users/:id + * + * @param user the User instance to delete + * @param hardDelete If true, contributions that would usually be moved to the + * ghost user will be deleted instead, as well as groups owned solely by this user + * @throws GitLabApiException if any exception occurs + */ + public void deleteUser(User user, Boolean hardDelete) throws GitLabApiException { + deleteUser(user.getId(), hardDelete); } /** -- GitLab