Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit 1ed5421

Browse files
authored
Merge pull request #254 from davidradl/git252
#252 allow altering of type and severities in audit log destination
2 parents a121523 + 864a112 commit 1ed5421

File tree

2 files changed

+103
-61
lines changed

2 files changed

+103
-61
lines changed

cra-client/src/components/ServerAuthor/components/ConfigureAuditLogDestinations.jsx

+100-57
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default function ConfigureAuditLogDestinations({
4747
setCurrentServerAuditDestinations,
4848
newServerName,
4949
fetchServerConfig,
50-
setLoadingText,
50+
setLoadingText
5151
} = useContext(ServerAuthorContext);
5252
const { userId, serverName: tenantId } = useContext(IdentificationContext);
5353

@@ -94,6 +94,30 @@ export default function ConfigureAuditLogDestinations({
9494
console.log("onChangeTypeSelected " + e.target.value);
9595
setCurrentDestinationTypeName(e.target.value);
9696
};
97+
/**
98+
* We are padded the id of the severity that has changed. This fuctions is careful to clone
99+
* the existing currentSupportedSeverities, so we can amend the array and then set it in state.
100+
*/
101+
const handleOnChangeSeverity = (id) => {
102+
console.log("onChangeTypeSelected ");
103+
let newCurrentSeverities;
104+
for (let i=0; i<currentSupportedSeverities.length; i++) {
105+
const currentSeverity = currentSupportedSeverities[i];
106+
if (currentSeverity.id === id) {
107+
// clone to a new object
108+
let newSeverity = {
109+
...currentSeverity,
110+
selected: !currentSeverity.selected, // toggle the selected state
111+
};
112+
//replace the element in the array
113+
newCurrentSeverities = currentSupportedSeverities.map(function(severity) { return severity.id == id ? newSeverity : severity; });
114+
115+
break;
116+
}
117+
}
118+
// set the new current supported severities in state
119+
setCurrentSupportedSeverities(newCurrentSeverities);
120+
};
97121
const getConnectorProviderClass = () => {
98122
let connectorClass = currentCustomConnectorClass;
99123

@@ -118,12 +142,18 @@ export default function ConfigureAuditLogDestinations({
118142
}
119143
return type;
120144
};
145+
const supportedSeverities = supportedAuditLogSeverities.map((s) => {
146+
return {
147+
...s,
148+
selected: true,
149+
};
150+
});
121151

122152
const onClickAdd = () => {
123153
setCurrentDestinationName(undefined);
124154
setCurrentDestinationId(undefined);
125155
setCurrentDestinationDescription(undefined);
126-
setCurrentSupportedSeverities(undefined);
156+
setCurrentSupportedSeverities(supportedSeverities);
127157
setCurrentDestinationTypeName('default');
128158

129159
setOperation("Add");
@@ -219,12 +249,23 @@ export default function ConfigureAuditLogDestinations({
219249
if (!isCopy) {
220250
destinationName = auditLogDestinationToEdit.name;
221251
}
252+
253+
254+
255+
const supportedSeveritiesSelectedNames = auditLogDestinationToEdit.supportedSeverities;
256+
257+
let checkedSupportedSeverities = [];
258+
for (let i=0;i<supportedAuditLogSeverities.length;i++) {
259+
let severity = supportedAuditLogSeverities[i];
260+
severity.selected = supportedSeveritiesSelectedNames.includes(severity.id);
261+
checkedSupportedSeverities.push(severity);
262+
}
222263
//we need to store the original name as this is the key that will be updated in the rest call.
223264
setCurrentDestinationId(destinationName);
224265
//the name could change in the editor
225266
setCurrentDestinationName(destinationName);
226267
setCurrentDestinationDescription(auditLogDestinationToEdit.description);
227-
setCurrentSupportedSeverities(auditLogDestinationToEdit.severities);
268+
setCurrentSupportedSeverities(checkedSupportedSeverities);
228269
setCurrentDestinationTypeName(auditLogDestinationToEdit.type);
229270

230271
let op = "Edit";
@@ -245,6 +286,10 @@ export default function ConfigureAuditLogDestinations({
245286
issueEdit();
246287
}
247288
};
289+
const onClickCancelOperation = () => {
290+
setOperation(undefined);
291+
};
292+
248293
const issueAdd = () => {
249294
let nameExists = false;
250295
for (let i = 0; i < currentServerAuditDestinations.length; i++) {
@@ -263,7 +308,7 @@ export default function ConfigureAuditLogDestinations({
263308
"The requested Audit Log Destination Name need to have a value. Please specify one."
264309
);
265310
} else {
266-
setOperation(undefined);
311+
267312

268313
const addAuditLogDestinationURL = encodeURI(
269314
"/servers/" +
@@ -274,36 +319,8 @@ export default function ConfigureAuditLogDestinations({
274319
newServerName +
275320
"/audit-log-destinations/connection"
276321
);
277-
const body = {
278-
class: "Connection",
279-
headerVersion: 0,
280-
displayName: currentDestinationName,
281-
description: currentDestinationDescription,
282-
connectorType: {
283-
class: "ConnectorType",
284-
headerVersion: 0,
285-
type: {
286-
class: "ElementType",
287-
headerVersion: 0,
288-
elementOrigin: "LOCAL_COHORT",
289-
elementVersion: 0,
290-
elementTypeId: "954421eb-33a6-462d-a8ca-b5709a1bd0d4",
291-
elementTypeName: "ConnectorType",
292-
elementTypeVersion: 1,
293-
elementTypeDescription:
294-
"A set of properties describing a type of connector.",
295-
},
296-
guid: "4afac741-3dcc-4c60-a4ca-a6dede994e3f",
297-
qualifiedName: "Console Audit Log Store Connector",
298-
displayName: "Console Audit Log Store Connector",
299-
description:
300-
"Connector supports logging of audit log messages to stdout.",
301-
connectorProviderClassName: getConnectorProviderClass(),
302-
},
303-
configurationProperties: {
304-
supportedSeverities: currentSupportedSeverities,
305-
},
306-
};
322+
setOperation(undefined);
323+
const body = getRestBody();
307324
console.log("addAuditLogDestinationURL " + addAuditLogDestinationURL);
308325
setLoadingText("Adding audit log destination");
309326
issueRestCreate(
@@ -328,7 +345,28 @@ export default function ConfigureAuditLogDestinations({
328345
"/audit-log-destinations/connection/" +
329346
currentDestinationId
330347
);
331-
const body = {
348+
const body = getRestBody();
349+
console.log("editAuditLogDestinationURL " + editAuditLogDestinationURL);
350+
setLoadingText("Editing audit log destination");
351+
issueRestUpdate(
352+
editAuditLogDestinationURL,
353+
body,
354+
onSuccessfulEditAuditLogDestination,
355+
onErrorAuditLogDestination,
356+
"omagServerConfig"
357+
);
358+
};
359+
360+
const getRestBody = () => {
361+
let restSeverities = [];
362+
for (let i=0;i<currentSupportedSeverities.length; i++) {
363+
const currentSeverity = currentSupportedSeverities[i];
364+
if (currentSeverity.selected) {
365+
restSeverities.push(currentSeverity.id);
366+
}
367+
}
368+
369+
return {
332370
class: "Connection",
333371
headerVersion: 0,
334372
displayName: currentDestinationName,
@@ -355,18 +393,10 @@ export default function ConfigureAuditLogDestinations({
355393
connectorProviderClassName: getConnectorProviderClass(),
356394
},
357395
configurationProperties: {
358-
supportedSeverities: currentSupportedSeverities,
396+
supportedSeverities: restSeverities
359397
},
360398
};
361-
console.log("editAuditLogDestinationURL " + editAuditLogDestinationURL);
362-
setLoadingText("Editing audit log destination");
363-
issueRestUpdate(
364-
editAuditLogDestinationURL,
365-
body,
366-
onSuccessfulEditAuditLogDestination,
367-
onErrorAuditLogDestination,
368-
"omagServerConfig"
369-
);
399+
370400
};
371401
const onSuccessfulAddAuditLogDestination = () => {
372402
console.log("onSuccessfulAddAuditLogDestination entry");
@@ -388,15 +418,16 @@ export default function ConfigureAuditLogDestinations({
388418
// setCurrentServerAuditDestinations(newAuditLogDestinations);
389419
document.getElementById("loading-container").style.display = "none";
390420
setLoadingText("Refreshing audit log destinations ");
391-
fetchServerConfig(refreshAuditLogDestinations, onErrorAuditLogDestination);
421+
// retrieveAllServers
422+
fetchServerConfig(refreshCurrentAuditLogDestinations, onErrorAuditLogDestination);
392423

393424
};
394425
const onSuccessfulEditAuditLogDestination = () => {
395426
console.log("onSuccessfulEditAuditLogDestination ");
396427
console.log(currentServerAuditDestinations);
397428
document.getElementById("loading-container").style.display = "none";
398429
setLoadingText("Refreshing audit log destinations ");
399-
fetchServerConfig(refreshAuditLogDestinations, onErrorAuditLogDestination);
430+
fetchServerConfig(refreshCurrentAuditLogDestinations, onErrorAuditLogDestination);
400431
};
401432

402433
const onSuccessfulRemoveAll = () => {
@@ -409,11 +440,11 @@ export default function ConfigureAuditLogDestinations({
409440
console.log("onSuccessfulRemove");
410441
// Fetch Server Config
411442
setLoadingText("Refreshing audit log destinations ");
412-
fetchServerConfig(refreshAuditLogDestinations, onErrorAuditLogDestination);
443+
fetchServerConfig(refreshCurrentAuditLogDestinations, onErrorAuditLogDestination);
413444
};
414445

415-
const refreshAuditLogDestinations = (response) => {
416-
console.log("refreshAuditLogDestinations");
446+
const refreshCurrentAuditLogDestinations = (response) => {
447+
console.log("refreshCurrentAuditLogDestinations");
417448
console.log(response);
418449

419450
const config = response.omagServerConfig;
@@ -446,8 +477,15 @@ export default function ConfigureAuditLogDestinations({
446477
auditLogConnection.connectorType.connectorProviderClassName
447478
);
448479
}
449-
450-
refreshedAuditLogConnection.supportedSeverities = [];
480+
//TODO
481+
const supportedSeveritiesSelectedNames = auditLogConnection.configurationProperties.supportedSeverities;
482+
const supportedSeveritiesNames = supportedAuditLogSeverities.map(a => a.id);
483+
let checkedSupportedSeverities = [];
484+
for (let i=0;i<supportedAuditLogSeverities.length;i++) {
485+
let severity = supportedAuditLogSeverities[i];
486+
severity.selected = supportedSeveritiesSelectedNames.includes(severity.id);
487+
checkedSupportedSeverities.push(severity);
488+
}
451489
if (
452490
auditLogConnection.configurationProperties &&
453491
auditLogConnection.configurationProperties.supportedSeverities
@@ -457,7 +495,7 @@ export default function ConfigureAuditLogDestinations({
457495
}
458496
refreshedAuditLogConnections.push(refreshedAuditLogConnection);
459497
}
460-
498+
// update the current server audit destinations with the values from the servere
461499
setCurrentServerAuditDestinations(refreshedAuditLogConnections);
462500
}
463501
}
@@ -510,15 +548,15 @@ export default function ConfigureAuditLogDestinations({
510548
autoComplete="off"
511549
/>
512550
<Select
513-
defaultValue="placeholder-item"
551+
defaultValue={currentDestinationTypeName}
514552
helperText={destinationTypeDescription}
515553
onChange={onChangeTypeSelected}
516554
id="select-server-type"
517555
invalidText="A valid value is required"
518556
labelText="Select Audit Log Destination Type"
519557
>
520558
{auditLogDestinations.map((dest, i) => (
521-
<SelectItem text={dest.label} value={dest.id} id={dest.id} />
559+
<SelectItem text={dest.label} value={dest.id} id={dest.id} />
522560
))}
523561
</Select>
524562
{currentDestinationTypeName === "connection" && (
@@ -554,14 +592,19 @@ export default function ConfigureAuditLogDestinations({
554592
labelText={severity.label}
555593
id={severity.id}
556594
checked={severity.selected}
595+
onChange={j => handleOnChangeSeverity(severity.id)}
596+
557597
/>
558598
))}
559599
</div>
560600
</div>
561-
601+
<button onClick={(e) => onClickCancelOperation()}>
602+
Cancel {operation}
603+
</button>
562604
<button onClick={(e) => onClickFinishedOperation()}>
563-
Enable this Audit Log Destination
605+
Issue {operation}
564606
</button>
607+
565608
</fieldset>
566609
)}
567610
{operation === undefined && (

cra-client/src/components/ServerAuthor/contexts/ServerAuthorContext.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ const ServerAuthorContextProvider = props => {
8080
const integrationServicesFormStartRef = useRef(null);
8181

8282
useEffect(() => {
83-
const fetchLists = async () => {
84-
retrieveAllServers();
85-
};
86-
fetchLists();
83+
retrieveAllServers();
8784
}, []);
8885
/**
8986
* Clear out all the context so the new server type doe not pick up old values in the wizard.
@@ -154,6 +151,8 @@ const cleanForNewServerType = () => {
154151
const restURL = encodeURI("/servers/" + serverName + "/server-author/users/" + userId +"/servers/" + serverName + "/audit-log-destinations");
155152
issueRestGet(restURL, onSuccessfulFetchAuditLogSeverities, onErrorFetchAuditLogSeverities, "severities");
156153
};
154+
155+
157156
const onErrorFetchPlatforms = () => {
158157
// error
159158
setAllServers([]);

0 commit comments

Comments
 (0)