feat(projects): support members and align rate payloads

This commit is contained in:
2026-04-24 22:20:57 +03:30
parent a44995017b
commit e7de587f59
5 changed files with 129 additions and 65 deletions

View File

@@ -1,16 +1,16 @@
from rest_framework.exceptions import ValidationError
from apps.projects.models import ProjectMembership
def add_project_member(project, user, role):
def add_project_member(project, user_id, role):
"""
Adds a user to a project. Ensures no duplicate active memberships exist.
"""
if ProjectMembership.objects.filter(project=project, user=user, is_deleted=False).exists():
if ProjectMembership.objects.filter(project=project, user_id=user_id, is_deleted=False).exists():
raise ValidationError({"user_id": "This user is already a member of the project."})
return ProjectMembership.objects.create(
project=project,
user=user,
user_id=user_id,
role=role,
is_active=True
)