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

Issue 46 sysadmin delete button #51

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public class DeploymentPropertiesController extends BaseController {
@Value("${jove.api.url}")
private String joveApiUrl;

@Value("${sysadmin.delete.user}")
private String sysadminDeleteUser;

/**
* Service to return the value of property stored in the deployment.properties file. Uses a
* whitelist strategy to only return properties that should be exposed.
Expand All @@ -105,8 +108,7 @@ public class DeploymentPropertiesController extends BaseController {
@GetMapping("/ajax/property")
@IgnoreInLoggingInterceptor(ignoreAll = true)
@ResponseBody
public String getPropertyValue(
@RequestParam(value = "name", required = true) String propertyName) {
public String getPropertyValue(@RequestParam(value = "name") String propertyName) {
// managed props e.g. for RSPAC-861
List<SystemPropertyValue> dbProperties = sysPropertyMgr.getAllSysadminProperties();
for (SystemPropertyValue spv : dbProperties) {
Expand Down Expand Up @@ -161,6 +163,8 @@ public String getPropertyValue(
return googleDriveClientId;
case "aspose.enabled":
return String.valueOf(isAsposeEnabled());
case "sysadmin.delete.user":
return sysadminDeleteUser;
default:
throw new IllegalArgumentException("No property available for name: " + propertyName);
}
Expand Down
18 changes: 15 additions & 3 deletions src/main/webapp/ui/src/eln/sysadmin/users/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ import Badge from "@mui/material/Badge";
import docLinks from "../../../assets/DocLinks";
import createAccentedTheme from "../../../accentedTheme";
import UserAliasIcon from "@mui/icons-material/ContactEmergency";
import { useDeploymentProperty } from "../../useDeploymentProperty";
import * as Parsers from "../../../util/parsers";

const Panel = ({
anchorEl,
Expand Down Expand Up @@ -646,10 +648,20 @@ const DeleteAction = ({
const { addAlert } = React.useContext(AlertContext);
const [open, setOpen] = React.useState(false);
const [username, setUsername] = React.useState("");
const canDelete = useDeploymentProperty("sysadmin.delete.user");

const allowedToDelete: Result<User> = selectedUser.mapError(
() => new Error("Only one user can be deleted at a time.")
);
const allowedToDelete: Result<User> = FetchingData.getSuccessValue(canDelete)
.flatMap(Parsers.isBoolean)
.flatMap(Parsers.isTrue)
.mapError(
() =>
new Error('The deployment property "sysadmin.delete.user" is false.')
)
.flatMap(() =>
selectedUser.mapError(
() => new Error("Only one user can be deleted at a time.")
)
);

return (
<>
Expand Down
13 changes: 8 additions & 5 deletions src/main/webapp/ui/src/eln/sysadmin/users/useUserListing.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,14 @@ export function useUserListing(): {|
>("/system/ajax/removeUserAccount/", {
userId: id,
});
if (typeof data.error !== "undefined") {
throw new Error(data.error.errorMessages[0]);
} else {
refreshListing();
}
Parsers.isObject(data)
.flatMap(Parsers.isNotNull)
.flatMap(Parsers.getValueWithKey("exceptionMessage"))
.flatMap(Parsers.isString)
.do((exceptionMessage) => {
throw new Error(exceptionMessage);
});
refreshListing();
} catch (error) {
if (error.response?.data?.message) {
const message = error.response.data.message;
Expand Down
Loading