Skip to content

Commit

Permalink
#5514 #5515 actionlogrecord for changeIdentifier
Browse files Browse the repository at this point in the history
Also unify the two commands to both log the change message as the old user. This is somewhat required for changeIdentifier as there is no other user object to populate the log method, and its not worth creating a new path for this case.
  • Loading branch information
matthew-a-dunlap committed Mar 12, 2019
1 parent 5dd6426 commit a8d2d34
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/java/edu/harvard/iq/dataverse/api/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public Response mergeInAuthenticatedUser(@PathParam("baseIdentifier") String bas
}

try {
execCommand(new MergeInAccountCommand(createDataverseRequest(baseAuthenticatedUser), consumedAuthenticatedUser, baseAuthenticatedUser));
execCommand(new MergeInAccountCommand(createDataverseRequest(consumedAuthenticatedUser), consumedAuthenticatedUser, baseAuthenticatedUser));
} catch (Exception e){
return error(Response.Status.BAD_REQUEST, "Error calling ChangeUserIdentifierCommand: " + e.getLocalizedMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ public class ChangeUserIdentifierCommand extends AbstractVoidCommand {

final AuthenticatedUser au;
final String newIdentifier;

final String oldIdentifier;

public ChangeUserIdentifierCommand(DataverseRequest aRequest, AuthenticatedUser au, String newIdentifier) {
super(
aRequest,
(DvObject) null
aRequest,
(DvObject) null
);
this.au = au;
this.newIdentifier = newIdentifier;
this.oldIdentifier = au.getUserIdentifier();
}

@Override
Expand All @@ -54,7 +55,7 @@ public void executeImpl(CommandContext ctxt) throws CommandException {
}

List<RoleAssignment> raList = ctxt.roleAssignees().getAssignmentsFor(au.getIdentifier()); //only AuthenticatedUser supported
BuiltinUser bu = ctxt.builtinUsers().findByUserName(au.getUserIdentifier());
BuiltinUser bu = ctxt.builtinUsers().findByUserName(oldIdentifier);
au.setUserIdentifier(newIdentifier);

if (bu != null) {
Expand All @@ -75,15 +76,18 @@ public void executeImpl(CommandContext ctxt) throws CommandException {
}
}

ctxt.actionLog().changeUserIdentifierInHistory("@" + oldIdentifier, "@" + newIdentifier);

AuthenticatedUserLookup aul = au.getAuthenticatedUserLookup();
aul.setPersistentUserId(newIdentifier);

for(RoleAssignment ra : raList) {
if(ra.getAssigneeIdentifier().charAt(0) == '@') {
ra.setAssigneeIdentifier("@" + newIdentifier);
} else {
throw new IllegalCommandException("Original userIdentifier provided does not seem to be an AuthenticatedUser", this);
}
ra.setAssigneeIdentifier("@" + newIdentifier);
}
}

@Override
public String describe() {
return "User " + oldIdentifier + " renamed to " + newIdentifier;
}
}

0 comments on commit a8d2d34

Please sign in to comment.