Skip to content

Commit

Permalink
Reflect changes in security scheme in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirishikesan committed Mar 22, 2024
1 parent 9b45105 commit 225098d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,21 @@ export default function RuntimeConfiguration() {
if (event.checked) {
if (state[action].includes(event.value)) {
return state; // Add for completeness, Ideally there couldn't exist this state
} else {
return { ...copyAPIConfig(state), [action]: [...state[action], event.value] };
} else if (event.value === API_SECURITY_MUTUAL_SSL
&& event.value !== DEFAULT_API_SECURITY_OAUTH2
&& event.value !== API_SECURITY_BASIC_AUTH
&& event.value !== API_SECURITY_API_KEY) {
return { ...copyAPIConfig(state),
[action]: [...state[action], event.value, API_SECURITY_MUTUAL_SSL_MANDATORY] };
} else if (event.value !== API_SECURITY_MUTUAL_SSL
&& (event.value === DEFAULT_API_SECURITY_OAUTH2
|| event.value === API_SECURITY_BASIC_AUTH
|| event.value === API_SECURITY_API_KEY)) {
return { ...copyAPIConfig(state),
[action]: [...state[action], event.value,
API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY] };
}
return { ...copyAPIConfig(state), [action]: [...state[action], event.value] };
} else if (state[action].includes(event.value)) {
// User has unchecked a security schema type
const newState = {
Expand All @@ -287,17 +299,31 @@ export default function RuntimeConfiguration() {
)
) {
const noMandatoryOAuthBasicAuth = newState[action]
.filter((schema) => schema !== API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY);
.filter((schema) => (schema !== API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY
&& schema !== API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_OPTIONAL
&& schema !== API_SECURITY_MUTUAL_SSL_MANDATORY
&& schema !== API_SECURITY_MUTUAL_SSL_OPTIONAL));
const newSecurityScheme = newState[action].includes(API_SECURITY_MUTUAL_SSL) ?
[...noMandatoryOAuthBasicAuth, API_SECURITY_MUTUAL_SSL_MANDATORY]
: noMandatoryOAuthBasicAuth;
return {
...newState,
[action]: noMandatoryOAuthBasicAuth,
[action]: newSecurityScheme,
};
} else if (!newState[action].includes(API_SECURITY_MUTUAL_SSL)) {
const noMandatoryMutualSSL = newState[action]
.filter((schema) => schema !== API_SECURITY_MUTUAL_SSL_MANDATORY);
.filter((schema) => (schema !== API_SECURITY_MUTUAL_SSL_MANDATORY
&& schema !== API_SECURITY_MUTUAL_SSL_OPTIONAL
&& schema !== API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY
&& schema !== API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_OPTIONAL));
const newSecurityScheme = (newState[action].includes(DEFAULT_API_SECURITY_OAUTH2)
|| newState[action].includes(API_SECURITY_BASIC_AUTH)
|| newState[action].includes(API_SECURITY_API_KEY)) ?
[...noMandatoryMutualSSL, API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY]
: noMandatoryMutualSSL;
return {
...newState,
[action]: noMandatoryMutualSSL,
[action]: newSecurityScheme,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ export default function ApplicationLevel(props) {

const [mandatoryValueRef, setMandatoryValueRef] = useState(mandatoryValue);

useEffect(() => {
setMandatoryValueRef(mandatoryValue);
});

return (
(<Root>
<Grid item xs={12}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ function TransportLevel(props) {

const [mandatoryValueRef, setMandatoryValueRef] = useState(mandatoryValue);

useEffect(() => {
setMandatoryValueRef(mandatoryValue);
});

return (
(<Root>
<Grid item xs={12}>
Expand Down

0 comments on commit 225098d

Please sign in to comment.