Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6915-feature-builtin-users-sendEmailNotification-new-optionalParameter #7033

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sendEmailNotification appears to be a path parameter rather than a query parameter, as documented above. @RightInTwo can you provide a full curl example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pdurbin, we added both ways (query and path), just as the create() function is implemented for both currently. The docs at http://guides.dataverse.org/en/latest/api/native-api.html#assign-default-role-to-user-creating-a-dataset-in-a-dataverse seem to omit the path variant completely, which is why we left it out as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I get it. The query parameter version is called "save". Thanks.

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) {
}

}