55import com .cloudinary .Util ;
66import com .cloudinary .api .ApiResponse ;
77import com .cloudinary .utils .ObjectUtils ;
8-
98import java .util .*;
109
1110/**
@@ -327,7 +326,7 @@ public ApiResponse users(Boolean pending, List<String> userIds, String prefix, S
327326 * @throws Exception If the request fails.
328327 */
329328 public ApiResponse createUser (String name , String email , Role role , List <String > subAccountsIds ) throws Exception {
330- return createUser (name , email , role , subAccountsIds );
329+ return createUser (name , email , role , subAccountsIds , null );
331330 }
332331
333332 /**
@@ -343,8 +342,25 @@ public ApiResponse createUser(String name, String email, Role role, List<String>
343342 * @throws Exception If the request fails.
344343 */
345344 public ApiResponse createUser (String name , String email , Role role , List <String > subAccountsIds , Map <String , Object > options ) throws Exception {
345+ return createUser (name , email , role , null , subAccountsIds , options );
346+ }
347+
348+ /**
349+ * Create a new user.
350+ *
351+ * @param name Required. Username.
352+ * @param email Required. User's email.
353+ * @param role Required. User's role.
354+ * @param enabled Optional. User's status (enabled or disabled).
355+ * @param subAccountsIds Optional. Sub-accounts for which the user should have access.
356+ * If not provided or empty, user should have access to all accounts.
357+ * @param options Generic advanced options map, see online documentation.
358+ * @return The newly created user details.
359+ * @throws Exception If the request fails.
360+ */
361+ public ApiResponse createUser (String name , String email , Role role , Boolean enabled , List <String > subAccountsIds , Map <String , Object > options ) throws Exception {
346362 List <String > uri = Arrays .asList (PROVISIONING , ACCOUNTS , accountId , USERS );
347- return performUserAction (Api .HttpMethod .POST , uri , email , name , role , subAccountsIds , options );
363+ return performUserAction (Api .HttpMethod .POST , uri , email , name , role , enabled , subAccountsIds , options );
348364 }
349365
350366 /**
@@ -377,8 +393,26 @@ public ApiResponse updateUser(String userId, String name, String email, Role rol
377393 * @throws Exception If the request fails.
378394 */
379395 public ApiResponse updateUser (String userId , String name , String email , Role role , List <String > subAccountsIds , Map <String , Object > options ) throws Exception {
396+ return updateUser (userId , name ,email ,role ,null , subAccountsIds , options );
397+ }
398+
399+ /**
400+ * Update an existing user.
401+ *
402+ * @param userId The id of the user to update.
403+ * @param name Username.
404+ * @param email User's email.
405+ * @param role User's role.
406+ * @param enabled User's status (enabled or disabled)
407+ * @param subAccountsIds Sub-accounts for which the user should have access.
408+ * If not provided or empty, user should have access to all accounts.
409+ * @param options Generic advanced options map, see online documentation.
410+ * @return The updated user details
411+ * @throws Exception If the request fails.
412+ */
413+ public ApiResponse updateUser (String userId , String name , String email , Role role , Boolean enabled , List <String > subAccountsIds , Map <String , Object > options ) throws Exception {
380414 List <String > uri = Arrays .asList (PROVISIONING , ACCOUNTS , accountId , USERS , userId );
381- return performUserAction (Api .HttpMethod .PUT , uri , email , name , role , subAccountsIds , options );
415+ return performUserAction (Api .HttpMethod .PUT , uri , email , name , role , enabled , subAccountsIds , options );
382416 }
383417
384418 /**
@@ -597,14 +631,15 @@ public ApiResponse userGroupUsers(String groupId, Map<String, Object> options) t
597631 * @return The response of the api call.
598632 * @throws Exception If the request fails.
599633 */
600- private ApiResponse performUserAction (Api .HttpMethod method , List <String > uri , String email , String name , Role role , List <String > subAccountsIds , Map <String , Object > options ) throws Exception {
634+ private ApiResponse performUserAction (Api .HttpMethod method , List <String > uri , String email , String name , Role role , Boolean enabled , List <String > subAccountsIds , Map <String , Object > options ) throws Exception {
601635 options = verifyOptions (options );
602636 options .put ("content_type" , "json" );
603637
604638 return callAccountApi (method , uri , ObjectUtils .asMap (
605639 "email" , email ,
606640 "name" , name ,
607641 "role" , role == null ? null : role .serializedValue ,
642+ "enabled" , enabled ,
608643 "sub_account_ids" , subAccountsIds ),
609644 options );
610645 }
@@ -616,4 +651,4 @@ private Map<String, Object> verifyOptions(Map<String, Object> options) {
616651
617652 return options ;
618653 }
619- }
654+ }
0 commit comments