Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Add name value to Permissions object creation in AbstractUserRole. #46

Open
avelis opened this issue Jun 9, 2016 · 2 comments

Comments

@avelis
Copy link

avelis commented Jun 9, 2016

The following line:

@classmethod
def get_or_create_permissions(cls, permission_names):

  ...
  permission, created = Permission.objects.get_or_create(content_type=user_ct,
                                                         codename=permission_name)
  ...

Ends up with not very descriptive permissions names e.g. auth | user |. The lack of name leaves the last value of the string representation of the object blank.

It would be a nice enhancement to have the ability to "Capital Case And Space" the permission_name assigned to the codename value in the Permissions object instance.

This would in turn allow for the following example permission description: auth | user | Can Edit Role

I don't have time at the moment to submit a PR that would facilitate this transformation. I am also unsure how to make this change backwards compatible with the Permissions.object.get_or_create method.

@filipeximenes
Copy link
Contributor

Hi @avelis, this does makes sense. I not sure how we would be able to do this. I imagine there could be some mapping in the Role to specify this. Something like:

class RolRole1(AbstractUserRole):
    available_permissions = {
        'permission1': {
            'default': True,
            'label': 'The permission 1'
        },
        'permission2': {
            'default': False,
            'label': 'Other name for the permission 2'
        }

    }

Is something like this what you have in mind?

@avelis
Copy link
Author

avelis commented Jun 22, 2016

@filipeximenes That works for me!

My solution (like in my mind only) was to transform the dictionary key string into a readable name value. Since camelToSnake is in this library, I had thoughts of making a "capticalCaseAndSpace" method that would perform the transformation of a dictionary key values. (e.g. capticalCaseAndSpace("manage_tickets") would return "Manage Tickets".

With that said, I your solution works just fine. 👍

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

No branches or pull requests

2 participants