mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 10:12:51 +00:00
refactor: add valid
This commit is contained in:
parent
50245bc723
commit
a8127efd86
|
|
@ -8366,4 +8366,10 @@ msgid "Get tool list"
|
|||
msgstr ""
|
||||
|
||||
msgid "Setting"
|
||||
msgstr ""
|
||||
|
||||
msgid "Get verification results"
|
||||
msgstr ""
|
||||
|
||||
msgid "Validation"
|
||||
msgstr ""
|
||||
|
|
@ -8492,4 +8492,10 @@ msgid "Get tool list"
|
|||
msgstr "获取工具列表"
|
||||
|
||||
msgid "Setting"
|
||||
msgstr "设置"
|
||||
msgstr "设置"
|
||||
|
||||
msgid "Get verification results"
|
||||
msgstr "获取验证结果"
|
||||
|
||||
msgid "Validation"
|
||||
msgstr "验证"
|
||||
|
|
|
|||
|
|
@ -8492,4 +8492,10 @@ msgid "Get tool list"
|
|||
msgstr "獲取工具列表"
|
||||
|
||||
msgid "Setting"
|
||||
msgstr "設置"
|
||||
msgstr "設置"
|
||||
|
||||
msgid "Get verification results"
|
||||
msgstr "獲取驗證結果"
|
||||
|
||||
msgid "Validation"
|
||||
msgstr "驗證"
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
# coding=utf-8
|
||||
"""
|
||||
@project: MaxKB
|
||||
@Author:虎
|
||||
@file: valid_serializers.py
|
||||
@date:2024/7/8 18:00
|
||||
@desc:
|
||||
"""
|
||||
import re
|
||||
|
||||
from django.core import validators
|
||||
from django.core.cache import cache
|
||||
from django.db.models import QuerySet
|
||||
from rest_framework import serializers
|
||||
|
||||
from application.models import Application
|
||||
from common.constants.cache_version import Cache_Version
|
||||
from common.exception.app_exception import AppApiException
|
||||
from knowledge.models import Knowledge
|
||||
from users.models import User
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
model_message_dict = {
|
||||
'dataset': {'model': Knowledge, 'count': 50,
|
||||
'message': _(
|
||||
'The community version supports up to 50 knowledge bases. If you need more knowledge bases, please contact us (https://fit2cloud.com/).')},
|
||||
'application': {'model': Application, 'count': 5,
|
||||
'message': _(
|
||||
'The community version supports up to 5 applications. If you need more applications, please contact us (https://fit2cloud.com/).')},
|
||||
'user': {'model': User, 'count': 2,
|
||||
'message': _(
|
||||
'The community version supports up to 2 users. If you need more users, please contact us (https://fit2cloud.com/).')}
|
||||
}
|
||||
|
||||
|
||||
class ValidSerializer(serializers.Serializer):
|
||||
valid_type = serializers.CharField(required=True, label=_('type'), validators=[
|
||||
validators.RegexValidator(regex=re.compile("^application|knowledge|user$"),
|
||||
message="类型只支持:application|knowledge|user", code=500)
|
||||
])
|
||||
valid_count = serializers.IntegerField(required=True, label=_('check quantity'))
|
||||
|
||||
def valid(self, is_valid=True):
|
||||
if is_valid:
|
||||
self.is_valid(raise_exception=True)
|
||||
model_value = model_message_dict.get(self.data.get('valid_type'))
|
||||
license_is_valid = cache.get(Cache_Version.SYSTEM.get_key(key='license_is_valid'),
|
||||
version=Cache_Version.SYSTEM.get_version())
|
||||
is_license_valid = license_is_valid if license_is_valid is not None else False
|
||||
if not is_license_valid:
|
||||
if self.data.get('valid_count') != model_value.get('count'):
|
||||
raise AppApiException(400, model_value.get('message'))
|
||||
if QuerySet(
|
||||
model_value.get('model')).count() >= model_value.get('count'):
|
||||
raise AppApiException(400, model_value.get('message'))
|
||||
return True
|
||||
|
|
@ -7,5 +7,6 @@ urlpatterns = [
|
|||
path('workspace/<str:workspace_id>/user_resource_permission/user/<str:user_id>',
|
||||
views.WorkSpaceUserResourcePermissionView.as_view()),
|
||||
path('email_setting', views.SystemSetting.Email.as_view()),
|
||||
path('profile', views.SystemProfile.as_view())
|
||||
path('profile', views.SystemProfile.as_view()),
|
||||
path('valid/<str:valid_type>/<int:valid_count>', views.Valid.as_view())
|
||||
]
|
||||
|
|
|
|||
|
|
@ -9,3 +9,4 @@
|
|||
from .user_resource_permission import *
|
||||
from .email_setting import *
|
||||
from .system_profile import *
|
||||
from .valid import *
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
# coding=utf-8
|
||||
"""
|
||||
@project: MaxKB
|
||||
@Author:虎
|
||||
@file: valid.py
|
||||
@date:2024/7/8 17:50
|
||||
@desc:
|
||||
"""
|
||||
from drf_spectacular.utils import extend_schema
|
||||
from rest_framework.request import Request
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from common.auth import TokenAuth
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from common.result import result
|
||||
from system_manage.serializers.valid_serializers import ValidSerializer
|
||||
|
||||
|
||||
class Valid(APIView):
|
||||
authentication_classes = [TokenAuth]
|
||||
|
||||
@extend_schema(
|
||||
methods=['GET'],
|
||||
description=_('Get verification results'),
|
||||
summary=_('Get verification results'),
|
||||
operation_id=_('Get verification results'), # type: ignore
|
||||
tags=[_('Validation')] # type: ignore
|
||||
)
|
||||
def get(self, request: Request, valid_type: str, valid_count: int):
|
||||
return result.success(ValidSerializer(data={'valid_type': valid_type, 'valid_count': valid_count}).valid())
|
||||
|
|
@ -101,6 +101,19 @@ const getSystemDefaultPassword: (
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取校验
|
||||
* @param valid_type 校验类型: application|knowledge|user
|
||||
* @param valid_count 校验数量: 5 | 50 | 2
|
||||
*/
|
||||
const getValid: (
|
||||
valid_type: string,
|
||||
valid_count: number,
|
||||
loading?: Ref<boolean>
|
||||
) => Promise<Result<any>> = (valid_type, valid_count, loading) => {
|
||||
return get(`/valid/${valid_type}/${valid_count}`, undefined, loading)
|
||||
}
|
||||
|
||||
export default {
|
||||
getUserManage,
|
||||
putUserManage,
|
||||
|
|
@ -109,5 +122,6 @@ export default {
|
|||
putUserManagePassword,
|
||||
resetPassword,
|
||||
resetCurrentPassword,
|
||||
getSystemDefaultPassword
|
||||
getSystemDefaultPassword,
|
||||
getValid
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ export default {
|
|||
label: 'Username',
|
||||
placeholder: 'Please enter username',
|
||||
requiredMessage: 'Please enter username',
|
||||
lengthMessage: 'Length must be between 6 and 20 words',
|
||||
lengthMessage: 'Length must be between 4 and 20 words',
|
||||
},
|
||||
password: {
|
||||
label: 'Login Password',
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ export default {
|
|||
nick_name: {
|
||||
label: 'Name',
|
||||
placeholder: 'Please enter name',
|
||||
lengthMessage: 'Length must be between 2 and 20 characters',
|
||||
},
|
||||
phone: {
|
||||
label: 'Phone',
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ export default {
|
|||
label: '用户名',
|
||||
placeholder: '请输入用户名',
|
||||
requiredMessage: '请输入用户名',
|
||||
lengthMessage: '长度在 6 到 20 个字符',
|
||||
lengthMessage: '长度在 4 到 20 个字符',
|
||||
},
|
||||
password: {
|
||||
label: '登录密码',
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ export default {
|
|||
nick_name: {
|
||||
label: '姓名',
|
||||
placeholder: '请输入姓名',
|
||||
lengthMessage: '长度在 2 到 20 个字符',
|
||||
},
|
||||
|
||||
phone: {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ export default {
|
|||
label: '使用者名稱',
|
||||
placeholder: '請輸入使用者名稱',
|
||||
requiredMessage: '請輸入使用者名稱',
|
||||
lengthMessage: '長度須介於 6 到 20 個字元之間',
|
||||
lengthMessage: '長度須介於 4 到 20 個字元之間',
|
||||
},
|
||||
password: {
|
||||
label: '登入密碼',
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ export default {
|
|||
nick_name: {
|
||||
label: '姓名',
|
||||
placeholder: '請輸入姓名',
|
||||
lengthMessage: '長度須介於 2 到 20 個字元之間',
|
||||
},
|
||||
|
||||
phone: {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { defineStore } from 'pinia'
|
||||
import { DeviceType, ValidType } from '@/enums/common'
|
||||
// import type { Ref } from 'vue'
|
||||
// import userApi from '@/api/user/user'
|
||||
import type { Ref } from 'vue'
|
||||
import userApi from '@/api/system/user-manage'
|
||||
|
||||
export interface commonTypes {
|
||||
breadcrumb: any
|
||||
|
|
@ -34,18 +34,18 @@ const useCommonStore = defineStore('common',{
|
|||
isMobile() {
|
||||
return this.device === DeviceType.Mobile
|
||||
},
|
||||
// async asyncGetValid(valid_type: ValidType, valid_count: number, loading?: Ref<boolean>) {
|
||||
// return new Promise((resolve, reject) => {
|
||||
// userApi
|
||||
// .getValid(valid_type, valid_count, loading)
|
||||
// .then((data) => {
|
||||
// resolve(data)
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// reject(error)
|
||||
// })
|
||||
// })
|
||||
// }
|
||||
async asyncGetValid(valid_type: ValidType, valid_count: number, loading?: Ref<boolean>) {
|
||||
return new Promise((resolve, reject) => {
|
||||
userApi
|
||||
.getValid(valid_type, valid_count, loading)
|
||||
.then((data) => {
|
||||
resolve(data)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('views.userManage.userForm.nick_name.label')">
|
||||
<el-form-item :label="$t('views.userManage.userForm.nick_name.label')" prop="nick_name" >
|
||||
<el-input
|
||||
v-model="userForm.nick_name"
|
||||
:placeholder="$t('views.userManage.userForm.nick_name.placeholder')"
|
||||
|
|
@ -168,12 +168,25 @@ const rules = reactive({
|
|||
trigger: 'blur',
|
||||
},
|
||||
{
|
||||
min: 6,
|
||||
min: 4,
|
||||
max: 20,
|
||||
message: t('views.login.loginForm.username.lengthMessage'),
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
nick_name: [
|
||||
{
|
||||
required: true,
|
||||
message: t('views.userManage.userForm.nick_name.placeholder'),
|
||||
trigger: 'blur',
|
||||
},
|
||||
{
|
||||
min: 1,
|
||||
max: 20,
|
||||
message: t('views.userManage.userForm.nick_name.lengthMessage'),
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
email: [
|
||||
{
|
||||
required: true,
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@
|
|||
<el-card>
|
||||
<div class="flex-between mb-16">
|
||||
<el-button type="primary" @click="createUser">{{
|
||||
$t('views.userManage.createUser')
|
||||
}}</el-button>
|
||||
$t('views.userManage.createUser')
|
||||
}}
|
||||
</el-button>
|
||||
<div class="flex-between complex-search">
|
||||
<el-select
|
||||
class="complex-search__left"
|
||||
|
|
@ -13,7 +14,7 @@
|
|||
style="width: 120px"
|
||||
@change="search_type_change"
|
||||
>
|
||||
<el-option :label="$t('views.login.loginForm.username.label')" value="name" />
|
||||
<el-option :label="$t('views.login.loginForm.username.label')" value="name"/>
|
||||
</el-select>
|
||||
<el-input
|
||||
v-if="search_type === 'name'"
|
||||
|
|
@ -33,14 +34,16 @@
|
|||
@changePage="getList"
|
||||
v-loading="loading"
|
||||
>
|
||||
<el-table-column prop="nick_name" :label="$t('views.userManage.userForm.nick_name.label')" />
|
||||
<el-table-column prop="username" :label="$t('views.login.loginForm.username.label')" />
|
||||
<el-table-column prop="nick_name" :label="$t('views.userManage.userForm.nick_name.label')"/>
|
||||
<el-table-column prop="username" :label="$t('views.login.loginForm.username.label')"/>
|
||||
<el-table-column prop="is_active" :label="$t('common.status.label')">
|
||||
<template #default="{ row }">
|
||||
<div v-if="row.is_active" class="flex align-center">
|
||||
<el-icon class="color-success mr-8" style="font-size: 16px"
|
||||
><SuccessFilled
|
||||
/></el-icon>
|
||||
>
|
||||
<SuccessFilled
|
||||
/>
|
||||
</el-icon>
|
||||
<span class="color-secondary">
|
||||
{{ $t('common.status.enabled') }}
|
||||
</span>
|
||||
|
|
@ -102,10 +105,10 @@
|
|||
:before-change="() => changeState(row)"
|
||||
/>
|
||||
</span>
|
||||
<el-divider direction="vertical" />
|
||||
<el-divider direction="vertical"/>
|
||||
<span class="mr-8">
|
||||
<el-button type="primary" text @click.stop="editUser(row)" :title="$t('common.edit')">
|
||||
<el-icon><EditPen /></el-icon>
|
||||
<el-icon><EditPen/></el-icon>
|
||||
</el-button>
|
||||
</span>
|
||||
|
||||
|
|
@ -116,7 +119,7 @@
|
|||
@click.stop="editPwdUser(row)"
|
||||
:title="$t('views.userManage.setting.updatePwd')"
|
||||
>
|
||||
<el-icon><Lock /></el-icon>
|
||||
<el-icon><Lock/></el-icon>
|
||||
</el-button>
|
||||
</span>
|
||||
<span>
|
||||
|
|
@ -127,26 +130,29 @@
|
|||
@click.stop="deleteUserManage(row)"
|
||||
:title="$t('common.delete')"
|
||||
>
|
||||
<el-icon><Delete /></el-icon>
|
||||
<el-icon><Delete/></el-icon>
|
||||
</el-button>
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</app-table>
|
||||
</el-card>
|
||||
<UserDrawer :title="title" ref="UserDrawerRef" @refresh="refresh" />
|
||||
<UserPwdDialog ref="UserPwdDialogRef" @refresh="refresh" />
|
||||
<UserDrawer :title="title" ref="UserDrawerRef" @refresh="refresh"/>
|
||||
<UserPwdDialog ref="UserPwdDialogRef" @refresh="refresh"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, ref, reactive, watch } from 'vue'
|
||||
import {onMounted, ref, reactive, watch} from 'vue'
|
||||
import UserDrawer from './component/UserDrawer.vue'
|
||||
import UserPwdDialog from './component/UserPwdDialog.vue'
|
||||
import userManageApi from '@/api/system/user-manage'
|
||||
import { datetimeFormat } from '@/utils/time'
|
||||
import { MsgSuccess, MsgConfirm } from '@/utils/message'
|
||||
import { t } from '@/locales'
|
||||
import {datetimeFormat} from '@/utils/time'
|
||||
import {MsgSuccess, MsgConfirm} from '@/utils/message'
|
||||
import {t} from '@/locales'
|
||||
import {ValidCount, ValidType} from "@/enums/common.ts";
|
||||
import useStore from "@/stores";
|
||||
const {common } = useStore()
|
||||
const search_type = ref('name')
|
||||
const search_form = ref<{
|
||||
name: string
|
||||
|
|
@ -167,8 +173,9 @@ const paginationConfig = reactive({
|
|||
const userTableData = ref<any[]>([])
|
||||
|
||||
const search_type_change = () => {
|
||||
search_form.value = { name: '' }
|
||||
search_form.value = {name: ''}
|
||||
}
|
||||
|
||||
function handleSizeChange() {
|
||||
paginationConfig.current_page = 1
|
||||
getList()
|
||||
|
|
@ -201,35 +208,34 @@ function changeState(row: any) {
|
|||
}
|
||||
|
||||
const title = ref('')
|
||||
|
||||
function editUser(row: any) {
|
||||
title.value = t('views.userManage.editUser')
|
||||
UserDrawerRef.value.open(row)
|
||||
}
|
||||
|
||||
function createUser() {
|
||||
title.value = t('views.userManage.createUser')
|
||||
UserDrawerRef.value.open()
|
||||
// common.asyncGetValid(ValidType.User, ValidCount.User, loading).then(async (res: any) => {
|
||||
// if (res?.data) {
|
||||
// title.value = t('views.userManage.createUser')
|
||||
// UserDrawerRef.value.open()
|
||||
// } else if (res?.code === 400) {
|
||||
// MsgConfirm(t('common.tip'), t('views.userManage.tip.professionalMessage'), {
|
||||
// cancelButtonText: t('common.confirm'),
|
||||
// confirmButtonText: t('common.professional'),
|
||||
// })
|
||||
// .then(() => {
|
||||
// window.open('https://maxkb.cn/pricing.html', '_blank')
|
||||
// })
|
||||
// .catch(() => {})
|
||||
// }
|
||||
// })
|
||||
common.asyncGetValid(ValidType.User, ValidCount.User, loading).then(async (res: any) => {
|
||||
if (res?.data) {
|
||||
title.value = t('views.userManage.createUser')
|
||||
UserDrawerRef.value.open()
|
||||
} else if (res?.code === 400) {
|
||||
MsgConfirm(t('common.tip'), t('views.userManage.tip.professionalMessage'), {
|
||||
cancelButtonText: t('common.confirm'),
|
||||
confirmButtonText: t('common.professional'),
|
||||
})
|
||||
.then(() => {
|
||||
window.open('https://maxkb.cn/pricing.html', '_blank')
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function deleteUserManage(row: any) {
|
||||
MsgConfirm(
|
||||
`${t('views.user.delete.confirmTitle')}${row.username} ?`,
|
||||
t('views.user.delete.confirmMessage'),
|
||||
`${t('views.userManage.delete.confirmTitle')}${row.username} ?`,
|
||||
t('views.userManage.delete.confirmMessage'),
|
||||
{
|
||||
confirmButtonText: t('common.confirm'),
|
||||
confirmButtonClass: 'danger',
|
||||
|
|
@ -242,7 +248,8 @@ function deleteUserManage(row: any) {
|
|||
getList()
|
||||
})
|
||||
})
|
||||
.catch(() => {})
|
||||
.catch(() => {
|
||||
})
|
||||
}
|
||||
|
||||
function editPwdUser(row: any) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue