Repository navigation
Roles and Permissions - #1018
Conversation
- Ref: https://github.com/Microdisseny/django-groupadmin-users - Adds ability to edit users within a particular group from the group admin page!
(doesn't do anything yet)
- ALL models must be covered by rulesets - Added a RULESET_IGNORE list for models we do not want permissions for
- Only runs when the group is changed - Does not add permissions if they already exist - Does not remove permissions if they do not exist
- Does not actually *do* anything any more as the RuleSet approach overrides it anyway
|
@eeintech please let me know what you think of this implementation. I think it's pretty clean, but I might have missed something! 👍 |
eeintech
left a comment
There was a problem hiding this comment.
So far what I see looks nice, however I don't see the option to dive down to the Model level for managing permissions inside the Admin interface, would be handy to still have the choice to do so, no?
| ], | ||
| 'purchase_order': [ | ||
| 'company_company', | ||
| 'part_supplierpart', |
There was a problem hiding this comment.
SupplierPart and SupplierPartBreak are models of the Company app, not the Part app.
There was a problem hiding this comment.
And the unit testing has been setup to detect any of the following cases
- A ruleset references a permission that does not exist
- An existing permission is not referenced by any ruleset
There was a problem hiding this comment.
@SchrodingersGat I was not able to create a new Group after pulling your branch, I hit the ContentType.DoesNotExist error...
There was a problem hiding this comment.
You're right, it does not actually use the table name, it does use the app name.
So company_supplierpart and company_supplierpricebreak are correct here.
I'm just writing some better unit testing to check for this. I'll push it momentarily
|
|
||
| (permission_name, model) = perm.split('_') | ||
|
|
||
| content_type = ContentType.objects.get(app_label=app, model=model) |
There was a problem hiding this comment.
To avoid Django to error for any mislabeled app and model (human mistakes can happen), I suggest replacing with:
try:
content_type = ContentType.objects.get(app_label=app, model=model)
permission = Permission.objects.get(content_type=content_type, codename=perm)
except ContentType.DoesNotExist:
permission = None
group.permissions.add(permission) does not error out if None object is passed.
Better yet would be to report this to the user in a "nice" way.
Originally I had thought this was a nice idea, but there is an issue. The new RuleSet approach is pretty "heavy handed" with the permission control - every time you save a group, the permisions all get updated on the group. I couldn't think of a clean way to still allow fine-grained control of the permissions (and this is the antithesis of what we are trying to achieve by simplifying the permissions in the first place). I think that the new ruleset approach is sufficient. Permissions can also be set individually for users if need be. What do you think? |
Umm I see, this would require a way to log individual users overwrites on each permission and add extra logic and complexity... I guess you are right, better abstract this layer completely and move forward with the rulesets. |
- Uses the app_model name, *NOT* the name of the database table - Adds extra tests to ensure that permissions get assigned and removed correctly
It's a good start - if in the future we find this approach is not sufficient for some nominal use case, we can always re-address it then... |
|
@eeintech please pull down the latest commit and see if it works for you now |
| model=model | ||
| ) | ||
|
|
||
| def __str__(self): |
There was a problem hiding this comment.
Replace with something like?
def __str__(self):
""" Ruleset string representation """
return f'{self.name} | v: {self.can_view} | a: {self.can_add} | ' \
f'c: {self.can_change} | d: {self.can_delete}'
There was a problem hiding this comment.
Gasp, this actually is captured in the admin form... Can put this on backburner / for debug only
|
@SchrodingersGat I noticed that It probably was the case with #1016 too... I was testing your latest changes (with |
|
Does it work better now that |
Yes it does 👍 |
|
Great! Now we'll need to add some documentation about this great new feature :) |

Closes #1018 (comment)
This PR augments the great work done by @eeintech in #1016
The default django permission management system is pretty complex to use, and while the fine-grained permissions control can be useful, we really want a "role" or "ruleset" approach.
This PR adds the RuleSet concept which maps to a particular group. The following table is provided in the admin page for each group:
Each row covers a particular set of database models, and each column determines the permission type for that ruleset.
Future work will be required to actually make use of the per-model permissions
(All this is pretty straight forward really)