Skip to content

Throw error when object is not defined and can manage all #946

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

You must be logged in to vote

Hey!
Thanks a lot for the help.
I actually found another solution for my problem:

can("manage", "all")
// "null" is a special subject created to handle null cases
cannot("manage", "null")

// Later
ForbiddenError.from(ability).throwUnlessCan(
    action,
    subject( resource ? model : NULL_MODEL_NAME, resource ?? {}),
    field
)

This way a user can do everything as long as the object exists.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by RenaudAubert
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