Skip to content

Commit 98558de

Browse files
Issue 46 sysadmin delete button (#51)
The delete user sysadmin menu item is now disabled if the deployment property is set, with an explanation as such. Furthermore, I've fixed the error handling for the network request to ensure that any other reason for the deletion operation failing is made apparent. --------- Co-authored-by: matthias <matthias@researchspace.com>
1 parent 570f958 commit 98558de

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

src/main/java/com/researchspace/webapp/controller/DeploymentPropertiesController.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ public class DeploymentPropertiesController extends BaseController {
9494
@Value("${jove.api.url}")
9595
private String joveApiUrl;
9696

97+
@Value("${sysadmin.delete.user}")
98+
private String sysadminDeleteUser;
99+
97100
/**
98101
* Service to return the value of property stored in the deployment.properties file. Uses a
99102
* whitelist strategy to only return properties that should be exposed.
@@ -105,8 +108,7 @@ public class DeploymentPropertiesController extends BaseController {
105108
@GetMapping("/ajax/property")
106109
@IgnoreInLoggingInterceptor(ignoreAll = true)
107110
@ResponseBody
108-
public String getPropertyValue(
109-
@RequestParam(value = "name", required = true) String propertyName) {
111+
public String getPropertyValue(@RequestParam(value = "name") String propertyName) {
110112
// managed props e.g. for RSPAC-861
111113
List<SystemPropertyValue> dbProperties = sysPropertyMgr.getAllSysadminProperties();
112114
for (SystemPropertyValue spv : dbProperties) {
@@ -161,6 +163,8 @@ public String getPropertyValue(
161163
return googleDriveClientId;
162164
case "aspose.enabled":
163165
return String.valueOf(isAsposeEnabled());
166+
case "sysadmin.delete.user":
167+
return sysadminDeleteUser;
164168
default:
165169
throw new IllegalArgumentException("No property available for name: " + propertyName);
166170
}

src/main/webapp/ui/src/eln/sysadmin/users/index.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ import Badge from "@mui/material/Badge";
8383
import docLinks from "../../../assets/DocLinks";
8484
import createAccentedTheme from "../../../accentedTheme";
8585
import UserAliasIcon from "@mui/icons-material/ContactEmergency";
86+
import { useDeploymentProperty } from "../../useDeploymentProperty";
87+
import * as Parsers from "../../../util/parsers";
8688

8789
const Panel = ({
8890
anchorEl,
@@ -646,10 +648,20 @@ const DeleteAction = ({
646648
const { addAlert } = React.useContext(AlertContext);
647649
const [open, setOpen] = React.useState(false);
648650
const [username, setUsername] = React.useState("");
651+
const canDelete = useDeploymentProperty("sysadmin.delete.user");
649652

650-
const allowedToDelete: Result<User> = selectedUser.mapError(
651-
() => new Error("Only one user can be deleted at a time.")
652-
);
653+
const allowedToDelete: Result<User> = FetchingData.getSuccessValue(canDelete)
654+
.flatMap(Parsers.isBoolean)
655+
.flatMap(Parsers.isTrue)
656+
.mapError(
657+
() =>
658+
new Error('The deployment property "sysadmin.delete.user" is false.')
659+
)
660+
.flatMap(() =>
661+
selectedUser.mapError(
662+
() => new Error("Only one user can be deleted at a time.")
663+
)
664+
);
653665

654666
return (
655667
<>

src/main/webapp/ui/src/eln/sysadmin/users/useUserListing.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,14 @@ export function useUserListing(): {|
317317
>("/system/ajax/removeUserAccount/", {
318318
userId: id,
319319
});
320-
if (typeof data.error !== "undefined") {
321-
throw new Error(data.error.errorMessages[0]);
322-
} else {
323-
refreshListing();
324-
}
320+
Parsers.isObject(data)
321+
.flatMap(Parsers.isNotNull)
322+
.flatMap(Parsers.getValueWithKey("exceptionMessage"))
323+
.flatMap(Parsers.isString)
324+
.do((exceptionMessage) => {
325+
throw new Error(exceptionMessage);
326+
});
327+
refreshListing();
325328
} catch (error) {
326329
if (error.response?.data?.message) {
327330
const message = error.response.data.message;

0 commit comments

Comments
 (0)