Skip to content

feat: 访问限制中新增身份验证设置 #1370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion apps/application/serializers/application_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,20 @@ def edit(self, instance: Dict, with_valid=True):
if 'show_source' in instance and instance.get('show_source') is not None:
application_access_token.show_source = instance.get('show_source')
application_access_token.save()
application_setting_model = DBModelManage.get_model('application_setting')
X_PACK_LICENSE_IS_VALID = (settings.XPACK_LICENSE_IS_VALID if hasattr(settings,
'XPACK_LICENSE_IS_VALID') else False)
if application_setting_model is not None and X_PACK_LICENSE_IS_VALID:
application_setting, _ = application_setting_model.objects.get_or_create(
application_id=self.data.get('application_id'))
if application_setting is not None:
application_setting.authentication = instance.get('authentication')
application_setting.authentication_value = {
"type": "password",
"value": instance.get('authentication_value')
}
application_setting.save()

get_application_access_token(application_access_token.access_token, False)
return self.one(with_valid=False)

Expand Down Expand Up @@ -734,7 +748,8 @@ def profile(self, with_valid=True):
'draggable': application_setting.draggable,
'show_guide': application_setting.show_guide,
'avatar': application_setting.avatar,
'float_icon': application_setting.float_icon}
'float_icon': application_setting.float_icon,
'authentication': application_setting.authentication}
return ApplicationSerializer.Query.reset_application(
{**ApplicationSerializer.ApplicationModel(application).data,
'stt_model_id': application.stt_model_id,
Expand Down
12 changes: 11 additions & 1 deletion ui/src/api/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,15 @@ const updatePlatformStatus: (application_id: string, data: any) => Promise<Resul
) => {
return post(`/platform/${application_id}/status`, data)
}
/**
* 验证密码
*/
const validatePassword: (application_id: string, password: string) => Promise<Result<any>> = (
application_id,
password
) => {
return get(`/application/${application_id}/auth/${password}`, undefined)
}

export default {
getAllAppilcation,
Expand Down Expand Up @@ -419,5 +428,6 @@ export default {
getPlatformStatus,
getPlatformConfig,
updatePlatformConfig,
updatePlatformStatus
updatePlatformStatus,
validatePassword
}
2 changes: 2 additions & 0 deletions ui/src/locales/lang/en_US/views/application-overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export default {
dialogTitle: 'Access Restrictions',
showSourceLabel: 'Show Source',
clientQueryLimitLabel: 'Each Client Query Limit',
authentication: 'Authentication',
authenticationValue: 'Authentication Password',
timesDays: 'Times/Day',
whitelistLabel: 'Whitelist',
whitelistPlaceholder:
Expand Down
2 changes: 2 additions & 0 deletions ui/src/locales/lang/zh_CN/views/application-overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export default {
showSourceLabel: '显示知识来源',
clientQueryLimitLabel: '每个客户端提问限制',
timesDays: '次/天',
authentication: '身份验证',
authenticationValue: '验证密码',
whitelistLabel: '白名单',
whitelistPlaceholder:
'请输入允许嵌入第三方的源地址,一行一个,如:\nhttp://127.0.0.1:5678\nhttps://dataease.io',
Expand Down
12 changes: 12 additions & 0 deletions ui/src/stores/modules/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ const useApplicationStore = defineStore({
reject(error)
})
})
},
async validatePassword(id: string, password: string, loading?: Ref<boolean>) {
return new Promise((resolve, reject) => {
applicationApi
.validatePassword(id, password)
.then((data) => {
resolve(data)
})
.catch((error) => {
reject(error)
})
})
}
}
})
Expand Down
47 changes: 45 additions & 2 deletions ui/src/views/application-overview/component/LimitDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@
$t('views.applicationOverview.appInfo.LimitDialog.timesDays')
}}</span>
</el-form-item>
<!-- 身份验证 -->
<el-form-item
:label="$t('views.applicationOverview.appInfo.LimitDialog.authentication')"
v-hasPermission="new ComplexPermission([], ['x-pack'], 'OR')"
>
<el-switch size="small" v-model="form.authentication"></el-switch>
</el-form-item>
<el-form-item
v-if="form.authentication"
:label="$t('views.applicationOverview.appInfo.LimitDialog.authenticationValue')"
v-hasPermission="new ComplexPermission([], ['x-pack'], 'OR')"
>
<el-input
v-model="form.authentication_value"
readonly
style="width: 300px; margin-right: 10px"
></el-input>
<el-button type="primary" text @click="copyClick(form.authentication_value)">
<AppIcon iconName="app-copy"></AppIcon>
</el-button>
<el-button @click="refreshAuthentication" type="primary" text style="margin-left: 1px">
<el-icon><RefreshRight /></el-icon>
</el-button>
</el-form-item>
<el-form-item
:label="$t('views.applicationOverview.appInfo.LimitDialog.whitelistLabel')"
@click.prevent
Expand Down Expand Up @@ -61,6 +85,8 @@ import type { FormInstance, FormRules } from 'element-plus'
import applicationApi from '@/api/application'
import { MsgSuccess, MsgConfirm } from '@/utils/message'
import { t } from '@/locales'
import { copyClick } from '@/utils/clipboard'
import { ComplexPermission } from '@/utils/permission/type'

const route = useRoute()
const {
Expand All @@ -73,7 +99,9 @@ const limitFormRef = ref()
const form = ref<any>({
access_num: 0,
white_active: true,
white_list: ''
white_list: '',
authentication_value: '',
authentication: false
})

const dialogVisible = ref<boolean>(false)
Expand All @@ -93,6 +121,8 @@ const open = (data: any) => {
form.value.access_num = data.access_num
form.value.white_active = data.white_active
form.value.white_list = data.white_list?.length ? data.white_list?.join('\n') : ''
form.value.authentication_value = data.authentication_value
form.value.authentication = data.authentication
dialogVisible.value = true
}

Expand All @@ -103,7 +133,9 @@ const submit = async (formEl: FormInstance | undefined) => {
const obj = {
white_list: form.value.white_list ? form.value.white_list.split('\n') : [],
white_active: form.value.white_active,
access_num: form.value.access_num
access_num: form.value.access_num,
authentication: form.value.authentication,
authentication_value: form.value.authentication_value
}
applicationApi.putAccessToken(id as string, obj, loading).then((res) => {
emit('refresh')
Expand All @@ -114,6 +146,17 @@ const submit = async (formEl: FormInstance | undefined) => {
}
})
}
function generateAuthenticationValue(length: number = 10) {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
const randomValues = new Uint8Array(length)
window.crypto.getRandomValues(randomValues)
return Array.from(randomValues)
.map((value) => chars[value % chars.length])
.join('')
}
function refreshAuthentication() {
form.value.authentication_value = generateAuthenticationValue()
}

defineExpose({ open })
</script>
Expand Down
Loading
Loading