Skip to content

Commit

Permalink
feat(admin-ui): implement jans assets listing #1635
Browse files Browse the repository at this point in the history
  • Loading branch information
syntrydy committed Apr 3, 2024
1 parent ccf7287 commit 25af419
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 46 deletions.
4 changes: 4 additions & 0 deletions admin-ui/app/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
},
"fields": {
"access_token_signing_alg": "JWS alg for signing",
"asset_name": "Asset Name",
"default_permission_in_token": "Default permission in token",
"aui_feature_ids": "Admin UI Features",
"introspection_signed_response_alg": "Introspection Signed Response Alg",
Expand Down Expand Up @@ -600,6 +601,7 @@
},
"messages": {
"add_permission": "Add Permission",
"add_asset":"Add Jans Asset",
"add_configuration": "Add Configuration",
"view_configuration": "View Configuration",
"view_trust_relationshi_details": "View Trust Relationship Details",
Expand Down Expand Up @@ -758,6 +760,8 @@
"acrs": "ACRs",
"active_users": "Actives Users && Access Token Stats",
"assets": "Jans Assets",
"asset_add": "Adding new Jans Asset",
"asset_edit": "Editing new Jans Asset",
"introspection_object": "Introspection Object",
"acrs_logging": "ACRs && Logging",
"algorithmic_keys": "Algorithmic Keys",
Expand Down
4 changes: 4 additions & 0 deletions admin-ui/app/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"copy_to_clipboard": "Copier dans le presse-papier"
},
"fields": {
"asset_name": "Asset Name",
"tag": "Étiqueter",
"issuer": "Émetteur",
"message_provider_type": "Type de fournisseur de messages",
Expand Down Expand Up @@ -542,6 +543,7 @@
},
"messages": {
"add_permission": "Ajouter une autorisation",
"add_asset":"Add Jans Asset",
"add_configuration": "Ajouter une configuration",
"view_configuration": "Afficher la configuration",
"new_role": "Nouveau rôle",
Expand Down Expand Up @@ -682,6 +684,8 @@
"titles": {
"acrs": "ACR",
"assets": "Jans Assets",
"asset_add": "Adding new Jans Asset",
"asset_edit": "Editing new Jans Asset",
"algorithmic_keys": "Clés algorithmiques",
"introspection_object": "Objet d'inspection",
"all_attributes": "Tous les attributs",
Expand Down
4 changes: 4 additions & 0 deletions admin-ui/app/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"copy_to_clipboard": "Copiar para área de transferência"
},
"fields": {
"asset_name": "Asset Name",
"tag": "Marcação",
"default_permission_in_token": "Permissão padrão no token",
"introspection_signed_response_alg": "Algoritmo de assinatura da resposta de introspeção",
Expand Down Expand Up @@ -537,6 +538,7 @@
},
"messages": {
"add_permission": "Adicionar permissão",
"add_asset":"Add Jans Asset",
"add_configuration": "Adicionar configuração",
"view_configuration": "Ver Configuração",
"add_idp": "Adicionar IDP SAML",
Expand Down Expand Up @@ -678,6 +680,8 @@
"titles": {
"acrs": "ACRs",
"assets": "Jans Assets",
"asset_add": "Adding new Jans Asset",
"asset_edit": "Editing new Jans Asset",
"algorithmic_keys": "Chaves Algorítmicas",
"introspection_object": "Objeto de introspecção",
"all_attributes": "Todos os Atributos",
Expand Down
202 changes: 202 additions & 0 deletions admin-ui/plugins/admin/components/Assets/AssetForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import React, { useCallback, useState, useEffect } from 'react'
import { Col, Form, Row, FormGroup } from 'Components'
import GluuInputRow from 'Routes/Apps/Gluu/GluuInputRow'
import { useFormik } from 'formik'
import GluuCommitFooter from 'Routes/Apps/Gluu/GluuCommitFooter'
import GluuCommitDialog from 'Routes/Apps/Gluu/GluuCommitDialog'
import { useTranslation } from 'react-i18next'
import { useDispatch, useSelector } from 'react-redux'
import * as Yup from 'yup'
import {
createAsset,
updateAsset,
} from 'Plugins/admin/redux/features/AssetSlice'
import { buildPayload } from 'Utils/PermChecker'
import { useNavigate, useParams } from 'react-router'
import GluuLabel from 'Routes/Apps/Gluu/GluuLabel'
import Toggle from 'react-toggle'
import { WEBHOOK } from 'Utils/ApiResources'

const AssetForm = () => {
const { id } = useParams()
const userAction = {}
const { selectedAsset } =
useSelector((state) => state.assetReducer)

const { t } = useTranslation()
const navigate = useNavigate()
const saveOperationFlag = useSelector(
(state) => state.assetReducer.saveOperationFlag
)
const errorInSaveOperationFlag = useSelector(
(state) => state.assetReducer.errorInSaveOperationFlag
)
const dispatch = useDispatch()
const [modal, setModal] = useState(false)

const validatePayload = (values) => {
let faulty = false
if (values.httpRequestBody) {
try {
JSON.parse(values.httpRequestBody)
} catch (error) {
faulty = true
formik.setFieldError(
'httpRequestBody',
t('messages.invalid_json_error')
)
}
}

return faulty
}


const formik = useFormik({
initialValues: {
creationDate: selectedAsset?.creationDate,
document: selectedAsset?.document || '',
displayName: selectedAsset?.displayName || '',
jansEnabled: selectedAsset?.jansEnabled || false,
description: selectedAsset?.description || '',
},
onSubmit: (values) => {
const faulty = validatePayload(values)
if (faulty) {
return
}
toggle()
},
validationSchema: Yup.object().shape({
document: Yup.string().required(t('messages.asset_document_error')),
displayName: Yup.string()
.required(t('messages.display_name_error'))
.matches(
/^\S*$/,
`${t('fields.asset_name')} ${t('messages.no_spaces')}`
),
description: Yup.string().required(t('messages.description_error')),
}),
})

const toggle = () => {
setModal(!modal)
}

const submitForm = useCallback(
(userMessage) => {
toggle()

const jansModuleProperties = formik.values.jansModuleProperty?.map((header) => {
return {
key: header.key || header.source,
value: header.value || header.destination,
}
})

const payload = {
...formik.values,
jansModuleProperty: jansModuleProperties || [],
}

if (id) {
payload['inum'] = selectedAsset.inum
payload['dn'] = selectedAsset.dn
payload['baseDn'] = selectedAsset.baseDn
}

buildPayload(userAction, userMessage, payload)
if (id) {
dispatch(updateAsset({ action: userAction }))
} else {
dispatch(createAsset({ action: userAction }))
}
},
[formik]
)

useEffect(() => {
if (saveOperationFlag && !errorInSaveOperationFlag) navigate('/adm/assets')

return function cleanup() {
dispatch(resetFlags())
}
}, [saveOperationFlag, errorInSaveOperationFlag])


return (
<>
<Form onSubmit={formik.handleSubmit}>
<Col sm={12}>
{id ? (
<GluuInputRow
label='fields.inum'
formik={formik}
value={selectedAsset?.inum}
lsize={4}
doc_entry='asset_id'
rsize={8}
doc_category={WEBHOOK}
name='assetId'
disabled={true}
/>
) : null}
<GluuInputRow
label='fields.asset_name'
formik={formik}
value={formik.values?.displayName}
lsize={4}
doc_entry='asset_name'
rsize={8}
required
name='displayName'
doc_category={WEBHOOK}
errorMessage={formik.errors.displayName}
showError={formik.errors.displayName && formik.touched.displayName}
/>

<GluuInputRow
label='fields.description'
formik={formik}
value={formik.values?.description}
doc_category={WEBHOOK}
doc_entry='description'
lsize={4}
rsize={8}
name='description'
/>
</Col>

<FormGroup row>
<GluuLabel
label='options.enabled'
size={4}
doc_category={WEBHOOK}
doc_entry='enabled'
/>
<Col sm={1}>
<Toggle
id='jansEnabled'
name='jansEnabled'
onChange={formik.handleChange}
defaultChecked={formik.values.jansEnabled}
/>
</Col>
</FormGroup>

<Row>
<Col>
<GluuCommitFooter
saveHandler={toggle}
hideButtons={{ save: true, back: false }}
type='submit'
/>
</Col>
</Row>
</Form>
<GluuCommitDialog handler={toggle} modal={modal} onAccept={submitForm} />
</>
)
}

export default AssetForm
8 changes: 6 additions & 2 deletions admin-ui/plugins/admin/components/Assets/JansAssetAddPage.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import React from 'react'
import { Card } from 'Components'
import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle'
import WebhookForm from '../Webhook/WebhookForm'
import AssetForm from './AssetForm'
import { useTranslation } from 'react-i18next'
import GluuLoader from 'Routes/Apps/Gluu/GluuLoader'
import { useSelector } from 'react-redux'
import SetTitle from 'Utils/SetTitle'

const JansAssetAddPage = () => {
const { t } = useTranslation()
SetTitle(t('titles.asset_add'))
const loading = useSelector((state) => state.assetReducer.loading)

return (
<GluuLoader blocking={loading}>
<Card style={applicationStyle.mainCard}>
<WebhookForm />
<AssetForm />
</Card>
</GluuLoader>
)
Expand Down
10 changes: 7 additions & 3 deletions admin-ui/plugins/admin/components/Assets/JansAssetEditPage.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React, { useEffect } from 'react'
import { Card } from 'Components'
import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle'
import WebhookForm from '../Webhook/WebhookForm'
import AssetForm from './AssetForm'
import { useTranslation } from 'react-i18next'
import GluuLoader from 'Routes/Apps/Gluu/GluuLoader'
import { useDispatch, useSelector } from 'react-redux'
import { getAssets, getAssetResponse } from 'Plugins/admin/redux/features/assetSlice'
import { getAssets, getAssetResponse } from 'Plugins/admin/redux/features/AssetSlice'
import { useParams } from 'react-router'
import SetTitle from 'Utils/SetTitle'

const JansAssetEditPage = () => {
const { id } = useParams()
const { t } = useTranslation()
const dispatch = useDispatch()
SetTitle(t('titles.asset_edit'))
const { loading } = useSelector((state) => state.assetReducer)

useEffect(() => {
Expand All @@ -19,7 +23,7 @@ const JansAssetEditPage = () => {
return (
<GluuLoader blocking={loading}>
<Card style={applicationStyle.mainCard}>
<WebhookForm />
<AssetForm />
</Card>
</GluuLoader>
)
Expand Down
Loading

0 comments on commit 25af419

Please sign in to comment.