class TenantViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows Tenant users to be viewed.
"""
model = TenantUser
serializer_class = TenantUserSerializer
def list(self, request, domain):
tenants = TenantUser.objects.all()
serializer = TenantUserSerializer(tenants)
return Response(serializer.data)
def retrieve(self, request, domain, pk=None):
current_tenant_user = get_current_tenant_user()
permissions = current_tenant_user.user.get_all_permissions()
if pk == 'me' or int(pk) == current_tenant_user.id:
tenant_user = current_tenant_user
else:
if not 'core.admin' in permissions:
return Response({"detail": "You don't have permission to perform this action."},
status=status.HTTP_403_FORBIDDEN)
try:
tenant_user = TenantUser.objects.get(id=pk)
except(TenantUser.DoesNotExist, Exception, ValueError):
return Response(status=status.HTTP_404_NOT_FOUND)
permissions = tenant_user.user.get_all_permissions()
serializer = TenantUserSerializer(tenant_user)
serializer.data['is_apps_admin'] = 'core.apps' in permissions
serializer.data['is_admin'] = 'core.admin' in permissions
serializer.data['is_user'] = 'core.user' in permissions
serializer.data['is_subscribed'] = 'core.active' in permissions
serializer.data['is_sales_admin'] = 'core.sales' in permissions
serializer.data['is_marketing_admin'] = 'core.marketing' in permissions
return Response(serializer.data)
My guess get_current_tenant_user
function doesn't return user. Ensure that user returned from that function with return
or yield
statement.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.