mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
feat: default state for project (#264)
This commit is contained in:
parent
c6f0990605
commit
97ffdc8124
@ -75,7 +75,6 @@ class ProjectViewSet(BaseViewSet):
|
|||||||
|
|
||||||
def create(self, request, slug):
|
def create(self, request, slug):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
workspace = Workspace.objects.get(slug=slug)
|
workspace = Workspace.objects.get(slug=slug)
|
||||||
|
|
||||||
serializer = ProjectSerializer(
|
serializer = ProjectSerializer(
|
||||||
@ -96,6 +95,7 @@ class ProjectViewSet(BaseViewSet):
|
|||||||
"color": "#5e6ad2",
|
"color": "#5e6ad2",
|
||||||
"sequence": 15000,
|
"sequence": 15000,
|
||||||
"group": "backlog",
|
"group": "backlog",
|
||||||
|
"default": True,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Todo",
|
"name": "Todo",
|
||||||
@ -132,6 +132,7 @@ class ProjectViewSet(BaseViewSet):
|
|||||||
sequence=state["sequence"],
|
sequence=state["sequence"],
|
||||||
workspace=serializer.instance.workspace,
|
workspace=serializer.instance.workspace,
|
||||||
group=state["group"],
|
group=state["group"],
|
||||||
|
default=state.get("default", False),
|
||||||
)
|
)
|
||||||
for state in states
|
for state in states
|
||||||
]
|
]
|
||||||
@ -188,7 +189,7 @@ class ProjectViewSet(BaseViewSet):
|
|||||||
{"name": "The project name is already taken"},
|
{"name": "The project name is already taken"},
|
||||||
status=status.HTTP_410_GONE,
|
status=status.HTTP_410_GONE,
|
||||||
)
|
)
|
||||||
except (Project.DoesNotExist or Workspace.DoesNotExist) as e:
|
except Project.DoesNotExist or Workspace.DoesNotExist as e:
|
||||||
return Response(
|
return Response(
|
||||||
{"error": "Project does not exist"}, status=status.HTTP_404_NOT_FOUND
|
{"error": "Project does not exist"}, status=status.HTTP_404_NOT_FOUND
|
||||||
)
|
)
|
||||||
@ -206,14 +207,12 @@ class ProjectViewSet(BaseViewSet):
|
|||||||
|
|
||||||
|
|
||||||
class InviteProjectEndpoint(BaseAPIView):
|
class InviteProjectEndpoint(BaseAPIView):
|
||||||
|
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
ProjectBasePermission,
|
ProjectBasePermission,
|
||||||
]
|
]
|
||||||
|
|
||||||
def post(self, request, slug, project_id):
|
def post(self, request, slug, project_id):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
email = request.data.get("email", False)
|
email = request.data.get("email", False)
|
||||||
role = request.data.get("role", False)
|
role = request.data.get("role", False)
|
||||||
|
|
||||||
@ -287,7 +286,6 @@ class InviteProjectEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
|
|
||||||
class UserProjectInvitationsViewset(BaseViewSet):
|
class UserProjectInvitationsViewset(BaseViewSet):
|
||||||
|
|
||||||
serializer_class = ProjectMemberInviteSerializer
|
serializer_class = ProjectMemberInviteSerializer
|
||||||
model = ProjectMemberInvite
|
model = ProjectMemberInvite
|
||||||
|
|
||||||
@ -301,7 +299,6 @@ class UserProjectInvitationsViewset(BaseViewSet):
|
|||||||
|
|
||||||
def create(self, request):
|
def create(self, request):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
invitations = request.data.get("invitations")
|
invitations = request.data.get("invitations")
|
||||||
project_invitations = ProjectMemberInvite.objects.filter(
|
project_invitations = ProjectMemberInvite.objects.filter(
|
||||||
pk__in=invitations, accepted=True
|
pk__in=invitations, accepted=True
|
||||||
@ -331,7 +328,6 @@ class UserProjectInvitationsViewset(BaseViewSet):
|
|||||||
|
|
||||||
|
|
||||||
class ProjectMemberViewSet(BaseViewSet):
|
class ProjectMemberViewSet(BaseViewSet):
|
||||||
|
|
||||||
serializer_class = ProjectMemberSerializer
|
serializer_class = ProjectMemberSerializer
|
||||||
model = ProjectMember
|
model = ProjectMember
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
@ -356,14 +352,12 @@ class ProjectMemberViewSet(BaseViewSet):
|
|||||||
|
|
||||||
|
|
||||||
class AddMemberToProjectEndpoint(BaseAPIView):
|
class AddMemberToProjectEndpoint(BaseAPIView):
|
||||||
|
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
ProjectBasePermission,
|
ProjectBasePermission,
|
||||||
]
|
]
|
||||||
|
|
||||||
def post(self, request, slug, project_id):
|
def post(self, request, slug, project_id):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
member_id = request.data.get("member_id", False)
|
member_id = request.data.get("member_id", False)
|
||||||
role = request.data.get("role", False)
|
role = request.data.get("role", False)
|
||||||
|
|
||||||
@ -412,13 +406,11 @@ class AddMemberToProjectEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
|
|
||||||
class AddTeamToProjectEndpoint(BaseAPIView):
|
class AddTeamToProjectEndpoint(BaseAPIView):
|
||||||
|
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
ProjectBasePermission,
|
ProjectBasePermission,
|
||||||
]
|
]
|
||||||
|
|
||||||
def post(self, request, slug, project_id):
|
def post(self, request, slug, project_id):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
team_members = TeamMember.objects.filter(
|
team_members = TeamMember.objects.filter(
|
||||||
workspace__slug=slug, team__in=request.data.get("teams", [])
|
workspace__slug=slug, team__in=request.data.get("teams", [])
|
||||||
@ -467,7 +459,6 @@ class AddTeamToProjectEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
|
|
||||||
class ProjectMemberInvitationsViewset(BaseViewSet):
|
class ProjectMemberInvitationsViewset(BaseViewSet):
|
||||||
|
|
||||||
serializer_class = ProjectMemberInviteSerializer
|
serializer_class = ProjectMemberInviteSerializer
|
||||||
model = ProjectMemberInvite
|
model = ProjectMemberInvite
|
||||||
|
|
||||||
@ -489,7 +480,6 @@ class ProjectMemberInvitationsViewset(BaseViewSet):
|
|||||||
|
|
||||||
|
|
||||||
class ProjectMemberInviteDetailViewSet(BaseViewSet):
|
class ProjectMemberInviteDetailViewSet(BaseViewSet):
|
||||||
|
|
||||||
serializer_class = ProjectMemberInviteSerializer
|
serializer_class = ProjectMemberInviteSerializer
|
||||||
model = ProjectMemberInvite
|
model = ProjectMemberInvite
|
||||||
|
|
||||||
@ -509,14 +499,12 @@ class ProjectMemberInviteDetailViewSet(BaseViewSet):
|
|||||||
|
|
||||||
|
|
||||||
class ProjectIdentifierEndpoint(BaseAPIView):
|
class ProjectIdentifierEndpoint(BaseAPIView):
|
||||||
|
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
ProjectBasePermission,
|
ProjectBasePermission,
|
||||||
]
|
]
|
||||||
|
|
||||||
def get(self, request, slug):
|
def get(self, request, slug):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
name = request.GET.get("name", "").strip().upper()
|
name = request.GET.get("name", "").strip().upper()
|
||||||
|
|
||||||
if name == "":
|
if name == "":
|
||||||
@ -541,7 +529,6 @@ class ProjectIdentifierEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
def delete(self, request, slug):
|
def delete(self, request, slug):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
name = request.data.get("name", "").strip().upper()
|
name = request.data.get("name", "").strip().upper()
|
||||||
|
|
||||||
if name == "":
|
if name == "":
|
||||||
@ -616,7 +603,6 @@ class ProjectJoinEndpoint(BaseAPIView):
|
|||||||
class ProjectUserViewsEndpoint(BaseAPIView):
|
class ProjectUserViewsEndpoint(BaseAPIView):
|
||||||
def post(self, request, slug, project_id):
|
def post(self, request, slug, project_id):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
project = Project.objects.get(pk=project_id, workspace__slug=slug)
|
project = Project.objects.get(pk=project_id, workspace__slug=slug)
|
||||||
|
|
||||||
project_member = ProjectMember.objects.filter(
|
project_member = ProjectMember.objects.filter(
|
||||||
@ -655,7 +641,6 @@ class ProjectUserViewsEndpoint(BaseAPIView):
|
|||||||
class ProjectMemberUserEndpoint(BaseAPIView):
|
class ProjectMemberUserEndpoint(BaseAPIView):
|
||||||
def get(self, request, slug, project_id):
|
def get(self, request, slug, project_id):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
project_member = ProjectMember.objects.get(
|
project_member = ProjectMember.objects.get(
|
||||||
project_id=project_id, workspace__slug=slug, member=request.user
|
project_id=project_id, workspace__slug=slug, member=request.user
|
||||||
)
|
)
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
# Third party imports
|
||||||
|
from rest_framework import status
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from . import BaseViewSet
|
from . import BaseViewSet
|
||||||
from plane.api.serializers import StateSerializer
|
from plane.api.serializers import StateSerializer
|
||||||
@ -6,7 +10,6 @@ from plane.db.models import State
|
|||||||
|
|
||||||
|
|
||||||
class StateViewSet(BaseViewSet):
|
class StateViewSet(BaseViewSet):
|
||||||
|
|
||||||
serializer_class = StateSerializer
|
serializer_class = StateSerializer
|
||||||
model = State
|
model = State
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
@ -27,3 +30,19 @@ class StateViewSet(BaseViewSet):
|
|||||||
.select_related("workspace")
|
.select_related("workspace")
|
||||||
.distinct()
|
.distinct()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def destroy(self, request, slug, project_id, pk):
|
||||||
|
try:
|
||||||
|
state = State.objects.get(
|
||||||
|
pk=pk, project_id=project_id, workspace__slug=slug
|
||||||
|
)
|
||||||
|
|
||||||
|
if state.default:
|
||||||
|
return Response(
|
||||||
|
{"error": "Default state cannot be deleted"}, status=False
|
||||||
|
)
|
||||||
|
|
||||||
|
state.delete()
|
||||||
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
except State.DoesNotExist:
|
||||||
|
return Response({"error": "State does not exists"}, status=status.HTTP_404)
|
||||||
|
@ -83,9 +83,14 @@ class Issue(ProjectBaseModel):
|
|||||||
try:
|
try:
|
||||||
from plane.db.models import State
|
from plane.db.models import State
|
||||||
|
|
||||||
self.state, created = State.objects.get_or_create(
|
default_state = State.objects.filter(
|
||||||
project=self.project, name="Backlog"
|
project=self.project, default=True
|
||||||
)
|
).first()
|
||||||
|
# if there is no default state assign any random state
|
||||||
|
if default_state is None:
|
||||||
|
self.state = State.objects.filter(project=self.project).first()
|
||||||
|
else:
|
||||||
|
self.state = default_state
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -23,6 +23,7 @@ class State(ProjectBaseModel):
|
|||||||
default="backlog",
|
default="backlog",
|
||||||
max_length=20,
|
max_length=20,
|
||||||
)
|
)
|
||||||
|
default = models.BooleanField(default=False)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Return name of the state"""
|
"""Return name of the state"""
|
||||||
|
Loading…
Reference in New Issue
Block a user