Merge pull request #4243 from LibreSign/fix/load-cert-custom-options

fix: load cert custom options
This commit is contained in:
Vitor Mattos 2025-01-04 13:43:22 -03:00 committed by GitHub
commit 21ef2feccd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 54 additions and 49 deletions

View file

@ -28,18 +28,15 @@
<div v-for="certificate in certificateList"
:key="certificate.id"
class="customNames">
<label :for="certificate.id" class="form-heading--required">
{{ certificate.label }}
</label>
<div class="item">
<NcTextField v-if="certificate"
:id="certificate.id"
v-model="certificate.value"
:success="typeof certificate.error === 'boolean' && !certificate.error"
:error="certificate.error"
:maxlength="certificate.max ? certificate.max : undefined"
:label="certificate.label"
:helper-text="certificate.helperText"
:maxlength="getOptionProperty(certificate.id, 'max')"
:label="getOptionProperty(certificate.id, 'label')"
:helper-text="getOptionProperty(certificate.id, 'helperText')"
@update:value="validate(certificate.id)" />
<NcButton :aria-label="t('settings', 'Remove custom name entry from root certificate')"
@click="removeOptionalAttribute(certificate.id)">
@ -82,12 +79,26 @@ export default {
},
data() {
return {
customNamesOptions: options,
certificateList: [],
options,
}
},
computed: {
customNamesOptions() {
return this.options.filter(itemA =>
!this.certificateList.some(itemB => itemB.id === itemA.id),
)
},
},
watch: {
names(values) {
this.certificateList = values
},
},
methods: {
getOptionProperty(id, property) {
return this.options.find(option => option.id === id)[property]
},
validateMin(item) {
return item.value.length >= item.min
},
@ -122,14 +133,12 @@ export default {
}
const list = this.certificateList.filter(item => item.id !== itemSelected.id)
this.certificateList = list
this.customNamesOptions = [...this.customNamesOptions, itemSelected]
}
},
async onOptionalAttributeSelect(selected) {
const custonOption = selectCustonOption(selected.id)
if (custonOption.isSome()) {
this.certificateList = [custonOption.unwrap(), ...this.certificateList]
this.customNamesOptions = this.customNamesOptions.filter(item => item.id !== selected.id)
}
},
@ -151,6 +160,7 @@ export default {
.item {
display: grid;
grid-template-columns: auto 54px;
align-items: center;
input[type='text'] {
width: 100%;
}

View file

@ -108,6 +108,7 @@ import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
import CertificateCustonOptions from './CertificateCustonOptions.vue'
import { selectCustonOption } from '../../helpers/certification.js'
import logger from '../../logger.js'
import { useConfigureCheckStore } from '../../store/configureCheck.js'
export default {
@ -185,14 +186,14 @@ export default {
this.modal = false
},
clearAndShowForm() {
this.certificate = {
this.$set(this, 'certificate', {
rootCert: {
commonName: '',
names: [],
},
cfsslUri: '',
configPath: '',
}
})
this.customData = false
this.formDisabled = false
this.modal = false
@ -209,7 +210,7 @@ export default {
if (!data.ocs.data || data.ocs.data.message) {
throw new Error(data.ocs.data)
}
this.certificate = data.ocs.data.data
this.$set(this, 'certificate', data.ocs.data.data)
this.afterCertificateGenerated()
this.configureCheckStore.checkSetup()
})
@ -237,23 +238,20 @@ export default {
return
}
this.formDisabled = true
try {
const response = await axios.get(
generateOcsUrl('/apps/libresign/api/v1/admin/certificate'),
)
if (!response.data.ocs.data || response.data.ocs.data.message) {
throw new Error(response.data.ocs.data)
}
this.certificate = response.data.ocs.data
this.customData = loadState('libresign', 'config_path').length > 0
&& (this.certificate?.cfsslUri?.length > 0 || this.certificate.configPath.length > 0)
if (this.certificate.generated) {
this.afterCertificateGenerated()
return
}
} catch (e) {
console.error(e)
}
await axios.get(generateOcsUrl('/apps/libresign/api/v1/admin/certificate'))
.then(({ data }) => {
if (!data.ocs.data || data.ocs.data.message) {
throw new Error(data.ocs.data)
}
this.$set(this, 'certificate', data.ocs.data)
this.customData = loadState('libresign', 'config_path').length > 0
&& (this.certificate?.cfsslUri?.length > 0 || this.certificate.configPath.length > 0)
if (this.certificate.generated) {
this.afterCertificateGenerated()
}
})
.catch((error) => logger.debug('Error when generate certificate', { error }))
this.formDisabled = false
},

View file

@ -97,6 +97,7 @@ import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
import CertificateCustonOptions from './CertificateCustonOptions.vue'
import { selectCustonOption } from '../../helpers/certification.js'
import logger from '../../logger.js'
import { useConfigureCheckStore } from '../../store/configureCheck.js'
export default {
@ -152,7 +153,6 @@ export default {
unsubscribe('libresign:certificate-engine:changed')
unsubscribe('libresign:update:certificateToSave')
},
methods: {
updateNames(names) {
this.certificate.rootCert.names = names
@ -172,13 +172,13 @@ export default {
this.modal = false
},
clearAndShowForm() {
this.certificate = {
this.$set(this, 'certificate', {
rootCert: {
commonName: '',
names: [],
},
configPath: '',
}
})
this.customData = false
this.formDisabled = false
this.modal = false
@ -195,7 +195,7 @@ export default {
if (!data.ocs.data || data.ocs.data.message) {
throw new Error(data.ocs.data)
}
this.certificate = data.ocs.data.data
this.$set(this, 'certificate', data.ocs.data.data)
this.afterCertificateGenerated()
this.configureCheckStore.checkSetup()
})
@ -222,22 +222,19 @@ export default {
return
}
this.formDisabled = true
try {
const response = await axios.get(
generateOcsUrl('/apps/libresign/api/v1/admin/certificate'),
)
if (!response.data.ocs.data || response.data.ocs.data.message) {
throw new Error(response.data.ocs.data)
}
this.certificate = response.data.ocs.data
this.customData = loadState('libresign', 'config_path').length > 0
&& this.certificate.configPath.length > 0
if (this.certificate.generated) {
this.afterCertificateGenerated()
}
} catch (e) {
console.error(e)
}
await axios.get(generateOcsUrl('/apps/libresign/api/v1/admin/certificate'))
.then(({ data }) => {
if (!data.ocs.data || data.ocs.data.message) {
throw new Error(data.ocs.data)
}
this.$set(this, 'certificate', data.ocs.data)
this.customData = loadState('libresign', 'config_path').length > 0
&& this.certificate.configPath.length > 0
if (this.certificate.generated) {
this.afterCertificateGenerated()
}
})
.catch((error) => logger.debug('Error when generate certificate', { error }))
this.formDisabled = false
},