From 26be8e191fd31ca338c830eb2dd30daa12d431e3 Mon Sep 17 00:00:00 2001 From: Steven Ferey Date: Mon, 3 Jun 2024 16:56:48 +0200 Subject: [PATCH] Allow merging of accounts that are members of the same group (#9909) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove unused import * Merge users with same groups * Added additional line in Permalinks config Added an additional line to restart Payara after changing settings in Permalinks section * Revert "#9717 grant CREATE instead of ALL per pdurbin" This reverts commit f71274e7c7a4d47ab7fb973320bcfdb7e6822fbd. * CREATE instead of ALL for public schema * Added: getZipDownloadLimit and getEmbargoEnabled API info endpoints * Added: docs for new info API endpoints * Fixed: missing guides reference in config.rst * Changed: :MaxEmbargoDurationInMonths setting directly exposed via API info endpoint * Changed: updated release notes * Changed: private Info.java method renamed * stub out page on API design, esp paths #9880 * remove embargo example, no longer used in #9881 * typo #9880 * Remove unused GPL-licensed code For unknown reasons, in 2009 several files from the JDK were copied into the Dataverse codebase, instead of referenced. It appears that these classes weren't really used. * Removed unused code --------- Co-authored-by: Jérôme ROUCOU Co-authored-by: Pradyumna Sridhara <95268690+prsridha@users.noreply.github.com> Co-authored-by: Philip Durbin Co-authored-by: GPortas Co-authored-by: bencomp Co-authored-by: jeromeroucou --- .../engine/command/impl/MergeInAccountCommand.java | 3 +-- src/test/java/edu/harvard/iq/dataverse/api/UsersIT.java | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/MergeInAccountCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/MergeInAccountCommand.java index 1ec51764d73..03f4dceef88 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/MergeInAccountCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/MergeInAccountCommand.java @@ -14,7 +14,6 @@ import edu.harvard.iq.dataverse.UserNotification; import edu.harvard.iq.dataverse.authorization.AuthenticatedUserLookup; import edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUser; -import edu.harvard.iq.dataverse.authorization.providers.oauth2.OAuth2TokenData; import edu.harvard.iq.dataverse.authorization.users.ApiToken; import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser; import edu.harvard.iq.dataverse.batch.util.LoggingUtil; @@ -25,7 +24,6 @@ import edu.harvard.iq.dataverse.engine.command.RequiredPermissions; import edu.harvard.iq.dataverse.engine.command.exception.CommandException; import edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException; -import edu.harvard.iq.dataverse.passwordreset.PasswordResetData; import edu.harvard.iq.dataverse.search.IndexResponse; import edu.harvard.iq.dataverse.search.savedsearch.SavedSearch; import edu.harvard.iq.dataverse.workflows.WorkflowComment; @@ -177,6 +175,7 @@ protected void executeImpl(CommandContext ctxt) throws CommandException { ctxt.em().createNativeQuery("Delete from OAuth2TokenData where user_id ="+consumedAU.getId()).executeUpdate(); + ctxt.em().createNativeQuery("DELETE FROM explicitgroup_authenticateduser consumed USING explicitgroup_authenticateduser ongoing WHERE consumed.containedauthenticatedusers_id="+ongoingAU.getId()+" AND ongoing.containedauthenticatedusers_id="+consumedAU.getId()).executeUpdate(); ctxt.em().createNativeQuery("UPDATE explicitgroup_authenticateduser SET containedauthenticatedusers_id="+ongoingAU.getId()+" WHERE containedauthenticatedusers_id="+consumedAU.getId()).executeUpdate(); ctxt.actionLog().changeUserIdentifierInHistory(consumedAU.getIdentifier(), ongoingAU.getIdentifier()); diff --git a/src/test/java/edu/harvard/iq/dataverse/api/UsersIT.java b/src/test/java/edu/harvard/iq/dataverse/api/UsersIT.java index 5880b08e5c2..0189ffd6e58 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/UsersIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/UsersIT.java @@ -8,6 +8,7 @@ import edu.harvard.iq.dataverse.authorization.DataverseRole; import edu.harvard.iq.dataverse.settings.SettingsServiceBean; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.UUID; import jakarta.json.Json; @@ -206,15 +207,13 @@ public void testMergeAccounts(){ String aliasInOwner = "groupFor" + dataverseAlias; String displayName = "Group for " + dataverseAlias; String user2identifier = "@" + usernameConsumed; + String target2identifier = "@" + targetname; Response createGroup = UtilIT.createGroup(dataverseAlias, aliasInOwner, displayName, superuserApiToken); createGroup.prettyPrint(); createGroup.then().assertThat() .statusCode(CREATED.getStatusCode()); - String groupIdentifier = JsonPath.from(createGroup.asString()).getString("data.identifier"); - - List roleAssigneesToAdd = new ArrayList<>(); - roleAssigneesToAdd.add(user2identifier); + List roleAssigneesToAdd = Arrays.asList(user2identifier, target2identifier); Response addToGroup = UtilIT.addToGroup(dataverseAlias, aliasInOwner, roleAssigneesToAdd, superuserApiToken); addToGroup.prettyPrint(); addToGroup.then().assertThat()