refactor: merge tenant configuration into tenant registry

This commit is contained in:
richjohnrambo
2026-09-22 16:47:40 +08:00
parent 851eca97ed
commit 85b564e2ac
22 changed files with 216 additions and 634 deletions
@@ -178,17 +178,8 @@ func (c *cConfig) ModerationPolicy(ctx context.Context, req *api.ModerationPolic
return nil, err
}
res = defaultModerationPolicy(tenant)
var tenantConfig struct {
AliyunModerationEnabled int `json:"aliyun_moderation_enabled"`
LocalModerationEnabled int `json:"local_moderation_enabled"`
}
if err = imtenant.RegistryDB().Model(dao.ImTenantConfig.Table()).Safe().Ctx(ctx).
Fields("aliyun_moderation_enabled", "local_moderation_enabled").
Where(dao.ImTenantConfig.Columns().TenantId, tenant.Id).Scan(&tenantConfig); err != nil {
return nil, gerror.Wrap(err, "获取商户内容审核开关失败")
}
res.AliyunEnabled = tenantConfig.AliyunModerationEnabled == 1
res.LocalWordsEnabled = tenantConfig.LocalModerationEnabled == 1
res.AliyunEnabled = tenant.AliyunModerationEnabled == 1
res.LocalWordsEnabled = tenant.LocalModerationEnabled == 1
res.Enabled = res.AliyunEnabled || res.LocalWordsEnabled
columns := dao.ImSecurityPolicy.Columns()
var row struct {
@@ -333,18 +324,7 @@ func (c *cConfig) RealnamePolicy(ctx context.Context, req *api.RealnamePolicyReq
return nil, err
}
res = defaultRealnamePolicy(tenant.Id)
var row *struct {
RealnameReviewPolicy int `json:"realname_review_policy"`
}
if err = imtenant.RegistryDB().Model(dao.ImTenantConfig.Table()).Safe().Ctx(ctx).
Fields("realname_review_policy").
Where(dao.ImTenantConfig.Columns().TenantId, tenant.Id).Scan(&row); err != nil {
return nil, gerror.Wrap(err, "获取租户实名认证策略失败")
}
if row == nil {
return res, nil
}
if row.RealnameReviewPolicy == 1 {
if tenant.RealnameReviewPolicy == 1 {
res.RealnameReviewPolicy = 1
}
return res, nil
@@ -553,8 +533,6 @@ func tenantToModel(tenant *entity.ImTenant) *api.TenantModel {
Code: tenant.Code,
Name: tenant.Name,
TenantDesc: &desc,
DBName: tenant.DbName,
DBDSN: tenant.DbDsn,
State: tenant.State,
CreatedAt: gtimeToRFC3339(tenant.CreatedAt),
CreatedBy: tenant.CreatedBy,