django-rules icon indicating copy to clipboard operation
django-rules copied to clipboard

Enhancement - Human readable name for rules/permissions

Open sergei-maertens opened this issue 6 years ago • 3 comments

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!

sergei-maertens avatar Jul 18 '17 12:07 sergei-maertens

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 :)

dfunckt avatar Jul 18 '17 13:07 dfunckt

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

sergei-maertens avatar Jul 18 '17 13:07 sergei-maertens

Resolved in #154

Would love feedback.

jacklinke avatar Nov 28 '21 21:11 jacklinke