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

Specify client side data model #200

Closed
Victordmdb opened this issue Jun 6, 2019 · 2 comments
Closed

Specify client side data model #200

Victordmdb opened this issue Jun 6, 2019 · 2 comments
Labels

Comments

@Victordmdb
Copy link

Victordmdb commented Jun 6, 2019

Currently, the ability package expects the data model to be structure as mongoose structure. But it would be practical if it were possible to specify the data fields (ie _id, name, ownerId...), then in another field specify which data structure it's referring to.

Or perhaps use an "alias" field in the data context in react for example.

My current workaround on the casl-react lib is to augment the data passed to the Can component:

<Can I="update" this={{...data, constructor: {name : "MyStruc" }}} > {...}</Can>

But this isn't very elegant. Or am I missing something.

@stalniy
Copy link
Owner

stalniy commented Jun 7, 2019

what you want to do it to change subjectName option. This function allows to determine subject name based on its instance. More info https://stalniy.github.io/casl/abilities/2017/07/21/check-abilities.html#instance-checks and check this example https://github.com/stalniy/casl-react-example/blob/master/src/config/ability.js#L6

@Victordmdb
Copy link
Author

@stalniy That work perfectly, you already thought of everything 👍

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

No branches or pull requests

2 participants