From 316fa371f24c575765ba4839c6d29be51406209a Mon Sep 17 00:00:00 2001 From: npc0-hue Date: Fri, 24 Oct 2025 11:39:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20-=20=E9=9D=9E=E6=9D=83=E9=99=90?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=8D=E6=98=BE=E7=A4=BA=E5=AF=86=E9=92=A5?= =?UTF-8?q?=E6=8C=89=E9=92=AE=20-=20=E7=94=A8=E6=88=B7id=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E8=87=AA=E5=A2=9E=E8=A7=A3=E5=86=B3=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/server/global/model.go | 2 +- admin/server/initialize/ensure_tables.go | 1 + admin/server/initialize/gorm.go | 76 +++++++++++++++++++ admin/server/initialize/gorm_pgsql.go | 4 + api/libs/oauth.py | 2 +- .../database/database_retrieval.py | 2 +- api/services/workspace_service.py | 5 +- .../develop/secret-key/secret-key-button.tsx | 4 + .../header/account-dropdown/index.tsx | 6 +- 9 files changed, 94 insertions(+), 8 deletions(-) diff --git a/admin/server/global/model.go b/admin/server/global/model.go index 9772eb312..d552080ac 100644 --- a/admin/server/global/model.go +++ b/admin/server/global/model.go @@ -7,7 +7,7 @@ import ( ) type GVA_MODEL struct { - ID uint `gorm:"primarykey" json:"ID"` // 主键ID + ID uint `gorm:"primarykey;autoIncrement" json:"ID"` // 主键ID CreatedAt time.Time // 创建时间 UpdatedAt time.Time // 更新时间 DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` // 删除时间 diff --git a/admin/server/initialize/ensure_tables.go b/admin/server/initialize/ensure_tables.go index d350eb07f..d3aa5da63 100644 --- a/admin/server/initialize/ensure_tables.go +++ b/admin/server/initialize/ensure_tables.go @@ -35,6 +35,7 @@ func (e *ensureTables) MigrateTable(ctx context.Context) (context.Context, error if !ok { return ctx, system.ErrMissingDBContext } + tables := []interface{}{ sysModel.SysApi{}, sysModel.SysUser{}, diff --git a/admin/server/initialize/gorm.go b/admin/server/initialize/gorm.go index 1bf6a6a03..af7991550 100644 --- a/admin/server/initialize/gorm.go +++ b/admin/server/initialize/gorm.go @@ -82,6 +82,11 @@ func RegisterTables() { os.Exit(0) } + // 如果是PostgreSQL数据库,创建必要的序列 + if global.GVA_CONFIG.System.DbType == "pgsql" { + createPostgreSQLSequences(db) + } + err = bizModel() if err != nil { @@ -90,3 +95,74 @@ func RegisterTables() { } global.GVA_LOG.Info("register table success") } + +// createPostgreSQLSequences 为PostgreSQL数据库创建必要的序列 +func createPostgreSQLSequences(db *gorm.DB) { + // 需要创建序列的表列表 + tables := []string{ + "sys_users", + "sys_apis", + "sys_base_menus", + "sys_authorities", + "sys_dictionaries", + "sys_operation_records", + "sys_auto_code_histories", + "sys_dictionary_details", + "sys_base_menu_parameters", + "sys_base_menu_btns", + "sys_authority_btns", + "sys_auto_code_packages", + "sys_export_templates", + "conditions", + "join_templates", + "sys_params", + "exa_files", + "exa_customers", + "exa_file_chunks", + "exa_file_upload_and_downloads", + "account_ding_talk_extends", + "app_request_test_batches", + "app_request_tests", + "system_integrations", + "forwarding_extends", + "batch_workflows", + "batch_workflow_tasks", + "sys_user_global_codes", + } + + for _, table := range tables { + sequenceName := fmt.Sprintf("%s_id_seq", table) + + // 检查序列是否已存在 + var exists bool + checkSQL := "SELECT EXISTS (SELECT 1 FROM pg_sequences WHERE sequencename = ?)" + if err := db.Raw(checkSQL, sequenceName).Scan(&exists).Error; err != nil { + log.Printf("检查序列 %s 是否存在时出错: %v", sequenceName, err) + continue + } + + if !exists { + // 创建序列 + createSQL := fmt.Sprintf("CREATE SEQUENCE IF NOT EXISTS %s START 1 INCREMENT 1", sequenceName) + if err := db.Exec(createSQL).Error; err != nil { + log.Printf("创建序列 %s 时出错: %v", sequenceName, err) + continue + } + + // 将序列设置为表的默认值 + alterSQL := fmt.Sprintf("ALTER TABLE %s ALTER COLUMN id SET DEFAULT nextval('%s')", table, sequenceName) + if err := db.Exec(alterSQL).Error; err != nil { + log.Printf("设置表 %s 的ID默认值时出错: %v", table, err) + continue + } + + // 更新序列的当前值(如果表中已有数据) + updateSQL := fmt.Sprintf("SELECT setval('%s', COALESCE((SELECT MAX(id) FROM %s), 1), true)", sequenceName, table) + if err := db.Exec(updateSQL).Error; err != nil { + log.Printf("更新序列 %s 的当前值时出错: %v", sequenceName, err) + } + + log.Printf("成功为表 %s 创建序列 %s", table, sequenceName) + } + } +} diff --git a/admin/server/initialize/gorm_pgsql.go b/admin/server/initialize/gorm_pgsql.go index 625c87385..1d126d583 100644 --- a/admin/server/initialize/gorm_pgsql.go +++ b/admin/server/initialize/gorm_pgsql.go @@ -26,6 +26,10 @@ func GormPgSql() *gorm.DB { sqlDB, _ := db.DB() sqlDB.SetMaxIdleConns(p.MaxIdleConns) sqlDB.SetMaxOpenConns(p.MaxOpenConns) + + // 为PostgreSQL创建必要的序列 + createPostgreSQLSequences(db) + return db } } diff --git a/api/libs/oauth.py b/api/libs/oauth.py index 6662b6d5e..3bd118f51 100644 --- a/api/libs/oauth.py +++ b/api/libs/oauth.py @@ -235,7 +235,7 @@ class OaOAuth(OAuth): endpoints = self._resolve_endpoints(config) auth_url = endpoints.get('authorize_url') - return f"{auth_url}{'&' if "?" in auth_url else '&'}{query_string}" + return f"{auth_url}{'&' if "?" in auth_url else '?'}{query_string}" def get_access_token(self, code: str): auto2_conf = self.get_auto2_conf() diff --git a/api/services/recommend_app/database/database_retrieval.py b/api/services/recommend_app/database/database_retrieval.py index c4b309fc0..fc4ea8016 100644 --- a/api/services/recommend_app/database/database_retrieval.py +++ b/api/services/recommend_app/database/database_retrieval.py @@ -88,7 +88,7 @@ class DatabaseRecommendAppRetrieval(RecommendAppRetrievalBase): category = class_dick[classId] recommended_app_result = { "id": recommended_app.id, - "app": recommended_app.app, + "app": recommended_app.app, "app_id": recommended_app.app_id, "description": description, "copyright": site.copyright, diff --git a/api/services/workspace_service.py b/api/services/workspace_service.py index d0a2f960e..16a21e48c 100644 --- a/api/services/workspace_service.py +++ b/api/services/workspace_service.py @@ -1,4 +1,3 @@ - from flask_login import current_user from configs import dify_config @@ -37,8 +36,8 @@ class WorkspaceService: tenant_extend_service = TenantExtendService super_admin_id = tenant_extend_service.get_super_admin_id().id super_admin_tenant_id = tenant_extend_service.get_super_admin_tenant_id().id - tenant_info["admin_extend"] = (super_admin_id == current_user.id) - tenant_info["tenant_extend"] = (super_admin_tenant_id == tenant.id) + tenant_info["admin_extend"] = super_admin_id == current_user.id + tenant_info["tenant_extend"] = super_admin_tenant_id == tenant.id # ----------------------- 二开部分Stop 添加用户权限 - ---------------------- can_replace_logo = FeatureService.get_features(tenant.id).can_replace_logo diff --git a/web/app/components/develop/secret-key/secret-key-button.tsx b/web/app/components/develop/secret-key/secret-key-button.tsx index 7d27c01d2..3894977b6 100644 --- a/web/app/components/develop/secret-key/secret-key-button.tsx +++ b/web/app/components/develop/secret-key/secret-key-button.tsx @@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next' import { RiKey2Line } from '@remixicon/react' import Button from '@/app/components/base/button' import SecretKeyModal from '@/app/components/develop/secret-key/secret-key-modal' +import {useAppContext} from "@/context/app-context"; type ISecretKeyButtonProps = { className?: string @@ -12,8 +13,11 @@ type ISecretKeyButtonProps = { } const SecretKeyButton = ({ className, appId, textCls }: ISecretKeyButtonProps) => { + const { isCurrentWorkspaceManager } = useAppContext() const [isVisible, setVisible] = useState(false) const { t } = useTranslation() + if (!isCurrentWorkspaceManager) + return "" return ( <>