Skip to content

How to handle lists with Casl ? #987

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

You must be logged in to vote

I wanted to have a particular example of eventual aggregated root.

If eventually you get currently logged in user as:

const user = {
  id: ...,
  permissions: [
    { workspaceId: ...., role: 'admin' },
    { workspaceId: ..., role: 'manager' }
  ]
}

Then you can define this permissions:

can('List', 'Workspace', { id: { $in: user.permissions.map(p => p.workspaceId) } }); // read

// assume if user is an admin of Workspace then he can update it, then do this:
const updatableWorkspaceIds = user.permissions.filter(p => p.role === 'admin').map(p => p.workspaceId);
if (updatableWorkspaceIds.length) can('Update', 'Workspace', { id: { $in: updatableWorkspaceIds  } })

or you can have permissions …

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@jlefebvre1997
Comment options

@stalniy
Comment options

Answer selected by jlefebvre1997
@jlefebvre1997
Comment options

@jlefebvre1997
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