修复root平台账户编辑角色误提交
This commit is contained in:
@@ -193,6 +193,17 @@ const ownerKeys: Record<string, string[]> = {
|
||||
gasorder_contract: ['user_account_identity', 'gas_basic_identity'],
|
||||
};
|
||||
|
||||
/** 判断目标是否为受保护的 root 平台账户。 */
|
||||
function isProtectedPlatformRootAccount(
|
||||
definition: ResourceUiDefinition,
|
||||
row: ResourceRow,
|
||||
) {
|
||||
return (
|
||||
definition.name === 'platform_account' &&
|
||||
String(row.platform_role_code ?? '') === 'root'
|
||||
);
|
||||
}
|
||||
|
||||
/** 返回当前模式需要展示的字段;编辑页会保留不可变字段但将其设为只读。 */
|
||||
export function pageFields(
|
||||
definition: ResourceUiDefinition,
|
||||
@@ -210,7 +221,11 @@ export function pageFields(
|
||||
if (definition.name === 'product_repair' && row.result !== 'pending') {
|
||||
editableKeys = ['remark'];
|
||||
}
|
||||
if (definition.name === 'platform_account' && context.role !== 'root') {
|
||||
const protectedRootAccount = isProtectedPlatformRootAccount(definition, row);
|
||||
if (
|
||||
definition.name === 'platform_account' &&
|
||||
(context.role !== 'root' || protectedRootAccount)
|
||||
) {
|
||||
editableKeys = editableKeys.filter((key) => key !== 'platform_role_code');
|
||||
}
|
||||
const visibleKeys = new Set([
|
||||
@@ -229,6 +244,8 @@ export function pageFields(
|
||||
)
|
||||
.map((field) => field.key),
|
||||
]);
|
||||
// root 角色保持可见但只读,避免管理员误以为账户没有关联角色。
|
||||
if (protectedRootAccount) visibleKeys.add('platform_role_code');
|
||||
return definition.fields.filter(
|
||||
(field) =>
|
||||
visibleKeys.has(field.key) &&
|
||||
@@ -246,7 +263,11 @@ export function editableFields(
|
||||
let keys = rule?.editKeys ?? definition.fields.map((field) => field.key);
|
||||
if (definition.name === 'product_repair' && row.result !== 'pending')
|
||||
keys = ['remark'];
|
||||
if (definition.name === 'platform_account' && context.role !== 'root') {
|
||||
if (
|
||||
definition.name === 'platform_account' &&
|
||||
(context.role !== 'root' ||
|
||||
isProtectedPlatformRootAccount(definition, row))
|
||||
) {
|
||||
keys = keys.filter((key) => key !== 'platform_role_code');
|
||||
}
|
||||
const allowed = new Set(keys);
|
||||
|
||||
Reference in New Issue
Block a user