relationAuth中对一种情况的边界处理不严谨

This commit is contained in:
Xu Chang 2023-07-18 19:18:40 +08:00
parent efec1e0231
commit b8c3f2f598
2 changed files with 30 additions and 2 deletions

View File

@ -196,7 +196,7 @@ var RelationAuth = /** @class */ (function () {
},
};
}
if (userId === filter_2.id) {
else if (userId === filter_2.id) {
// 说明userId满足条件直接返回relativePath
return {
relativePath: path[1],
@ -210,6 +210,15 @@ var RelationAuth = /** @class */ (function () {
var _a, _b;
// 这里如果不是relation关系则最后一项是指向user的外键名否则最后一项就是最后一层的对象有区别
if (idx === restPaths_1.length - 1 && !path[3]) {
var rel_1 = (0, relation_1.judgeRelation)(_this.schema, entity2, restPaths_1[idx]);
if (rel_1 === 2) {
return {
relativePath: path[1],
path: path,
filter: tslib_1.__assign({ entity: 'user', entityId: userId }, filter2),
};
}
(0, assert_1.default)(typeof rel_1 === 'string');
return {
relativePath: path[1],
path: path,
@ -782,6 +791,9 @@ var RelationAuth = /** @class */ (function () {
};
}
}
else if (process.env.NODE_ENV === 'development') {
console.warn("\u5BF9\u53EFdeduce\u6743\u9650\u7684\u5BF9\u8C61".concat(entity, "\u7684\u52A8\u4F5C").concat(action, "\u627E\u4E0D\u5230\u53EF\u63A8\u5BFC\u7684\u5916\u952E\u5173\u7CFB\uFF0C\u8BF7\u68C0\u67E5\u662F\u5426\u5E94\u8BE5\u5E26\u4E0A\u8BE5\u5916\u952E\u518D\u5904\u7406"));
}
}
};
/**

View File

@ -243,7 +243,7 @@ export class RelationAuth<ED extends EntityDict & BaseEntityDict>{
},
};
}
if (userId === filter!.id) {
else if (userId === filter!.id) {
// 说明userId满足条件直接返回relativePath
return {
relativePath: path[1],
@ -261,6 +261,19 @@ export class RelationAuth<ED extends EntityDict & BaseEntityDict>{
} => {
// 这里如果不是relation关系则最后一项是指向user的外键名否则最后一项就是最后一层的对象有区别
if (idx === restPaths.length - 1 && !path[3]) {
const rel = judgeRelation(this.schema, entity2, restPaths[idx]);
if (rel === 2) {
return {
relativePath: path[1],
path,
filter: {
entity: 'user',
entityId: userId,
...filter2!,
},
};
}
assert (typeof rel === 'string');
return {
relativePath: path[1],
path,
@ -940,6 +953,9 @@ export class RelationAuth<ED extends EntityDict & BaseEntityDict>{
};
}
}
else if (process.env.NODE_ENV === 'development') {
console.warn(`对可deduce权限的对象${entity as string}的动作${action}找不到可推导的外键关系,请检查是否应该带上该外键再处理`);
}
}
}