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

Allow access to AbilityFactory #198

Closed
andreialecu opened this issue Dec 13, 2021 · 5 comments · Fixed by #535
Closed

Allow access to AbilityFactory #198

andreialecu opened this issue Dec 13, 2021 · 5 comments · Fixed by #535
Labels
Milestone

Comments

@andreialecu
Copy link
Contributor

andreialecu commented Dec 13, 2021

I'd like to be able to use packRules to share permissions with an Angular front end app.

The following hack works:

	const user = userProxy?.getFromRequest();
    if (user) {
      const abilityFactory: AbilityFactory = (this.accessService as any)
        .abilityFactory;
      console.log(packRules(abilityFactory.createForUser(user).rules));

Where this.accessService basically hijacks this private field from AccessService:

constructor(private abilityFactory: AbilityFactory) {}

Exporting AbilityFactory, or an API to get to the underlying casl abilities would be great.

@liquidautumn
Copy link
Collaborator

Yes, this is unacceptable. I'm thinking about handling this specific use case, as it should be quite common. ie this.accessService.getAbilitiesForUser(user, { pack: true }). Combined with #202 it'll make lib client code much cleaner.

@github-actions
Copy link

github-actions bot commented Dec 2, 2022

🎉 This issue has been resolved in version 1.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@kinglouie
Copy link

@liquidautumn I'm trying to get all rules defined across all modules in my auth module to return the rules on my login route, how do I use this.accessService.getAbility(user) to get them?

As far as I understand when I want to use accessService in my auth module, I need to import CaslModule.forFeature({ permissions}) but because of the expected permissions parameter I do not get all defined permissions.

@Hatzl
Copy link

Hatzl commented Jul 15, 2024

@kinglouie did you find any solution for that?

@kinglouie
Copy link

@Hatzl unfortunately not

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

Successfully merging a pull request may close this issue.

4 participants