在进行权限检查时,对相对路径的计算

This commit is contained in:
Xu Chang 2023-07-12 12:58:37 +08:00
parent 0c83caba1a
commit 8575186962
2 changed files with 15 additions and 15 deletions

View File

@ -136,8 +136,8 @@ var RelationAuth = /** @class */ (function () {
|| !anchor.relativePath; } // relativePath如果是'', 所有的路径都成立
);
if (relatedAnchor) {
var entity_1 = relatedAnchor.entity, relativePath_1 = relatedAnchor.relativePath, filter_2 = relatedAnchor.filter;
var restPath = relativePath_1 === path[1] ? '' : relativePath_1 === '' ? path[1] : path[1].slice(relativePath_1.length + 1);
var entity_1 = relatedAnchor.entity, relativePath = relatedAnchor.relativePath, filter_2 = relatedAnchor.filter;
var restPath = relativePath === path[1] ? '' : relativePath === '' ? path[1] : path[1].slice(relativePath.length + 1);
if (restPath === '') {
// 处理一种特殊情况如果根结点是create则userRelation或者userId应该附着在创建的信息上
if (actions[0] === 'create' && actions.length === 1) {
@ -149,7 +149,7 @@ var RelationAuth = /** @class */ (function () {
return relationId;
});
return {
relativePath: '',
relativePath: path[1],
relationIds: relationIds,
path: path,
};
@ -158,7 +158,7 @@ var RelationAuth = /** @class */ (function () {
else {
if (filter_2.id === userId) {
return {
relativePath: '',
relativePath: path[1],
path: path,
};
}
@ -166,7 +166,7 @@ var RelationAuth = /** @class */ (function () {
}
if (path[3]) {
return {
relativePath: relativePath_1,
relativePath: path[1],
path: path,
filter: {
entity: entity_1,
@ -177,7 +177,7 @@ var RelationAuth = /** @class */ (function () {
if (userId === filter_2.id) {
// 说明userId满足条件直接返回relativePath
return {
relativePath: '',
relativePath: path[1],
path: path,
};
}
@ -189,14 +189,14 @@ var RelationAuth = /** @class */ (function () {
// 这里如果不是relation关系则最后一项是指向user的外键名否则最后一项就是最后一层的对象有区别
if (idx === restPaths_1.length - 1 && !path[3]) {
return {
relativePath: relativePath_1,
relativePath: path[1],
path: path,
filter: tslib_1.__assign((_a = {}, _a["".concat(restPaths_1[idx], "Id")] = userId, _a), filter2),
};
}
else if (idx === restPaths_1.length && path[3]) {
return {
relativePath: relativePath_1,
relativePath: path[1],
path: path,
filter: {
entity: entity2,

View File

@ -206,7 +206,7 @@ export class RelationAuth<ED extends EntityDict & BaseEntityDict>{
}
);
return {
relativePath: '',
relativePath: path[1],
relationIds,
path,
};
@ -215,7 +215,7 @@ export class RelationAuth<ED extends EntityDict & BaseEntityDict>{
else {
if (filter!.id === userId) {
return {
relativePath: '',
relativePath: path[1],
path,
};
}
@ -223,7 +223,7 @@ export class RelationAuth<ED extends EntityDict & BaseEntityDict>{
}
if (path[3]) {
return {
relativePath,
relativePath: path[1],
path,
filter: {
entity,
@ -234,7 +234,7 @@ export class RelationAuth<ED extends EntityDict & BaseEntityDict>{
if (userId === filter!.id) {
// 说明userId满足条件直接返回relativePath
return {
relativePath: '',
relativePath: path[1],
path,
};
}
@ -250,7 +250,7 @@ export class RelationAuth<ED extends EntityDict & BaseEntityDict>{
// 这里如果不是relation关系则最后一项是指向user的外键名否则最后一项就是最后一层的对象有区别
if (idx === restPaths.length - 1 && !path[3]) {
return {
relativePath,
relativePath: path[1],
path,
filter: {
[`${restPaths[idx]}Id`]: userId,
@ -260,7 +260,7 @@ export class RelationAuth<ED extends EntityDict & BaseEntityDict>{
}
else if (idx === restPaths.length && path[3]) {
return {
relativePath,
relativePath: path[1],
path,
filter: {
entity: entity2,
@ -306,7 +306,7 @@ export class RelationAuth<ED extends EntityDict & BaseEntityDict>{
).filter(
ele => !!ele
) as {
relativePath: string; // (当前目标对象)与在anchor定位出来的对象的相对路径
relativePath: string; // (当前目标对象)与将用于测试的cascadePath的destEntity的相对路径
path: AuthCascadePath<ED>; // 对象的AuthCascadePath
filter?: ED[keyof ED]['Selection']['filter']; // 如果有relation是对userRelation的查询条件没有relation则是对path所标定的源对象的查询条件两者都没有则说明查询条件上已经标定了源对象的userId了
relationIds?: string[]; // 如果有值表示userRelation是本动作所创建出来的relationIds是相对应的relationIds