feat(clients): add clients app basic structure and endpoints
This commit is contained in:
22
apps/clients/api/permissions.py
Normal file
22
apps/clients/api/permissions.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from rest_framework import permissions
|
||||
from apps.workspaces.models import WorkspaceMembership
|
||||
|
||||
|
||||
class IsClientWorkspaceMember(permissions.BasePermission):
|
||||
"""
|
||||
Allows access only to users who are active members of the workspace associated with the client.
|
||||
"""
|
||||
message = "شما عضو فضای کاری این مشتری نیستید."
|
||||
|
||||
def has_object_permission(self, request, view, obj):
|
||||
"""
|
||||
Validates if the user exists in the workspace memberships for the requested client's workspace.
|
||||
"""
|
||||
if not request.user.is_authenticated:
|
||||
return False
|
||||
|
||||
return WorkspaceMembership.objects.filter(
|
||||
workspace=obj.workspace,
|
||||
user=request.user,
|
||||
is_active=True
|
||||
).exists()
|
||||
Reference in New Issue
Block a user