Skip to content

Commit

Permalink
feat: remove Auth Server Defaults page #307
Browse files Browse the repository at this point in the history
  • Loading branch information
duttarnab committed Jul 18, 2022
1 parent 96ee136 commit 0d54fed
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 243 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { FormGroup, Card, CardBody } from 'Components'
import GluuLoader from 'Routes/Apps/Gluu/GluuLoader'
import GluuCommitFooter from 'Routes/Apps/Gluu/GluuCommitFooter'
import GluuCommitDialog from 'Routes/Apps/Gluu/GluuCommitDialog'
import GluuRibbon from 'Routes/Apps/Gluu/GluuRibbon'
import useExitPrompt from 'Routes/Apps/Gluu/useExitPrompt'
import DefaultAcrInput from './DefaultAcrInput'
import PropertyBuilder from './JsonPropertyBuilder'
import { SIMPLE_PASSWORD_AUTH, FETCHING_SCRIPTS } from 'Plugins/auth-server/common/Constants'
import { connect } from 'react-redux'
import {
buildPayload,
Expand All @@ -17,32 +19,49 @@ import {
patchJsonConfig,
} from 'Plugins/auth-server/redux/actions/JsonConfigActions'
import { FETCHING_JSON_PROPERTIES } from 'Plugins/auth-server/common/Constants'
import SetTitle from 'Utils/SetTitle'
import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle'
import { getAcrsConfig, editAcrs } from 'Plugins/auth-server/redux/actions/AcrsActions'
import { getScripts } from 'Redux/actions/InitActions'
import { useTranslation } from 'react-i18next'

function ConfigPage({ configuration, loading, dispatch, permissions }) {
const { t } = useTranslation()
function ConfigPage({ acrs, scripts, configuration, loading, dispatch, permissions }) {
const lSize = 6
const userAction = {}
const [modal, setModal] = useState(false)
const [patches, setPatches] = useState([])
const [operations, setOperations] = useState([])
const [showExitPrompt, setShowExitPrompt] = useExitPrompt(true)
SetTitle(t('titles.jans_json_property'))
const [put, setPut] = useState([])
const { t } = useTranslation()
const authScripts = scripts
.filter((item) => item.scriptType == 'PERSON_AUTHENTICATION')
.filter((item) => item.enabled)
.map((item) => item.name)

authScripts.push(SIMPLE_PASSWORD_AUTH)

useEffect(() => {
buildPayload(userAction, FETCHING_JSON_PROPERTIES, {})
dispatch(getJsonConfig())
dispatch(getJsonConfig(userAction))
dispatch(getAcrsConfig())
dispatch(getScripts(userAction))
}, [])

useEffect(() => {
return () => {
setShowExitPrompt(false)
}
}, [])

const patchHandler = (patch) => {
setPatches((existingPatches) => [...existingPatches, patch])
const newPatches = patches
newPatches.push(patch)
setPatches(newPatches)
setOperations(newPatches)
}
const putHandler = (put) => {
setPut(put)
setOperations(patches.concat(put))
}
function submitForm(message) {
toggle()
Expand All @@ -53,6 +72,11 @@ function ConfigPage({ configuration, loading, dispatch, permissions }) {
const postBody = {}
postBody['patchRequest'] = patches
buildPayload(userAction, message, postBody)
if (!!put) {
const opts = {}
opts['authenticationMethod'] = { 'defaultAcr': put.value }
dispatch(editAcrs(opts))
}
dispatch(patchJsonConfig(userAction))
}
}
Expand All @@ -61,8 +85,12 @@ function ConfigPage({ configuration, loading, dispatch, permissions }) {
}
return (
<GluuLoader blocking={loading}>
<Card style={applicationStyle.mainCard}>
<Card>
<GluuRibbon title="titles.jans_json_property" fromLeft doTranslate />
<CardBody style={{ minHeight: 500 }}>
<FormGroup row></FormGroup>
<FormGroup row></FormGroup>
<FormGroup row></FormGroup>
{Object.keys(configuration).map((propKey, idx) => (
<PropertyBuilder
key={idx}
Expand All @@ -72,6 +100,19 @@ function ConfigPage({ configuration, loading, dispatch, permissions }) {
handler={patchHandler}
/>
))}

<DefaultAcrInput
id="defaultAcr"
name="defaultAcr"
lsize={lSize}
rsize={lSize}
type="select"
label={t('fields.default_acr')}
handler={putHandler}
value={acrs.defaultAcr}
options={authScripts}
path={'/ACR'}
/>
<FormGroup row></FormGroup>
{hasPermission(permissions, PROPERTIES_WRITE) && (
<GluuCommitFooter saveHandler={toggle} />
Expand All @@ -83,7 +124,7 @@ function ConfigPage({ configuration, loading, dispatch, permissions }) {
<GluuCommitDialog
handler={toggle}
modal={modal}
operations={patches}
operations={operations}
onAccept={submitForm}
/>
)}
Expand All @@ -98,6 +139,8 @@ const mapStateToProps = (state) => {
configuration: state.jsonConfigReducer.configuration,
permissions: state.authReducer.permissions,
loading: state.jsonConfigReducer.loading,
acrs: state.acrReducer.acrs,
scripts: state.initReducer.scripts,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import React, { useState, useEffect } from 'react'
import GluuLabel from 'Routes/Apps/Gluu/GluuLabel'
import GluuTooltip from 'Routes/Apps/Gluu/GluuTooltip'
import { useTranslation } from 'react-i18next'
import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle'
import {
Col,
InputGroup,
CustomInput,
FormGroup,
Button,
} from 'Components'

function DefaultAcrInput({
label,
name,
value,
required,
lsize,
rsize,
isArray,
handler,
options,
path,
}) {
const { t } = useTranslation()
const VALUE = 'value'
const PATH = 'path'
const [show, setShow] = useState(false)
const [correctValue, setCorrectValue] = useState([])
const [data, setData] = useState(value)

useEffect(() => {
setData(value)
}, [value])

const onValueChanged = (data) => {
setShow(true)
setData(data)
}
const onAccept = () => {
const put = {}
put[PATH] = path
if (isArray) {
put[VALUE] = correctValue
} else {
put[VALUE] = document.getElementById(name).value
}
put['op'] = 'replace'
handler(put)
setShow(!show)
setData(document.getElementById(name).value)
}
const onCancel = () => {
setCorrectValue([])
setShow(!show)
}
return (
<FormGroup row>
<Col sm={10}>
<GluuTooltip doc_category="json_properties" doc_entry={name}>
<FormGroup row>
<GluuLabel
label={label}
size={lsize}
required={required}
withTooltip={false}
/>
<Col sm={rsize}>
<InputGroup>
<CustomInput
type="select"
data-testid={name}
id={name}
name={name}
value={data}
onChange={(e) => { onValueChanged(e.target.value) }}
>
<option value="">{t('actions.choose')}...</option>
{options.map((item, key) => (
<option key={key}>
{item}
</option>
))}
</CustomInput>
</InputGroup>
</Col>
</FormGroup>
</GluuTooltip>
</Col>
<Col sm={2}>
{show && (
<>
<Button
color="primary"
style={applicationStyle.buttonStyle}
size="sm"
onClick={onAccept}
>
<i className="fa fa-check mr-2"></i>
</Button>{' '}
<Button color="danger" size="sm" onClick={onCancel}>
<i className="fa fa-times mr-2"></i>
</Button>
</>
)}
</Col>
</FormGroup>
)
}

DefaultAcrInput.defaultProps = {
type: 'text',
lsize: 3,
rsize: 9,
required: false,
}

export default DefaultAcrInput

This file was deleted.

Loading

0 comments on commit 0d54fed

Please sign in to comment.