Skip to content

Commit 76a1ab4

Browse files
Merge branch 'main' into pr@main@perf_custom_oauth
2 parents 8108af2 + c5ce41f commit 76a1ab4

File tree

10 files changed

+78
-27
lines changed

10 files changed

+78
-27
lines changed

backend/common/core/schemas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class TokenPayload(BaseModel):
1414
class Token(SQLModel):
1515
access_token: str
1616
token_type: str = "bearer"
17+
platform_info: Optional[dict] = None
1718

1819
class XOAuth2PasswordBearer(OAuth2PasswordBearer):
1920
async def __call__(self, request: Request) -> Optional[str]:

backend/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ dependencies = [
4848
"xlrd>=2.0.2",
4949
"clickhouse-sqlalchemy>=0.3.2",
5050
"dicttoxml>=1.7.16",
51-
"dmpython>=2.5.22; platform_system != 'Darwin'",
51+
"dmpython==2.5.22; platform_system != 'Darwin'",
5252
"redshift-connector>=2.1.8",
5353
"elasticsearch[requests] (>=7.10,<8.0)",
5454
]

backend/templates/template.yaml

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -467,35 +467,65 @@ template:
467467
{question}
468468
permissions:
469469
system: |
470-
### 请使用语言:{lang} 回答
470+
<Instruction>
471+
你是"SQLBOT",智能问数小助手,可以根据用户提问,专业生成SQL与可视化图表。
472+
你当前的任务是在给定的SQL基础上,根据提供的一组过滤条件,将过滤条件添加到该SQL内并生成一句新SQL
473+
提供的SQL在<sql>内,提供的过滤条件在<filter-list>内
474+
</Instruction>
471475
472-
### 说明:
473-
提供给你一句SQL和一组表的过滤条件,从这组表的过滤条件中找出SQL中用到的表所对应的过滤条件,将用到的表所对应的过滤条件添加到提供给你的SQL中(不要替换SQL中原有的条件),生成符合{engine}数据库引擎规范的新SQL语句(如果过滤条件为空则无需处理)。
474-
表的过滤条件json格式如下:
475-
[{{"table":"表名","filter":"过滤条件"}},...]
476476
你必须遵守以下规则:
477-
- 生成的SQL必须符合{engine}的规范。
478-
- 不要替换原来SQL中的过滤条件,将新过滤条件添加到SQL中,生成一个新的sql。
479-
- 如果存在冗余的过滤条件则进行去重后再生成新SQL。
480-
- 给过滤条件中的字段前加上表别名(如果没有表别名则加表名),如:table.field。
481-
- 生成SQL时,必须避免关键字冲突:
482-
- 如数据库引擎是 PostgreSQL、Oracle、ClickHouse、达梦(DM)、AWS Redshift、Elasticsearch,则在schema、表名、字段名、别名外层加双引号;
483-
- 如数据库引擎是 MySQL、Doris,则在表名、字段名、别名外层加反引号;
484-
- 如数据库引擎是 Microsoft SQL Server,则在schema、表名、字段名、别名外层加方括号。
485-
- 生成的SQL使用JSON格式返回:
486-
{{"success":true,"sql":"生成的SQL语句"}}
487-
- 如果不能生成SQL,回答:
488-
{{"success":false,"message":"无法生成SQL的原因"}}
489-
490-
### 响应, 请直接返回JSON结果:
477+
<Rules>
478+
<rule>
479+
请使用语言:{lang} 回答,若有深度思考过程,则思考过程也需要使用 {lang} 输出
480+
</rule>
481+
<rule>
482+
生成的SQL必须符合数据库引擎: {engine} 的语法规范
483+
</rule>
484+
<rule>
485+
必须以原SQL为基础,不要替换原来SQL中的过滤条件,将新过滤条件添加到SQL中,生成一个新的sql
486+
</rule>
487+
<rule>
488+
提供的过滤条件形如:[{{"table":"表名","filter":"过滤条件"}},...]
489+
</rule>
490+
<rule>
491+
若提供的过滤条件为空或找不到SQL中使用到的table,则不需要修改原SQL
492+
</rule>
493+
<rule>
494+
你需要在过滤条件中找到匹配原SQL中使用到的table,并将对应的filter内条件添加到SQL中
495+
</rule>
496+
<rule>
497+
如果存在冗余的过滤条件则进行去重后再生成新SQL
498+
</rule>
499+
<rule>
500+
给过滤条件中的字段前加上表别名(如果没有表别名则加表名),如:table.field。
501+
</rule>
502+
<rule>
503+
生成SQL时,必须避免关键字冲突:
504+
- 如数据库引擎是 PostgreSQL、Oracle、ClickHouse、达梦(DM)、AWS Redshift、Elasticsearch,则在schema、表名、字段名、别名外层加双引号;
505+
- 如数据库引擎是 MySQL、Doris,则在表名、字段名、别名外层加反引号;
506+
- 如数据库引擎是 Microsoft SQL Server,则在schema、表名、字段名、别名外层加方括号。
507+
</rule>
508+
<rule>
509+
生成的SQL使用JSON格式返回:{{"success":true,"sql":"生成的SQL语句"}}
510+
</rule>
511+
<rule>
512+
若无法生成,则返回:{{"success":false,"message":"无法生成SQL的原因"}}
513+
</rule>
514+
<rule>
515+
在返回的JSON的sql字段字符串内,必须注意符号的转译是否正确
516+
</rule>
517+
518+
</Rules>
519+
520+
### 响应, 请根据上述要求直接返回JSON结果:
491521
```json
492-
493522
user: |
494-
### sql:
523+
<sql>
495524
{sql}
496-
497-
### 过滤条件:
525+
</sql>
526+
<filter-list>
498527
{filter}
528+
</filter-list>
499529
dynamic_sql:
500530
system: |
501531
### 请使用语言:{lang} 回答

frontend/src/i18n/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@
718718
"client_id": "Client ID",
719719
"client_secret": "Client Secret",
720720
"redirect_url": "Redirect URL",
721+
"logout_redirect_url": "Logout Redirect URL",
722+
"logout_redirect_url_placeholder": "By default, users will be redirected to the SQLBot login page after logout. You can customize the redirect address here.",
721723
"oauth2_settings": "OAuth2 Settings",
722724
"scope": "Scope",
723725
"userinfo_url": "User Info URL",

frontend/src/i18n/ko-KR.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@
718718
"client_id": "클라이언트 ID",
719719
"client_secret": "클라이언트 시크릿",
720720
"redirect_url": "리디렉션 URL",
721+
"logout_redirect_url": "로그아웃 후 리디렉션 URL",
722+
"logout_redirect_url_placeholder": "기본적으로 로그아웃 후 SQLBot 로그인 페이지로 이동합니다. 여기서 리디렉션 주소를 사용자 지정할 수 있습니다.",
721723
"oauth2_settings": "OAuth2 설정",
722724
"scope": "권한 범위",
723725
"userinfo_url": "사용자 정보 URL",

frontend/src/i18n/zh-CN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@
718718
"client_id": "客户端 ID",
719719
"client_secret": "客户端密钥",
720720
"redirect_url": "回调地址",
721+
"logout_redirect_url": "注销回调地址",
722+
"logout_redirect_url_placeholder": "注销后默认跳转至 SQLBot 登录页面,可自定义设置注销后跳转地址",
721723
"oauth2_settings": "OAuth2 设置",
722724
"scope": "授权范围",
723725
"userinfo_url": "用户信息地址",

frontend/src/stores/user.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { AuthApi } from '@/api/login'
44
import { useCache } from '@/utils/useCache'
55
import { i18n } from '@/i18n'
66
import { store } from './index'
7+
import { getQueryString } from '@/utils/utils'
78

89
const { wsCache } = useCache()
910

@@ -91,6 +92,11 @@ export const UserStore = defineStore('user', {
9192
window.location.href = res
9293
window.open(res, '_self')
9394
}
95+
if (getQueryString('code') && getQueryString('state')?.includes('oauth2_state')) {
96+
const logout_url = location.origin + location.pathname + '#/login'
97+
window.location.href = logout_url
98+
window.open(res, logout_url)
99+
}
94100
},
95101

96102
async info() {

frontend/src/views/login/xpack/Handler.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ const oauth2Login = () => {
220220
.post('/system/authentication/sso/4', urlParams)
221221
.then((res: any) => {
222222
const token = res.access_token
223-
const id_token = res.id_token
223+
const platform_info = res.platform_info
224224
if (token && isPlatformClient()) {
225225
wsCache.set('de-platform-client', true)
226226
}
@@ -229,7 +229,7 @@ const oauth2Login = () => {
229229
userStore.setTime(Date.now())
230230
userStore.setPlatformInfo({
231231
flag: 'oauth2',
232-
data: id_token,
232+
data: platform_info ? JSON.stringify(platform_info) : '',
233233
origin: 4,
234234
})
235235
const queryRedirectPath = getCurLocation()

frontend/src/views/system/authentication/Oauth2Editor.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const state = reactive({
2929
redirect_url: '',
3030
token_auth_method: 'basic',
3131
userinfo_auth_method: 'header',
32+
logout_redirect_url: '',
3233
mapping: '',
3334
}),
3435
})
@@ -347,6 +348,13 @@ onBeforeMount(() => {
347348
<el-input v-model="state.form.redirect_url" :placeholder="t('common.please_input')" />
348349
</el-form-item>
349350

351+
<el-form-item :label="t('authentication.logout_redirect_url')" prop="logout_redirect_url">
352+
<el-input
353+
v-model="state.form.logout_redirect_url"
354+
:placeholder="t('authentication.logout_redirect_url_placeholder')"
355+
/>
356+
</el-form-item>
357+
350358
<el-form-item :label="t('authentication.field_mapping')" prop="mapping">
351359
<el-input
352360
v-model="state.form.mapping"

frontend/src/views/system/training/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ const onRowFormClose = () => {
727727
</el-drawer>
728728
<el-drawer
729729
v-model="rowInfoDialog"
730-
:title="$t('professional.professional_term_details')"
730+
:title="$t('training.training_data_details')"
731731
destroy-on-close
732732
size="600px"
733733
:before-close="onRowFormClose"

0 commit comments

Comments
 (0)