-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
feat: adds accessibleBy helper and deprecates toMongoQuery
and accessibleRecordsPlugin
#795
Conversation
…essibleRecordsPlugin`
Codecov Report
@@ Coverage Diff @@
## master #795 +/- ##
==========================================
- Coverage 94.93% 92.59% -2.35%
==========================================
Files 34 3 -31
Lines 731 54 -677
Branches 175 13 -162
==========================================
- Hits 694 50 -644
+ Misses 20 2 -18
+ Partials 17 2 -15
... and 31 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Why was the accessible records plugin deprecated? |
Because of many many issues related to breaking changes in mongoose types and related complexity. I want to re-orient this library to be more MongoDB specific, so:
PS: I don't like ts experience in mongoose especially when it comes to applying multiple plugins and there are other issues. That's why few years ago, I started working on alternative library that can be used instead of mongoose, lightweight alternative on top of json schema. Basically driver + super duper types + fail safe. https://github.com/stalniy/jongo/blob/main/src/example.ts . So, another aim is to reduce maintenance burden. |
Oh I see. However, I think that there is something wrong with the query returned by accessibleBy function.
In mongoose (7.0.1) it does not work, throws an error if permission isnt granted:
I tried the query manually in mongo shell and it worked, so I think that this is a bug related to mongoose maybe? |
I also tried this in mongo shell and it worked. Strange. Let me check. |
Yes, it's mongoose. update @casl/mongoose to use I'm wondering whether MongoDB v7 does optimize this query because v4 does full collection scan according to execution plan |
Postgresql optimizes queries with |
migrating to the current method of
currently using this implementation works -->
please advise |
They use exactly the same functions underneath you need to provide more context. A full fake example, otherwise I won’t be able to help |
here is an example for a findById search with permissions using NestJS
|
What is |
your docs say to do this
so when using class instance Im chaining the model to the |
What you use after dot of accessibleBy is a subject type. It should be entity name which you use in your rules definition. Otherwise there is no way for cask to know what rules to convert in your case to mongo query. That’s why you get result you get. Casl has no rules for I was thinking to add additional helper function To fix your case, you need to do |
Hi @stalniy Any chance to make this new approach work with subjects defined as classes (with modelName) (+ I do not understand how to use new Lets say i have subject accessibleBy(ability, 'read').User // doesn't work This is how internal PureAbility map looks like: |
Currently it doesn’t work with classes. But I think it’s easily fixable. I will add method
|
I am using nestjs (based on fastify) with mongoose and casl and was facing an issue with accessibleBy. |
Hi @stalniy! I lost this comment above, tried to search it several times, but no luck. I'm glad it appeared in notifications :) Is |
It’s planned. Just didn’t have time for this. |
@stalniy maybe I will try to make PR for |
@Alex0007 I've already started doing it. I understand your concern but I plan to get rid of mongoose plugins because of its typing complexity. Anyway, this will be easy to replicate in userland because it will be just a wrapper around By the way, I want to change the interface to this:
And there won't be |
draft PR is here -> #880 Need to test |
Hi! Love this package a lot! Just wondering hows the |
Before
After