Skip to content

Commit

Permalink
Merge pull request #7033 from WZBSocialScienceCenter/6915-feature-bui…
Browse files Browse the repository at this point in the history
…ltin-users-sendEmailNotification-new-optionalParameter

6915-feature-builtin-users-sendEmailNotification-new-optionalParameter
  • Loading branch information
kcondon authored Jul 14, 2020
2 parents 378aaad + b5204a7 commit c1a3834
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/sphinx-guides/source/api/native-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2311,6 +2311,8 @@ Place this ``user-add.json`` file in your current directory and run the followin
curl -d @user-add.json -H "Content-type:application/json" "$SERVER_URL/api/builtin-users?password=$NEWUSER_PASSWORD&key=$BUILTIN_USERS_KEY"
Optionally, you may use a third query parameter "sendEmailNotification=false" to explicitly disable sending an email notification to the new user.
Roles
-----
Expand Down
44 changes: 41 additions & 3 deletions src/main/java/edu/harvard/iq/dataverse/api/BuiltinUsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ public Response getApiToken( @PathParam("username") String username, @QueryParam
//and use the values to create BuiltinUser/AuthenticatedUser.
//--MAD 4.9.3
@POST
public Response save(BuiltinUser user, @QueryParam("password") String password, @QueryParam("key") String key) {
return internalSave(user, password, key);
public Response save(BuiltinUser user, @QueryParam("password") String password, @QueryParam("key") String key, @QueryParam("sendEmailNotification") Boolean sendEmailNotification) {
if( sendEmailNotification == null )
sendEmailNotification = true;

return internalSave(user, password, key, sendEmailNotification);
}

/**
Expand All @@ -105,7 +108,29 @@ public Response create(BuiltinUser user, @PathParam("password") String password,
return internalSave(user, password, key);
}

/**
* Created this new endpoint to resolve issue #6915, optionally preventing
* the email notification to the new user on account creation by adding
* "false" as the third path parameter.
*
* @param user
* @param password
* @param key
* @param sendEmailNotification
* @return
*/
@POST
@Path("{password}/{key}/{sendEmailNotification}")
public Response create(BuiltinUser user, @PathParam("password") String password, @PathParam("key") String key, @PathParam("sendEmailNotification") Boolean sendEmailNotification) {
return internalSave(user, password, key, sendEmailNotification);
}

// internalSave without providing an explicit "sendEmailNotification"
private Response internalSave(BuiltinUser user, String password, String key) {
return internalSave(user, password, key, true);
}

private Response internalSave(BuiltinUser user, String password, String key, Boolean sendEmailNotification) {
String expectedKey = settingsSvc.get(API_KEY_IN_SETTINGS);

if (expectedKey == null) {
Expand Down Expand Up @@ -149,7 +174,7 @@ private Response internalSave(BuiltinUser user, String password, String key) {
} catch (Exception e) {
logger.info("The root dataverse is not present. Don't send a notification to dataverseAdmin.");
}
if (rootDataversePresent) {
if (rootDataversePresent && sendEmailNotification) {
userNotificationSvc.sendNotification(au,
new Timestamp(new Date().getTime()),
UserNotification.Type.CREATEACC, null);
Expand Down Expand Up @@ -188,3 +213,16 @@ private Response internalSave(BuiltinUser user, String password, String key) {
}

}













0 comments on commit c1a3834

Please sign in to comment.