mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-19 03:04:05 +00:00
Add super-admin Administration section and restructure global vs company settings
- Add Administration sidebar section (super-admin only) with Companies, Users, and Global Settings pages - Add super-admin middleware, controllers, and API routes under /api/v1/super-admin/ - Allow super-admins to manage all companies and users across tenants - Add user impersonation with short-lived tokens, audit logging, and UI banner - Move system-level settings (Mail, PDF, Backup, Update, File Disk) from per-company to Administration > Global Settings - Convert save_pdf_to_disk from CompanySetting to global Setting - Add per-company mail configuration overrides (optional, falls back to global) - Add CompanyMailConfigService to apply company mail config before sending emails
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
<template>
|
||||
<MailTestModal :store-type="'company'" />
|
||||
|
||||
<BaseSettingCard
|
||||
:title="$t('settings.mail.company_mail_config')"
|
||||
:description="$t('settings.mail.company_mail_config_desc')"
|
||||
>
|
||||
<div class="mt-8">
|
||||
<BaseSwitchSection
|
||||
v-model="useCustomMailConfig"
|
||||
:title="$t('settings.mail.use_custom_mail_config')"
|
||||
:description="$t('settings.mail.use_custom_mail_config_desc')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="useCustomMailConfig && companyMailStore.mailConfigData" class="mt-8">
|
||||
<component
|
||||
:is="mailDriver"
|
||||
:config-data="companyMailStore.mailConfigData"
|
||||
:is-saving="isSaving"
|
||||
:mail-drivers="companyMailStore.mail_drivers"
|
||||
:is-fetching-initial-data="isFetchingInitialData"
|
||||
@on-change-driver="(val) => changeDriver(val)"
|
||||
@submit-data="saveEmailConfig"
|
||||
>
|
||||
<BaseButton
|
||||
variant="primary-outline"
|
||||
type="button"
|
||||
class="ml-2"
|
||||
:content-loading="isFetchingInitialData"
|
||||
@click="openMailTestModal"
|
||||
>
|
||||
{{ $t('general.test_mail_conf') }}
|
||||
</BaseButton>
|
||||
</component>
|
||||
</div>
|
||||
|
||||
<div v-if="!useCustomMailConfig" class="mt-4 p-4 rounded-md bg-gray-50 text-sm text-gray-500">
|
||||
{{ $t('settings.mail.using_global_mail_config') }}
|
||||
</div>
|
||||
</BaseSettingCard>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import Smtp from '@/scripts/admin/views/settings/mail-driver/SmtpMailDriver.vue'
|
||||
import Mailgun from '@/scripts/admin/views/settings/mail-driver/MailgunMailDriver.vue'
|
||||
import Ses from '@/scripts/admin/views/settings/mail-driver/SesMailDriver.vue'
|
||||
import Basic from '@/scripts/admin/views/settings/mail-driver/BasicMailDriver.vue'
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { useCompanyMailStore } from '@/scripts/admin/stores/company-mail'
|
||||
import { useModalStore } from '@/scripts/stores/modal'
|
||||
import MailTestModal from '@/scripts/admin/components/modal-components/MailTestModal.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
let isSaving = ref(false)
|
||||
let isFetchingInitialData = ref(false)
|
||||
|
||||
const companyMailStore = useCompanyMailStore()
|
||||
const modalStore = useModalStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
const useCustomMailConfig = ref(false)
|
||||
|
||||
loadData()
|
||||
|
||||
async function loadData() {
|
||||
isFetchingInitialData.value = true
|
||||
await companyMailStore.fetchMailDrivers()
|
||||
await companyMailStore.fetchMailConfig()
|
||||
useCustomMailConfig.value =
|
||||
companyMailStore.mailConfigData?.use_custom_mail_config === 'YES'
|
||||
isFetchingInitialData.value = false
|
||||
}
|
||||
|
||||
function changeDriver(value) {
|
||||
companyMailStore.mail_driver = value
|
||||
companyMailStore.mailConfigData.mail_driver = value
|
||||
}
|
||||
|
||||
const mailDriver = computed(() => {
|
||||
if (companyMailStore.mail_driver === 'smtp') return Smtp
|
||||
if (companyMailStore.mail_driver === 'mailgun') return Mailgun
|
||||
if (companyMailStore.mail_driver === 'sendmail') return Basic
|
||||
if (companyMailStore.mail_driver === 'ses') return Ses
|
||||
if (companyMailStore.mail_driver === 'mail') return Basic
|
||||
return Smtp
|
||||
})
|
||||
|
||||
watch(useCustomMailConfig, async (newVal, oldVal) => {
|
||||
if (oldVal === undefined) return
|
||||
|
||||
if (!newVal) {
|
||||
isSaving.value = true
|
||||
await companyMailStore.updateMailConfig({
|
||||
use_custom_mail_config: 'NO',
|
||||
mail_driver: '',
|
||||
})
|
||||
isSaving.value = false
|
||||
}
|
||||
})
|
||||
|
||||
async function saveEmailConfig(value) {
|
||||
try {
|
||||
isSaving.value = true
|
||||
await companyMailStore.updateMailConfig({
|
||||
...value,
|
||||
use_custom_mail_config: 'YES',
|
||||
})
|
||||
isSaving.value = false
|
||||
} catch (e) {
|
||||
isSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function openMailTestModal() {
|
||||
modalStore.openModal({
|
||||
title: t('general.test_mail_conf'),
|
||||
componentName: 'MailTestModal',
|
||||
size: 'sm',
|
||||
})
|
||||
}
|
||||
</script>
|
||||
@@ -84,7 +84,7 @@
|
||||
|
||||
<script setup>
|
||||
import { useDiskStore } from '@/scripts/admin/stores/disk'
|
||||
import { useCompanyStore } from '@/scripts/admin/stores/company'
|
||||
import { useGlobalStore } from '@/scripts/admin/stores/global'
|
||||
import { useDialogStore } from '@/scripts/stores/dialog'
|
||||
import { useModalStore } from '@/scripts/stores/modal'
|
||||
import { ref, computed, reactive, onMounted, inject } from 'vue'
|
||||
@@ -95,7 +95,7 @@ const utils = inject('utils')
|
||||
|
||||
const modalStore = useModalStore()
|
||||
const diskStore = useDiskStore()
|
||||
const companyStore = useCompanyStore()
|
||||
const globalStore = useGlobalStore()
|
||||
const dialogStore = useDialogStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -139,7 +139,7 @@ const fileDiskColumns = computed(() => {
|
||||
]
|
||||
})
|
||||
|
||||
const savePdfToDisk = ref(companyStore.selectedCompanySettings.save_pdf_to_disk)
|
||||
const savePdfToDisk = ref(globalStore.globalSettings?.save_pdf_to_disk || 'NO')
|
||||
|
||||
const savePdfToDiskField = computed({
|
||||
get: () => {
|
||||
@@ -156,7 +156,7 @@ const savePdfToDiskField = computed({
|
||||
|
||||
savePdfToDisk.value = value
|
||||
|
||||
await companyStore.updateCompanySettings({
|
||||
await globalStore.updateGlobalSettings({
|
||||
data,
|
||||
message: 'general.setting_updated',
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user