-
Notifications
You must be signed in to change notification settings - Fork 31
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
Feauture request: add field restricting access #254
Comments
Do you have any thoughts on how it can be implemented? I was thinking about this feature quite a lot, there is issue #6 about it, but I can't come up with implementation without significant amount of magic involved. It'd require post-request interceptor to look into response and figure out where in response json subject is positioned, then nullify restricted fields. Or it would be implemented at orm level to avoid selecting unneeded fields or maybe both. Any input appreciated, I'm warming up for biggerish update to this lib and this feature indeed is top priority. |
I am thinking about the implementation and I have only two possible options, but I have not tested any: // https://casl.js.org/v5/en/guide/restricting-fields
const ARTICLE_FIELDS = ['title', 'description', 'authorId', 'published'];
const options = { fieldsFrom: rule => rule.fields || ARTICLE_FIELDS};
const fields = permittedFieldsOf(ability, 'update', ownArticle, options);
const rawArticle = pick(reqBody, fields); // { title: 'CASL', description: 'powerful' } The second one is to use But for now, these are just speculations. P.S. cannot('update', 'ArticleInputDTO', { published: { $exists: true } })
cannot('update', 'ArticleInputDTO', { comment: { $exists: true } })
...
const input: ArticleInputDTO = { title: 'Some title', published: new Date() }
can('update', ArticleInputDTO) // false they filter incoming input by existing fields |
Any updates? |
Would love to see this functionality. One of the big benefits with CASL is that it implements attribute based access control, so it's a shame that this otherwise amazing package is missing it. |
How's the progress? Is there any way to make it move faster? Like code contribution and test etc. |
@liquidautumn wondering if there is an update for this. I am actively looking at this and was wondering if there is a plan on how to implement it? I would like to see it get get a PR created |
hi @liquidautumn @chrber04 i recently had to implement support for restricting fields on top of throwing forbidden error to support custom messages. if you guys think that this makes sense i could probobly create a PR however i am not sure how to support
|
CASL supports restricting access to fields:
https://casl.js.org/v5/en/guide/restricting-fields
But, as I see it, there is no functionality for accessService:
https://github.com/getjerry/nest-casl/blob/master/src/access.service.ts#L18
It would be great to implement that a feature.
The text was updated successfully, but these errors were encountered: