chore: seed migration objects batch 5
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/simple"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
@@ -28,7 +29,7 @@ func resolveImAdminScope(ctx context.Context, selectedTenantId int64) (scope ima
|
||||
scope.OperatorId = operatorId
|
||||
scope.RoleKey = contexts.GetRoleKey(ctx)
|
||||
scope.RequestId = gctx.CtxId(ctx)
|
||||
if service.AdminMember().VerifySuperId(ctx, operatorId) {
|
||||
if isImPlatformAdmin(ctx, operatorId) {
|
||||
if selectedTenantId <= 0 {
|
||||
return scope, gerror.New("请选择IM租户")
|
||||
}
|
||||
@@ -39,12 +40,12 @@ func resolveImAdminScope(ctx context.Context, selectedTenantId int64) (scope ima
|
||||
return scope, nil
|
||||
}
|
||||
|
||||
if contexts.GetDeptType(ctx) != consts.DeptTypeTenant {
|
||||
return scope, gerror.New("当前账号不是租户管理员,不能管理邀请码")
|
||||
if !contexts.IsTenantDept(ctx) {
|
||||
return scope, gerror.New("当前账号无权管理IM租户")
|
||||
}
|
||||
tenantId := contexts.GetTenantId(ctx)
|
||||
if tenantId <= 0 {
|
||||
return scope, gerror.New("当前管理员未关联租户")
|
||||
tenantId, err := resolveImAdminBoundTenant(ctx)
|
||||
if err != nil {
|
||||
return scope, err
|
||||
}
|
||||
if err = ensureImTenantActive(ctx, tenantId); err != nil {
|
||||
return scope, err
|
||||
@@ -53,6 +54,21 @@ func resolveImAdminScope(ctx context.Context, selectedTenantId int64) (scope ima
|
||||
return scope, nil
|
||||
}
|
||||
|
||||
func isImPlatformAdmin(ctx context.Context, operatorId int64) bool {
|
||||
if contexts.IsCompanyDept(ctx) {
|
||||
return true
|
||||
}
|
||||
return service.AdminMember().VerifySuperId(ctx, operatorId)
|
||||
}
|
||||
|
||||
func resolveImAdminBoundTenant(ctx context.Context) (int64, error) {
|
||||
tenantId := contexts.GetTenantId(ctx)
|
||||
if tenantId <= 0 {
|
||||
return 0, gerror.New("当前管理员未关联IM租户")
|
||||
}
|
||||
return tenantId, nil
|
||||
}
|
||||
|
||||
func ensureImTenantActive(ctx context.Context, tenantId int64) (err error) {
|
||||
var tenant *entity.ImTenant
|
||||
if err = imtenant.RegistryDB(ctx).Model(dao.ImTenant.Table()).Safe().Ctx(ctx).WherePri(tenantId).Scan(&tenant); err != nil {
|
||||
@@ -67,6 +83,14 @@ func ensureImTenantActive(ctx context.Context, tenantId int64) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func resolveImTenantDB(ctx context.Context, selectedTenantId int64) (db gdb.DB, tenant *entity.ImTenant, err error) {
|
||||
scope, err := resolveImAdminScope(ctx, selectedTenantId)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return imtenant.DB(ctx, scope.TenantId)
|
||||
}
|
||||
|
||||
func writeImAdminAudit(ctx context.Context, tenantId int64, action string, targetType string, targetId int64, result string, detail g.Map) error {
|
||||
operatorId := contexts.GetUserId(ctx)
|
||||
request := ghttp.RequestFromCtx(ctx)
|
||||
|
||||
Reference in New Issue
Block a user