fix: resolve bound im tenant for company admins
This commit is contained in:
@@ -53,7 +53,7 @@ func resolveImAdminScopeWithAll(ctx context.Context, selectedTenantId int64, all
|
|||||||
return scope, nil
|
return scope, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !contexts.IsTenantDept(ctx) {
|
if !contexts.IsTenantDept(ctx) && !(contexts.IsCompanyDept(ctx) && contexts.GetTenantId(ctx) > 0) {
|
||||||
return scope, gerror.New("当前账号无权管理IM租户")
|
return scope, gerror.New("当前账号无权管理IM租户")
|
||||||
}
|
}
|
||||||
tenantId, err := resolveImAdminBoundTenant(ctx)
|
tenantId, err := resolveImAdminBoundTenant(ctx)
|
||||||
@@ -68,10 +68,10 @@ func resolveImAdminScopeWithAll(ctx context.Context, selectedTenantId int64, all
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isImPlatformAdmin(ctx context.Context, operatorId int64) bool {
|
func isImPlatformAdmin(ctx context.Context, operatorId int64) bool {
|
||||||
if contexts.IsCompanyDept(ctx) {
|
if service.AdminMember().VerifySuperId(ctx, operatorId) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return service.AdminMember().VerifySuperId(ctx, operatorId)
|
return contexts.IsCompanyDept(ctx) && contexts.GetTenantId(ctx) <= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveImAdminBoundTenant(ctx context.Context) (int64, error) {
|
func resolveImAdminBoundTenant(ctx context.Context) (int64, error) {
|
||||||
|
|||||||
@@ -8,12 +8,21 @@ import (
|
|||||||
"hotgo/internal/model"
|
"hotgo/internal/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCompanyDepartmentIsImPlatformAdmin(t *testing.T) {
|
func TestBoundCompanyDepartmentUsesBoundTenant(t *testing.T) {
|
||||||
ctx := context.WithValue(context.Background(), consts.ContextHTTPKey, &model.Context{
|
ctx := context.WithValue(context.Background(), consts.ContextHTTPKey, &model.Context{
|
||||||
User: &model.Identity{Id: 14, TenantId: 1, DeptType: consts.DeptTypeCompany, RoleKey: "imManage"},
|
User: &model.Identity{Id: 14, TenantId: 1, DeptType: consts.DeptTypeCompany, RoleKey: "imManage"},
|
||||||
})
|
})
|
||||||
|
if isImPlatformAdmin(ctx, 14) {
|
||||||
|
t.Fatal("expected bound company department IM manager to use its bound tenant")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnboundCompanyDepartmentIsImPlatformAdmin(t *testing.T) {
|
||||||
|
ctx := context.WithValue(context.Background(), consts.ContextHTTPKey, &model.Context{
|
||||||
|
User: &model.Identity{Id: 14, DeptType: consts.DeptTypeCompany, RoleKey: "imManage"},
|
||||||
|
})
|
||||||
if !isImPlatformAdmin(ctx, 14) {
|
if !isImPlatformAdmin(ctx, 14) {
|
||||||
t.Fatal("expected company department IM manager to use platform tenant selection")
|
t.Fatal("expected unbound company department IM manager to use platform tenant selection")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,6 +40,14 @@ func TestResolveImAdminBoundTenant(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: 2,
|
want: 2,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "company department with tenant binding",
|
||||||
|
identity: &model.Identity{
|
||||||
|
TenantId: 1,
|
||||||
|
DeptType: consts.DeptTypeCompany,
|
||||||
|
},
|
||||||
|
want: 1,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|||||||
Reference in New Issue
Block a user