Skip to content

Support for Relational Policies in CASL #1001

Closed Answered by stalniy
kenfdev asked this question in Q&A
Discussion options

You must be logged in to vote

There is no such thing in casl but you can get it with some restrictions (e.g., you won't be able to translate casl permissions into database query with built-in helpers). To do this, you can switch to lambda based permission definition or define custom $where operator.

So, the entities:

class Organization {
  constructor(ownerId) {
    this.ownerId = ownerId;
  }
}

class Issue {
  constructor(org) {
    this.org = org
  }
}

Lambda version:

const lambdaMatcher = (matchConditions) => matchConditions;

export default function defineAbilityFor(user) {
  const { can, build } = new AbilityBuilder(PureAbility);

  can('create', Organization, (org) => org.ownerId === user.id);
  can('create', I…

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@kenfdev
Comment options

@stalniy
Comment options

Answer selected by kenfdev
@stalniy
Comment options

@kenfdev
Comment options

@stalniy
Comment options

@stalniy
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants