Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unneeded filterQuery redefinition #39

Closed
vonagam opened this issue Jan 8, 2019 · 20 comments
Closed

Unneeded filterQuery redefinition #39

vonagam opened this issue Jan 8, 2019 · 20 comments

Comments

@vonagam
Copy link
Contributor

vonagam commented Jan 8, 2019

Currently you can safely remove filterQuery and nothing will change.

First, it should exit here because filtered.query will be an object. I assume it is a typo and it should have been if (! utils.isPlainObject(query)), it would make sense that way.

But even after this, convertOperators is converting operators, but const key = operators[prop] ? operators[prop] : prop will always be prop itself. defaultOperators returns object where keys and values are equal, there is no mismatch or converting.

Am i missing something?

@dekelev
Copy link
Member

dekelev commented Jan 8, 2019

@vonagam thanks for this. I've took the updated version of filterQuery method from feathers-sequelize and it looks like it was already fixed there. The fix is published in feathers-objection v2.0.1

@vonagam
Copy link
Contributor Author

vonagam commented Jan 8, 2019

Hm... so you keep this method for convenience, to be comparable with feathers-sequelize in migration paths?

Because there is no need for convertOperators in feathers-objection right now otherwise.

@dekelev
Copy link
Member

dekelev commented Jan 8, 2019

Right. Feathers Crow release dictates security guidelines that were already implemented in most of the well-known Feathers DB adapters, including feathers-sequelize. Some of the recent updates in feathers-objection were simply synced from feathers-sequelize. All these DB adapters, including feathers-objection, are using the same test-suite from feathers that was released recently to test the new filtering functionalities.

@vonagam
Copy link
Contributor Author

vonagam commented Jan 8, 2019

Ok. Got it.

(Just to be clear: Ran tests. Removed filterQuery method, saw two failings. Fixed by reassignment of whitelist in options super(Object.assign({...}, options, {whitelist})) here. All tests are passing.)

@vonagam vonagam closed this as completed Jan 8, 2019
@dekelev
Copy link
Member

dekelev commented Jan 8, 2019

$like is in the whitelist operators list. it should not be added to the service options.

@vonagam
Copy link
Contributor Author

vonagam commented Jan 8, 2019

Why not? options.whitelist is for additionalOperators in filterQuery. And it is its only usage. And $like is additional operator used in feathers-objection.

@dekelev
Copy link
Member

dekelev commented Jan 8, 2019

$like is not unique to feathers-objection and is part of the operators that are allowed now by default in feathers-sequelize. It shouldn't be different in feathers-objection.

@vonagam
Copy link
Contributor Author

vonagam commented Jan 8, 2019

In feathers-objection:
const filtered = super.filterQuery(params, { operators: this.whitelist })

In feathers-sequelize:
const filtered = super.filterQuery(params);

So currently they have different behaviours.

In feathers-objection all operators are allowed, and you can enable additional (like $eager, which is really a filter), but you can't disable $like operator for example.

In feathers-sequelize all operators are allowed by default, but if you pass whitelist option and it does not include $like then $like will not be allowed.

@vonagam
Copy link
Contributor Author

vonagam commented Jan 8, 2019

Ok, you can simply remove filterQuery and fix test to match feathers-sequelize's behaviour by adding $like to this whitelist.

Otherwise this test will fall, because $like is used but not whitelisted.

@dekelev
Copy link
Member

dekelev commented Jan 8, 2019

OK, thanks for that check.

@vonagam
Copy link
Contributor Author

vonagam commented Jan 8, 2019

Sorry, no mistake, you can disable $like in feathers-sequelize and can't in feathers-objection.

@dekelev
Copy link
Member

dekelev commented Jan 8, 2019

:) ok, releasing a patch

@dekelev
Copy link
Member

dekelev commented Jan 8, 2019

removing filterQuery method

@vonagam
Copy link
Contributor Author

vonagam commented Jan 8, 2019

It's a breaking change, though, if you want to match sequelize behaviour.

@dekelev
Copy link
Member

dekelev commented Jan 8, 2019

right, so minor version.

@vonagam
Copy link
Contributor Author

vonagam commented Jan 8, 2019

I mean, that if somebody used { "whitelist": [ "$eager" ] } and used $like in queries. (Like in current tests) And you change behaviour to sequelize's. Then their code will fail (Like tests was). And then they have to add $like towhitelist (Like what you need to fix tests if you match sequelize).

So it is major version change.

@dekelev
Copy link
Member

dekelev commented Jan 8, 2019

OK. It'll be 3.0.0

@vonagam
Copy link
Contributor Author

vonagam commented Jan 8, 2019

Here is if you remove all unneeded stuff.

@dekelev
Copy link
Member

dekelev commented Jan 8, 2019

Cool. removed all that too.

@dekelev
Copy link
Member

dekelev commented Jan 8, 2019

published as 3.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants