Woocommerce and some fixes
This commit is contained in:
@@ -1,7 +1,25 @@
|
||||
from rest_framework import permissions
|
||||
|
||||
|
||||
class IsCreator(permissions.BasePermission):
|
||||
class IsCompanyOwner(permissions.BasePermission):
|
||||
"""
|
||||
Grant permission if request.user.company same as obj.id
|
||||
"""
|
||||
|
||||
def has_object_permission(self, request, view, obj):
|
||||
if obj is not None:
|
||||
# allow if authenticated and method is safe
|
||||
if request.method in permissions.SAFE_METHODS:
|
||||
return True
|
||||
|
||||
# admins always have permission
|
||||
if request.user.is_staff is True:
|
||||
return True
|
||||
# permission if user is the object's creator
|
||||
return obj == request.user.company
|
||||
return False
|
||||
|
||||
class IsProductOwner(permissions.BasePermission):
|
||||
"""
|
||||
Grant permission if request.user same as obj.creator
|
||||
"""
|
||||
@@ -16,10 +34,9 @@ class IsCreator(permissions.BasePermission):
|
||||
if request.user.is_staff is True:
|
||||
return True
|
||||
# permission if user is the object's creator
|
||||
return obj.creator == request.user
|
||||
return obj.company == request.user.company
|
||||
return False
|
||||
|
||||
|
||||
class IsStaff(permissions.BasePermission):
|
||||
"""
|
||||
Grant permission if request.user.is_staff is True
|
||||
|
||||
Reference in New Issue
Block a user