Skip to content

Commit

Permalink
reformat code (no-op) IQSS#9887
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Apr 12, 2024
1 parent 074498f commit a97b931
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions src/main/java/edu/harvard/iq/dataverse/api/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -1030,49 +1030,49 @@ public Response deleteRole(@Context ContainerRequestContext crc, @PathParam("id"
}, getRequestUser(crc));
}

@Path("superuser/{identifier}")
@Deprecated
@POST
public Response toggleSuperuser(@PathParam("identifier") String identifier) {
ActionLogRecord alr = new ActionLogRecord(ActionLogRecord.ActionType.Admin, "toggleSuperuser")
.setInfo(identifier);
try {
final AuthenticatedUser user = authSvc.getAuthenticatedUser(identifier);
return setSuperuserStatus(user, !user.isSuperuser());
} catch (Exception e) {
alr.setActionResult(ActionLogRecord.Result.InternalError);
alr.setInfo(alr.getInfo() + "// " + e.getMessage());
return error(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
} finally {
actionLogSvc.log(alr);
}
}
@Path("superuser/{identifier}")
@Deprecated
@POST
public Response toggleSuperuser(@PathParam("identifier") String identifier) {
ActionLogRecord alr = new ActionLogRecord(ActionLogRecord.ActionType.Admin, "toggleSuperuser")
.setInfo(identifier);
try {
final AuthenticatedUser user = authSvc.getAuthenticatedUser(identifier);
return setSuperuserStatus(user, !user.isSuperuser());
} catch (Exception e) {
alr.setActionResult(ActionLogRecord.Result.InternalError);
alr.setInfo(alr.getInfo() + "// " + e.getMessage());
return error(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
} finally {
actionLogSvc.log(alr);
}
}

private Response setSuperuserStatus(AuthenticatedUser user, Boolean isSuperuser) {
if (user.isDeactivated()) {
return error(Status.BAD_REQUEST, "You cannot make a deactivated user a superuser.");
}
user.setSuperuser(isSuperuser);
return ok("User " + user.getIdentifier() + " " + (user.isSuperuser() ? "set" : "removed")
+ " as a superuser.");
}
private Response setSuperuserStatus(AuthenticatedUser user, Boolean isSuperuser) {
if (user.isDeactivated()) {
return error(Status.BAD_REQUEST, "You cannot make a deactivated user a superuser.");
}
user.setSuperuser(isSuperuser);
return ok("User " + user.getIdentifier() + " " + (user.isSuperuser() ? "set" : "removed")
+ " as a superuser.");
}

@Path("superuser/{identifier}")
@PUT
//using string instead of boolean so user doesnt need to add Content type header in their request
public Response setSuperuserStatus(@PathParam("identifier") String identifier, String isSuperuser) {
ActionLogRecord alr = new ActionLogRecord(ActionLogRecord.ActionType.Admin, "changeSuperUserStatus")
.setInfo(identifier + ":" + isSuperuser);
try {
@Path("superuser/{identifier}")
@PUT
//using string instead of boolean so user doesnt need to add Content type header in their request
public Response setSuperuserStatus(@PathParam("identifier") String identifier, String isSuperuser) {
ActionLogRecord alr = new ActionLogRecord(ActionLogRecord.ActionType.Admin, "changeSuperUserStatus")
.setInfo(identifier + ":" + isSuperuser);
try {
return setSuperuserStatus(authSvc.getAuthenticatedUser(identifier), StringUtil.isTrue(isSuperuser));
} catch (Exception e) {
alr.setActionResult(ActionLogRecord.Result.InternalError);
alr.setInfo(alr.getInfo() + "// " + e.getMessage());
return error(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
} finally {
actionLogSvc.log(alr);
}
}
} catch (Exception e) {
alr.setActionResult(ActionLogRecord.Result.InternalError);
alr.setInfo(alr.getInfo() + "// " + e.getMessage());
return error(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
} finally {
actionLogSvc.log(alr);
}
}

@GET
@Path("validate/datasets")
Expand Down

0 comments on commit a97b931

Please sign in to comment.