Added API part and tests

This commit is contained in:
Antoine Nguyen
2025-09-05 13:38:57 +02:00
parent 5f2ea34f4e
commit d98db498df
100 changed files with 9675 additions and 977 deletions
@@ -172,7 +172,7 @@
</div>
</template>
<script setup lang="js">
<script setup>
import DomainDNSForm from './form_steps/DomainDNSForm.vue'
import DomainGeneralForm from './form_steps/DomainGeneralForm.vue'
import DomainLimitationsForm from './form_steps/DomainLimitationsForm.vue'
@@ -0,0 +1,117 @@
<template>
<div>
<v-card v-if="policy">
<v-card-title>
<span>{{ $gettext('Content filter') }}</span>
<v-btn
class="ml-2"
icon="mdi-circle-edit-outline"
:title="$gettext('Edit content filter settings')"
variant="text"
density="compact"
@click="showEditForm = true"
></v-btn>
</v-card-title>
<v-card-text>
<v-row>
<v-col cols="6">{{ $gettext('Spam filters') }}</v-col>
<v-col cols="6">
<BooleanIcon
v-if="
policy.bypass_spam_checks !== null &&
policy.bypass_spam_checks !== ''
"
:value="policy.bypass_spam_checks !== 'Y'"
variant="flat"
/>
<span v-else>{{ $gettext('Default value') }}</span>
</v-col>
</v-row>
<v-row>
<v-col cols="6">{{ $gettext('Virus filters') }}</v-col>
<v-col cols="6">
<BooleanIcon
v-if="
policy.bypass_virus_checks !== null &&
policy.bypass_virus_checks !== ''
"
:value="policy.bypass_virus_checks !== 'Y'"
variant="flat"
/>
<span v-else>{{ $gettext('Default value') }}</span>
</v-col>
</v-row>
<v-row>
<v-col cols="6">{{ $gettext('Banned filters') }}</v-col>
<v-col cols="6">
<BooleanIcon
v-if="
policy.bypass_banned_checks !== null &&
policy.bypass_banned_checks !== ''
"
:value="policy.bypass_banned_checks !== 'Y'"
variant="flat"
/>
<span v-else>{{ $gettext('Default value') }}</span>
</v-col>
</v-row>
<v-row>
<v-col cols="6">{{
$gettext('Spam classification threshold')
}}</v-col>
<v-col cols="6">
<span v-if="policy.spam_tag2_level !== null">
{{ policy.spam_tag2_level }}
</span>
<span v-else>{{ $gettext('Default value') }}</span>
</v-col>
</v-row>
<v-row>
<v-col cols="6">{{ $gettext('Rejection threshold') }}</v-col>
<v-col cols="6">
<span v-if="policy.spam_kill_level !== null">
{{ policy.spam_kill_level }}
</span>
<span v-else>{{ $gettext('Default value') }}</span>
</v-col>
</v-row>
<v-row>
<v-col cols="6">{{ $gettext('Spam marker') }}</v-col>
<v-col cols="6">
<span v-if="policy.spam_subject_tag2 !== null">
{{ policy.spam_subject_tag2 }}
</span>
<span v-else>{{ $gettext('Default value') }}</span>
</v-col>
</v-row>
</v-card-text>
</v-card>
<v-dialog v-model="showEditForm" width="1000">
<DomainPolicyForm
v-model="policy"
:domain-id="props.domain.pk"
@close="showEditForm = false"
/>
</v-dialog>
</div>
</template>
<script setup>
import { ref } from 'vue'
import BooleanIcon from '@/components/tools/BooleanIcon'
import DomainPolicyForm from './DomainPolicyForm'
import api from '@/api/amavis'
const props = defineProps({
domain: {
type: Object,
default: null,
},
})
const policy = ref(null)
const showEditForm = ref(false)
const resp = await api.getDomainPolicy(props.domain.pk)
policy.value = resp.data
</script>
@@ -0,0 +1,168 @@
<template>
<v-card>
<v-card-title class="text-h5">
<span> {{ $gettext('Content filter settings') }} </span>
</v-card-title>
<v-card-text>
<v-row>
<v-col cols="6">
<YesNoDefaultField
v-model="form.bypass_virus_checks"
:label="$gettext('Disable virus checks')"
color="primary"
hide-details
/>
<YesNoDefaultField
v-model="form.bypass_spam_checks"
:label="$gettext('Disable spam checks')"
color="primary"
class="mt-6"
hide-details
/>
<YesNoDefaultField
v-model="form.bypass_banned_checks"
:label="$gettext('Disable banned checks')"
color="primary"
class="mt-6"
hide-details
/>
</v-col>
<v-col cols="6">
<div>
<label class="v-label mb-4">{{ $gettext('Spam marker') }}</label>
<v-row>
<v-col cols="9">
<v-text-field
v-model="form.spam_subject_tag2"
variant="outlined"
density="compact"
:disabled="useDefaultMarker"
/>
</v-col>
<v-col cols="3">
<v-checkbox
v-model="useDefaultMarker"
:label="$gettext('default')"
color="primary"
density="compact"
hide-details
@update:model-value="clearSpamMarker"
/>
</v-col>
</v-row>
</div>
<div class="v-label mb-4">{{ $gettext('Thresholds') }}</div>
<v-row class="align-center">
<v-col cols="4">
<v-text-field
v-model="form.spam_tag2_level"
variant="outlined"
density="compact"
type="number"
hide-details
>
</v-text-field>
</v-col>
<v-col cols="8">
{{ $gettext('or more is spam') }}
</v-col>
</v-row>
<v-row class="align-center">
<v-col cols="4">
<v-text-field
v-model="form.spam_kill_level"
variant="outlined"
density="compact"
type="number"
hide-details
>
</v-text-field>
</v-col>
<v-col cols="8">
{{ $gettext('or more throw spam message away') }}
</v-col>
</v-row>
</v-col>
</v-row>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn :loading="loading" @click="emit('close')">
{{ $gettext('Cancel') }}
</v-btn>
<v-btn color="primary" :loading="loading" @click="submit">
{{ $gettext('Apply') }}
</v-btn>
</v-card-actions>
</v-card>
</template>
<script setup>
import { ref } from 'vue'
import YesNoDefaultField from '@/components/tools/YesNoDefaultField'
import api from '@/api/amavis'
const props = defineProps({
domainId: {
type: Number,
default: null,
},
modelValue: {
type: Object,
default: () => {},
},
})
const emit = defineEmits(['close', 'update:modelValue'])
const form = ref({})
const loading = ref(false)
const useDefaultMarker = ref(false)
form.value = {
bypass_virus_checks:
props.modelValue.bypass_virus_checks === null
? ''
: props.modelValue.bypass_virus_checks,
bypass_spam_checks:
props.modelValue.bypass_spam_checks === null
? ''
: props.modelValue.bypass_spam_checks,
bypass_banned_checks:
props.modelValue.bypass_banned_checks === null
? ''
: props.modelValue.bypass_banned_checks,
spam_tag2_level: props.modelValue.spam_tag2_level,
spam_kill_level: props.modelValue.spam_kill_level,
spam_subject_tag2: props.modelValue.spam_subject_tag2,
}
if (form.value.spam_subject_tag2 === null) {
useDefaultMarker.value = true
}
const clearSpamMarker = (value) => {
if (value) {
form.value.spam_subject_tag2 = null
}
}
const submit = async () => {
loading.value = true
const data = { ...form.value }
if (data.spam_tag2_level === '') {
data.spam_tag2_level = null
}
if (data.spam_kill_level === '') {
data.spam_kill_level = null
}
try {
const resp = await api.updateDomainPolicy(props.domainId, data)
emit('update:modelValue', resp.data)
emit('close')
} finally {
loading.value = false
}
}
</script>
@@ -0,0 +1,20 @@
<template>
<v-form ref="vFormRef">
<v-switch
v-model="model.bypass_virus_checks"
:label="$gettext('Bypass virus checks')"
/>
</v-form>
</template>
<script setup>
import { ref } from 'vue'
const model = defineModel()
const vFormRef = ref()
defineExpose({
vFormRef,
})
</script>
@@ -87,6 +87,7 @@
>
</v-btn>
<v-btn
v-if="manualLearningEnabled"
class="ml-2"
size="small"
variant="tonal"
@@ -144,6 +145,14 @@
{{ item.type }}
</v-chip>
</template>
<template #[`item.status`]="{ item }">
<v-icon
v-if="item.status"
:icon="getStatusIcon(item)"
:title="getStatusTitle(item)"
size="small"
/>
</template>
<template #[`item.from_address`]="{ item }">
<span :title="item.from_address">
{{ $truncate(item.from_address, 30) }}
@@ -158,23 +167,42 @@
{{ $date(item.datetime) }}
</template>
</v-data-table-server>
<ConfirmDialog ref="learningRecipientRef">
<v-radio-group v-model="learningDatabase" class="mt-4" hide-details>
<v-radio
v-for="lrcpt in learningRecipients"
:key="lrcpt.value"
:value="lrcpt.value"
:label="lrcpt.title"
>
</v-radio>
</v-radio-group>
</ConfirmDialog>
</v-card>
</template>
<script setup>
import { ref } from 'vue'
import { ref, watch } from 'vue'
import { useGettext } from 'vue3-gettext'
import { useRouter } from 'vue-router'
import { useRoute, useRouter } from 'vue-router'
import debounce from 'debounce'
import { useBusStore } from '@/stores'
import { useAuthStore, useBusStore } from '@/stores'
import { useAmavis } from '@/composables/amavis'
import ConfirmDialog from '@/components/tools/ConfirmDialog'
import api from '@/api/amavis'
import constants from '@/constants'
const { $gettext } = useGettext()
const router = useRouter()
const route = useRoute()
const authStore = useAuthStore()
const { displayNotification } = useBusStore()
const { manualLearningEnabled, learningRecipients } = await useAmavis()
const currentPage = ref(1)
const itemsPerPageR = ref(10)
const learningDatabase = ref(null)
const learningRecipientRef = ref(null)
const loading = ref(false)
const messages = ref([])
const search = ref('')
@@ -199,7 +227,8 @@ const messageTypes = [
]
const headers = [
{ title: '', key: 'type' },
{ title: '', key: 'type', width: '5%' },
{ title: '', key: 'status', width: '5%' },
{ title: $gettext('Score'), key: 'score' },
{ title: $gettext('To'), key: 'to_address' },
{ title: $gettext('From'), key: 'from_address' },
@@ -207,6 +236,13 @@ const headers = [
{ title: $gettext('Date'), key: 'datetime' },
]
watch(
() => route.query.requests,
() => {
fetchContent()
}
)
const getRowProps = ({ item }) => {
return {
class: item.style,
@@ -230,6 +266,32 @@ const getTypeColor = (value) => {
return ''
}
const getStatusIcon = (item) => {
if (item.status === 'R') {
return 'mdi-reply'
}
if (item.status === 'S') {
return 'mdi-thumb-down-outline'
}
if (item.status === 'H') {
return 'mdi-thumb-up-outline'
}
return ''
}
const getStatusTitle = (item) => {
if (item.status === 'R') {
return $gettext('Message released')
}
if (item.status === 'S') {
return $gettext('Message marked as spam')
}
if (item.status === 'H') {
return $gettext('Message marked as non-spam')
}
return ''
}
const updatedOptions = async ({ page, itemsPerPage, sortBy }) => {
currentPage.value = page
itemsPerPageR.value = itemsPerPage
@@ -255,6 +317,9 @@ const _fetchContent = async () => {
if (typeFilter.value !== 'all') {
params.msgtype = typeFilter.value
}
if (route.query?.requests === '1') {
params.viewrequests = 1
}
try {
const resp = await api.getQuarantineContent(params)
messages.value = resp.data.results
@@ -313,9 +378,24 @@ const releaseSelection = async () => {
}
const markSelection = async (mtype) => {
if (
manualLearningEnabled.value &&
authStore.authUser.role !== constants.USER
) {
learningDatabase.value =
authStore.authUser.role === constants.SUPER_ADMIN ? 'global' : 'domain'
await learningRecipientRef.value.open(
$gettext('Learning database'),
$gettext('Which database should be used for this learning:'),
{ width: 600, noconfirm: true }
)
}
loading.value = true
const data = prepareSelectionPayload()
data.type = mtype
if (learningDatabase.value) {
data.database = learningDatabase.value
}
try {
await api.markMessageSelection(data)
displayNotification({ msg: $gettext('Selection is being processed...') })
+2 -19
View File
@@ -49,9 +49,6 @@
:title="item.text"
:prepend-icon="item.icon"
>
<template v-if="item.withBell && displayInformationBell" #append>
<v-icon color="red" icon="mdi-bell-alert-outline" />
</template>
</v-list-item>
<v-list-group v-else :value="item.text">
<template #activator="{ props }">
@@ -92,10 +89,9 @@
<script setup>
import { useRouter } from 'vue-router'
import { ref, computed, onMounted } from 'vue'
import { ref, computed } from 'vue'
import { useLogos } from '@/composables/logos'
import { useGlobalStore, useAuthStore, useLayoutStore } from '@/stores'
import constants from '@/constants.json'
import { useAuthStore, useLayoutStore } from '@/stores'
const props = defineProps({
color: {
@@ -113,7 +109,6 @@ const props = defineProps({
},
})
const globalStore = useGlobalStore()
const authStore = useAuthStore()
const layoutStore = useLayoutStore()
const router = useRouter()
@@ -125,12 +120,6 @@ const drawer = ref(true)
const authUser = computed(() => authStore.authUser)
const isAuthenticated = computed(() => authStore.isAuthenticated)
const displayInformationBell = computed(
() =>
globalStore.notifications.length !== undefined &&
globalStore.notifications.length !== 0
)
function displayMenuItem(item) {
if (isAuthenticated.value) {
const condition =
@@ -142,12 +131,6 @@ function displayMenuItem(item) {
}
return false
}
onMounted(() => {
if (authUser.value.role === constants.SUPER_ADMIN) {
globalStore.fetchNotifications()
}
})
</script>
<style lang="scss" scoped>
+61 -21
View File
@@ -1,28 +1,65 @@
<template>
<div v-if="user" class="top-menu">
<v-menu activator="parent" location="bottom">
<template #activator="{ props }">
<v-btn icon="mdi-apps" flat class="mr-4" v-bind="props"></v-btn>
</template>
<v-card min-width="350" max-width="400" class="pa-4">
<v-row class="justify-center">
<v-col
v-for="application in applications"
:key="application.name"
cols="6"
<v-btn
v-if="globalStore.activeNotifications"
icon
color="error"
class="mr-4"
variant="tonal"
size="small"
>
<v-icon icon="mdi-bell" />
<v-menu activator="parent" location="bottom">
<v-list>
<div class="text-center">
<v-list-item :title="$gettext('Notifications')" />
</div>
<v-divider></v-divider>
<v-list-item
v-for="notif in globalStore.notifications"
:key="notif.id"
:to="notif.url"
>
<v-sheet
rounded
class="application text-center pa-4 text-body-2"
@click="$router.push(application.url)"
<template #prepend>
<v-badge
:color="notif.color"
:content="notif.counter"
inline
></v-badge>
</template>
<v-list-item-title>{{ notif.text }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-btn>
<v-btn icon class="mr-4" variant="flat">
<v-icon icon="mdi-apps" />
<v-menu activator="parent" location="bottom">
<v-card min-width="350" max-width="400" class="pa-4">
<v-row class="justify-center">
<v-col
v-for="application in applications"
:key="application.name"
cols="6"
>
<v-icon color="primary" :icon="application.icon" size="x-large" />
<div class="mt-2">{{ application.label }}</div>
</v-sheet>
</v-col>
</v-row>
</v-card>
</v-menu>
<v-sheet
rounded
class="application text-center pa-4 text-body-2"
@click="$router.push(application.url)"
>
<v-icon
color="primary"
:icon="application.icon"
size="x-large"
/>
<div class="mt-2">{{ application.label }}</div>
</v-sheet>
</v-col>
</v-row>
</v-card>
</v-menu>
</v-btn>
<v-btn icon flat color="primary">
{{ userInitials }}
@@ -60,6 +97,7 @@
import { computed, onMounted, ref } from 'vue'
import { getActivePinia } from 'pinia'
import { useGettext } from 'vue3-gettext'
import { useGlobalStore } from '@/stores'
import accountApi from '@/api/account'
const props = defineProps({
@@ -74,6 +112,7 @@ const props = defineProps({
})
const { $gettext } = useGettext()
const globalStore = useGlobalStore()
const applications = ref([])
@@ -112,6 +151,7 @@ onMounted(() => {
accountApi.getAvailableApplications().then((resp) => {
applications.value = resp.data
})
globalStore.fetchNotifications()
})
</script>
@@ -6,7 +6,7 @@
@keydown.esc="cancel"
>
<v-card>
<v-toolbar :color="options.color" density="compact" flat>
<v-toolbar :color="options.color" density="compact" variant="flat">
<v-toolbar-title class="text-body-2 font-weight-bold">
{{ title }}
</v-toolbar-title>
@@ -28,7 +28,7 @@
</v-dialog>
</template>
<script setup lang="js">
<script setup>
import { ref } from 'vue'
import { useGettext } from 'vue3-gettext'
@@ -0,0 +1,11 @@
<template>
<v-radio-group v-model="model" inline>
<v-radio :label="$gettext('yes')" value="Y" />
<v-radio :label="$gettext('no')" value="N" />
<v-radio :label="$gettext('default')" value="" />
</v-radio-group>
</template>
<script setup>
const model = defineModel()
</script>