Skip to content

Commit

Permalink
feat(admin-ui): implement asset update and deletion #1635
Browse files Browse the repository at this point in the history
  • Loading branch information
syntrydy committed Apr 10, 2024
1 parent 73fb0ad commit 272c760
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 48 deletions.
3 changes: 3 additions & 0 deletions admin-ui/app/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,9 @@
"yes": "Yes"
},
"documentation": {
"asset":{
"jansModuleProperty": "Jans Module Properties"
},
"webhook": {
"url": "Webhook URL.",
"enabled": "Toggle to activate or deactivate the webhook functionality.",
Expand Down
3 changes: 3 additions & 0 deletions admin-ui/app/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,9 @@
"yes": "Oui"
},
"documentation": {
"asset":{
"jansModuleProperty": "Jans Module Properties"
},
"webhook": {
"url": "URL du webhook.",
"enabled": "Basculez pour activer ou désactiver la fonctionnalité du webhook.",
Expand Down
3 changes: 3 additions & 0 deletions admin-ui/app/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,9 @@
"yes": "sim"
},
"documentation": {
"asset":{
"jansModuleProperty": "Jans Module Properties"
},
"webhook": {
"url": "URL do webhook.",
"enabled": "Ative ou desative a funcionalidade do webhook.",
Expand Down
13 changes: 1 addition & 12 deletions admin-ui/plugins/admin/components/Assets/AssetForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const AssetForm = () => {
)
const dispatch = useDispatch()
const [modal, setModal] = useState(false)

const validatePayload = (values) => {
let faulty = false
return faulty
Expand All @@ -46,6 +45,7 @@ const AssetForm = () => {
if (file) {
setAssetFile(file)
formik.setFieldValue('document', assetFile)
formik.setFieldValue('displayName', file?.name || '')
}
}

Expand All @@ -64,7 +64,6 @@ const AssetForm = () => {
jansModuleProperty: selectedAsset?.jansModuleProperty || []
},
onSubmit: (values) => {
console.log(values)
const faulty = validatePayload(values)
if (faulty) {
return
Expand All @@ -89,24 +88,14 @@ const AssetForm = () => {
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(updateJansAsset({ action: userAction }))
Expand Down
26 changes: 23 additions & 3 deletions admin-ui/plugins/admin/redux/api/AssetApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,30 @@ export default class AssetApi {
}

updateJansAsset = (body) => {
const document = {
"displayName": body.displayName, "description": body.description,
"document": body.displayName, "jansModuleProperty": body?.jansModuleProperty || [], "jansEnabled": body.jansEnabled
}
const formData = new FormData();
const assetFileBlob = new Blob([body.document], {
type: 'application/octet-stream',
})
const documentBlob = new Blob(
[
JSON.stringify({
...document,
}),
],
{
type: 'application/json',
}
)
formData.append('document', documentBlob);
formData.append('assetFile', assetFileBlob);
return new Promise((resolve, reject) => {
this.api.putAsset(document, assetfile, (error, data) => {
handleResponse(error, reject, resolve, data)
})
axios.putForm('/api/v1/jans-assets/upload', formData, { headers: { Authorization: `Bearer ${token}` } })
.then(result => handleResponse(undefined, reject, resolve, result))
.catch(error => handleResponse(error, reject, resolve, undefined));
})
}

Expand Down
34 changes: 1 addition & 33 deletions admin-ui/plugins/admin/redux/features/AssetSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,7 @@ import reducerRegistry from 'Redux/reducers/ReducerRegistry'
import { createSlice } from '@reduxjs/toolkit'

const initialState = {
assets: [{
"dn": "inum=0b436302-b729-4eb2-b211-335980dcab43,ou=document,o=jans",
"selected": false,
"inum": "0b436302-b729-4eb2-b211-335980dcab43",
"displayName": "mermaid-extra.css",
"description": "/opt/jans/jetty/jans-config-api/",
"creationDate": "2024-04-1T12:53:00",
"document": ".mermaid {\r\n\toverflow: auto;\r\n}\r\n\r\n.mermaid svg {\r\n\twidth: 1315px;\r\n\theight: 600px;\r\n}\r\n",
"jansModuleProperty": [
"config-api",
"jar",
"/opt/jans/jetty/jans-config-api/custom/lib"
],
"jansLevel": "1",
"jansRevision": "2",
"jansEnabled": true,
"baseDn": "inum=0b436302-b729-4eb2-b211-335980dcab43,ou=document,o=jans"
},
{
"dn": "inum=9d2f39f5-a910-4a03-a888-6f0f1ee03445,ou=document,o=jans",
"selected": false,
"inum": "9d2f39f5-a910-4a03-a888-6f0f1ee03445",
"displayName": "kc-saml-plugin.jar",
"description": "/opt/jans/jetty/jans-config-api/",
"creationDate": "2024-03-14T12:53:00",
"jansModuleProperty": [
"config-api",
"jar",
"/opt/jans/jetty/jans-config-api/custom/lib"
],
"jansEnabled": true,
"baseDn": "inum=9d2f39f5-a910-4a03-a888-6f0f1ee03445,ou=document,o=jans"
}],
assets: [],
loading: false,
saveOperationFlag: false,
errorInSaveOperationFlag: false,
Expand Down

0 comments on commit 272c760

Please sign in to comment.