I installed django-rules to my project to define rules for my actions. The list function hast no permission setting per default so you have to add them to the permission_type_map as written here but without an effect. For the other actions i am able to change the behavior if i set it to is_superuser or something else.
from django.db import models
import rules
from rules.contrib.models import RulesModel
from rules.contrib.rest_framework import AutoPermissionViewSetMixin
from base.models import BaseModel
class Company(RulesModel, BaseModel):
name = models.CharField(max_length=100)
active = models.BooleanField(default=True)
permission_type_map = {
**AutoPermissionViewSetMixin.permission_type_map,
"list": "all",
}
class Meta:
rules_permissions = {
# TODO: rules need to be defined
"add": rules.always_allow,
"view": rules.always_allow,
"delete": rules.always_allow,
"change": rules.always_allow,
"all": rules.is_superuser
}
What do i miss here?
I'm new to django-rules, but from what I can see in the docs you can only extend/change
permission_type_mapwhen using or subclassingAutoPermissionViewSetMixin. Try defining thepermission_type_mapdict in your ViewSet class instead: