feat: add tenant bound restriction for IM dashboard and management pages
1. extract isTenantBound utility from user store logic 2. add disabled state to tenant select components across all IM pages 3. update policy tenant options logic to hide global option for bound tenants 4. add backend scope validation for IM admin operations
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type imAdminScope struct {
|
||||
@@ -85,6 +86,43 @@ func resolveImAdminBoundTenant(ctx context.Context) (int64, error) {
|
||||
return tenantId, nil
|
||||
}
|
||||
|
||||
// ensureImRecordTenantAllowed 校验目标记录/租户是否在当前操作者允许范围内。
|
||||
// 平台管理员(超管/平台角色/未绑定租户的公司部门)可访问任意租户的记录;
|
||||
// 其余账号强制限定为自己绑定的租户(与 resolveImAdminScope 的范围逻辑一致)。
|
||||
// 适用于入参不含租户ID、需按已查出的记录租户做后置校验的场景。
|
||||
func ensureImRecordTenantAllowed(ctx context.Context, recordTenantId int64) error {
|
||||
if isImPlatformAdmin(ctx, contexts.GetUserId(ctx)) {
|
||||
return nil
|
||||
}
|
||||
if !contexts.IsTenantDept(ctx) && !(contexts.IsCompanyDept(ctx) && contexts.GetTenantId(ctx) > 0) {
|
||||
return gerror.New("当前账号无权管理IM租户")
|
||||
}
|
||||
boundTenantId, err := resolveImAdminBoundTenant(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if boundTenantId != recordTenantId {
|
||||
return gerror.New("无权访问其他商户的IM数据")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// lookupImTenantByCode 按租户编码查询租户(用于入参只有租户编码的管理端接口)
|
||||
func lookupImTenantByCode(ctx context.Context, code string) (tenant *entity.ImTenant, err error) {
|
||||
code = strings.TrimSpace(code)
|
||||
if code == "" {
|
||||
return nil, gerror.New("请选择IM租户")
|
||||
}
|
||||
if err = imtenant.RegistryDB().Model(dao.ImTenant.Table()).Safe().Ctx(ctx).
|
||||
Where(dao.ImTenant.Columns().Code, code).Scan(&tenant); err != nil {
|
||||
return nil, gerror.Wrap(err, "获取IM租户失败")
|
||||
}
|
||||
if tenant == nil || tenant.Id <= 0 {
|
||||
return nil, gerror.New("IM租户不存在")
|
||||
}
|
||||
return tenant, nil
|
||||
}
|
||||
|
||||
func ensureImTenantActive(ctx context.Context, tenantId int64) (err error) {
|
||||
var tenant *entity.ImTenant
|
||||
if err = imtenant.RegistryDB().Model(dao.ImTenant.Table()).Safe().Ctx(ctx).WherePri(tenantId).Scan(&tenant); err != nil {
|
||||
|
||||
@@ -10,18 +10,13 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/library/imadmin"
|
||||
"hotgo/internal/library/imkafka"
|
||||
"hotgo/internal/library/imtenant"
|
||||
"hotgo/internal/model/entity"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
type sSysImDeadLetter struct{}
|
||||
@@ -39,7 +34,7 @@ func (s *sSysImDeadLetter) List(ctx context.Context, in *sysin.ImDeadLetterListI
|
||||
if err = in.Filter(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tenant, err := s.getTenant(ctx, in.TenantId)
|
||||
tenant, err := resolveImAdminTenant(ctx, in.TenantId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -81,7 +76,7 @@ func (s *sSysImDeadLetter) View(ctx context.Context, in *sysin.ImDeadLetterViewI
|
||||
if err = in.Filter(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tenant, err := s.getTenant(ctx, in.TenantId)
|
||||
tenant, err := resolveImAdminTenant(ctx, in.TenantId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -120,7 +115,7 @@ func (s *sSysImDeadLetter) publishActionCommand(ctx context.Context, in *sysin.I
|
||||
if err := in.Filter(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tenant, err := s.getTenant(ctx, in.TenantId)
|
||||
tenant, err := resolveImAdminTenant(ctx, in.TenantId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -162,22 +157,6 @@ func (s *sSysImDeadLetter) publishActionCommand(ctx context.Context, in *sysin.I
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *sSysImDeadLetter) getTenant(ctx context.Context, tenantId int64) (tenant *entity.ImTenant, err error) {
|
||||
if tenantId <= 0 {
|
||||
return nil, gerror.New("请选择IM租户")
|
||||
}
|
||||
if err = imtenant.RegistryDB().Model(dao.ImTenant.Table()).Safe().Ctx(ctx).WherePri(tenantId).Scan(&tenant); err != nil {
|
||||
return nil, gerror.Wrap(err, "获取IM租户失败")
|
||||
}
|
||||
if tenant == nil || tenant.Id <= 0 {
|
||||
return nil, gerror.New("IM租户不存在")
|
||||
}
|
||||
if tenant.State != consts.ImTenantStateActive {
|
||||
return nil, gerror.New("IM租户未启用")
|
||||
}
|
||||
return tenant, nil
|
||||
}
|
||||
|
||||
func convertDeadLetterModel(in *sysin.ImDeadLetterListModelRaw) *sysin.ImDeadLetterListModel {
|
||||
if in == nil {
|
||||
return &sysin.ImDeadLetterListModel{}
|
||||
|
||||
@@ -33,7 +33,12 @@ func (s *sSysImKafkaCommand) List(ctx context.Context, in *sysin.ImKafkaCommandL
|
||||
if err = in.Filter(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
where, args := buildImKafkaCommandWhere(in)
|
||||
// 强制租户范围:商户绑定账号忽略前端所选租户,平台管理员使用所选租户
|
||||
scope, err := resolveImAdminScope(ctx, in.TenantId)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
where, args := buildImKafkaCommandWhere(in, scope.TenantId)
|
||||
db := imtenant.RegistryDB()
|
||||
totalValue, err := db.GetValue(ctx, "SELECT COUNT(*) FROM im_admin_commands "+where, args...)
|
||||
if err != nil {
|
||||
@@ -91,16 +96,16 @@ func (s *sSysImKafkaCommand) View(ctx context.Context, in *sysin.ImKafkaCommandV
|
||||
if err = row.Struct(&res); err != nil {
|
||||
return nil, gerror.Wrap(err, "解析IM后台命令详情失败,请稍后重试!")
|
||||
}
|
||||
// 后置校验记录归属租户是否在操作者允许范围内
|
||||
if err = ensureImRecordTenantAllowed(ctx, res.TenantId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func buildImKafkaCommandWhere(in *sysin.ImKafkaCommandListInp) (string, []any) {
|
||||
parts := []string{"1=1"}
|
||||
args := []any{}
|
||||
if in.TenantId > 0 {
|
||||
parts = append(parts, "tenant_id=?")
|
||||
args = append(args, in.TenantId)
|
||||
}
|
||||
func buildImKafkaCommandWhere(in *sysin.ImKafkaCommandListInp, scopeTenantId int64) (string, []any) {
|
||||
parts := []string{"tenant_id=?"}
|
||||
args := []any{scopeTenantId}
|
||||
if in.CommandId != "" {
|
||||
parts = append(parts, "command_id LIKE ?")
|
||||
args = append(args, "%"+in.CommandId+"%")
|
||||
@@ -136,6 +141,14 @@ func (s *sSysImKafkaCommand) CacheInvalidate(ctx context.Context, in *sysin.ImKa
|
||||
if err = in.Filter(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 校验目标租户是否在操作者允许范围内
|
||||
tenant, err := lookupImTenantByCode(ctx, in.TenantCode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = ensureImRecordTenantAllowed(ctx, tenant.Id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user := contexts.GetUser(ctx)
|
||||
actor := &imkafka.Actor{
|
||||
Type: "admin",
|
||||
@@ -170,6 +183,14 @@ func (s *sSysImKafkaCommand) WorkbenchEvent(ctx context.Context, in *sysin.ImKaf
|
||||
if err = in.Filter(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 校验目标租户是否在操作者允许范围内
|
||||
tenant, err := lookupImTenantByCode(ctx, in.TenantCode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = ensureImRecordTenantAllowed(ctx, tenant.Id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user := contexts.GetUser(ctx)
|
||||
actor := &imkafka.Actor{
|
||||
Type: "admin",
|
||||
|
||||
@@ -2,7 +2,7 @@ import { computed, ref } from 'vue';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { defRangeShortcuts } from '@/utils/dateUtil';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -40,6 +40,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@ import { computed, ref } from 'vue';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -42,6 +42,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: false,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@ import { computed, ref } from 'vue';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { defRangeShortcuts } from '@/utils/dateUtil';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
export const tenantOptions = ref<any[]>([]);
|
||||
|
||||
@@ -45,6 +45,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: false,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<n-select
|
||||
v-model:value="tenantId"
|
||||
:options="imQueryTenantOptions"
|
||||
:disabled="isTenantBound()"
|
||||
class="tenant-select"
|
||||
placeholder="请选择商户"
|
||||
/>
|
||||
@@ -40,6 +41,7 @@
|
||||
import { useMessage } from 'naive-ui';
|
||||
import { Overview, Trends } from '@/api/imDashboard';
|
||||
import { imQueryTenantOptions, loadImQueryTenantOptions } from '@/views/imAdminQueryShared';
|
||||
import { isTenantBound } from '@/views/imTenantOptions';
|
||||
|
||||
const message = useMessage();
|
||||
const tenantId = ref(0);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { computed, ref } from 'vue';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -50,6 +50,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@ import { computed, ref } from 'vue';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -46,6 +46,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: false,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<n-select
|
||||
v-model:value="selectedTenantId"
|
||||
:options="tenantOptions"
|
||||
:disabled="isTenantBound()"
|
||||
placeholder="请选择商户"
|
||||
@update:value="loadConfig"
|
||||
/>
|
||||
@@ -72,6 +73,7 @@
|
||||
import { useMessage } from 'naive-ui';
|
||||
import { usePermission } from '@/hooks/web/usePermission';
|
||||
import { Get, Update } from '@/api/imFeedbackConfig';
|
||||
import { isTenantBound } from '@/views/imTenantOptions';
|
||||
import { loadOptions, loadTenantOptions, newState, rules, State, tenantOptions } from './model';
|
||||
|
||||
const message = useMessage();
|
||||
|
||||
@@ -3,7 +3,7 @@ import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { defRangeShortcuts } from '@/utils/dateUtil';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -49,6 +49,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: false,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@ import { computed, ref } from 'vue';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -42,6 +42,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: false,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -4,7 +4,7 @@ import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { defRangeShortcuts } from '@/utils/dateUtil';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -122,6 +122,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: false,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -3,7 +3,7 @@ import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { defRangeShortcuts } from '@/utils/dateUtil';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -52,6 +52,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -3,6 +3,7 @@ import { FormSchema } from '@/components/Form';
|
||||
import { defRangeShortcuts } from '@/utils/dateUtil';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { imQueryTenantOptions } from '@/views/imAdminQueryShared';
|
||||
import { isTenantBound } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -13,6 +14,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
label: '商户',
|
||||
componentProps: {
|
||||
clearable: false,
|
||||
disabled: isTenantBound(),
|
||||
options: computed(() => imQueryTenantOptions.value),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<n-select
|
||||
v-model:value="selectedTenantId"
|
||||
:options="tenantOptions"
|
||||
:disabled="isTenantBound()"
|
||||
placeholder="请选择商户"
|
||||
@update:value="loadConfig"
|
||||
/>
|
||||
@@ -78,6 +79,7 @@
|
||||
import { useMessage } from 'naive-ui';
|
||||
import { usePermission } from '@/hooks/web/usePermission';
|
||||
import { Get, Update } from '@/api/imMailboxConfig';
|
||||
import { isTenantBound } from '@/views/imTenantOptions';
|
||||
import { loadOptions, loadTenantOptions, newState, rules, State, tenantOptions } from './model';
|
||||
|
||||
const message = useMessage();
|
||||
|
||||
@@ -3,6 +3,7 @@ import { FormSchema } from '@/components/Form';
|
||||
import { defRangeShortcuts } from '@/utils/dateUtil';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { imQueryTenantOptions } from '@/views/imAdminQueryShared';
|
||||
import { isTenantBound } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -14,6 +15,7 @@ export function createMessageSchemas(group: boolean) {
|
||||
label: '商户',
|
||||
componentProps: {
|
||||
clearable: false,
|
||||
disabled: isTenantBound(),
|
||||
options: computed(() => imQueryTenantOptions.value),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@ import { computed, ref } from 'vue';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -44,6 +44,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: false,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@ import { computed, ref } from 'vue';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -77,6 +77,7 @@ export const departmentSchemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: false,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -3,7 +3,7 @@ import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { defRangeShortcuts } from '@/utils/dateUtil';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -48,6 +48,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: false,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { ref } from 'vue';
|
||||
import { useUserStore } from '@/store/modules/user';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
export { getDefaultTenantValue } from '@/views/imTenantOptions';
|
||||
|
||||
@@ -9,7 +8,8 @@ const tenantOnlyOptions = ref<any[]>([]);
|
||||
|
||||
export async function loadPolicyTenantOptions(includeGlobal = true) {
|
||||
const tenants = await loadImTenantOptions(tenantOnlyOptions, { page: 1, perPage: 100 });
|
||||
const canUseGlobal = includeGlobal && useUserStore().isCompanyDept;
|
||||
// 商户绑定账号不显示“全局默认”,仅平台管理员(未绑定租户)可配置全局策略
|
||||
const canUseGlobal = includeGlobal && !isTenantBound();
|
||||
policyTenantOptions.value = canUseGlobal
|
||||
? [{ label: '全局默认', value: 0 }, ...tenants]
|
||||
: tenants;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { defRangeShortcuts } from '@/utils/dateUtil';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -46,6 +46,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: false,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -2,6 +2,7 @@ import { computed, ref } from 'vue';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { policyTenantOptions } from '@/views/imPolicyShared';
|
||||
import { isTenantBound } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
export const schemas = ref<FormSchema[]>([
|
||||
@@ -9,7 +10,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
field: 'tenantId',
|
||||
component: 'NSelect',
|
||||
label: '商户',
|
||||
componentProps: { options: computed(() => policyTenantOptions.value), clearable: false },
|
||||
componentProps: { options: computed(() => policyTenantOptions.value), clearable: false, disabled: isTenantBound() },
|
||||
},
|
||||
{
|
||||
field: 'publishStatus',
|
||||
|
||||
@@ -3,6 +3,7 @@ import { NTag } from 'naive-ui';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { policyTenantOptions } from '@/views/imPolicyShared';
|
||||
import { isTenantBound } from '@/views/imTenantOptions';
|
||||
import { renderOptionTag } from '@/utils';
|
||||
|
||||
const dict = useDictStore();
|
||||
@@ -12,7 +13,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
field: 'tenantId',
|
||||
component: 'NSelect',
|
||||
label: '商户',
|
||||
componentProps: { options: computed(() => policyTenantOptions.value), clearable: false },
|
||||
componentProps: { options: computed(() => policyTenantOptions.value), clearable: false, disabled: isTenantBound() },
|
||||
},
|
||||
{ field: 'word', component: 'NInput', label: '敏感词', componentProps: { clearable: true } },
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { computed, ref } from 'vue';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -34,6 +34,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Ref } from 'vue';
|
||||
import { List as TenantList } from '@/api/imTenant';
|
||||
import { useUserStore } from '@/store/modules/user';
|
||||
import type { FormSchema } from '@/components/Form';
|
||||
|
||||
export interface ImTenantOption {
|
||||
label: string;
|
||||
@@ -26,15 +27,10 @@ export async function loadImTenantOptions(
|
||||
target: Ref<ImTenantOption[]>,
|
||||
params: Record<string, any> = { page: 1, perPage: 100 }
|
||||
) {
|
||||
const userStore = useUserStore();
|
||||
const userInfo = { ...readTokenUserInfo(userStore.getToken), ...(userStore.getUserInfo as any) };
|
||||
const boundTenantId = Number(userInfo?.tenantId || userInfo?.tenantID || 0);
|
||||
const boundTenantId = getBoundTenantId();
|
||||
|
||||
if (!userStore.isCompanyDept) {
|
||||
if (boundTenantId <= 0) {
|
||||
target.value = [];
|
||||
return target.value;
|
||||
}
|
||||
// 登录用户已绑定商户租户:仅返回自己商户选项(与后端 resolveImAdminScope 强制范围一致)
|
||||
if (boundTenantId > 0) {
|
||||
let tenant: any = null;
|
||||
try {
|
||||
const res = await TenantList({ ...params, id: boundTenantId, page: 1, perPage: 1 });
|
||||
@@ -42,20 +38,11 @@ export async function loadImTenantOptions(
|
||||
} catch {
|
||||
tenant = null;
|
||||
}
|
||||
target.value = [
|
||||
tenant
|
||||
? toTenantOption(tenant)
|
||||
: {
|
||||
label: formatImTenantLabel({
|
||||
id: boundTenantId,
|
||||
name: userInfo?.tenantName,
|
||||
code: userInfo?.tenantCode,
|
||||
}),
|
||||
value: boundTenantId,
|
||||
code: userInfo?.tenantCode,
|
||||
name: userInfo?.tenantName,
|
||||
},
|
||||
];
|
||||
if (!tenant) {
|
||||
const info = readTokenUserInfo(useUserStore().getToken);
|
||||
tenant = { id: boundTenantId, name: info?.tenantName, code: info?.tenantCode };
|
||||
}
|
||||
target.value = [toTenantOption(tenant)];
|
||||
return target.value;
|
||||
}
|
||||
|
||||
@@ -64,6 +51,26 @@ export async function loadImTenantOptions(
|
||||
return target.value;
|
||||
}
|
||||
|
||||
// 登录用户绑定的商户租户ID(按绑定租户判定,与后端 resolveImAdminScope 的范围逻辑一致)
|
||||
export function getBoundTenantId(): number {
|
||||
const userStore = useUserStore();
|
||||
const userInfo = { ...readTokenUserInfo(userStore.getToken), ...(userStore.getUserInfo as any) };
|
||||
return Number(userInfo?.tenantId || userInfo?.tenantID || 0);
|
||||
}
|
||||
|
||||
// 登录用户是否为商户绑定账号(true=下拉框只显示并锁定自己商户)
|
||||
export function isTenantBound(): boolean {
|
||||
return getBoundTenantId() > 0;
|
||||
}
|
||||
|
||||
// 商户绑定账号:锁定搜索表单中的商户下拉项(仅一项、不可清除、不可更改)
|
||||
export function lockTenantSchema(schema?: FormSchema) {
|
||||
if (!schema || !isTenantBound()) return;
|
||||
const props: any = (schema.componentProps = schema.componentProps || {});
|
||||
props.disabled = true;
|
||||
props.clearable = false;
|
||||
}
|
||||
|
||||
function toTenantOption(item: any): ImTenantOption {
|
||||
return {
|
||||
label: formatImTenantLabel(item),
|
||||
|
||||
@@ -3,7 +3,7 @@ import { NImage, NTag } from 'naive-ui';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { List as PolicyGroupList } from '@/api/imUserPolicyGroup';
|
||||
import defaultAvatar from '@/assets/images/schoolboy.png';
|
||||
|
||||
@@ -86,6 +86,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: false,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -3,6 +3,7 @@ import { FormSchema } from '@/components/Form';
|
||||
import { defRangeShortcuts } from '@/utils/dateUtil';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { imQueryTenantOptions } from '@/views/imAdminQueryShared';
|
||||
import { isTenantBound } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -13,6 +14,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
label: '商户',
|
||||
componentProps: {
|
||||
clearable: false,
|
||||
disabled: isTenantBound(),
|
||||
options: computed(() => imQueryTenantOptions.value),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
|
||||
@@ -2,6 +2,7 @@ import { computed, ref } from 'vue';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { policyTenantOptions } from '@/views/imPolicyShared';
|
||||
import { isTenantBound } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -24,7 +25,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
field: 'tenantId',
|
||||
component: 'NSelect',
|
||||
label: '商户',
|
||||
componentProps: { options: computed(() => policyTenantOptions.value), clearable: false },
|
||||
componentProps: { options: computed(() => policyTenantOptions.value), clearable: false, disabled: isTenantBound() },
|
||||
},
|
||||
{
|
||||
field: 'keyword',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { defRangeShortcuts } from '@/utils/dateUtil';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -88,6 +88,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: false,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@ import { computed, ref } from 'vue';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
import { isTenantBound, loadImTenantOptions } from '@/views/imTenantOptions';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
@@ -44,6 +44,7 @@ export const schemas = ref<FormSchema[]>([
|
||||
componentProps: {
|
||||
clearable: false,
|
||||
options: computed(() => tenantOptions.value),
|
||||
disabled: isTenantBound(),
|
||||
placeholder: '请选择商户',
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user