@@ -311,64 +311,123 @@ public Pager<User> findUsers(String emailOrUsername, int itemsPerPage) throws Gi
311
311
312
312
/**
313
313
* 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.
314
318
*
315
319
* POST /users
316
320
*
317
321
* email (required) - Email
318
- * password (required) - Password
322
+ * password (optional) - Password
323
+ * reset_password (optional) - Send user password reset link - true or false(default)
319
324
* username (required) - Username
320
325
* name (required) - Name
321
326
* skype (optional) - Skype ID
322
- * linkedin (optional) - Linkedin
327
+ * linkedin (optional) - LinkedIn
323
328
* twitter (optional) - Twitter account
324
- * website_url (optional) - Website url
329
+ * website_url (optional) - Website URL
330
+ * organization (optional) - Organization name
325
331
* projects_limit (optional) - Number of projects user can create
326
332
* extern_uid (optional) - External UID
327
333
* provider (optional) - External provider name
328
- * bio (optional) - User's bio
334
+ * bio (optional) - User's biography
335
+ * location (optional) - User's location
329
336
* admin (optional) - User is admin - true or false (default)
330
337
* 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
331
342
*
332
343
* @param user the User instance with the user info to create
333
344
* @param password the password for the new user
334
345
* @param projectsLimit the maximum number of project
335
346
* @return created User instance
336
347
* @throws GitLabApiException if any exception occurs
337
348
*/
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 );
340
351
Response response = post (Response .Status .CREATED , formData , "users" );
341
352
return (response .readEntity (User .class ));
342
353
}
343
354
344
355
/**
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).
346
358
*
347
- * PUT /users/:id
359
+ * Creates a user with reset_password being <code>true</code>
360
+ *
361
+ * POST /users
348
362
*
349
363
* email (required) - Email
350
- * password (required) - Password
364
+ * password (optional) - Password
365
+ * reset_password (optional) - Send user password reset link - true or false(default)
351
366
* username (required) - Username
352
367
* name (required) - Name
353
368
* skype (optional) - Skype ID
354
- * linkedin (optional) - Linkedin
369
+ * linkedin (optional) - LinkedIn
355
370
* twitter (optional) - Twitter account
356
- * website_url (optional) - Website url
371
+ * website_url (optional) - Website URL
372
+ * organization (optional) - Organization name
357
373
* projects_limit (optional) - Number of projects user can create
358
374
* extern_uid (optional) - External UID
359
375
* provider (optional) - External provider name
360
- * bio (optional) - User's bio
376
+ * bio (optional) - User's biography
377
+ * location (optional) - User's location
361
378
* admin (optional) - User is admin - true or false (default)
362
379
* 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
363
422
*
364
423
* @param user the User instance with the user info to modify
365
424
* @param password the new password for the user
366
425
* @param projectsLimit the maximum number of project
367
426
* @return the modified User instance
368
427
* @throws GitLabApiException if any exception occurs
369
428
*/
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 );
372
431
Response response = put (Response .Status .OK , form .asMap (), "users" , user .getId ());
373
432
return (response .readEntity (User .class ));
374
433
}
@@ -560,7 +619,7 @@ public SshKey addSshKey(Integer userId, String title, String key) throws GitLabA
560
619
}
561
620
562
621
/**
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
564
623
* on a key that is already deleted or not available results in success.
565
624
*
566
625
* DELETE /user/keys/:key_id
@@ -744,24 +803,34 @@ public void revokeImpersonationToken(Integer userId, Integer tokenId) throws Git
744
803
* @param create whether the form is being populated to create a new user
745
804
* @return the populated Form instance
746
805
*/
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
+
748
814
return (new GitLabApiForm ()
749
815
.withParam ("email" , user .getEmail (), create )
750
- .withParam ("password" , password , create )
816
+ .withParam ("password" , password , false )
817
+ .withParam ("reset_password" , resetPassword , false )
751
818
.withParam ("username" , user .getUsername (), create )
752
819
.withParam ("name" , user .getName (), create )
753
820
.withParam ("skype" , user .getSkype (), false )
754
821
.withParam ("linkedin" , user .getLinkedin (), false )
755
822
.withParam ("twitter" , user .getTwitter (), false )
756
823
.withParam ("website_url" , user .getWebsiteUrl (), false )
757
- .withParam ("projects_limit" , projectsLimit , false )
758
824
.withParam ("organization" , user .getOrganization (), false )
825
+ .withParam ("projects_limit" , projectsLimit , false )
826
+ .withParam ("extern_uid" , user .getExternUid (), false )
759
827
.withParam ("provider" , user .getProvider (), false )
760
828
.withParam ("bio" , user .getBio (), false )
761
829
.withParam ("location" , user .getLocation (), false )
762
830
.withParam ("admin" , user .getIsAdmin (), false )
763
831
.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 ));
766
835
}
767
836
}
0 commit comments