Skip to content

Commit

Permalink
chore: project active filter (makeplane#3971)
Browse files Browse the repository at this point in the history
  • Loading branch information
NarayanBavisetti authored Mar 14, 2024
1 parent 0bc4b6c commit 42b524b
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions apiserver/plane/app/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ def get_queryset(self):
.get_queryset()
.filter(workspace__slug=self.kwargs.get("slug"))
.filter(
Q(project_projectmember__member=self.request.user)
Q(
project_projectmember__member=self.request.user,
project_projectmember__is_active=True,
)
| Q(network=2)
)
.select_related(
Expand Down Expand Up @@ -173,10 +176,7 @@ def list(self, request, slug):
for field in request.GET.get("fields", "").split(",")
if field
]
projects = (
self.get_queryset()
.order_by("sort_order", "name")
)
projects = self.get_queryset().order_by("sort_order", "name")
if request.GET.get("per_page", False) and request.GET.get(
"cursor", False
):
Expand Down Expand Up @@ -576,9 +576,11 @@ def post(self, request, slug, project_id, pk):
_ = WorkspaceMember.objects.create(
workspace_id=project_invite.workspace_id,
member=user,
role=15
if project_invite.role >= 15
else project_invite.role,
role=(
15
if project_invite.role >= 15
else project_invite.role
),
)
else:
# Else make him active
Expand Down Expand Up @@ -685,9 +687,14 @@ def create(self, request, slug, project_id):
)

bulk_project_members = []
member_roles = {member.get("member_id"): member.get("role") for member in members}
member_roles = {
member.get("member_id"): member.get("role") for member in members
}
# Update roles in the members array based on the member_roles dictionary
for project_member in ProjectMember.objects.filter(project_id=project_id, member_id__in=[member.get("member_id") for member in members]):
for project_member in ProjectMember.objects.filter(
project_id=project_id,
member_id__in=[member.get("member_id") for member in members],
):
project_member.role = member_roles[str(project_member.member_id)]
project_member.is_active = True
bulk_project_members.append(project_member)
Expand All @@ -710,9 +717,9 @@ def create(self, request, slug, project_id):
role=member.get("role", 10),
project_id=project_id,
workspace_id=project.workspace_id,
sort_order=sort_order[0] - 10000
if len(sort_order)
else 65535,
sort_order=(
sort_order[0] - 10000 if len(sort_order) else 65535
),
)
)
bulk_issue_props.append(
Expand All @@ -733,7 +740,10 @@ def create(self, request, slug, project_id):
bulk_issue_props, batch_size=10, ignore_conflicts=True
)

project_members = ProjectMember.objects.filter(project_id=project_id, member_id__in=[member.get("member_id") for member in members])
project_members = ProjectMember.objects.filter(
project_id=project_id,
member_id__in=[member.get("member_id") for member in members],
)
serializer = ProjectMemberRoleSerializer(project_members, many=True)
return Response(serializer.data, status=status.HTTP_201_CREATED)

Expand Down

0 comments on commit 42b524b

Please sign in to comment.