Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Support setting error messages from ACL #38

Open
JaneJeon opened this issue Oct 20, 2019 · 5 comments
Open

Support setting error messages from ACL #38

JaneJeon opened this issue Oct 20, 2019 · 5 comments

Comments

@JaneJeon
Copy link
Contributor

Hi, so I've dug thru the source code and found that the only "attributes" of a grant allowed are the role, resource, action, attributes, and condition.

However, I'd like to specify the error message when defining the ACL. I know this isn't possible now, but could you please add this feature? Thank you!

@koladilip
Copy link
Contributor

Can you please describe more on how exactly this feature should work?

@JaneJeon
Copy link
Contributor Author

Sure thing, so right now I'm defining my ACL like this in JSON and instantiating the role-acl instance like this (very simple example - basically says a user can only edit his own profile, and they can't edit the id or the role):

{
  "user": {
    "grants": [
      {
        "resource": "User",
        "action": "update",
        "attributes": [
          "*",
          "!id",
          "!role"
        ],
        "condition": {
          "Fn": "EQUALS",
          "args": {
            "id": "$.id"
          }
        }
      }
    ]
  }
}

At the moment, I can't say "your request failed because you tried to edit someone else's profile" or "your request failed because you tried to edit your user id". For that matter, I can't even differentiate between those two failure points.

So it would be nice if I could do something like this:

{
  "user": {
    "grants": [
      {
        "resource": "User",
        "action": "update",
        "attributes": [
          "*",
          "!id",
          "!role"
        ],
        "condition": {
          "Fn": "EQUALS",
          "args": {
            "id": "$.id"
          },
          "message": "You can only edit your own profile!"
        }
      }
    ]
  }
}

And then when I check an invalid request (say I violate both the attributes and the condition) with the ACL, it returns a list of error messages as a property, maybe like

["Cannot edit id or role", "You can only edit your own profile!"]

@koladilip
Copy link
Contributor

koladilip commented Oct 21, 2019 via email

@koladilip
Copy link
Contributor

Any updates?

@JaneJeon
Copy link
Contributor Author

@koladilip sorry, I've been busy with work (who isn't haha) but I was basically thinking of something akin to this: https://stalniy.github.io/casl/abilities/2017/07/20/define-abilities.html#forbidden-reasons

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

No branches or pull requests

2 participants