|
17 | 17 | const infos = ref()
|
18 | 18 | const listInfos = ref(null)
|
19 | 19 | const isSendingTestEmail = ref(false)
|
| 20 | + const fieldErrors = ref({ |
| 21 | + restrictList: null, |
| 22 | + restrictRule: null, |
| 23 | + }) |
| 24 | + const _settings = ref({ |
| 25 | + checkForUpdate: appSettings.checkForUpdate, |
| 26 | + useEncryption: appSettings.useEncryption, |
| 27 | + restrictRegistration: appSettings.restrictRegistration, |
| 28 | + restrictList: appSettings.restrictList, |
| 29 | + restrictRule: appSettings.restrictRule, |
| 30 | + disableRegistration: appSettings.disableRegistration, |
| 31 | + enableSso: appSettings.enableSso, |
| 32 | + }) |
20 | 33 |
|
21 | 34 | /**
|
22 | 35 | * Saves a setting on the backend
|
23 | 36 | * @param {string} preference
|
24 | 37 | * @param {any} value
|
25 | 38 | */
|
26 | 39 | function saveSetting(setting, value) {
|
| 40 | + fieldErrors.value[setting] = null |
| 41 | +
|
27 | 42 | appSettingService.update(setting, value).then(response => {
|
| 43 | + appSettings[setting] = value |
28 | 44 | useNotifyStore().success({ type: 'is-success', text: trans('settings.forms.setting_saved') })
|
29 | 45 | })
|
| 46 | + .catch(error => { |
| 47 | + if( error.response.status === 422 ) { |
| 48 | + fieldErrors.value[setting] = error.response.data.message |
| 49 | + } |
| 50 | + else { |
| 51 | + notify.error(error); |
| 52 | + } |
| 53 | + }) |
| 54 | + } |
| 55 | +
|
| 56 | + /** |
| 57 | + * Saves a setting on the backend |
| 58 | + * @param {string} preference |
| 59 | + * @param {any} value |
| 60 | + */ |
| 61 | + function saveOrDeleteSetting(setting, value) { |
| 62 | + if (value == '') { |
| 63 | + fieldErrors.value[setting] = null |
| 64 | +
|
| 65 | + appSettingService.delete(setting, { returnError: true }).then(response => { |
| 66 | + appSettings[setting] = '' |
| 67 | + useNotifyStore().success({ type: 'is-success', text: trans('settings.forms.setting_saved') }) |
| 68 | + }) |
| 69 | + .catch(error => { |
| 70 | + // appSettings[setting] = oldValue |
| 71 | +
|
| 72 | + if( error.response.status !== 404 ) { |
| 73 | + notify.error(error); |
| 74 | + } |
| 75 | + }) |
| 76 | + } |
| 77 | + else { |
| 78 | + saveSetting(setting, value) |
| 79 | + } |
30 | 80 | }
|
31 | 81 |
|
32 | 82 | /**
|
|
47 | 97 | }
|
48 | 98 | })
|
49 | 99 |
|
50 |
| - onMounted(() => { |
| 100 | + onMounted(async () => { |
| 101 | + appSettingService.get({ returnError: true }) |
| 102 | + .then(response => { |
| 103 | + // we reset those two because they are not registered on server side |
| 104 | + // in order to be able to set them to blank |
| 105 | + _settings.value.restrictList = '' |
| 106 | + _settings.value.restrictRule = '' |
| 107 | +
|
| 108 | + response.data.forEach(setting => { |
| 109 | + appSettings[setting.key] = setting.value |
| 110 | + _settings.value[setting.key] = setting.value |
| 111 | + }) |
| 112 | + }) |
| 113 | + .catch(error => { |
| 114 | + notify.alert({ text: trans('errors.data_cannot_be_refreshed_from_server') }) |
| 115 | + }) |
| 116 | +
|
51 | 117 | systemService.getSystemInfos({returnError: true}).then(response => {
|
52 | 118 | infos.value = response.data.common
|
53 | 119 | })
|
|
66 | 132 | <form>
|
67 | 133 | <h4 class="title is-4 pt-4 has-text-grey-light">{{ $t('settings.general') }}</h4>
|
68 | 134 | <!-- Check for update -->
|
69 |
| - <FormCheckbox v-model="appSettings.checkForUpdate" @update:model-value="val => saveSetting('checkForUpdate', val)" fieldName="checkForUpdate" label="commons.check_for_update" help="commons.check_for_update_help" /> |
| 135 | + <FormCheckbox v-model="_settings.checkForUpdate" @update:model-value="val => saveSetting('checkForUpdate', val)" fieldName="checkForUpdate" label="commons.check_for_update" help="commons.check_for_update_help" /> |
70 | 136 | <VersionChecker />
|
71 | 137 | <div class="field">
|
72 | 138 | <!-- <h5 class="title is-5">{{ $t('settings.security') }}</h5> -->
|
|
86 | 152 | </div>
|
87 | 153 | <h4 class="title is-4 pt-4 has-text-grey-light">{{ $t('settings.security') }}</h4>
|
88 | 154 | <!-- protect db -->
|
89 |
| - <FormCheckbox v-model="appSettings.useEncryption" @update:model-value="val => saveSetting('useEncryption', val)" fieldName="useEncryption" label="admin.forms.use_encryption.label" help="admin.forms.use_encryption.help" /> |
| 155 | + <FormCheckbox v-model="_settings.useEncryption" @update:model-value="val => saveSetting('useEncryption', val)" fieldName="useEncryption" label="admin.forms.use_encryption.label" help="admin.forms.use_encryption.help" /> |
90 | 156 | <h4 class="title is-4 pt-4 has-text-grey-light">{{ $t('admin.registrations') }}</h4>
|
| 157 | + <!-- restrict registration --> |
| 158 | + <FormCheckbox v-model="_settings.restrictRegistration" @update:model-value="val => saveSetting('restrictRegistration', val)" fieldName="restrictRegistration" :isDisabled="appSettings.disableRegistration" label="admin.forms.restrict_registration.label" help="admin.forms.restrict_registration.help" /> |
| 159 | + <!-- restrict list --> |
| 160 | + <FormField v-model="_settings.restrictList" @change:model-value="val => saveOrDeleteSetting('restrictList', val)" :fieldError="fieldErrors.restrictList" fieldName="restrictList" :isDisabled="!appSettings.restrictRegistration || appSettings.disableRegistration" label="admin.forms.restrict_list.label" help="admin.forms.restrict_list.help" :isIndented="true" /> |
| 161 | + <!-- restrict rule --> |
| 162 | + <FormField v-model="_settings.restrictRule" @change:model-value="val => saveOrDeleteSetting('restrictRule', val)" :fieldError="fieldErrors.restrictRule" fieldName="restrictRule" :isDisabled="!appSettings.restrictRegistration || appSettings.disableRegistration" label="admin.forms.restrict_rule.label" help="admin.forms.restrict_rule.help" :isIndented="true" leftIcon="slash" rightIcon="slash" /> |
91 | 163 | <!-- disable registration -->
|
92 |
| - <FormCheckbox v-model="appSettings.disableRegistration" @update:model-value="val => saveSetting('disableRegistration', val)" fieldName="disableRegistration" label="admin.forms.disable_registration.label" help="admin.forms.disable_registration.help" /> |
| 164 | + <FormCheckbox v-model="_settings.disableRegistration" @update:model-value="val => saveSetting('disableRegistration', val)" fieldName="disableRegistration" label="admin.forms.disable_registration.label" help="admin.forms.disable_registration.help" /> |
93 | 165 | <!-- disable SSO registration -->
|
94 |
| - <FormCheckbox v-model="appSettings.enableSso" @update:model-value="val => saveSetting('enableSso', val)" fieldName="enableSso" label="admin.forms.enable_sso.label" help="admin.forms.enable_sso.help" /> |
| 166 | + <FormCheckbox v-model="_settings.enableSso" @update:model-value="val => saveSetting('enableSso', val)" fieldName="enableSso" label="admin.forms.enable_sso.label" help="admin.forms.enable_sso.help" /> |
95 | 167 | </form>
|
96 | 168 | <h4 class="title is-4 pt-5 has-text-grey-light">{{ $t('commons.environment') }}</h4>
|
97 | 169 | <div v-if="infos" class="about-debug box is-family-monospace is-size-7">
|
|
0 commit comments