@@ -311,64 +311,123 @@ public Pager<User> findUsers(String emailOrUsername, int itemsPerPage) throws Gi
311311
312312 /**
313313 * Creates a new user. Note only administrators can create new users.
314+ * Either password or reset_password should be specified (reset_password takes priority).
315+ *
316+ * If both the User object's projectsLimit and the parameter projectsLimit is specified
317+ * the parameter will take precedence.
314318 *
315319 * POST /users
316320 *
317321 * email (required) - Email
318- * password (required) - Password
322+ * password (optional) - Password
323+ * reset_password (optional) - Send user password reset link - true or false(default)
319324 * username (required) - Username
320325 * name (required) - Name
321326 * skype (optional) - Skype ID
322- * linkedin (optional) - Linkedin
327+ * linkedin (optional) - LinkedIn
323328 * twitter (optional) - Twitter account
324- * website_url (optional) - Website url
329+ * website_url (optional) - Website URL
330+ * organization (optional) - Organization name
325331 * projects_limit (optional) - Number of projects user can create
326332 * extern_uid (optional) - External UID
327333 * provider (optional) - External provider name
328- * bio (optional) - User's bio
334+ * bio (optional) - User's biography
335+ * location (optional) - User's location
329336 * admin (optional) - User is admin - true or false (default)
330337 * can_create_group (optional) - User can create groups - true or false
338+ * skip_confirmation (optional) - Skip confirmation - true or false (default)
339+ * external (optional) - Flags the user as external - true or false(default)
340+ * avatar (optional) - Image file for user's avatar
341+ * shared_runners_minutes_limit (optional) - Pipeline minutes quota for this user
331342 *
332343 * @param user the User instance with the user info to create
333344 * @param password the password for the new user
334345 * @param projectsLimit the maximum number of project
335346 * @return created User instance
336347 * @throws GitLabApiException if any exception occurs
337348 */
338- public User createUser (User user , String password , Integer projectsLimit ) throws GitLabApiException {
339- Form formData = userToForm (user , projectsLimit , password , true );
349+ public User createUser (User user , CharSequence password , Integer projectsLimit ) throws GitLabApiException {
350+ Form formData = userToForm (user , projectsLimit , password , null , true );
340351 Response response = post (Response .Status .CREATED , formData , "users" );
341352 return (response .readEntity (User .class ));
342353 }
343354
344355 /**
345- * Modifies an existing user. Only administrators can change attributes of a user.
356+ * Creates a new user. Note only administrators can create new users.
357+ * Either password or reset_password should be specified (reset_password takes priority).
346358 *
347- * PUT /users/:id
359+ * Creates a user with reset_password being <code>true</code>
360+ *
361+ * POST /users
348362 *
349363 * email (required) - Email
350- * password (required) - Password
364+ * password (optional) - Password
365+ * reset_password (optional) - Send user password reset link - true or false(default)
351366 * username (required) - Username
352367 * name (required) - Name
353368 * skype (optional) - Skype ID
354- * linkedin (optional) - Linkedin
369+ * linkedin (optional) - LinkedIn
355370 * twitter (optional) - Twitter account
356- * website_url (optional) - Website url
371+ * website_url (optional) - Website URL
372+ * organization (optional) - Organization name
357373 * projects_limit (optional) - Number of projects user can create
358374 * extern_uid (optional) - External UID
359375 * provider (optional) - External provider name
360- * bio (optional) - User's bio
376+ * bio (optional) - User's biography
377+ * location (optional) - User's location
361378 * admin (optional) - User is admin - true or false (default)
362379 * can_create_group (optional) - User can create groups - true or false
380+ * skip_confirmation (optional) - Skip confirmation - true or false (default)
381+ * external (optional) - Flags the user as external - true or false(default)
382+ * avatar (optional) - Image file for user's avatar
383+ * shared_runners_minutes_limit (optional) - Pipeline minutes quota for this user
384+ *
385+ * @param user the User instance with the user info to create
386+ * @param password the password for the new user
387+ * @param resetPassword whether to send a password reset link
388+ * @return created User instance
389+ * @throws GitLabApiException if any exception occurs
390+ */
391+ public User createUser (User user , CharSequence password , boolean resetPassword ) throws GitLabApiException {
392+ Form formData = userToForm (user , null , password , resetPassword , true );
393+ Response response = post (Response .Status .CREATED , formData , "users" );
394+ return (response .readEntity (User .class ));
395+ }
396+
397+ /**
398+ * Modifies an existing user. Only administrators can change attributes of a user.
399+ *
400+ * PUT /users/:id
401+ *
402+ * email - Email
403+ * username - Username
404+ * name - Name
405+ * password - Password
406+ * skype - Skype ID
407+ * linkedin - LinkedIn
408+ * twitter - Twitter account
409+ * website_url - Website URL
410+ * organization - Organization name
411+ * projects_limit - Limit projects each user can create
412+ * extern_uid - External UID
413+ * provider - External provider name
414+ * bio - User's biography
415+ * location (optional) - User's location
416+ * admin (optional) - User is admin - true or false (default)
417+ * can_create_group (optional) - User can create groups - true or false
418+ * skip_reconfirmation (optional) - Skip reconfirmation - true or false (default)
419+ * external (optional) - Flags the user as external - true or false(default)
420+ * shared_runners_minutes_limit (optional) - Pipeline minutes quota for this user
421+ * avatar (optional) - Image file for user's avatar
363422 *
364423 * @param user the User instance with the user info to modify
365424 * @param password the new password for the user
366425 * @param projectsLimit the maximum number of project
367426 * @return the modified User instance
368427 * @throws GitLabApiException if any exception occurs
369428 */
370- public User modifyUser (User user , String password , Integer projectsLimit ) throws GitLabApiException {
371- Form form = userToForm (user , projectsLimit , password , false );
429+ public User modifyUser (User user , CharSequence password , Integer projectsLimit ) throws GitLabApiException {
430+ Form form = userToForm (user , projectsLimit , password , false , false );
372431 Response response = put (Response .Status .OK , form .asMap (), "users" , user .getId ());
373432 return (response .readEntity (User .class ));
374433 }
@@ -560,7 +619,7 @@ public SshKey addSshKey(Integer userId, String title, String key) throws GitLabA
560619 }
561620
562621 /**
563- * Deletes key owned by currently authenticated user. This is an idempotent function and calling it
622+ * Deletes key owned by currently authenticated user. This is an idempotent function and calling it
564623 * on a key that is already deleted or not available results in success.
565624 *
566625 * DELETE /user/keys/:key_id
@@ -744,24 +803,34 @@ public void revokeImpersonationToken(Integer userId, Integer tokenId) throws Git
744803 * @param create whether the form is being populated to create a new user
745804 * @return the populated Form instance
746805 */
747- Form userToForm (User user , Integer projectsLimit , String password , boolean create ) {
806+ Form userToForm (User user , Integer projectsLimit , CharSequence password , Boolean resetPassword , boolean create ) {
807+ if (create ) {
808+ if ((password == null || password .toString ().trim ().isEmpty ()) && !resetPassword ) {
809+ throw new IllegalArgumentException ("either password or reset_password must be set" );
810+ }
811+ }
812+ projectsLimit = (projectsLimit == null ) ? user .getProjectsLimit () : projectsLimit ;
813+
748814 return (new GitLabApiForm ()
749815 .withParam ("email" , user .getEmail (), create )
750- .withParam ("password" , password , create )
816+ .withParam ("password" , password , false )
817+ .withParam ("reset_password" , resetPassword , false )
751818 .withParam ("username" , user .getUsername (), create )
752819 .withParam ("name" , user .getName (), create )
753820 .withParam ("skype" , user .getSkype (), false )
754821 .withParam ("linkedin" , user .getLinkedin (), false )
755822 .withParam ("twitter" , user .getTwitter (), false )
756823 .withParam ("website_url" , user .getWebsiteUrl (), false )
757- .withParam ("projects_limit" , projectsLimit , false )
758824 .withParam ("organization" , user .getOrganization (), false )
825+ .withParam ("projects_limit" , projectsLimit , false )
826+ .withParam ("extern_uid" , user .getExternUid (), false )
759827 .withParam ("provider" , user .getProvider (), false )
760828 .withParam ("bio" , user .getBio (), false )
761829 .withParam ("location" , user .getLocation (), false )
762830 .withParam ("admin" , user .getIsAdmin (), false )
763831 .withParam ("can_create_group" , user .getCanCreateGroup (), false )
764- .withParam ("external" , user .getExternal (), false ))
765- .withParam ("skip_confirmation" ,user .getSkipConfirmation (),false );
832+ .withParam ("skip_confirmation" , user .getSkipConfirmation (), false )
833+ .withParam ("external" , user .getExternal (), false )
834+ .withParam ("shared_runners_minutes_limit" , user .getSharedRunnersMinutesLimit (),false ));
766835 }
767836}
0 commit comments