Skip to content

Commit 57d678f

Browse files
committed
chore: delete certification.js file and adjustment some files
Signed-off-by: Crisciany Souza <criscianysilva1997@gmail.com>
1 parent a68e74e commit 57d678f

File tree

5 files changed

+48
-93
lines changed

5 files changed

+48
-93
lines changed

lib/Service/Certificate/RulesService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ public function __construct(
4646
}
4747

4848
public function getRule(string $fieldName): array {
49-
if (!array_key_exists($fieldName, $this->rules)) return [];
49+
if (!array_key_exists($fieldName, $this->rules)) {
50+
return [];
51+
}
5052
if (!isset($this->rules[$fieldName]['helperText'])) {
5153
$this->rules[$fieldName]['helperText'] = $this->getHelperText($fieldName);
5254
if (empty($this->rules[$fieldName]['helperText'])) {

lib/Settings/Admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
use OCA\Libresign\AppInfo\Application;
1212
use OCA\Libresign\Exception\LibresignException;
1313
use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory;
14+
use OCA\Libresign\Service\Certificate\RulesService;
1415
use OCA\Libresign\Service\CertificatePolicyService;
1516
use OCA\Libresign\Service\IdentifyMethodService;
1617
use OCA\Libresign\Service\SignatureBackgroundService;
1718
use OCA\Libresign\Service\SignatureTextService;
18-
use OCA\Libresign\Service\Certificate\RulesService;
1919
use OCP\AppFramework\Http\TemplateResponse;
2020
use OCP\AppFramework\Services\IInitialState;
2121
use OCP\IAppConfig;

src/helpers/certification.js

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/views/Settings/CertificateCustonOptions.vue

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import NcListItem from '@nextcloud/vue/components/NcListItem'
6060
import NcPopover from '@nextcloud/vue/components/NcPopover'
6161
import NcTextField from '@nextcloud/vue/components/NcTextField'
6262
63-
import { options, selectCustonOption } from '../../helpers/certification.js'
63+
import { loadState } from '@nextcloud/initial-state'
6464
6565
export default {
6666
name: 'CertificateCustonOptions',
@@ -80,16 +80,17 @@ export default {
8080
data() {
8181
return {
8282
certificateList: [],
83+
allOptions: loadState('libresign', 'rules_service') || [],
8384
}
8485
},
8586
computed: {
8687
customNamesOptions() {
87-
return this.options.filter(itemA =>
88-
!this.certificateList.some(itemB => itemB.id === itemA.id),
89-
)
88+
return this.allOptions
89+
.filter(itemA => itemA.id !== 'CN')
90+
.filter(itemA => !this.certificateList.some(itemB => itemB.id === itemA.id))
9091
},
9192
options() {
92-
return options.filter(option => option.id !== 'CN')
93+
return this.allOptions.filter(option => option.id !== 'CN')
9394
},
9495
},
9596
watch: {
@@ -98,6 +99,13 @@ export default {
9899
},
99100
},
100101
methods: {
102+
selectCustonOption(id) {
103+
const found = this.allOptions.find(option => option.id === id)
104+
if (found) {
105+
return { ...found, value: '' }
106+
}
107+
return null
108+
},
101109
getOptionProperty(id, property) {
102110
return this.options.find(option => option.id === id)[property]
103111
},
@@ -111,20 +119,20 @@ export default {
111119
return true
112120
},
113121
validate(id) {
114-
const custonOption = selectCustonOption(id)
115-
if (custonOption.isSome()) {
116-
const item = custonOption.unwrap()
117-
if (this.validateMin(item) && this.validateMax(item)) {
118-
item.error = false
119-
} else {
120-
item.error = true
121-
}
122-
const listToSave = this.certificateList.map(certificate => ({
123-
id: certificate.id,
124-
value: certificate.value,
125-
}))
126-
emit('libresign:update:certificateToSave', listToSave)
127-
}
122+
const option = this.certificateList.find(c => c.id === id)
123+
if (!option) return
124+
125+
const rule = this.allOptions.find(o => o.id === id)
126+
if (!rule) return
127+
128+
option.error = !(this.validateMin({ ...rule, value: option.value }) &&
129+
this.validateMax({ ...rule, value: option.value }))
130+
131+
const listToSave = this.certificateList.map(certificate => ({
132+
id: certificate.id,
133+
value: certificate.value,
134+
}))
135+
emit('libresign:update:certificateToSave', listToSave)
128136
},
129137
async removeOptionalAttribute(id) {
130138
const custonOption = selectCustonOption(id)

src/views/Settings/RootCertificateCfssl.vue

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ import NcTextField from '@nextcloud/vue/components/NcTextField'
126126
import CertificateCustonOptions from './CertificateCustonOptions.vue'
127127
import CertificatePolicy from './CertificatePolicy.vue'
128128
129-
import { selectCustonOption } from '../../helpers/certification.js'
130129
import logger from '../../logger.js'
131130
import { useConfigureCheckStore } from '../../store/configureCheck.js'
132131
@@ -148,6 +147,7 @@ export default {
148147
data() {
149148
const OID = loadState('libresign', 'certificate_policies_oid')
150149
const CPS = loadState('libresign', 'certificate_policies_cps')
150+
const rules = loadState('libresign', 'rules_service') || []
151151
return {
152152
isThisEngine: loadState('libresign', 'certificate_engine') === 'cfssl',
153153
modal: false,
@@ -170,6 +170,7 @@ export default {
170170
CPS,
171171
toggleCertificatePolicy: !!(OID || CPS),
172172
certificatePolicyValid: !!OID && !!CPS,
173+
allOptions: rules,
173174
}
174175
},
175176
computed: {
@@ -212,9 +213,22 @@ export default {
212213
updateNames(names) {
213214
this.certificate.rootCert.names = names
214215
},
216+
selectCustonOption(id) {
217+
return this.allOptions.find(option => option.id === id) || null
218+
},
215219
getLabelFromId(id) {
216-
const item = selectCustonOption(id).unwrap()
217-
return item.label
220+
const option = selectCustonOption(id)
221+
return option ? option.label : id
222+
},
223+
validateField(id, value) {
224+
const rule = this.selectCustonOption(id)
225+
if (!rule) return true
226+
227+
if (rule.required && !value) return false
228+
if (rule.min && value.length < rule.min) return false
229+
if (rule.max && value.length > rule.max) return false
230+
231+
return true
218232
},
219233
changeEngine(engine) {
220234
this.isThisEngine = engine === 'cfssl'

0 commit comments

Comments
 (0)