dfunckt / django-rules

Awesome Django authorization, without the database
MIT License
1.86k stars 148 forks source link

Enhancement - Human readable name for rules/permissions #59

Open sergei-maertens opened 7 years ago

sergei-maertens commented 7 years ago

Hi, I've been a fan of this lib for a long time, so now I'm implementing it on a bigger scale than usual in a project and ran into an enhancement.

The context is that we want to connect some custom rules/permissions with roles, and build an UI around this. We like the format of appname:permission_name to name a permission, but this is not very readable for the end-user assigning permissions to roles. Similar to Django's permission system, we'd like to be able to provide a human readable name to the permission.

API wise, I suggest extending the API from

rules.add_perm('appname:permission_name', some_predicate)

to

rules.add_perm('appname:permission_name', some_predicate, verbose_name=_("A translatable string") )

Looking at the source code, this would make the RuleSet a bit more complex object than a simple dict, a single rule within a RuleSet would probably need to be an object itself where the verbose_name is also kept.

Thoughts? Comments? I'm willing to contribute on this with a PR!

dfunckt commented 7 years ago

This sounds great to me and it's definitely desirable given Django's native perms also have this ability. I also like the API. Only question is what verbose_name should be if not specified -- should it be automatically set to the rule name or not?

PR implementing this is very welcome :)

sergei-maertens commented 7 years ago

Defaulting to name seems sane to me, as currently that's also what's returned in repr

jacklinke commented 2 years ago

Resolved in #154

Would love feedback.