fix(多公司): 站点超管不替别家公司建下级账号,admin 候选与首任管理员都收在本公司

- AdminUserService:建号前两道不变式——ensureSubSuperAccountStaysWithOperatorCompany(超管只能往别家开"那家的公司超管",往下的组长/员工一律 403)+ ensureCreatorSharesCompany 提成执行体(created_by_id 与 company_id 不得分属两家,超管是唯一豁免),建号与移人共用一份,避免"另一侧照样落库"
- 列表侧 admin 候选按 companyIdFilter 过滤:全平台列 admin 就是"admin 替别家建账号"的入口
- ShopManageController 同步一处;配套 AdminUserServiceCompanyTest 9 例(本机 mvn -o test 19 例全绿,含 PublishBrandLabel/PublishWorkbook 两支)
- 前端 CreateUserDialog/GroupEditorDialog/UsersPage + 两个 model 与 types 随之收口,新增 company-user-create.test.ts 61 行用例
- 注:这批改动原为另一路会话在飞文件,按用户"所有的都提交推送"指示收口,提交前已跑其自带用例
This commit is contained in:
2026-10-09 09:11:30 +08:00
parent 39fc5d537f
commit 65b40e5cc0
11 changed files with 305 additions and 27 deletions
@@ -3,7 +3,10 @@ import { computed, reactive, ref, watch } from 'vue'
import { submitCreateUser } from './user-create-adapter'
import {
createEmptyCreateUserForm,
defaultRoleChoice,
mayCarryOwnExpiry,
resolveRoleChoices,
type CreatableUserRole,
type CreateUserForm,
type CreateUserFormErrors,
validateCreateUserForm,
@@ -17,10 +20,14 @@ const props = defineProps<{
operatorSuper?: boolean
/** 操作者角色(company_super_admin 也能建管理员/普通账号)。 */
operatorRole?: string | null
/** 所属管理员候选(列表响应 admins;仅超管创建普通账号时展示)。 */
/** 所属管理员候选(列表响应 admins;仅超管创建普通账号时展示,已按当前公司 tab 收窄)。 */
adminOptions?: Array<{ id: number; username: string }>
/** 公司候选(站点超管创建公司超级管理员时必选)。 */
companyOptions?: Array<{ id: number; companyName: string }>
/** 操作者自己那家公司(会话 current-user.companyId)。 */
operatorCompanyId?: number | null
/** 当前公司 tab:这次建号落在哪家,就决定能建哪些角色。 */
activeCompanyId?: number | null
}>()
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'created'): void }>()
@@ -30,29 +37,40 @@ const busy = ref(false)
/** 角色下拉:站点超管可选公司超管/管理员/普通账号;公司超管只可选管理员/普通账号;
* 管理员不显示角色选择(后端强制 normal)。 */
const ROLE_CHOICES: Array<{ value: 'company_super_admin' | 'admin' | 'normal'; label: string }> = [
{ value: 'company_super_admin', label: '公司超级管理员' },
{ value: 'admin', label: '管理员' },
{ value: 'normal', label: '普通账号' },
]
const ROLE_LABELS: Record<CreatableUserRole, string> = {
company_super_admin: '公司超级管理员',
admin: '管理员',
normal: '普通账号',
}
const canChooseRole = computed(() => props.operatorSuper || props.operatorRole === 'company_super_admin')
const roleChoices = computed(() =>
props.operatorSuper ? ROLE_CHOICES : ROLE_CHOICES.filter((opt) => opt.value !== 'company_super_admin'),
/** 可选角色集合的唯一来源是 user-create-model 那个纯函数(后端有同一口径的一条 403)。 */
const allowedRoles = computed<CreatableUserRole[]>(() =>
resolveRoleChoices(props.operatorSuper === true, props.operatorCompanyId, props.activeCompanyId),
)
const roleChoices = computed(() => allowedRoles.value.map((value) => ({ value, label: ROLE_LABELS[value] })))
/** 只有管理员/公司超管有「自己的到期时间」;普通账号跟随上级级联,不给它入口。 */
const expiryEditable = computed(() => mayCarryOwnExpiry(form.role))
// 公司 tab 收窄了可选角色时,把残留的旧选择收敛回合法项(并清掉上一家的所属管理员):
// 留着它,用户看到的是一个已经不给选的选项,提交会被后端 403 打回。
watch(allowedRoles, (roles) => {
if (roles.includes(form.role)) return
form.role = defaultRoleChoice(roles)
form.createdBy = null
})
watch(
() => props.modelValue,
(open) => {
if (!open) return
form.username = ''
form.password = ''
form.role = 'normal'
form.role = defaultRoleChoice(allowedRoles.value)
form.columnIds = []
form.createdBy = null
form.expiresAt = ''
form.companyId = null
// 预填当前 tab:跨公司时角色本来就只剩公司超管,而那一例必须带公司
form.companyId = props.activeCompanyId ?? null
errors.username = undefined
errors.password = undefined
errors.companyId = undefined