feat: 新增商户管理员账号自动创建功能,优化租户权限控制

1.  后端实现租户创建时自动绑定创建管理员账号,支持超管/普通管理员权限区分
2.  前端适配超管权限控制业务库名、连接串等敏感字段展示与编辑
3.  优化租户数据库回退逻辑,未配置独立库时自动回落默认库
4.  调整租户列表与详情页的权限数据脱敏逻辑
This commit is contained in:
Austin
2026-09-21 17:50:38 +08:00
parent 197c6c86f4
commit c9673ca871
6 changed files with 232 additions and 47 deletions
+13 -15
View File
@@ -18,17 +18,6 @@ import (
"github.com/gogf/gf/v2/os/gtime"
)
// ImTenantUpdateFields 修改IM租户字段过滤
type ImTenantUpdateFields struct {
Code string `json:"code" dc:"租户编码"`
Name string `json:"name" dc:"租户名称"`
TenantDesc string `json:"tenantDesc" dc:"租户描述"`
DbName string `json:"dbName" dc:"业务库名"`
DbDsn string `json:"dbDsn" dc:"独立连接串"`
State int `json:"state" dc:"状态"`
UpdatedBy int64 `json:"updatedBy" dc:"更新者"`
}
// ImTenantInsertFields 新增IM租户字段过滤
type ImTenantInsertFields struct {
Code string `json:"code" dc:"租户编码"`
@@ -76,6 +65,8 @@ type ImTenantEditInp struct {
LocalModerationEnabled int `json:"localModerationEnabled" dc:"是否启用本地内容审核"`
MessageEncryptionEnabled int `json:"messageEncryptionEnabled" dc:"是否启用消息加密"`
RealnameReviewPolicy int `json:"realnameReviewPolicy" dc:"实名审核策略"`
AdminUsername string `json:"adminUsername" dc:"新增商户时自动创建的后台管理员账号名"`
AdminPassword string `json:"adminPassword" dc:"新增商户时自动创建的后台管理员初始密码"`
}
func (in *ImTenantEditInp) Filter(ctx context.Context) (err error) {
@@ -85,9 +76,6 @@ func (in *ImTenantEditInp) Filter(ctx context.Context) (err error) {
if e := g.Validator().Rules("required|max-length:128").Data(in.Name).Messages("租户名称不能为空|租户名称不能超过128个字符").Run(ctx); e != nil {
return e.Current()
}
if in.DbName == "" && in.DbDsn == "" {
return gerror.New("业务库名和独立连接串至少填写一个")
}
if !dict.HasOptionKey(consts.ImTenantStateOptions, in.State) {
return gerror.New("租户状态不正确")
}
@@ -99,10 +87,20 @@ func (in *ImTenantEditInp) Filter(ctx context.Context) (err error) {
if in.RealnameReviewPolicy != 0 && in.RealnameReviewPolicy != 1 {
return gerror.New("实名审核策略不正确")
}
if in.Id == 0 {
if e := g.Validator().Rules("required|length:3,32|regex:^[a-zA-Z0-9_-]+$").Data(in.AdminUsername).Messages("管理员账号不能为空|管理员账号长度应为3到32位|管理员账号仅支持字母、数字、下划线和横线").Run(ctx); e != nil {
return e.Current()
}
if e := g.Validator().Rules("required|length:6,32").Data(in.AdminPassword).Messages("管理员密码不能为空|管理员密码长度应为6到32位").Run(ctx); e != nil {
return e.Current()
}
}
return
}
type ImTenantEditModel struct{}
type ImTenantEditModel struct {
AdminUsername string `json:"adminUsername" dc:"已创建的后台管理员账号名"`
}
// ImTenantViewInp 获取指定IM租户信息
type ImTenantViewInp struct {