From cd3547e16566596f5af43cbc6769593ef99a86dd Mon Sep 17 00:00:00 2001 From: David Lam Date: Sun, 6 May 2018 15:18:21 -0400 Subject: [PATCH 1/8] add extern uid field for create --- src/main/java/org/gitlab4j/api/UserApi.java | 8 +++++--- src/main/java/org/gitlab4j/api/models/User.java | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/UserApi.java b/src/main/java/org/gitlab4j/api/UserApi.java index df9df2876..2cd41ecae 100644 --- a/src/main/java/org/gitlab4j/api/UserApi.java +++ b/src/main/java/org/gitlab4j/api/UserApi.java @@ -560,7 +560,7 @@ public SshKey addSshKey(Integer userId, String title, String key) throws GitLabA } /** - * Deletes key owned by currently authenticated user. This is an idempotent function and calling it + * Deletes key owned by currently authenticated user. This is an idempotent function and calling it * on a key that is already deleted or not available results in success. * * DELETE /user/keys/:key_id @@ -745,6 +745,7 @@ public void revokeImpersonationToken(Integer userId, Integer tokenId) throws Git * @return the populated Form instance */ Form userToForm(User user, Integer projectsLimit, String password, boolean create) { + return (new GitLabApiForm() .withParam("email", user.getEmail(), create) .withParam("password", password, create) @@ -761,7 +762,8 @@ Form userToForm(User user, Integer projectsLimit, String password, boolean creat .withParam("location", user.getLocation(), false) .withParam("admin", user.getIsAdmin(), false) .withParam("can_create_group", user.getCanCreateGroup(), false) - .withParam("external", user.getExternal(), false)) - .withParam("skip_confirmation",user.getSkipConfirmation(),false); + .withParam("external", user.getExternal(), false) + .withParam("extern_uid", user.getExternUid(), false) + .withParam("skip_confirmation",user.getSkipConfirmation(),false)); } } diff --git a/src/main/java/org/gitlab4j/api/models/User.java b/src/main/java/org/gitlab4j/api/models/User.java index 950422d59..ff4149016 100644 --- a/src/main/java/org/gitlab4j/api/models/User.java +++ b/src/main/java/org/gitlab4j/api/models/User.java @@ -4,4 +4,13 @@ @XmlRootElement public class User extends AbstractUser { + private String externUid; + + public void setExternUid(String externUid) { + this.externUid = externUid; + } + + public String getExternUid() { + return this.externUid; + } } From d9fb9d21f068af58194ec27215babe62ac4db0cb Mon Sep 17 00:00:00 2001 From: David Lam Date: Mon, 7 May 2018 12:12:05 -0400 Subject: [PATCH 2/8] added fluent builder pattern to User --- .../java/org/gitlab4j/api/models/User.java | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/src/main/java/org/gitlab4j/api/models/User.java b/src/main/java/org/gitlab4j/api/models/User.java index ff4149016..b27e7773f 100644 --- a/src/main/java/org/gitlab4j/api/models/User.java +++ b/src/main/java/org/gitlab4j/api/models/User.java @@ -4,8 +4,26 @@ @XmlRootElement public class User extends AbstractUser { + private String password; + private Boolean resetPassword; private String externUid; + public void setPassword(String password) { + this.password = password; + } + + public String getPassword() { + return this.password; + } + + public void setResetPassword(Boolean resetPassword) { + this.resetPassword = resetPassword; + } + + public Boolean getResetPassword() { + return this.resetPassword; + } + public void setExternUid(String externUid) { this.externUid = externUid; } @@ -13,4 +31,104 @@ public void setExternUid(String externUid) { public String getExternUid() { return this.externUid; } + + public User withEmail(String email) { + setEmail(email); + return this; + } + + public User withPassword(String password) { + setPassword(password); + return this; + } + + public User withResetPassword(boolean resetPassword) { + setResetPassword(resetPassword); + return this; + } + + public User withName(String name) { + setName(name); + return this; + } + + public User withUsername(String username) { + setUsername(username); + return this; + } + + public User withSkype(String skype) { + setSkype(skype); + return this; + } + + public User withLinkedin(String linkedIn) { + setLinkedin(linkedIn); + return this; + } + + public User withTwitter(String twitter) { + setTwitter(twitter); + return this; + } + + public User withWebsiteUrl(String websiteUrl) { + setWebsiteUrl(websiteUrl); + return this; + } + + public User withOrganization(String organization) { + setOrganization(organization); + return this; + } + + public User withProjectLimit(Integer projectsLimit) { + setProjectsLimit(projectsLimit); + return this; + } + + public User withExternUid(String externUid) { + setExternUid(externUid); + return this; + } + + public User withProvider(String provider) { + setProvider(provider); + return this; + } + + public User withBio(String bio) { + setBio(bio); + return this; + } + + public User withLocation(String location) { + setLocation(location); + return this; + } + + public User withIsAdmin(Boolean isAdmin) { + setIsAdmin(isAdmin); + return this; + } + + public User withCanCreateGroup(Boolean canCreateGroup) { + setCanCreateGroup(canCreateGroup); + return this; + } + + public User withSkipConfirmation(Boolean skipConfirmation) { + setSkipConfirmation(skipConfirmation); + return this; + } + + public User withExternal(Boolean external) { + setExternal(external); + return this; + } + + public User withSharedRunnersMinuteLimit(Integer sharedRunnersMinuteLimit) { + setSharedRunnersMinutesLimit(sharedRunnersMinuteLimit); + return this; + } } From 4f40ff64beaa62d1a0a95bc650219f01b4cd8e79 Mon Sep 17 00:00:00 2001 From: David Lam Date: Mon, 7 May 2018 12:12:32 -0400 Subject: [PATCH 3/8] updated form constructor and added convenience method for createUser --- src/main/java/org/gitlab4j/api/UserApi.java | 64 ++++++++++++++++++--- 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/UserApi.java b/src/main/java/org/gitlab4j/api/UserApi.java index 2cd41ecae..f8c237faf 100644 --- a/src/main/java/org/gitlab4j/api/UserApi.java +++ b/src/main/java/org/gitlab4j/api/UserApi.java @@ -311,23 +311,31 @@ public Pager findUsers(String emailOrUsername, int itemsPerPage) throws Gi /** * Creates a new user. Note only administrators can create new users. + * Either password or reset_password should be specified (reset_password takes priority). * * POST /users * * email (required) - Email - * password (required) - Password + * password (optional) - Password + * reset_password (optional) - Send user password reset link - true or false(default) * username (required) - Username * name (required) - Name * skype (optional) - Skype ID - * linkedin (optional) - Linkedin + * linkedin (optional) - LinkedIn * twitter (optional) - Twitter account - * website_url (optional) - Website url + * website_url (optional) - Website URL + * organization (optional) - Organization name * projects_limit (optional) - Number of projects user can create * extern_uid (optional) - External UID * provider (optional) - External provider name - * bio (optional) - User's bio + * bio (optional) - User's biography + * location (optional) - User's location * admin (optional) - User is admin - true or false (default) * can_create_group (optional) - User can create groups - true or false + * skip_confirmation (optional) - Skip confirmation - true or false (default) + * external (optional) - Flags the user as external - true or false(default) + * avatar (optional) - Image file for user's avatar + * shared_runners_minutes_limit (optional) - Pipeline minutes quota for this user * * @param user the User instance with the user info to create * @param password the password for the new user @@ -341,6 +349,44 @@ public User createUser(User user, String password, Integer projectsLimit) throws return (response.readEntity(User.class)); } + /** + * Creates a new user. Note only administrators can create new users. + * Either password or reset_password should be specified (reset_password takes priority). + * + * POST /users + * + * email (required) - Email + * password (optional) - Password + * reset_password (optional) - Send user password reset link - true or false(default) + * username (required) - Username + * name (required) - Name + * skype (optional) - Skype ID + * linkedin (optional) - LinkedIn + * twitter (optional) - Twitter account + * website_url (optional) - Website URL + * organization (optional) - Organization name + * projects_limit (optional) - Number of projects user can create + * extern_uid (optional) - External UID + * provider (optional) - External provider name + * bio (optional) - User's biography + * location (optional) - User's location + * admin (optional) - User is admin - true or false (default) + * can_create_group (optional) - User can create groups - true or false + * skip_confirmation (optional) - Skip confirmation - true or false (default) + * external (optional) - Flags the user as external - true or false(default) + * avatar (optional) - Image file for user's avatar + * shared_runners_minutes_limit (optional) - Pipeline minutes quota for this user + * + * @param user the User instance with the user info to create + * @return created User instance + * @throws GitLabApiException if any exception occurs + */ + public User createUser(User user) throws GitLabApiException { + Form formData = userToForm(user, null, null, true); + Response response = post(Response.Status.CREATED, formData, "users"); + return (response.readEntity(User.class)); + } + /** * Modifies an existing user. Only administrators can change attributes of a user. * @@ -745,25 +791,29 @@ public void revokeImpersonationToken(Integer userId, Integer tokenId) throws Git * @return the populated Form instance */ Form userToForm(User user, Integer projectsLimit, String password, boolean create) { + projectsLimit = (user.getProjectsLimit() == null) ? user.getProjectsLimit() : projectsLimit; + password = (user.getPassword() == null) ? user.getPassword() : password; return (new GitLabApiForm() .withParam("email", user.getEmail(), create) .withParam("password", password, create) + .withParam("reset_password", user.getResetPassword(), false) .withParam("username", user.getUsername(), create) .withParam("name", user.getName(), create) .withParam("skype", user.getSkype(), false) .withParam("linkedin", user.getLinkedin(), false) .withParam("twitter", user.getTwitter(), false) .withParam("website_url", user.getWebsiteUrl(), false) - .withParam("projects_limit", projectsLimit, false) .withParam("organization", user.getOrganization(), false) + .withParam("projects_limit", projectsLimit, false) + .withParam("extern_uid", user.getExternUid(), false) .withParam("provider", user.getProvider(), false) .withParam("bio", user.getBio(), false) .withParam("location", user.getLocation(), false) .withParam("admin", user.getIsAdmin(), false) .withParam("can_create_group", user.getCanCreateGroup(), false) + .withParam("skip_confirmation", user.getSkipConfirmation(), false) .withParam("external", user.getExternal(), false) - .withParam("extern_uid", user.getExternUid(), false) - .withParam("skip_confirmation",user.getSkipConfirmation(),false)); + .withParam("shared_runners_minutes_limit", user.getSharedRunnersMinutesLimit(),false)); } } From 87399fbc177a9034e4e855e1f399df9cd790955b Mon Sep 17 00:00:00 2001 From: David Lam Date: Mon, 7 May 2018 12:17:53 -0400 Subject: [PATCH 4/8] prefer parameters of User form data specification --- src/main/java/org/gitlab4j/api/UserApi.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/UserApi.java b/src/main/java/org/gitlab4j/api/UserApi.java index f8c237faf..7d3199d06 100644 --- a/src/main/java/org/gitlab4j/api/UserApi.java +++ b/src/main/java/org/gitlab4j/api/UserApi.java @@ -791,8 +791,8 @@ public void revokeImpersonationToken(Integer userId, Integer tokenId) throws Git * @return the populated Form instance */ Form userToForm(User user, Integer projectsLimit, String password, boolean create) { - projectsLimit = (user.getProjectsLimit() == null) ? user.getProjectsLimit() : projectsLimit; - password = (user.getPassword() == null) ? user.getPassword() : password; + projectsLimit = (projectsLimit == null) ? user.getProjectsLimit() : projectsLimit; + password = (password == null) ? user.getPassword() : password; return (new GitLabApiForm() .withParam("email", user.getEmail(), create) From 40b0c50f5e4b2fadddf4458b82387904f1611271 Mon Sep 17 00:00:00 2001 From: David Lam Date: Mon, 7 May 2018 21:42:24 -0400 Subject: [PATCH 5/8] extracted password and reset_password as parameters --- src/main/java/org/gitlab4j/api/UserApi.java | 59 ++++++++++++++++--- .../java/org/gitlab4j/api/models/User.java | 28 --------- 2 files changed, 51 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/UserApi.java b/src/main/java/org/gitlab4j/api/UserApi.java index 7d3199d06..4328ce911 100644 --- a/src/main/java/org/gitlab4j/api/UserApi.java +++ b/src/main/java/org/gitlab4j/api/UserApi.java @@ -344,7 +344,7 @@ public Pager findUsers(String emailOrUsername, int itemsPerPage) throws Gi * @throws GitLabApiException if any exception occurs */ public User createUser(User user, String password, Integer projectsLimit) throws GitLabApiException { - Form formData = userToForm(user, projectsLimit, password, true); + Form formData = userToForm(user, projectsLimit, password, null, true); Response response = post(Response.Status.CREATED, formData, "users"); return (response.readEntity(User.class)); } @@ -378,11 +378,50 @@ public User createUser(User user, String password, Integer projectsLimit) throws * shared_runners_minutes_limit (optional) - Pipeline minutes quota for this user * * @param user the User instance with the user info to create + * @param resetPassword whether to send user password reset link * @return created User instance * @throws GitLabApiException if any exception occurs */ - public User createUser(User user) throws GitLabApiException { - Form formData = userToForm(user, null, null, true); + public User createUser(User user, boolean resetPassword) throws GitLabApiException { + Form formData = userToForm(user, null, null, resetPassword, true); + Response response = post(Response.Status.CREATED, formData, "users"); + return (response.readEntity(User.class)); + } + + /** + * Creates a new user. Note only administrators can create new users. + * Either password or reset_password should be specified (reset_password takes priority). + * + * POST /users + * + * email (required) - Email + * password (optional) - Password + * reset_password (optional) - Send user password reset link - true or false(default) + * username (required) - Username + * name (required) - Name + * skype (optional) - Skype ID + * linkedin (optional) - LinkedIn + * twitter (optional) - Twitter account + * website_url (optional) - Website URL + * organization (optional) - Organization name + * projects_limit (optional) - Number of projects user can create + * extern_uid (optional) - External UID + * provider (optional) - External provider name + * bio (optional) - User's biography + * location (optional) - User's location + * admin (optional) - User is admin - true or false (default) + * can_create_group (optional) - User can create groups - true or false + * skip_confirmation (optional) - Skip confirmation - true or false (default) + * external (optional) - Flags the user as external - true or false(default) + * avatar (optional) - Image file for user's avatar + * shared_runners_minutes_limit (optional) - Pipeline minutes quota for this user + * + * @param user the User instance with the user info to create + * @return created User instance + * @throws GitLabApiException if any exception occurs + */ + public User createUser(User user, String password) throws GitLabApiException { + Form formData = userToForm(user, null, password, null, true); Response response = post(Response.Status.CREATED, formData, "users"); return (response.readEntity(User.class)); } @@ -414,7 +453,7 @@ public User createUser(User user) throws GitLabApiException { * @throws GitLabApiException if any exception occurs */ public User modifyUser(User user, String password, Integer projectsLimit) throws GitLabApiException { - Form form = userToForm(user, projectsLimit, password, false); + Form form = userToForm(user, projectsLimit, password, null, false); Response response = put(Response.Status.OK, form.asMap(), "users", user.getId()); return (response.readEntity(User.class)); } @@ -790,14 +829,18 @@ public void revokeImpersonationToken(Integer userId, Integer tokenId) throws Git * @param create whether the form is being populated to create a new user * @return the populated Form instance */ - Form userToForm(User user, Integer projectsLimit, String password, boolean create) { + Form userToForm(User user, Integer projectsLimit, String password, Boolean resetPassword, boolean create) { + if (create) { + if ((password == null || password.trim().isEmpty()) && !resetPassword) { + throw new RuntimeException("either password or reset_password must be set"); + } + } projectsLimit = (projectsLimit == null) ? user.getProjectsLimit() : projectsLimit; - password = (password == null) ? user.getPassword() : password; return (new GitLabApiForm() .withParam("email", user.getEmail(), create) - .withParam("password", password, create) - .withParam("reset_password", user.getResetPassword(), false) + .withParam("password", password, false) + .withParam("reset_password", resetPassword, false) .withParam("username", user.getUsername(), create) .withParam("name", user.getName(), create) .withParam("skype", user.getSkype(), false) diff --git a/src/main/java/org/gitlab4j/api/models/User.java b/src/main/java/org/gitlab4j/api/models/User.java index b27e7773f..88a192d06 100644 --- a/src/main/java/org/gitlab4j/api/models/User.java +++ b/src/main/java/org/gitlab4j/api/models/User.java @@ -4,26 +4,8 @@ @XmlRootElement public class User extends AbstractUser { - private String password; - private Boolean resetPassword; private String externUid; - public void setPassword(String password) { - this.password = password; - } - - public String getPassword() { - return this.password; - } - - public void setResetPassword(Boolean resetPassword) { - this.resetPassword = resetPassword; - } - - public Boolean getResetPassword() { - return this.resetPassword; - } - public void setExternUid(String externUid) { this.externUid = externUid; } @@ -37,16 +19,6 @@ public User withEmail(String email) { return this; } - public User withPassword(String password) { - setPassword(password); - return this; - } - - public User withResetPassword(boolean resetPassword) { - setResetPassword(resetPassword); - return this; - } - public User withName(String name) { setName(name); return this; From 4bdf77227b3c2ad01e478db4e0484960c4edd104 Mon Sep 17 00:00:00 2001 From: David Lam Date: Tue, 8 May 2018 01:16:27 -0400 Subject: [PATCH 6/8] use charsequence; use IllegalArgumentException; update createUser methods --- src/main/java/org/gitlab4j/api/UserApi.java | 56 +++++++++++++-------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/UserApi.java b/src/main/java/org/gitlab4j/api/UserApi.java index 4328ce911..4f206154f 100644 --- a/src/main/java/org/gitlab4j/api/UserApi.java +++ b/src/main/java/org/gitlab4j/api/UserApi.java @@ -1,5 +1,6 @@ package org.gitlab4j.api; +import java.nio.charset.Charset; import java.util.Date; import java.util.List; import java.util.Optional; @@ -13,6 +14,7 @@ import org.gitlab4j.api.models.ImpersonationToken.Scope; import org.gitlab4j.api.models.SshKey; import org.gitlab4j.api.models.User; +import org.gitlab4j.api.utils.SecretString; /** * This class provides an entry point to all the GitLab API users calls. @@ -313,6 +315,9 @@ public Pager findUsers(String emailOrUsername, int itemsPerPage) throws Gi * Creates a new user. Note only administrators can create new users. * Either password or reset_password should be specified (reset_password takes priority). * + * If both the User object's projectsLimit and the parameter projectsLimit is specified + * the parameter will take precedence. + * * POST /users * * email (required) - Email @@ -343,7 +348,7 @@ public Pager findUsers(String emailOrUsername, int itemsPerPage) throws Gi * @return created User instance * @throws GitLabApiException if any exception occurs */ - public User createUser(User user, String password, Integer projectsLimit) throws GitLabApiException { + public User createUser(User user, CharSequence password, Integer projectsLimit) throws GitLabApiException { Form formData = userToForm(user, projectsLimit, password, null, true); Response response = post(Response.Status.CREATED, formData, "users"); return (response.readEntity(User.class)); @@ -353,6 +358,8 @@ public User createUser(User user, String password, Integer projectsLimit) throws * Creates a new user. Note only administrators can create new users. * Either password or reset_password should be specified (reset_password takes priority). * + * Creates a user with reset_password being true + * * POST /users * * email (required) - Email @@ -378,12 +385,11 @@ public User createUser(User user, String password, Integer projectsLimit) throws * shared_runners_minutes_limit (optional) - Pipeline minutes quota for this user * * @param user the User instance with the user info to create - * @param resetPassword whether to send user password reset link * @return created User instance * @throws GitLabApiException if any exception occurs */ - public User createUser(User user, boolean resetPassword) throws GitLabApiException { - Form formData = userToForm(user, null, null, resetPassword, true); + public User createUserWithReset(User user) throws GitLabApiException { + Form formData = userToForm(user, null, null, true, true); Response response = post(Response.Status.CREATED, formData, "users"); return (response.readEntity(User.class)); } @@ -420,7 +426,7 @@ public User createUser(User user, boolean resetPassword) throws GitLabApiExcepti * @return created User instance * @throws GitLabApiException if any exception occurs */ - public User createUser(User user, String password) throws GitLabApiException { + public User createUserWithPassword(User user, CharSequence password) throws GitLabApiException { Form formData = userToForm(user, null, password, null, true); Response response = post(Response.Status.CREATED, formData, "users"); return (response.readEntity(User.class)); @@ -431,20 +437,26 @@ public User createUser(User user, String password) throws GitLabApiException { * * PUT /users/:id * - * email (required) - Email - * password (required) - Password - * username (required) - Username - * name (required) - Name - * skype (optional) - Skype ID - * linkedin (optional) - Linkedin - * twitter (optional) - Twitter account - * website_url (optional) - Website url - * projects_limit (optional) - Number of projects user can create - * extern_uid (optional) - External UID - * provider (optional) - External provider name - * bio (optional) - User's bio + * email - Email + * username - Username + * name - Name + * password - Password + * skype - Skype ID + * linkedin - LinkedIn + * twitter - Twitter account + * website_url - Website URL + * organization - Organization name + * projects_limit - Limit projects each user can create + * extern_uid - External UID + * provider - External provider name + * bio - User's biography + * location (optional) - User's location * admin (optional) - User is admin - true or false (default) * can_create_group (optional) - User can create groups - true or false + * skip_reconfirmation (optional) - Skip reconfirmation - true or false (default) + * external (optional) - Flags the user as external - true or false(default) + * shared_runners_minutes_limit (optional) - Pipeline minutes quota for this user + * avatar (optional) - Image file for user's avatar * * @param user the User instance with the user info to modify * @param password the new password for the user @@ -452,8 +464,8 @@ public User createUser(User user, String password) throws GitLabApiException { * @return the modified User instance * @throws GitLabApiException if any exception occurs */ - public User modifyUser(User user, String password, Integer projectsLimit) throws GitLabApiException { - Form form = userToForm(user, projectsLimit, password, null, false); + public User modifyUser(User user, CharSequence password, Integer projectsLimit) throws GitLabApiException { + Form form = userToForm(user, projectsLimit, password, false, false); Response response = put(Response.Status.OK, form.asMap(), "users", user.getId()); return (response.readEntity(User.class)); } @@ -829,10 +841,10 @@ public void revokeImpersonationToken(Integer userId, Integer tokenId) throws Git * @param create whether the form is being populated to create a new user * @return the populated Form instance */ - Form userToForm(User user, Integer projectsLimit, String password, Boolean resetPassword, boolean create) { + Form userToForm(User user, Integer projectsLimit, CharSequence password, Boolean resetPassword, boolean create) { if (create) { - if ((password == null || password.trim().isEmpty()) && !resetPassword) { - throw new RuntimeException("either password or reset_password must be set"); + if ((password == null || password.toString().trim().isEmpty()) && !resetPassword) { + throw new IllegalArgumentException("either password or reset_password must be set"); } } projectsLimit = (projectsLimit == null) ? user.getProjectsLimit() : projectsLimit; From eab307c4c4a2acd65bd34812494f1d0493370290 Mon Sep 17 00:00:00 2001 From: David Lam Date: Tue, 8 May 2018 01:20:53 -0400 Subject: [PATCH 7/8] remove unused imports --- src/main/java/org/gitlab4j/api/UserApi.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/UserApi.java b/src/main/java/org/gitlab4j/api/UserApi.java index 4f206154f..430044acc 100644 --- a/src/main/java/org/gitlab4j/api/UserApi.java +++ b/src/main/java/org/gitlab4j/api/UserApi.java @@ -1,6 +1,5 @@ package org.gitlab4j.api; -import java.nio.charset.Charset; import java.util.Date; import java.util.List; import java.util.Optional; @@ -14,7 +13,6 @@ import org.gitlab4j.api.models.ImpersonationToken.Scope; import org.gitlab4j.api.models.SshKey; import org.gitlab4j.api.models.User; -import org.gitlab4j.api.utils.SecretString; /** * This class provides an entry point to all the GitLab API users calls. From 9d2d144bc67c94603d16fc7204e452dac863673e Mon Sep 17 00:00:00 2001 From: David Lam Date: Tue, 8 May 2018 13:01:27 -0400 Subject: [PATCH 8/8] moved to one createUser method --- src/main/java/org/gitlab4j/api/UserApi.java | 44 ++------------------- 1 file changed, 4 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/UserApi.java b/src/main/java/org/gitlab4j/api/UserApi.java index 430044acc..6e751db0f 100644 --- a/src/main/java/org/gitlab4j/api/UserApi.java +++ b/src/main/java/org/gitlab4j/api/UserApi.java @@ -383,49 +383,13 @@ public User createUser(User user, CharSequence password, Integer projectsLimit) * shared_runners_minutes_limit (optional) - Pipeline minutes quota for this user * * @param user the User instance with the user info to create + * @param password the password for the new user + * @param resetPassword whether to send a password reset link * @return created User instance * @throws GitLabApiException if any exception occurs */ - public User createUserWithReset(User user) throws GitLabApiException { - Form formData = userToForm(user, null, null, true, true); - Response response = post(Response.Status.CREATED, formData, "users"); - return (response.readEntity(User.class)); - } - - /** - * Creates a new user. Note only administrators can create new users. - * Either password or reset_password should be specified (reset_password takes priority). - * - * POST /users - * - * email (required) - Email - * password (optional) - Password - * reset_password (optional) - Send user password reset link - true or false(default) - * username (required) - Username - * name (required) - Name - * skype (optional) - Skype ID - * linkedin (optional) - LinkedIn - * twitter (optional) - Twitter account - * website_url (optional) - Website URL - * organization (optional) - Organization name - * projects_limit (optional) - Number of projects user can create - * extern_uid (optional) - External UID - * provider (optional) - External provider name - * bio (optional) - User's biography - * location (optional) - User's location - * admin (optional) - User is admin - true or false (default) - * can_create_group (optional) - User can create groups - true or false - * skip_confirmation (optional) - Skip confirmation - true or false (default) - * external (optional) - Flags the user as external - true or false(default) - * avatar (optional) - Image file for user's avatar - * shared_runners_minutes_limit (optional) - Pipeline minutes quota for this user - * - * @param user the User instance with the user info to create - * @return created User instance - * @throws GitLabApiException if any exception occurs - */ - public User createUserWithPassword(User user, CharSequence password) throws GitLabApiException { - Form formData = userToForm(user, null, password, null, true); + public User createUser(User user, CharSequence password, boolean resetPassword) throws GitLabApiException { + Form formData = userToForm(user, null, password, resetPassword, true); Response response = post(Response.Status.CREATED, formData, "users"); return (response.readEntity(User.class)); }