2024-01-29 08:55:56 +01:00
|
|
|
<script setup>
|
|
|
|
import AdminTabs from '@/layouts/AdminTabs.vue'
|
|
|
|
import appSettingService from '@/services/appSettingService'
|
2024-02-22 14:12:47 +01:00
|
|
|
import systemService from '@/services/systemService'
|
2024-01-29 08:55:56 +01:00
|
|
|
import { useAppSettingsStore } from '@/stores/appSettings'
|
|
|
|
import { useNotifyStore } from '@/stores/notify'
|
2024-02-26 15:06:26 +01:00
|
|
|
import { useUserStore } from '@/stores/user'
|
2024-01-29 08:55:56 +01:00
|
|
|
import VersionChecker from '@/components/VersionChecker.vue'
|
2024-02-22 14:12:47 +01:00
|
|
|
import CopyButton from '@/components/CopyButton.vue'
|
2024-01-29 08:55:56 +01:00
|
|
|
|
|
|
|
const $2fauth = inject('2fauth')
|
2024-02-26 15:06:26 +01:00
|
|
|
const user = useUserStore()
|
2024-01-29 08:55:56 +01:00
|
|
|
const notify = useNotifyStore()
|
|
|
|
const appSettings = useAppSettingsStore()
|
|
|
|
const returnTo = useStorage($2fauth.prefix + 'returnTo', 'accounts')
|
|
|
|
|
2024-02-22 14:12:47 +01:00
|
|
|
const infos = ref()
|
|
|
|
const listInfos = ref(null)
|
2024-02-26 15:06:26 +01:00
|
|
|
const isSendingTestEmail = ref(false)
|
2024-02-29 13:42:28 +01:00
|
|
|
const fieldErrors = ref({
|
|
|
|
restrictList: null,
|
|
|
|
restrictRule: null,
|
|
|
|
})
|
|
|
|
const _settings = ref({
|
|
|
|
checkForUpdate: appSettings.checkForUpdate,
|
|
|
|
useEncryption: appSettings.useEncryption,
|
|
|
|
restrictRegistration: appSettings.restrictRegistration,
|
|
|
|
restrictList: appSettings.restrictList,
|
|
|
|
restrictRule: appSettings.restrictRule,
|
|
|
|
disableRegistration: appSettings.disableRegistration,
|
|
|
|
enableSso: appSettings.enableSso,
|
|
|
|
})
|
2024-02-22 14:12:47 +01:00
|
|
|
|
2024-01-29 08:55:56 +01:00
|
|
|
/**
|
|
|
|
* Saves a setting on the backend
|
|
|
|
* @param {string} preference
|
|
|
|
* @param {any} value
|
|
|
|
*/
|
|
|
|
function saveSetting(setting, value) {
|
2024-02-29 13:42:28 +01:00
|
|
|
fieldErrors.value[setting] = null
|
|
|
|
|
2024-01-29 08:55:56 +01:00
|
|
|
appSettingService.update(setting, value).then(response => {
|
2024-02-29 13:42:28 +01:00
|
|
|
appSettings[setting] = value
|
2024-01-29 08:55:56 +01:00
|
|
|
useNotifyStore().success({ type: 'is-success', text: trans('settings.forms.setting_saved') })
|
|
|
|
})
|
2024-02-29 13:42:28 +01:00
|
|
|
.catch(error => {
|
|
|
|
if( error.response.status === 422 ) {
|
|
|
|
fieldErrors.value[setting] = error.response.data.message
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
notify.error(error);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves a setting on the backend
|
|
|
|
* @param {string} preference
|
|
|
|
* @param {any} value
|
|
|
|
*/
|
|
|
|
function saveOrDeleteSetting(setting, value) {
|
|
|
|
if (value == '') {
|
|
|
|
fieldErrors.value[setting] = null
|
|
|
|
|
|
|
|
appSettingService.delete(setting, { returnError: true }).then(response => {
|
|
|
|
appSettings[setting] = ''
|
|
|
|
useNotifyStore().success({ type: 'is-success', text: trans('settings.forms.setting_saved') })
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
// appSettings[setting] = oldValue
|
|
|
|
|
|
|
|
if( error.response.status !== 404 ) {
|
|
|
|
notify.error(error);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
saveSetting(setting, value)
|
|
|
|
}
|
2024-01-29 08:55:56 +01:00
|
|
|
}
|
|
|
|
|
2024-02-26 15:06:26 +01:00
|
|
|
/**
|
|
|
|
* Sends a test email
|
|
|
|
*/
|
|
|
|
function sendTestEmail() {
|
|
|
|
isSendingTestEmail.value = true;
|
|
|
|
|
|
|
|
systemService.sendTestEmail()
|
|
|
|
.finally(() => {
|
|
|
|
isSendingTestEmail.value = false;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-01-29 08:55:56 +01:00
|
|
|
onBeforeRouteLeave((to) => {
|
|
|
|
if (! to.name.startsWith('admin.')) {
|
|
|
|
notify.clear()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-02-29 13:42:28 +01:00
|
|
|
onMounted(async () => {
|
|
|
|
appSettingService.get({ returnError: true })
|
|
|
|
.then(response => {
|
|
|
|
// we reset those two because they are not registered on server side
|
|
|
|
// in order to be able to set them to blank
|
|
|
|
_settings.value.restrictList = ''
|
|
|
|
_settings.value.restrictRule = ''
|
|
|
|
|
|
|
|
response.data.forEach(setting => {
|
|
|
|
appSettings[setting.key] = setting.value
|
|
|
|
_settings.value[setting.key] = setting.value
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
notify.alert({ text: trans('errors.data_cannot_be_refreshed_from_server') })
|
|
|
|
})
|
|
|
|
|
2024-02-22 14:12:47 +01:00
|
|
|
systemService.getSystemInfos({returnError: true}).then(response => {
|
|
|
|
infos.value = response.data.common
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
infos.value = null
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2024-01-29 08:55:56 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<AdminTabs activeTab="admin.appSetup" />
|
|
|
|
<div class="options-tabs">
|
|
|
|
<FormWrapper>
|
|
|
|
<form>
|
|
|
|
<h4 class="title is-4 pt-4 has-text-grey-light">{{ $t('settings.general') }}</h4>
|
|
|
|
<!-- Check for update -->
|
2024-02-29 13:42:28 +01:00
|
|
|
<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" />
|
2024-01-29 08:55:56 +01:00
|
|
|
<VersionChecker />
|
2024-02-26 15:06:26 +01:00
|
|
|
<div class="field">
|
|
|
|
<!-- <h5 class="title is-5">{{ $t('settings.security') }}</h5> -->
|
|
|
|
<label class="label" v-html="$t('admin.forms.test_email.label')" />
|
|
|
|
<p class="help" v-html="$t('admin.forms.test_email.help')" />
|
|
|
|
<p class="help" v-html="$t('admin.forms.test_email.email_will_be_send_to_x', { email: user.email })" />
|
|
|
|
</div>
|
|
|
|
<div class="columns is-mobile is-vcentered">
|
|
|
|
<div class="column is-narrow">
|
|
|
|
<button type="button" :class="isSendingTestEmail ? 'is-loading' : ''" class="button is-link is-rounded is-small" @click="sendTestEmail">
|
|
|
|
<span class="icon is-small">
|
|
|
|
<FontAwesomeIcon :icon="['far', 'paper-plane']" />
|
|
|
|
</span>
|
|
|
|
<span>{{ $t('commons.send') }}</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-01-30 16:15:02 +01:00
|
|
|
<h4 class="title is-4 pt-4 has-text-grey-light">{{ $t('settings.security') }}</h4>
|
2024-01-29 08:55:56 +01:00
|
|
|
<!-- protect db -->
|
2024-02-29 13:42:28 +01:00
|
|
|
<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" />
|
2024-01-30 16:15:02 +01:00
|
|
|
<h4 class="title is-4 pt-4 has-text-grey-light">{{ $t('admin.registrations') }}</h4>
|
2024-02-29 13:42:28 +01:00
|
|
|
<!-- restrict registration -->
|
|
|
|
<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" />
|
|
|
|
<!-- restrict list -->
|
|
|
|
<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" />
|
|
|
|
<!-- restrict rule -->
|
|
|
|
<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" />
|
2024-01-29 08:55:56 +01:00
|
|
|
<!-- disable registration -->
|
2024-02-29 13:42:28 +01:00
|
|
|
<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" />
|
2024-01-29 08:55:56 +01:00
|
|
|
<!-- disable SSO registration -->
|
2024-02-29 13:42:28 +01:00
|
|
|
<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" />
|
2024-01-29 08:55:56 +01:00
|
|
|
</form>
|
2024-02-22 14:12:47 +01:00
|
|
|
<h4 class="title is-4 pt-5 has-text-grey-light">{{ $t('commons.environment') }}</h4>
|
|
|
|
<div v-if="infos" class="about-debug box is-family-monospace is-size-7">
|
|
|
|
<CopyButton id="btnCopyEnvVars" :token="listInfos?.innerText" />
|
|
|
|
<ul ref="listInfos" id="listInfos">
|
|
|
|
<li v-for="(value, preference) in infos" :value="value" :key="preference">
|
|
|
|
<b>{{ preference }}</b>: <span class="has-text-grey">{{ value }}</span>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div v-else-if="infos === null" class="about-debug box is-family-monospace is-size-7 has-text-warning-dark">
|
|
|
|
{{ $t('errors.error_during_data_fetching') }}
|
|
|
|
</div>
|
2024-01-29 08:55:56 +01:00
|
|
|
</FormWrapper>
|
|
|
|
</div>
|
|
|
|
<VueFooter :showButtons="true">
|
|
|
|
<ButtonBackCloseCancel :returnTo="{ name: returnTo }" action="close" />
|
|
|
|
</VueFooter>
|
|
|
|
</div>
|
|
|
|
</template>
|