jazzband / django-auditlog

A Django app that keeps a log of changes made to an object.
MIT License
1.15k stars 414 forks source link

Why does audit log creates duplicate permissions for single LogEntry model? #660

Closed mohsiniscoding closed 3 months ago

mohsiniscoding commented 3 months ago

I've added the django auditlog to my project. I've different user groups with is_staff=True. I want to allow some users to only view LogEntries table and detail page (view_logentry permission). when I add permission view_logentry to my Group it shows this error:

CommandError: Unable to load data: get() returned more than one Permission -- it returned 2!

It's because there are multiple permission for the same LogEntry model, check the image below: image

To properly add the permissions I'm using this approach:

for permission in Permission.objects.filter(codename='view_logentry'):
    if permission.natural_key()[1] == 'auditlog':
        group.permissions.add(permission)

But I still want to know if there is an issue with my implementation or this result is expected duplicate permission codename) Thanks!

hramezani commented 3 months ago

TheAdministration | log entry| ... is for django admin app LogEntry model which is a different model than auditlog.LogEntry. I added both view permissions from both apps and it works.