Repository navigation
[WEB-10025] fix: require active workspace members as project lead/assignee #10214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pablohashescobar
merged 2 commits into
preview
from
fix/web-10025-project-lead-membership
Nov 11, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
apps/api/plane/tests/contract/app/test_project_lead_membership_app.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # Copyright (c) 2023-present Plane Software, Inc. and contributors | ||
| # SPDX-License-Identifier: AGPL-3.0-only | ||
| # See the LICENSE file for details. | ||
|
|
||
| from uuid import uuid4 | ||
|
|
||
| import pytest | ||
| from rest_framework import status | ||
|
|
||
| from plane.db.models import Project, ProjectMember, User, WorkspaceMember | ||
|
|
||
|
|
||
| def _user(prefix): | ||
| uid = uuid4().hex[:8] | ||
| return User.objects.create(email=f"{prefix}-{uid}@plane.so", username=f"{prefix}_{uid}") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def outsider(db): | ||
| return _user("outsider") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def inactive_member(db, workspace): | ||
| user = _user("inactive") | ||
| WorkspaceMember.objects.create(workspace=workspace, member=user, role=15, is_active=False) | ||
| return user | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def project(db, workspace, create_user): | ||
| project = Project.objects.create(name="P", identifier="PP", workspace=workspace) | ||
| ProjectMember.objects.create(project=project, member=create_user, role=20) | ||
| return project | ||
|
|
||
|
|
||
| @pytest.mark.contract | ||
| class TestProjectLeadMembership: | ||
| @pytest.mark.django_db | ||
| @pytest.mark.parametrize("field", ["project_lead", "default_assignee"]) | ||
| @pytest.mark.parametrize("who", ["outsider", "inactive_member"]) | ||
| def test_create_rejects_non_member(self, request, session_client, workspace, field, who): | ||
| user = request.getfixturevalue(who) | ||
| resp = session_client.post( | ||
| f"/api/workspaces/{workspace.slug}/projects/", | ||
| {"name": "X", "identifier": "XX", field: str(user.id)}, | ||
| format="json", | ||
| ) | ||
| assert resp.status_code == status.HTTP_400_BAD_REQUEST | ||
| assert field in resp.data | ||
| assert not Project.objects.filter(identifier="XX").exists() | ||
| assert not ProjectMember.objects.filter(member=user).exists() | ||
|
|
||
| @pytest.mark.django_db | ||
| @pytest.mark.parametrize("field", ["project_lead", "default_assignee"]) | ||
| def test_update_rejects_non_member(self, session_client, workspace, project, outsider, field): | ||
| resp = session_client.patch( | ||
| f"/api/workspaces/{workspace.slug}/projects/{project.id}/", | ||
| {field: str(outsider.id)}, | ||
| format="json", | ||
| ) | ||
| assert resp.status_code == status.HTTP_400_BAD_REQUEST | ||
| project.refresh_from_db() | ||
| assert getattr(project, f"{field}_id") is None | ||
|
|
||
| @pytest.mark.django_db | ||
| def test_create_accepts_active_member_lead(self, session_client, workspace): | ||
| lead = _user("lead") | ||
| WorkspaceMember.objects.create(workspace=workspace, member=lead, role=15) | ||
| resp = session_client.post( | ||
| f"/api/workspaces/{workspace.slug}/projects/", | ||
| {"name": "Y", "identifier": "YY", "project_lead": str(lead.id)}, | ||
| format="json", | ||
| ) | ||
| assert resp.status_code == status.HTTP_201_CREATED | ||
| assert ProjectMember.objects.filter(project_id=resp.data["id"], member=lead, role=20).exists() | ||
|
|
||
| @pytest.mark.django_db | ||
| def test_update_allows_unchanged_inactive_assignment(self, session_client, workspace, project, inactive_member): | ||
| project.project_lead = inactive_member | ||
| project.save() | ||
| resp = session_client.patch( | ||
| f"/api/workspaces/{workspace.slug}/projects/{project.id}/", | ||
| {"project_lead": str(inactive_member.id), "name": "Renamed"}, | ||
| format="json", | ||
| ) | ||
| assert resp.status_code == status.HTTP_200_OK | ||
| project.refresh_from_db() | ||
| assert project.name == "Renamed" | ||
| assert project.project_lead_id == inactive_member.id |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.