Skip to content

Commit

Permalink
Fix get items is array (#110)
Browse files Browse the repository at this point in the history
* Fixes data filtering error when pagination is enabled

In the 'authorizeAfter' function, an incorrect definition of the data
format when calling the 'feathersUtils.getItemsIsArray' function
resulted in the 'isArray' variable being incorrectly set to 'false',
which resulted in the 'getOrFind' variable being incorrectly set to
'get'. As a result, it affected incorrect data filtering when the user
requests data using the 'find' method with pagination enabled and
a restriction on allowed fields.

* Fixes data filtering error when pagination is enabled

In the 'authorizeAfter' function, an incorrect definition of the data
format when calling the 'feathersUtils.getItemsIsArray' function
resulted in the 'isArray' variable being incorrectly set to 'false',
which resulted in the 'getOrFind' variable being incorrectly set to
'get'. As a result, it affected incorrect data filtering when the user
requests data using the 'find' method with pagination enabled and
a restriction on allowed fields.

Fix #95

* fix: getItemsIsArray result/automatic

---------

Co-authored-by: German Shapkov <[email protected]>
  • Loading branch information
fratzinger and Servaker authored Nov 13, 2023
1 parent 94541cc commit b05eb3f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@feathersjs/feathers": "^5.0.6",
"@feathersjs/transport-commons": "^5.0.6",
"feathers-hooks-common": "^8.0.0",
"feathers-utils": "^3.0.3",
"feathers-utils": "^3.1.3",
"lodash": "^4.17.21"
},
"devDependencies": {
Expand Down
48 changes: 48 additions & 0 deletions test/hooks/authorize/authorize.general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,5 +896,53 @@ describe("authorize.general.test.ts", function () {
});
await Promise.all(promises);
});

it("after - passes multi with 'pagination' with 'find' rule", async function () {
const expectedResult = {
"total": 1,
"limit": 10,
"skip": 0,
"data": [{ id: 1, userId: 1, test: true }]
};
const makeContext = (method, type) => {
return {
service: {},
path: "tests",
method,
type,
result: _cloneDeep(expectedResult),
id: null,
params: {
ability: defineAbility(
(can) => {
can(["find", "create", "patch", "remove"], "all");
},
{ resolveAction }
),
query: {},
},
} as unknown as HookContext;
};

const types = ["after"];
const methods = ["find"];
const promises: Promise<any>[] = [];
types.forEach((type) => {
methods.forEach((method) => {
const context = makeContext(method, type);
const promise = authorize({ availableFields: undefined })(
context
).then(({ result }) => {
assert.deepStrictEqual(
result,
expectedResult,
`returns complete object for '${type}:${method}'`
);
});
promises.push(promise);
});
});
await Promise.all(promises);
});
});
});

0 comments on commit b05eb3f

Please sign in to comment.