forked from github/plane
Compare commits
72 Commits
preview
...
chore/inst
Author | SHA1 | Date | |
---|---|---|---|
|
827a00c1d3 | ||
|
784be47e91 | ||
|
0fdd9c28bf | ||
|
644b06749b | ||
|
dd8c7a7487 | ||
|
e6a1f34713 | ||
|
1dff6b63f8 | ||
|
59dbbb29cd | ||
|
6cb3939835 | ||
|
021c0675b7 | ||
|
67000892e5 | ||
|
3df4794e77 | ||
|
42ccd1de58 | ||
|
c8c89007c0 | ||
|
4cf3e69e22 | ||
|
fb1f65c2c1 | ||
|
d91b4e6fa1 | ||
|
561223ea71 | ||
|
982eba0bd1 | ||
|
7aaf840fb1 | ||
|
15927c9cae | ||
|
d46d70fcd5 | ||
|
de581102e3 | ||
|
b903126e5a | ||
|
f44f70168f | ||
|
3c10f00b04 | ||
|
f1de05e4de | ||
|
61d4e2e016 | ||
|
c1eb5055e5 | ||
|
8d942e28da | ||
|
f7461af3f5 | ||
|
29f3e02adc | ||
|
9a704458b3 | ||
|
668dfd2e38 | ||
|
3b3f94ed03 | ||
|
e945aa9b71 | ||
|
6595a387d0 | ||
|
8839e42dc0 | ||
|
9db6312081 | ||
|
779ef2a4aa | ||
|
51e17643a2 | ||
|
4c2074b6ff | ||
|
c9ffc9465f | ||
|
2b6c489513 | ||
|
0c63f21718 | ||
|
a987df38f4 | ||
|
878707f444 | ||
|
9369ee5008 | ||
|
0a88db975a | ||
|
dd60dec887 | ||
|
0c1097592e | ||
|
bed66235f2 | ||
|
26b1e9d5f1 | ||
|
79347ec62b | ||
|
7b965179d8 | ||
|
fc51ffc589 | ||
|
96f6e37cc5 | ||
|
29774ce84a | ||
|
8cbe9c26fc | ||
|
7f42566207 | ||
|
b60237b676 | ||
|
1fe09d369f | ||
|
b7757c6b1a | ||
|
1a25bacce1 | ||
|
6797df239d | ||
|
43e7c10eb7 | ||
|
bdc9c9c2a8 | ||
|
f0c72bf249 | ||
|
a8904bfc48 | ||
|
b31041726b | ||
|
e6f947ad90 | ||
|
7963993171 |
10
.env.example
10
.env.example
@ -21,15 +21,15 @@ AWS_S3_BUCKET_NAME="uploads"
|
|||||||
FILE_SIZE_LIMIT=5242880
|
FILE_SIZE_LIMIT=5242880
|
||||||
|
|
||||||
# GPT settings
|
# GPT settings
|
||||||
OPENAI_API_BASE="https://api.openai.com/v1" # change if using a custom endpoint
|
OPENAI_API_BASE="https://api.openai.com/v1" # deprecated
|
||||||
OPENAI_API_KEY="sk-" # add your openai key here
|
OPENAI_API_KEY="sk-" # deprecated
|
||||||
GPT_ENGINE="gpt-3.5-turbo" # use "gpt-4" if you have access
|
GPT_ENGINE="gpt-3.5-turbo" # deprecated
|
||||||
|
|
||||||
# Settings related to Docker
|
# Settings related to Docker
|
||||||
DOCKERIZED=1
|
DOCKERIZED=1 # deprecated
|
||||||
|
|
||||||
# set to 1 If using the pre-configured minio setup
|
# set to 1 If using the pre-configured minio setup
|
||||||
USE_MINIO=1
|
USE_MINIO=1
|
||||||
|
|
||||||
# Nginx Configuration
|
# Nginx Configuration
|
||||||
NGINX_PORT=80
|
NGINX_PORT=80
|
||||||
|
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -79,3 +79,4 @@ pnpm-workspace.yaml
|
|||||||
tmp/
|
tmp/
|
||||||
## packages
|
## packages
|
||||||
dist
|
dist
|
||||||
|
.temp/
|
||||||
|
@ -43,8 +43,6 @@ FROM python:3.11.1-alpine3.17 AS backend
|
|||||||
ENV PYTHONDONTWRITEBYTECODE 1
|
ENV PYTHONDONTWRITEBYTECODE 1
|
||||||
ENV PYTHONUNBUFFERED 1
|
ENV PYTHONUNBUFFERED 1
|
||||||
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
|
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
|
||||||
ENV DJANGO_SETTINGS_MODULE plane.settings.production
|
|
||||||
ENV DOCKERIZED 1
|
|
||||||
|
|
||||||
WORKDIR /code
|
WORKDIR /code
|
||||||
|
|
||||||
|
24
ENV_SETUP.md
24
ENV_SETUP.md
@ -31,12 +31,10 @@ AWS_S3_BUCKET_NAME="uploads"
|
|||||||
FILE_SIZE_LIMIT=5242880
|
FILE_SIZE_LIMIT=5242880
|
||||||
|
|
||||||
# GPT settings
|
# GPT settings
|
||||||
OPENAI_API_BASE="https://api.openai.com/v1" # change if using a custom endpoint
|
OPENAI_API_BASE="https://api.openai.com/v1" # deprecated
|
||||||
OPENAI_API_KEY="sk-" # add your openai key here
|
OPENAI_API_KEY="sk-" # deprecated
|
||||||
GPT_ENGINE="gpt-3.5-turbo" # use "gpt-4" if you have access
|
GPT_ENGINE="gpt-3.5-turbo" # deprecated
|
||||||
|
|
||||||
# Settings related to Docker
|
|
||||||
DOCKERIZED=1
|
|
||||||
# set to 1 If using the pre-configured minio setup
|
# set to 1 If using the pre-configured minio setup
|
||||||
USE_MINIO=1
|
USE_MINIO=1
|
||||||
|
|
||||||
@ -78,7 +76,7 @@ NEXT_PUBLIC_ENABLE_OAUTH=0
|
|||||||
# Backend
|
# Backend
|
||||||
# Debug value for api server use it as 0 for production use
|
# Debug value for api server use it as 0 for production use
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
DJANGO_SETTINGS_MODULE="plane.settings.selfhosted"
|
DJANGO_SETTINGS_MODULE="plane.settings.selfhosted" # deprecated
|
||||||
|
|
||||||
# Error logs
|
# Error logs
|
||||||
SENTRY_DSN=""
|
SENTRY_DSN=""
|
||||||
@ -115,24 +113,22 @@ AWS_S3_BUCKET_NAME="uploads"
|
|||||||
FILE_SIZE_LIMIT=5242880
|
FILE_SIZE_LIMIT=5242880
|
||||||
|
|
||||||
# GPT settings
|
# GPT settings
|
||||||
OPENAI_API_BASE="https://api.openai.com/v1" # change if using a custom endpoint
|
OPENAI_API_BASE="https://api.openai.com/v1" # deprecated
|
||||||
OPENAI_API_KEY="sk-" # add your openai key here
|
OPENAI_API_KEY="sk-" # deprecated
|
||||||
GPT_ENGINE="gpt-3.5-turbo" # use "gpt-4" if you have access
|
GPT_ENGINE="gpt-3.5-turbo" # deprecated
|
||||||
|
|
||||||
|
# Settings related to Docker
|
||||||
|
DOCKERIZED=1 # Deprecated
|
||||||
|
|
||||||
# Github
|
# Github
|
||||||
GITHUB_CLIENT_SECRET="" # For fetching release notes
|
GITHUB_CLIENT_SECRET="" # For fetching release notes
|
||||||
|
|
||||||
# Settings related to Docker
|
|
||||||
DOCKERIZED=1
|
|
||||||
# set to 1 If using the pre-configured minio setup
|
# set to 1 If using the pre-configured minio setup
|
||||||
USE_MINIO=1
|
USE_MINIO=1
|
||||||
|
|
||||||
# Nginx Configuration
|
# Nginx Configuration
|
||||||
NGINX_PORT=80
|
NGINX_PORT=80
|
||||||
|
|
||||||
# Default Creds
|
|
||||||
DEFAULT_EMAIL="captain@plane.so"
|
|
||||||
DEFAULT_PASSWORD="password123"
|
|
||||||
|
|
||||||
# SignUps
|
# SignUps
|
||||||
ENABLE_SIGNUP="1"
|
ENABLE_SIGNUP="1"
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
# Backend
|
# Backend
|
||||||
# Debug value for api server use it as 0 for production use
|
# Debug value for api server use it as 0 for production use
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
DJANGO_SETTINGS_MODULE="plane.settings.production"
|
CORS_ALLOWED_ORIGINS=""
|
||||||
|
|
||||||
# Error logs
|
# Error logs
|
||||||
SENTRY_DSN=""
|
SENTRY_DSN=""
|
||||||
|
SENTRY_ENVIRONMENT="development"
|
||||||
|
|
||||||
# Database Settings
|
# Database Settings
|
||||||
PGUSER="plane"
|
PGUSER="plane"
|
||||||
@ -18,15 +19,6 @@ REDIS_HOST="plane-redis"
|
|||||||
REDIS_PORT="6379"
|
REDIS_PORT="6379"
|
||||||
REDIS_URL="redis://${REDIS_HOST}:6379/"
|
REDIS_URL="redis://${REDIS_HOST}:6379/"
|
||||||
|
|
||||||
# Email Settings
|
|
||||||
EMAIL_HOST=""
|
|
||||||
EMAIL_HOST_USER=""
|
|
||||||
EMAIL_HOST_PASSWORD=""
|
|
||||||
EMAIL_PORT=587
|
|
||||||
EMAIL_FROM="Team Plane <team@mailer.plane.so>"
|
|
||||||
EMAIL_USE_TLS="1"
|
|
||||||
EMAIL_USE_SSL="0"
|
|
||||||
|
|
||||||
# AWS Settings
|
# AWS Settings
|
||||||
AWS_REGION=""
|
AWS_REGION=""
|
||||||
AWS_ACCESS_KEY_ID="access-key"
|
AWS_ACCESS_KEY_ID="access-key"
|
||||||
@ -38,24 +30,22 @@ AWS_S3_BUCKET_NAME="uploads"
|
|||||||
FILE_SIZE_LIMIT=5242880
|
FILE_SIZE_LIMIT=5242880
|
||||||
|
|
||||||
# GPT settings
|
# GPT settings
|
||||||
OPENAI_API_BASE="https://api.openai.com/v1" # change if using a custom endpoint
|
OPENAI_API_BASE="https://api.openai.com/v1" # deprecated
|
||||||
OPENAI_API_KEY="sk-" # add your openai key here
|
OPENAI_API_KEY="sk-" # deprecated
|
||||||
GPT_ENGINE="gpt-3.5-turbo" # use "gpt-4" if you have access
|
GPT_ENGINE="gpt-3.5-turbo" # deprecated
|
||||||
|
|
||||||
# Github
|
# Github
|
||||||
GITHUB_CLIENT_SECRET="" # For fetching release notes
|
GITHUB_CLIENT_SECRET="" # For fetching release notes
|
||||||
|
|
||||||
# Settings related to Docker
|
# Settings related to Docker
|
||||||
DOCKERIZED=1
|
DOCKERIZED=1 # deprecated
|
||||||
|
|
||||||
# set to 1 If using the pre-configured minio setup
|
# set to 1 If using the pre-configured minio setup
|
||||||
USE_MINIO=1
|
USE_MINIO=1
|
||||||
|
|
||||||
# Nginx Configuration
|
# Nginx Configuration
|
||||||
NGINX_PORT=80
|
NGINX_PORT=80
|
||||||
|
|
||||||
# Default Creds
|
|
||||||
DEFAULT_EMAIL="captain@plane.so"
|
|
||||||
DEFAULT_PASSWORD="password123"
|
|
||||||
|
|
||||||
# SignUps
|
# SignUps
|
||||||
ENABLE_SIGNUP="1"
|
ENABLE_SIGNUP="1"
|
||||||
@ -70,6 +60,6 @@ ENABLE_MAGIC_LINK_LOGIN="0"
|
|||||||
# Email redirections and minio domain settings
|
# Email redirections and minio domain settings
|
||||||
WEB_URL="http://localhost"
|
WEB_URL="http://localhost"
|
||||||
|
|
||||||
|
|
||||||
# Gunicorn Workers
|
# Gunicorn Workers
|
||||||
GUNICORN_WORKERS=2
|
GUNICORN_WORKERS=2
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ USER captain
|
|||||||
COPY manage.py manage.py
|
COPY manage.py manage.py
|
||||||
COPY plane plane/
|
COPY plane plane/
|
||||||
COPY templates templates/
|
COPY templates templates/
|
||||||
|
COPY package.json package.json
|
||||||
COPY gunicorn.config.py ./
|
COPY gunicorn.config.py ./
|
||||||
USER root
|
USER root
|
||||||
RUN apk --no-cache add "bash~=5.2"
|
RUN apk --no-cache add "bash~=5.2"
|
||||||
|
@ -3,7 +3,18 @@ set -e
|
|||||||
python manage.py wait_for_db
|
python manage.py wait_for_db
|
||||||
python manage.py migrate
|
python manage.py migrate
|
||||||
|
|
||||||
# Create a Default User
|
# Set default value for ENABLE_REGISTRATION
|
||||||
python bin/user_script.py
|
ENABLE_REGISTRATION=${ENABLE_REGISTRATION:-1}
|
||||||
|
|
||||||
|
# Check if ENABLE_REGISTRATION is not set to '0'
|
||||||
|
if [ "$ENABLE_REGISTRATION" != "0" ]; then
|
||||||
|
# Register instance
|
||||||
|
python manage.py register_instance
|
||||||
|
# Load the configuration variable
|
||||||
|
python manage.py configure_instance
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create the default bucket
|
||||||
|
python manage.py create_bucket
|
||||||
|
|
||||||
exec gunicorn -w $GUNICORN_WORKERS -k uvicorn.workers.UvicornWorker plane.asgi:application --bind 0.0.0.0:8000 --max-requests 1200 --max-requests-jitter 1000 --access-logfile -
|
exec gunicorn -w $GUNICORN_WORKERS -k uvicorn.workers.UvicornWorker plane.asgi:application --bind 0.0.0.0:8000 --max-requests 1200 --max-requests-jitter 1000 --access-logfile -
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
import os, sys
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
sys.path.append("/code")
|
|
||||||
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "plane.settings.production")
|
|
||||||
import django
|
|
||||||
|
|
||||||
django.setup()
|
|
||||||
|
|
||||||
from plane.db.models import User
|
|
||||||
|
|
||||||
|
|
||||||
def populate():
|
|
||||||
default_email = os.environ.get("DEFAULT_EMAIL", "captain@plane.so")
|
|
||||||
default_password = os.environ.get("DEFAULT_PASSWORD", "password123")
|
|
||||||
|
|
||||||
if not User.objects.filter(email=default_email).exists():
|
|
||||||
user = User.objects.create(email=default_email, username=uuid.uuid4().hex)
|
|
||||||
user.set_password(default_password)
|
|
||||||
user.save()
|
|
||||||
print(f"User created with an email: {default_email}")
|
|
||||||
else:
|
|
||||||
print(f"User already exists with the default email: {default_email}")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
populate()
|
|
4
apiserver/package.json
Normal file
4
apiserver/package.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"name": "plane-api",
|
||||||
|
"version": "0.13.2"
|
||||||
|
}
|
0
apiserver/plane/api/middleware/__init__.py
Normal file
0
apiserver/plane/api/middleware/__init__.py
Normal file
47
apiserver/plane/api/middleware/api_authentication.py
Normal file
47
apiserver/plane/api/middleware/api_authentication.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# Django imports
|
||||||
|
from django.utils import timezone
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
|
# Third party imports
|
||||||
|
from rest_framework import authentication
|
||||||
|
from rest_framework.exceptions import AuthenticationFailed
|
||||||
|
|
||||||
|
# Module imports
|
||||||
|
from plane.db.models import APIToken
|
||||||
|
|
||||||
|
|
||||||
|
class APIKeyAuthentication(authentication.BaseAuthentication):
|
||||||
|
"""
|
||||||
|
Authentication with an API Key
|
||||||
|
"""
|
||||||
|
|
||||||
|
www_authenticate_realm = "api"
|
||||||
|
media_type = "application/json"
|
||||||
|
auth_header_name = "X-Api-Key"
|
||||||
|
|
||||||
|
def get_api_token(self, request):
|
||||||
|
return request.headers.get(self.auth_header_name)
|
||||||
|
|
||||||
|
def validate_api_token(self, token):
|
||||||
|
try:
|
||||||
|
api_token = APIToken.objects.get(
|
||||||
|
Q(Q(expired_at__gt=timezone.now()) | Q(expired_at__isnull=True)),
|
||||||
|
token=token,
|
||||||
|
is_active=True,
|
||||||
|
)
|
||||||
|
except APIToken.DoesNotExist:
|
||||||
|
raise AuthenticationFailed("Given API token is not valid")
|
||||||
|
|
||||||
|
# save api token last used
|
||||||
|
api_token.last_used = timezone.now()
|
||||||
|
api_token.save(update_fields=["last_used"])
|
||||||
|
return (api_token.user, api_token.token)
|
||||||
|
|
||||||
|
def authenticate(self, request):
|
||||||
|
token = self.get_api_token(request=request)
|
||||||
|
if not token:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Validate the API token
|
||||||
|
user, token = self.validate_api_token(token)
|
||||||
|
return user, token
|
@ -1,2 +0,0 @@
|
|||||||
from .workspace import WorkSpaceBasePermission, WorkSpaceAdminPermission, WorkspaceEntityPermission, WorkspaceViewerPermission
|
|
||||||
from .project import ProjectBasePermission, ProjectEntityPermission, ProjectMemberPermission, ProjectLitePermission
|
|
45
apiserver/plane/api/rate_limit.py
Normal file
45
apiserver/plane/api/rate_limit.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
from django.utils import timezone
|
||||||
|
from rest_framework.throttling import SimpleRateThrottle
|
||||||
|
|
||||||
|
|
||||||
|
class ApiKeyRateThrottle(SimpleRateThrottle):
|
||||||
|
scope = 'api_key'
|
||||||
|
|
||||||
|
def get_cache_key(self, request, view):
|
||||||
|
# Retrieve the API key from the request header
|
||||||
|
api_key = request.headers.get('X-Api-Key')
|
||||||
|
if not api_key:
|
||||||
|
return None # Allow the request if there's no API key
|
||||||
|
|
||||||
|
# Use the API key as part of the cache key
|
||||||
|
return f'{self.scope}:{api_key}'
|
||||||
|
|
||||||
|
def allow_request(self, request, view):
|
||||||
|
# Calculate the current time as a Unix timestamp
|
||||||
|
now = timezone.now().timestamp()
|
||||||
|
|
||||||
|
# Use the parent class's method to check if the request is allowed
|
||||||
|
allowed = super().allow_request(request, view)
|
||||||
|
|
||||||
|
if allowed:
|
||||||
|
# Calculate the remaining limit and reset time
|
||||||
|
history = self.cache.get(self.key, [])
|
||||||
|
|
||||||
|
# Remove old histories
|
||||||
|
while history and history[-1] <= now - self.duration:
|
||||||
|
history.pop()
|
||||||
|
|
||||||
|
# Calculate the requests
|
||||||
|
num_requests = len(history)
|
||||||
|
|
||||||
|
# Check available requests
|
||||||
|
available = self.num_requests - num_requests
|
||||||
|
|
||||||
|
# Unix timestamp for when the rate limit will reset
|
||||||
|
reset_time = int(now + self.duration)
|
||||||
|
|
||||||
|
# Add headers
|
||||||
|
request.META['X-RateLimit-Remaining'] = max(0, available)
|
||||||
|
request.META['X-RateLimit-Reset'] = reset_time
|
||||||
|
|
||||||
|
return allowed
|
@ -1,102 +1,16 @@
|
|||||||
from .base import BaseSerializer
|
from .user import UserLiteSerializer
|
||||||
from .user import (
|
from .workspace import WorkspaceLiteSerializer
|
||||||
UserSerializer,
|
from .project import ProjectSerializer, ProjectLiteSerializer
|
||||||
UserLiteSerializer,
|
|
||||||
ChangePasswordSerializer,
|
|
||||||
ResetPasswordSerializer,
|
|
||||||
UserAdminLiteSerializer,
|
|
||||||
UserMeSerializer,
|
|
||||||
UserMeSettingsSerializer,
|
|
||||||
)
|
|
||||||
from .workspace import (
|
|
||||||
WorkSpaceSerializer,
|
|
||||||
WorkSpaceMemberSerializer,
|
|
||||||
TeamSerializer,
|
|
||||||
WorkSpaceMemberInviteSerializer,
|
|
||||||
WorkspaceLiteSerializer,
|
|
||||||
WorkspaceThemeSerializer,
|
|
||||||
WorkspaceMemberAdminSerializer,
|
|
||||||
WorkspaceMemberMeSerializer,
|
|
||||||
)
|
|
||||||
from .project import (
|
|
||||||
ProjectSerializer,
|
|
||||||
ProjectListSerializer,
|
|
||||||
ProjectDetailSerializer,
|
|
||||||
ProjectMemberSerializer,
|
|
||||||
ProjectMemberInviteSerializer,
|
|
||||||
ProjectIdentifierSerializer,
|
|
||||||
ProjectFavoriteSerializer,
|
|
||||||
ProjectLiteSerializer,
|
|
||||||
ProjectMemberLiteSerializer,
|
|
||||||
ProjectDeployBoardSerializer,
|
|
||||||
ProjectMemberAdminSerializer,
|
|
||||||
ProjectPublicMemberSerializer,
|
|
||||||
)
|
|
||||||
from .state import StateSerializer, StateLiteSerializer
|
|
||||||
from .view import GlobalViewSerializer, IssueViewSerializer, IssueViewFavoriteSerializer
|
|
||||||
from .cycle import (
|
|
||||||
CycleSerializer,
|
|
||||||
CycleIssueSerializer,
|
|
||||||
CycleFavoriteSerializer,
|
|
||||||
CycleWriteSerializer,
|
|
||||||
)
|
|
||||||
from .asset import FileAssetSerializer
|
|
||||||
from .issue import (
|
from .issue import (
|
||||||
IssueCreateSerializer,
|
|
||||||
IssueActivitySerializer,
|
|
||||||
IssueCommentSerializer,
|
|
||||||
IssuePropertySerializer,
|
|
||||||
IssueAssigneeSerializer,
|
|
||||||
LabelSerializer,
|
|
||||||
IssueSerializer,
|
IssueSerializer,
|
||||||
IssueFlatSerializer,
|
LabelSerializer,
|
||||||
IssueStateSerializer,
|
|
||||||
IssueLinkSerializer,
|
IssueLinkSerializer,
|
||||||
IssueLiteSerializer,
|
|
||||||
IssueAttachmentSerializer,
|
IssueAttachmentSerializer,
|
||||||
IssueSubscriberSerializer,
|
IssueCommentSerializer,
|
||||||
IssueReactionSerializer,
|
IssueAttachmentSerializer,
|
||||||
CommentReactionSerializer,
|
IssueActivitySerializer,
|
||||||
IssueVoteSerializer,
|
|
||||||
IssueRelationSerializer,
|
|
||||||
RelatedIssueSerializer,
|
|
||||||
IssuePublicSerializer,
|
|
||||||
)
|
)
|
||||||
|
from .state import StateLiteSerializer, StateSerializer
|
||||||
from .module import (
|
from .cycle import CycleSerializer, CycleIssueSerializer
|
||||||
ModuleWriteSerializer,
|
from .module import ModuleSerializer, ModuleIssueSerializer
|
||||||
ModuleSerializer,
|
from .inbox import InboxIssueSerializer
|
||||||
ModuleIssueSerializer,
|
|
||||||
ModuleLinkSerializer,
|
|
||||||
ModuleFavoriteSerializer,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .api_token import APITokenSerializer
|
|
||||||
|
|
||||||
from .integration import (
|
|
||||||
IntegrationSerializer,
|
|
||||||
WorkspaceIntegrationSerializer,
|
|
||||||
GithubIssueSyncSerializer,
|
|
||||||
GithubRepositorySerializer,
|
|
||||||
GithubRepositorySyncSerializer,
|
|
||||||
GithubCommentSyncSerializer,
|
|
||||||
SlackProjectSyncSerializer,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .importer import ImporterSerializer
|
|
||||||
|
|
||||||
from .page import PageSerializer, PageBlockSerializer, PageFavoriteSerializer
|
|
||||||
|
|
||||||
from .estimate import (
|
|
||||||
EstimateSerializer,
|
|
||||||
EstimatePointSerializer,
|
|
||||||
EstimateReadSerializer,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .inbox import InboxSerializer, InboxIssueSerializer, IssueStateInboxSerializer
|
|
||||||
|
|
||||||
from .analytic import AnalyticViewSerializer
|
|
||||||
|
|
||||||
from .notification import NotificationSerializer
|
|
||||||
|
|
||||||
from .exporter import ExporterHistorySerializer
|
|
@ -1,14 +0,0 @@
|
|||||||
from .base import BaseSerializer
|
|
||||||
from plane.db.models import APIToken
|
|
||||||
|
|
||||||
|
|
||||||
class APITokenSerializer(BaseSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = APIToken
|
|
||||||
fields = [
|
|
||||||
"label",
|
|
||||||
"user",
|
|
||||||
"user_type",
|
|
||||||
"workspace",
|
|
||||||
"created_at",
|
|
||||||
]
|
|
@ -1,22 +1,22 @@
|
|||||||
|
# Third party imports
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
|
||||||
class BaseSerializer(serializers.ModelSerializer):
|
class BaseSerializer(serializers.ModelSerializer):
|
||||||
id = serializers.PrimaryKeyRelatedField(read_only=True)
|
id = serializers.PrimaryKeyRelatedField(read_only=True)
|
||||||
|
|
||||||
class DynamicBaseSerializer(BaseSerializer):
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
# If 'fields' is provided in the arguments, remove it and store it separately.
|
# If 'fields' is provided in the arguments, remove it and store it separately.
|
||||||
# This is done so as not to pass this custom argument up to the superclass.
|
# This is done so as not to pass this custom argument up to the superclass.
|
||||||
fields = kwargs.pop("fields", None)
|
fields = kwargs.pop("fields", [])
|
||||||
|
self.expand = kwargs.pop("expand", []) or []
|
||||||
|
|
||||||
# Call the initialization of the superclass.
|
# Call the initialization of the superclass.
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# If 'fields' was provided, filter the fields of the serializer accordingly.
|
# If 'fields' was provided, filter the fields of the serializer accordingly.
|
||||||
if fields is not None:
|
if fields:
|
||||||
self.fields = self._filter_fields(fields)
|
self.fields = self._filter_fields(fields=fields)
|
||||||
|
|
||||||
def _filter_fields(self, fields):
|
def _filter_fields(self, fields):
|
||||||
"""
|
"""
|
||||||
@ -52,7 +52,54 @@ class DynamicBaseSerializer(BaseSerializer):
|
|||||||
allowed = set(allowed)
|
allowed = set(allowed)
|
||||||
|
|
||||||
# Remove fields from the serializer that aren't in the 'allowed' list.
|
# Remove fields from the serializer that aren't in the 'allowed' list.
|
||||||
for field_name in (existing - allowed):
|
for field_name in existing - allowed:
|
||||||
self.fields.pop(field_name)
|
self.fields.pop(field_name)
|
||||||
|
|
||||||
return self.fields
|
return self.fields
|
||||||
|
|
||||||
|
def to_representation(self, instance):
|
||||||
|
response = super().to_representation(instance)
|
||||||
|
|
||||||
|
# Ensure 'expand' is iterable before processing
|
||||||
|
if self.expand:
|
||||||
|
for expand in self.expand:
|
||||||
|
if expand in self.fields:
|
||||||
|
# Import all the expandable serializers
|
||||||
|
from . import (
|
||||||
|
WorkspaceLiteSerializer,
|
||||||
|
ProjectLiteSerializer,
|
||||||
|
UserLiteSerializer,
|
||||||
|
StateLiteSerializer,
|
||||||
|
IssueSerializer,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Expansion mapper
|
||||||
|
expansion = {
|
||||||
|
"user": UserLiteSerializer,
|
||||||
|
"workspace": WorkspaceLiteSerializer,
|
||||||
|
"project": ProjectLiteSerializer,
|
||||||
|
"default_assignee": UserLiteSerializer,
|
||||||
|
"project_lead": UserLiteSerializer,
|
||||||
|
"state": StateLiteSerializer,
|
||||||
|
"created_by": UserLiteSerializer,
|
||||||
|
"issue": IssueSerializer,
|
||||||
|
"actor": UserLiteSerializer,
|
||||||
|
"owned_by": UserLiteSerializer,
|
||||||
|
"members": UserLiteSerializer,
|
||||||
|
}
|
||||||
|
# Check if field in expansion then expand the field
|
||||||
|
if expand in expansion:
|
||||||
|
if isinstance(response.get(expand), list):
|
||||||
|
exp_serializer = expansion[expand](
|
||||||
|
getattr(instance, expand), many=True
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
exp_serializer = expansion[expand](
|
||||||
|
getattr(instance, expand)
|
||||||
|
)
|
||||||
|
response[expand] = exp_serializer.data
|
||||||
|
else:
|
||||||
|
# You might need to handle this case differently
|
||||||
|
response[expand] = getattr(instance, f"{expand}_id", None)
|
||||||
|
|
||||||
|
return response
|
@ -3,43 +3,19 @@ from rest_framework import serializers
|
|||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from .base import BaseSerializer
|
from .base import BaseSerializer
|
||||||
from .user import UserLiteSerializer
|
from plane.db.models import Cycle, CycleIssue
|
||||||
from .issue import IssueStateSerializer
|
|
||||||
from .workspace import WorkspaceLiteSerializer
|
|
||||||
from .project import ProjectLiteSerializer
|
|
||||||
from plane.db.models import Cycle, CycleIssue, CycleFavorite
|
|
||||||
|
|
||||||
|
|
||||||
class CycleWriteSerializer(BaseSerializer):
|
|
||||||
def validate(self, data):
|
|
||||||
if (
|
|
||||||
data.get("start_date", None) is not None
|
|
||||||
and data.get("end_date", None) is not None
|
|
||||||
and data.get("start_date", None) > data.get("end_date", None)
|
|
||||||
):
|
|
||||||
raise serializers.ValidationError("Start date cannot exceed end date")
|
|
||||||
return data
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Cycle
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class CycleSerializer(BaseSerializer):
|
class CycleSerializer(BaseSerializer):
|
||||||
owned_by = UserLiteSerializer(read_only=True)
|
|
||||||
is_favorite = serializers.BooleanField(read_only=True)
|
|
||||||
total_issues = serializers.IntegerField(read_only=True)
|
total_issues = serializers.IntegerField(read_only=True)
|
||||||
cancelled_issues = serializers.IntegerField(read_only=True)
|
cancelled_issues = serializers.IntegerField(read_only=True)
|
||||||
completed_issues = serializers.IntegerField(read_only=True)
|
completed_issues = serializers.IntegerField(read_only=True)
|
||||||
started_issues = serializers.IntegerField(read_only=True)
|
started_issues = serializers.IntegerField(read_only=True)
|
||||||
unstarted_issues = serializers.IntegerField(read_only=True)
|
unstarted_issues = serializers.IntegerField(read_only=True)
|
||||||
backlog_issues = serializers.IntegerField(read_only=True)
|
backlog_issues = serializers.IntegerField(read_only=True)
|
||||||
assignees = serializers.SerializerMethodField(read_only=True)
|
|
||||||
total_estimates = serializers.IntegerField(read_only=True)
|
total_estimates = serializers.IntegerField(read_only=True)
|
||||||
completed_estimates = serializers.IntegerField(read_only=True)
|
completed_estimates = serializers.IntegerField(read_only=True)
|
||||||
started_estimates = serializers.IntegerField(read_only=True)
|
started_estimates = serializers.IntegerField(read_only=True)
|
||||||
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
|
||||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
|
||||||
|
|
||||||
def validate(self, data):
|
def validate(self, data):
|
||||||
if (
|
if (
|
||||||
@ -50,26 +26,6 @@ class CycleSerializer(BaseSerializer):
|
|||||||
raise serializers.ValidationError("Start date cannot exceed end date")
|
raise serializers.ValidationError("Start date cannot exceed end date")
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_assignees(self, obj):
|
|
||||||
members = [
|
|
||||||
{
|
|
||||||
"avatar": assignee.avatar,
|
|
||||||
"display_name": assignee.display_name,
|
|
||||||
"id": assignee.id,
|
|
||||||
}
|
|
||||||
for issue_cycle in obj.issue_cycle.prefetch_related(
|
|
||||||
"issue__assignees"
|
|
||||||
).all()
|
|
||||||
for assignee in issue_cycle.issue.assignees.all()
|
|
||||||
]
|
|
||||||
# Use a set comprehension to return only the unique objects
|
|
||||||
unique_objects = {frozenset(item.items()) for item in members}
|
|
||||||
|
|
||||||
# Convert the set back to a list of dictionaries
|
|
||||||
unique_list = [dict(item) for item in unique_objects]
|
|
||||||
|
|
||||||
return unique_list
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Cycle
|
model = Cycle
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
@ -81,7 +37,6 @@ class CycleSerializer(BaseSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class CycleIssueSerializer(BaseSerializer):
|
class CycleIssueSerializer(BaseSerializer):
|
||||||
issue_detail = IssueStateSerializer(read_only=True, source="issue")
|
|
||||||
sub_issues_count = serializers.IntegerField(read_only=True)
|
sub_issues_count = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -92,16 +47,3 @@ class CycleIssueSerializer(BaseSerializer):
|
|||||||
"project",
|
"project",
|
||||||
"cycle",
|
"cycle",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class CycleFavoriteSerializer(BaseSerializer):
|
|
||||||
cycle_detail = CycleSerializer(source="cycle", read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = CycleFavorite
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
"user",
|
|
||||||
]
|
|
||||||
|
@ -1,31 +1,8 @@
|
|||||||
# Third party frameworks
|
# Module improts
|
||||||
from rest_framework import serializers
|
|
||||||
|
|
||||||
# Module imports
|
|
||||||
from .base import BaseSerializer
|
from .base import BaseSerializer
|
||||||
from .issue import IssueFlatSerializer, LabelLiteSerializer
|
from plane.db.models import InboxIssue
|
||||||
from .project import ProjectLiteSerializer
|
|
||||||
from .state import StateLiteSerializer
|
|
||||||
from .user import UserLiteSerializer
|
|
||||||
from plane.db.models import Inbox, InboxIssue, Issue
|
|
||||||
|
|
||||||
|
|
||||||
class InboxSerializer(BaseSerializer):
|
|
||||||
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
|
||||||
pending_issue_count = serializers.IntegerField(read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Inbox
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"project",
|
|
||||||
"workspace",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class InboxIssueSerializer(BaseSerializer):
|
class InboxIssueSerializer(BaseSerializer):
|
||||||
issue_detail = IssueFlatSerializer(source="issue", read_only=True)
|
|
||||||
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = InboxIssue
|
model = InboxIssue
|
||||||
@ -34,24 +11,3 @@ class InboxIssueSerializer(BaseSerializer):
|
|||||||
"project",
|
"project",
|
||||||
"workspace",
|
"workspace",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class InboxIssueLiteSerializer(BaseSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = InboxIssue
|
|
||||||
fields = ["id", "status", "duplicate_to", "snoozed_till", "source"]
|
|
||||||
read_only_fields = fields
|
|
||||||
|
|
||||||
|
|
||||||
class IssueStateInboxSerializer(BaseSerializer):
|
|
||||||
state_detail = StateLiteSerializer(read_only=True, source="state")
|
|
||||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
|
||||||
label_details = LabelLiteSerializer(read_only=True, source="labels", many=True)
|
|
||||||
assignee_details = UserLiteSerializer(read_only=True, source="assignees", many=True)
|
|
||||||
sub_issues_count = serializers.IntegerField(read_only=True)
|
|
||||||
bridge_id = serializers.UUIDField(read_only=True)
|
|
||||||
issue_inbox = InboxIssueLiteSerializer(read_only=True, many=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Issue
|
|
||||||
fields = "__all__"
|
|
||||||
|
@ -1,87 +1,39 @@
|
|||||||
# Django imports
|
# Django imports
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
# Third Party imports
|
# Third party imports
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from .base import BaseSerializer, DynamicBaseSerializer
|
|
||||||
from .user import UserLiteSerializer
|
|
||||||
from .state import StateSerializer, StateLiteSerializer
|
|
||||||
from .project import ProjectLiteSerializer
|
|
||||||
from .workspace import WorkspaceLiteSerializer
|
|
||||||
from plane.db.models import (
|
from plane.db.models import (
|
||||||
User,
|
User,
|
||||||
Issue,
|
Issue,
|
||||||
IssueActivity,
|
State,
|
||||||
IssueComment,
|
|
||||||
IssueProperty,
|
|
||||||
IssueAssignee,
|
IssueAssignee,
|
||||||
IssueSubscriber,
|
|
||||||
IssueLabel,
|
|
||||||
Label,
|
Label,
|
||||||
CycleIssue,
|
IssueLabel,
|
||||||
Cycle,
|
|
||||||
Module,
|
|
||||||
ModuleIssue,
|
|
||||||
IssueLink,
|
IssueLink,
|
||||||
|
IssueComment,
|
||||||
IssueAttachment,
|
IssueAttachment,
|
||||||
IssueReaction,
|
IssueActivity,
|
||||||
CommentReaction,
|
ProjectMember,
|
||||||
IssueVote,
|
|
||||||
IssueRelation,
|
|
||||||
)
|
)
|
||||||
|
from .base import BaseSerializer
|
||||||
|
|
||||||
|
|
||||||
class IssueFlatSerializer(BaseSerializer):
|
class IssueSerializer(BaseSerializer):
|
||||||
## Contain only flat fields
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Issue
|
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"name",
|
|
||||||
"description",
|
|
||||||
"description_html",
|
|
||||||
"priority",
|
|
||||||
"start_date",
|
|
||||||
"target_date",
|
|
||||||
"sequence_id",
|
|
||||||
"sort_order",
|
|
||||||
"is_draft",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class IssueProjectLiteSerializer(BaseSerializer):
|
|
||||||
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Issue
|
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"project_detail",
|
|
||||||
"name",
|
|
||||||
"sequence_id",
|
|
||||||
]
|
|
||||||
read_only_fields = fields
|
|
||||||
|
|
||||||
|
|
||||||
##TODO: Find a better way to write this serializer
|
|
||||||
## Find a better approach to save manytomany?
|
|
||||||
class IssueCreateSerializer(BaseSerializer):
|
|
||||||
state_detail = StateSerializer(read_only=True, source="state")
|
|
||||||
created_by_detail = UserLiteSerializer(read_only=True, source="created_by")
|
|
||||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
|
||||||
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
|
||||||
|
|
||||||
assignees = serializers.ListField(
|
assignees = serializers.ListField(
|
||||||
child=serializers.PrimaryKeyRelatedField(queryset=User.objects.all()),
|
child=serializers.PrimaryKeyRelatedField(
|
||||||
|
queryset=User.objects.values_list("id", flat=True)
|
||||||
|
),
|
||||||
write_only=True,
|
write_only=True,
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
labels = serializers.ListField(
|
labels = serializers.ListField(
|
||||||
child=serializers.PrimaryKeyRelatedField(queryset=Label.objects.all()),
|
child=serializers.PrimaryKeyRelatedField(
|
||||||
|
queryset=Label.objects.values_list("id", flat=True)
|
||||||
|
),
|
||||||
write_only=True,
|
write_only=True,
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
@ -98,12 +50,6 @@ class IssueCreateSerializer(BaseSerializer):
|
|||||||
"updated_at",
|
"updated_at",
|
||||||
]
|
]
|
||||||
|
|
||||||
def to_representation(self, instance):
|
|
||||||
data = super().to_representation(instance)
|
|
||||||
data['assignees'] = [str(assignee.id) for assignee in instance.assignees.all()]
|
|
||||||
data['labels'] = [str(label.id) for label in instance.labels.all()]
|
|
||||||
return data
|
|
||||||
|
|
||||||
def validate(self, data):
|
def validate(self, data):
|
||||||
if (
|
if (
|
||||||
data.get("start_date", None) is not None
|
data.get("start_date", None) is not None
|
||||||
@ -111,6 +57,44 @@ class IssueCreateSerializer(BaseSerializer):
|
|||||||
and data.get("start_date", None) > data.get("target_date", None)
|
and data.get("start_date", None) > data.get("target_date", None)
|
||||||
):
|
):
|
||||||
raise serializers.ValidationError("Start date cannot exceed target date")
|
raise serializers.ValidationError("Start date cannot exceed target date")
|
||||||
|
|
||||||
|
# Validate assignees are from project
|
||||||
|
if data.get("assignees", []):
|
||||||
|
print(data.get("assignees"))
|
||||||
|
data["assignees"] = ProjectMember.objects.filter(
|
||||||
|
project_id=self.context.get("project_id"),
|
||||||
|
member_id__in=data["assignees"],
|
||||||
|
).values_list("member_id", flat=True)
|
||||||
|
|
||||||
|
# Validate labels are from project
|
||||||
|
if data.get("labels", []):
|
||||||
|
data["labels"] = Label.objects.filter(
|
||||||
|
project_id=self.context.get("project_id"),
|
||||||
|
id__in=data["labels"],
|
||||||
|
).values_list("id", flat=True)
|
||||||
|
|
||||||
|
# Check state is from the project only else raise validation error
|
||||||
|
if (
|
||||||
|
data.get("state")
|
||||||
|
and not State.objects.filter(
|
||||||
|
project_id=self.context.get("project_id"), pk=data.get("state")
|
||||||
|
).exists()
|
||||||
|
):
|
||||||
|
raise serializers.ValidationError(
|
||||||
|
"State is not valid please pass a valid state_id"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check parent issue is from workspace as it can be cross workspace
|
||||||
|
if (
|
||||||
|
data.get("parent")
|
||||||
|
and not Issue.objects.filter(
|
||||||
|
workspce_id=self.context.get("workspace_id"), pk=data.get("parent")
|
||||||
|
).exists()
|
||||||
|
):
|
||||||
|
raise serializers.ValidationError(
|
||||||
|
"Parent is not valid issue_id please pass a valid issue_id"
|
||||||
|
)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
@ -131,14 +115,14 @@ class IssueCreateSerializer(BaseSerializer):
|
|||||||
IssueAssignee.objects.bulk_create(
|
IssueAssignee.objects.bulk_create(
|
||||||
[
|
[
|
||||||
IssueAssignee(
|
IssueAssignee(
|
||||||
assignee=user,
|
assignee_id=assignee_id,
|
||||||
issue=issue,
|
issue=issue,
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
workspace_id=workspace_id,
|
workspace_id=workspace_id,
|
||||||
created_by_id=created_by_id,
|
created_by_id=created_by_id,
|
||||||
updated_by_id=updated_by_id,
|
updated_by_id=updated_by_id,
|
||||||
)
|
)
|
||||||
for user in assignees
|
for assignee_id in assignees
|
||||||
],
|
],
|
||||||
batch_size=10,
|
batch_size=10,
|
||||||
)
|
)
|
||||||
@ -158,14 +142,14 @@ class IssueCreateSerializer(BaseSerializer):
|
|||||||
IssueLabel.objects.bulk_create(
|
IssueLabel.objects.bulk_create(
|
||||||
[
|
[
|
||||||
IssueLabel(
|
IssueLabel(
|
||||||
label=label,
|
label_id=label_id,
|
||||||
issue=issue,
|
issue=issue,
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
workspace_id=workspace_id,
|
workspace_id=workspace_id,
|
||||||
created_by_id=created_by_id,
|
created_by_id=created_by_id,
|
||||||
updated_by_id=updated_by_id,
|
updated_by_id=updated_by_id,
|
||||||
)
|
)
|
||||||
for label in labels
|
for label_id in labels
|
||||||
],
|
],
|
||||||
batch_size=10,
|
batch_size=10,
|
||||||
)
|
)
|
||||||
@ -187,14 +171,14 @@ class IssueCreateSerializer(BaseSerializer):
|
|||||||
IssueAssignee.objects.bulk_create(
|
IssueAssignee.objects.bulk_create(
|
||||||
[
|
[
|
||||||
IssueAssignee(
|
IssueAssignee(
|
||||||
assignee=user,
|
assignee_id=assignee_id,
|
||||||
issue=instance,
|
issue=instance,
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
workspace_id=workspace_id,
|
workspace_id=workspace_id,
|
||||||
created_by_id=created_by_id,
|
created_by_id=created_by_id,
|
||||||
updated_by_id=updated_by_id,
|
updated_by_id=updated_by_id,
|
||||||
)
|
)
|
||||||
for user in assignees
|
for assignee_id in assignees
|
||||||
],
|
],
|
||||||
batch_size=10,
|
batch_size=10,
|
||||||
)
|
)
|
||||||
@ -204,14 +188,14 @@ class IssueCreateSerializer(BaseSerializer):
|
|||||||
IssueLabel.objects.bulk_create(
|
IssueLabel.objects.bulk_create(
|
||||||
[
|
[
|
||||||
IssueLabel(
|
IssueLabel(
|
||||||
label=label,
|
label_id=label_id,
|
||||||
issue=instance,
|
issue=instance,
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
workspace_id=workspace_id,
|
workspace_id=workspace_id,
|
||||||
created_by_id=created_by_id,
|
created_by_id=created_by_id,
|
||||||
updated_by_id=updated_by_id,
|
updated_by_id=updated_by_id,
|
||||||
)
|
)
|
||||||
for label in labels
|
for label_id in labels
|
||||||
],
|
],
|
||||||
batch_size=10,
|
batch_size=10,
|
||||||
)
|
)
|
||||||
@ -220,33 +204,29 @@ class IssueCreateSerializer(BaseSerializer):
|
|||||||
instance.updated_at = timezone.now()
|
instance.updated_at = timezone.now()
|
||||||
return super().update(instance, validated_data)
|
return super().update(instance, validated_data)
|
||||||
|
|
||||||
|
def to_representation(self, instance):
|
||||||
|
data = super().to_representation(instance)
|
||||||
|
if "assignees" in self.fields:
|
||||||
|
if "assignees" in self.expand:
|
||||||
|
from .user import UserLiteSerializer
|
||||||
|
|
||||||
class IssueActivitySerializer(BaseSerializer):
|
data["assignees"] = UserLiteSerializer(
|
||||||
actor_detail = UserLiteSerializer(read_only=True, source="actor")
|
instance.assignees.all(), many=True
|
||||||
issue_detail = IssueFlatSerializer(read_only=True, source="issue")
|
).data
|
||||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
else:
|
||||||
|
data["assignees"] = [
|
||||||
class Meta:
|
str(assignee.id) for assignee in instance.assignees.all()
|
||||||
model = IssueActivity
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class IssuePropertySerializer(BaseSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = IssueProperty
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"user",
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
]
|
]
|
||||||
|
if "labels" in self.fields:
|
||||||
|
if "labels" in self.expand:
|
||||||
|
data["labels"] = LabelSerializer(instance.labels.all(), many=True).data
|
||||||
|
else:
|
||||||
|
data["labels"] = [str(label.id) for label in instance.labels.all()]
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
class LabelSerializer(BaseSerializer):
|
class LabelSerializer(BaseSerializer):
|
||||||
workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True)
|
|
||||||
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Label
|
model = Label
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
@ -256,133 +236,7 @@ class LabelSerializer(BaseSerializer):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class LabelLiteSerializer(BaseSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = Label
|
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"name",
|
|
||||||
"color",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class IssueLabelSerializer(BaseSerializer):
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = IssueLabel
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class IssueRelationSerializer(BaseSerializer):
|
|
||||||
issue_detail = IssueProjectLiteSerializer(read_only=True, source="related_issue")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = IssueRelation
|
|
||||||
fields = [
|
|
||||||
"issue_detail",
|
|
||||||
"relation_type",
|
|
||||||
"related_issue",
|
|
||||||
"issue",
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
]
|
|
||||||
|
|
||||||
class RelatedIssueSerializer(BaseSerializer):
|
|
||||||
issue_detail = IssueProjectLiteSerializer(read_only=True, source="issue")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = IssueRelation
|
|
||||||
fields = [
|
|
||||||
"issue_detail",
|
|
||||||
"relation_type",
|
|
||||||
"related_issue",
|
|
||||||
"issue",
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class IssueAssigneeSerializer(BaseSerializer):
|
|
||||||
assignee_details = UserLiteSerializer(read_only=True, source="assignee")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = IssueAssignee
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class CycleBaseSerializer(BaseSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = Cycle
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
"created_by",
|
|
||||||
"updated_by",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class IssueCycleDetailSerializer(BaseSerializer):
|
|
||||||
cycle_detail = CycleBaseSerializer(read_only=True, source="cycle")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = CycleIssue
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
"created_by",
|
|
||||||
"updated_by",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleBaseSerializer(BaseSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = Module
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
"created_by",
|
|
||||||
"updated_by",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class IssueModuleDetailSerializer(BaseSerializer):
|
|
||||||
module_detail = ModuleBaseSerializer(read_only=True, source="module")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ModuleIssue
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
"created_by",
|
|
||||||
"updated_by",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class IssueLinkSerializer(BaseSerializer):
|
class IssueLinkSerializer(BaseSerializer):
|
||||||
created_by_detail = UserLiteSerializer(read_only=True, source="created_by")
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = IssueLink
|
model = IssueLink
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
@ -422,57 +276,7 @@ class IssueAttachmentSerializer(BaseSerializer):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class IssueReactionSerializer(BaseSerializer):
|
|
||||||
|
|
||||||
actor_detail = UserLiteSerializer(read_only=True, source="actor")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = IssueReaction
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
"issue",
|
|
||||||
"actor",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class CommentReactionLiteSerializer(BaseSerializer):
|
|
||||||
actor_detail = UserLiteSerializer(read_only=True, source="actor")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = CommentReaction
|
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"reaction",
|
|
||||||
"comment",
|
|
||||||
"actor_detail",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class CommentReactionSerializer(BaseSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = CommentReaction
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = ["workspace", "project", "comment", "actor"]
|
|
||||||
|
|
||||||
|
|
||||||
class IssueVoteSerializer(BaseSerializer):
|
|
||||||
|
|
||||||
actor_detail = UserLiteSerializer(read_only=True, source="actor")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = IssueVote
|
|
||||||
fields = ["issue", "vote", "workspace", "project", "actor", "actor_detail"]
|
|
||||||
read_only_fields = fields
|
|
||||||
|
|
||||||
|
|
||||||
class IssueCommentSerializer(BaseSerializer):
|
class IssueCommentSerializer(BaseSerializer):
|
||||||
actor_detail = UserLiteSerializer(read_only=True, source="actor")
|
|
||||||
issue_detail = IssueFlatSerializer(read_only=True, source="issue")
|
|
||||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
|
||||||
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
|
||||||
comment_reactions = CommentReactionLiteSerializer(read_only=True, many=True)
|
|
||||||
is_member = serializers.BooleanField(read_only=True)
|
is_member = serializers.BooleanField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -489,127 +293,27 @@ class IssueCommentSerializer(BaseSerializer):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class IssueStateFlatSerializer(BaseSerializer):
|
class IssueAttachmentSerializer(BaseSerializer):
|
||||||
state_detail = StateLiteSerializer(read_only=True, source="state")
|
|
||||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Issue
|
model = IssueAttachment
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"sequence_id",
|
|
||||||
"name",
|
|
||||||
"state_detail",
|
|
||||||
"project_detail",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
# Issue Serializer with state details
|
|
||||||
class IssueStateSerializer(BaseSerializer):
|
|
||||||
label_details = LabelLiteSerializer(read_only=True, source="labels", many=True)
|
|
||||||
state_detail = StateLiteSerializer(read_only=True, source="state")
|
|
||||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
|
||||||
assignee_details = UserLiteSerializer(read_only=True, source="assignees", many=True)
|
|
||||||
sub_issues_count = serializers.IntegerField(read_only=True)
|
|
||||||
bridge_id = serializers.UUIDField(read_only=True)
|
|
||||||
attachment_count = serializers.IntegerField(read_only=True)
|
|
||||||
link_count = serializers.IntegerField(read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Issue
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class IssueSerializer(BaseSerializer):
|
|
||||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
|
||||||
state_detail = StateSerializer(read_only=True, source="state")
|
|
||||||
parent_detail = IssueStateFlatSerializer(read_only=True, source="parent")
|
|
||||||
label_details = LabelSerializer(read_only=True, source="labels", many=True)
|
|
||||||
assignee_details = UserLiteSerializer(read_only=True, source="assignees", many=True)
|
|
||||||
related_issues = IssueRelationSerializer(read_only=True, source="issue_relation", many=True)
|
|
||||||
issue_relations = RelatedIssueSerializer(read_only=True, source="issue_related", many=True)
|
|
||||||
issue_cycle = IssueCycleDetailSerializer(read_only=True)
|
|
||||||
issue_module = IssueModuleDetailSerializer(read_only=True)
|
|
||||||
issue_link = IssueLinkSerializer(read_only=True, many=True)
|
|
||||||
issue_attachment = IssueAttachmentSerializer(read_only=True, many=True)
|
|
||||||
sub_issues_count = serializers.IntegerField(read_only=True)
|
|
||||||
issue_reactions = IssueReactionSerializer(read_only=True, many=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Issue
|
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
read_only_fields = [
|
read_only_fields = [
|
||||||
"workspace",
|
"id",
|
||||||
"project",
|
|
||||||
"created_by",
|
"created_by",
|
||||||
"updated_by",
|
"updated_by",
|
||||||
"created_at",
|
"created_at",
|
||||||
"updated_at",
|
"updated_at",
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class IssueLiteSerializer(DynamicBaseSerializer):
|
|
||||||
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
|
||||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
|
||||||
state_detail = StateLiteSerializer(read_only=True, source="state")
|
|
||||||
label_details = LabelLiteSerializer(read_only=True, source="labels", many=True)
|
|
||||||
assignee_details = UserLiteSerializer(read_only=True, source="assignees", many=True)
|
|
||||||
sub_issues_count = serializers.IntegerField(read_only=True)
|
|
||||||
cycle_id = serializers.UUIDField(read_only=True)
|
|
||||||
module_id = serializers.UUIDField(read_only=True)
|
|
||||||
attachment_count = serializers.IntegerField(read_only=True)
|
|
||||||
link_count = serializers.IntegerField(read_only=True)
|
|
||||||
issue_reactions = IssueReactionSerializer(read_only=True, many=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Issue
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"start_date",
|
|
||||||
"target_date",
|
|
||||||
"completed_at",
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
"created_by",
|
|
||||||
"updated_by",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class IssuePublicSerializer(BaseSerializer):
|
|
||||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
|
||||||
state_detail = StateLiteSerializer(read_only=True, source="state")
|
|
||||||
reactions = IssueReactionSerializer(read_only=True, many=True, source="issue_reactions")
|
|
||||||
votes = IssueVoteSerializer(read_only=True, many=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Issue
|
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"name",
|
|
||||||
"description_html",
|
|
||||||
"sequence_id",
|
|
||||||
"state",
|
|
||||||
"state_detail",
|
|
||||||
"project",
|
|
||||||
"project_detail",
|
|
||||||
"workspace",
|
|
||||||
"priority",
|
|
||||||
"target_date",
|
|
||||||
"reactions",
|
|
||||||
"votes",
|
|
||||||
]
|
|
||||||
read_only_fields = fields
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class IssueSubscriberSerializer(BaseSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = IssueSubscriber
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
"workspace",
|
||||||
"project",
|
"project",
|
||||||
"issue",
|
"issue",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class IssueActivitySerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = IssueActivity
|
||||||
|
fields = "__all__"
|
||||||
|
exclude = [
|
||||||
|
"created_by",
|
||||||
|
"udpated_by",
|
||||||
|
]
|
||||||
|
@ -1,31 +1,33 @@
|
|||||||
# Third Party imports
|
# Third party imports
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from .base import BaseSerializer
|
from .base import BaseSerializer
|
||||||
from .user import UserLiteSerializer
|
|
||||||
from .project import ProjectLiteSerializer
|
|
||||||
from .workspace import WorkspaceLiteSerializer
|
|
||||||
|
|
||||||
from plane.db.models import (
|
from plane.db.models import (
|
||||||
User,
|
User,
|
||||||
Module,
|
Module,
|
||||||
|
ModuleLink,
|
||||||
ModuleMember,
|
ModuleMember,
|
||||||
ModuleIssue,
|
ModuleIssue,
|
||||||
ModuleLink,
|
ProjectMember,
|
||||||
ModuleFavorite,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ModuleWriteSerializer(BaseSerializer):
|
class ModuleSerializer(BaseSerializer):
|
||||||
members = serializers.ListField(
|
members = serializers.ListField(
|
||||||
child=serializers.PrimaryKeyRelatedField(queryset=User.objects.all()),
|
child=serializers.PrimaryKeyRelatedField(
|
||||||
|
queryset=User.objects.values_list("id", flat=True)
|
||||||
|
),
|
||||||
write_only=True,
|
write_only=True,
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
|
is_favorite = serializers.BooleanField(read_only=True)
|
||||||
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
total_issues = serializers.IntegerField(read_only=True)
|
||||||
workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True)
|
cancelled_issues = serializers.IntegerField(read_only=True)
|
||||||
|
completed_issues = serializers.IntegerField(read_only=True)
|
||||||
|
started_issues = serializers.IntegerField(read_only=True)
|
||||||
|
unstarted_issues = serializers.IntegerField(read_only=True)
|
||||||
|
backlog_issues = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Module
|
model = Module
|
||||||
@ -41,12 +43,24 @@ class ModuleWriteSerializer(BaseSerializer):
|
|||||||
|
|
||||||
def to_representation(self, instance):
|
def to_representation(self, instance):
|
||||||
data = super().to_representation(instance)
|
data = super().to_representation(instance)
|
||||||
data['members'] = [str(member.id) for member in instance.members.all()]
|
data["members"] = [str(member.id) for member in instance.members.all()]
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def validate(self, data):
|
def validate(self, data):
|
||||||
if data.get("start_date", None) is not None and data.get("target_date", None) is not None and data.get("start_date", None) > data.get("target_date", None):
|
if (
|
||||||
|
data.get("start_date", None) is not None
|
||||||
|
and data.get("target_date", None) is not None
|
||||||
|
and data.get("start_date", None) > data.get("target_date", None)
|
||||||
|
):
|
||||||
raise serializers.ValidationError("Start date cannot exceed target date")
|
raise serializers.ValidationError("Start date cannot exceed target date")
|
||||||
|
|
||||||
|
if data.get("members", []):
|
||||||
|
print(data.get("members"))
|
||||||
|
data["members"] = ProjectMember.objects.filter(
|
||||||
|
project_id=self.context.get("project_id"),
|
||||||
|
member_id__in=data["members"],
|
||||||
|
).values_list("member_id", flat=True)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
@ -99,23 +113,7 @@ class ModuleWriteSerializer(BaseSerializer):
|
|||||||
return super().update(instance, validated_data)
|
return super().update(instance, validated_data)
|
||||||
|
|
||||||
|
|
||||||
class ModuleFlatSerializer(BaseSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = Module
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
"created_by",
|
|
||||||
"updated_by",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleIssueSerializer(BaseSerializer):
|
class ModuleIssueSerializer(BaseSerializer):
|
||||||
module_detail = ModuleFlatSerializer(read_only=True, source="module")
|
|
||||||
issue_detail = ProjectLiteSerializer(read_only=True, source="issue")
|
|
||||||
sub_issues_count = serializers.IntegerField(read_only=True)
|
sub_issues_count = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -133,8 +131,6 @@ class ModuleIssueSerializer(BaseSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class ModuleLinkSerializer(BaseSerializer):
|
class ModuleLinkSerializer(BaseSerializer):
|
||||||
created_by_detail = UserLiteSerializer(read_only=True, source="created_by")
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ModuleLink
|
model = ModuleLink
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
@ -157,42 +153,3 @@ class ModuleLinkSerializer(BaseSerializer):
|
|||||||
{"error": "URL already exists for this Issue"}
|
{"error": "URL already exists for this Issue"}
|
||||||
)
|
)
|
||||||
return ModuleLink.objects.create(**validated_data)
|
return ModuleLink.objects.create(**validated_data)
|
||||||
|
|
||||||
|
|
||||||
class ModuleSerializer(BaseSerializer):
|
|
||||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
|
||||||
lead_detail = UserLiteSerializer(read_only=True, source="lead")
|
|
||||||
members_detail = UserLiteSerializer(read_only=True, many=True, source="members")
|
|
||||||
link_module = ModuleLinkSerializer(read_only=True, many=True)
|
|
||||||
is_favorite = serializers.BooleanField(read_only=True)
|
|
||||||
total_issues = serializers.IntegerField(read_only=True)
|
|
||||||
cancelled_issues = serializers.IntegerField(read_only=True)
|
|
||||||
completed_issues = serializers.IntegerField(read_only=True)
|
|
||||||
started_issues = serializers.IntegerField(read_only=True)
|
|
||||||
unstarted_issues = serializers.IntegerField(read_only=True)
|
|
||||||
backlog_issues = serializers.IntegerField(read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Module
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
"created_by",
|
|
||||||
"updated_by",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleFavoriteSerializer(BaseSerializer):
|
|
||||||
module_detail = ModuleFlatSerializer(source="module", read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ModuleFavorite
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
"user",
|
|
||||||
]
|
|
||||||
|
@ -2,30 +2,55 @@
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from .base import BaseSerializer, DynamicBaseSerializer
|
from plane.db.models import Project, ProjectIdentifier, WorkspaceMember, State, Estimate
|
||||||
from plane.api.serializers.workspace import WorkSpaceSerializer, WorkspaceLiteSerializer
|
from .base import BaseSerializer
|
||||||
from plane.api.serializers.user import UserLiteSerializer, UserAdminLiteSerializer
|
|
||||||
from plane.db.models import (
|
|
||||||
Project,
|
|
||||||
ProjectMember,
|
|
||||||
ProjectMemberInvite,
|
|
||||||
ProjectIdentifier,
|
|
||||||
ProjectFavorite,
|
|
||||||
ProjectDeployBoard,
|
|
||||||
ProjectPublicMember,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectSerializer(BaseSerializer):
|
class ProjectSerializer(BaseSerializer):
|
||||||
workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True)
|
|
||||||
|
total_members = serializers.IntegerField(read_only=True)
|
||||||
|
total_cycles = serializers.IntegerField(read_only=True)
|
||||||
|
total_modules = serializers.IntegerField(read_only=True)
|
||||||
|
is_member = serializers.BooleanField(read_only=True)
|
||||||
|
sort_order = serializers.FloatField(read_only=True)
|
||||||
|
member_role = serializers.IntegerField(read_only=True)
|
||||||
|
is_deployed = serializers.BooleanField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Project
|
model = Project
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
read_only_fields = [
|
read_only_fields = [
|
||||||
"workspace",
|
"workspace",
|
||||||
|
"id",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def validate(self, data):
|
||||||
|
# Check project lead should be a member of the workspace
|
||||||
|
if (
|
||||||
|
data.get("project_lead", None) is not None
|
||||||
|
and not WorkspaceMember.objects.filter(
|
||||||
|
workspace_id=self.context["workspace_id"],
|
||||||
|
member_id=data.get("project_lead"),
|
||||||
|
).exists()
|
||||||
|
):
|
||||||
|
raise serializers.ValidationError(
|
||||||
|
"Project lead should be a user in the workspace"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check default assignee should be a member of the workspace
|
||||||
|
if (
|
||||||
|
data.get("default_assignee", None) is not None
|
||||||
|
and not WorkspaceMember.objects.filter(
|
||||||
|
workspace_id=self.context["workspace_id"],
|
||||||
|
member_id=data.get("default_assignee"),
|
||||||
|
).exists()
|
||||||
|
):
|
||||||
|
raise serializers.ValidationError(
|
||||||
|
"Default assignee should be a user in the workspace"
|
||||||
|
)
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
identifier = validated_data.get("identifier", "").strip().upper()
|
identifier = validated_data.get("identifier", "").strip().upper()
|
||||||
if identifier == "":
|
if identifier == "":
|
||||||
@ -35,6 +60,7 @@ class ProjectSerializer(BaseSerializer):
|
|||||||
name=identifier, workspace_id=self.context["workspace_id"]
|
name=identifier, workspace_id=self.context["workspace_id"]
|
||||||
).exists():
|
).exists():
|
||||||
raise serializers.ValidationError(detail="Project Identifier is taken")
|
raise serializers.ValidationError(detail="Project Identifier is taken")
|
||||||
|
|
||||||
project = Project.objects.create(
|
project = Project.objects.create(
|
||||||
**validated_data, workspace_id=self.context["workspace_id"]
|
**validated_data, workspace_id=self.context["workspace_id"]
|
||||||
)
|
)
|
||||||
@ -45,36 +71,6 @@ class ProjectSerializer(BaseSerializer):
|
|||||||
)
|
)
|
||||||
return project
|
return project
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
|
||||||
identifier = validated_data.get("identifier", "").strip().upper()
|
|
||||||
|
|
||||||
# If identifier is not passed update the project and return
|
|
||||||
if identifier == "":
|
|
||||||
project = super().update(instance, validated_data)
|
|
||||||
return project
|
|
||||||
|
|
||||||
# If no Project Identifier is found create it
|
|
||||||
project_identifier = ProjectIdentifier.objects.filter(
|
|
||||||
name=identifier, workspace_id=instance.workspace_id
|
|
||||||
).first()
|
|
||||||
if project_identifier is None:
|
|
||||||
project = super().update(instance, validated_data)
|
|
||||||
project_identifier = ProjectIdentifier.objects.filter(
|
|
||||||
project=project
|
|
||||||
).first()
|
|
||||||
if project_identifier is not None:
|
|
||||||
project_identifier.name = identifier
|
|
||||||
project_identifier.save()
|
|
||||||
return project
|
|
||||||
# If found check if the project_id to be updated and identifier project id is same
|
|
||||||
if project_identifier.project_id == instance.id:
|
|
||||||
# If same pass update
|
|
||||||
project = super().update(instance, validated_data)
|
|
||||||
return project
|
|
||||||
|
|
||||||
# If not same fail update
|
|
||||||
raise serializers.ValidationError(detail="Project Identifier is already taken")
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectLiteSerializer(BaseSerializer):
|
class ProjectLiteSerializer(BaseSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -89,126 +85,3 @@ class ProjectLiteSerializer(BaseSerializer):
|
|||||||
"description",
|
"description",
|
||||||
]
|
]
|
||||||
read_only_fields = fields
|
read_only_fields = fields
|
||||||
|
|
||||||
|
|
||||||
class ProjectListSerializer(DynamicBaseSerializer):
|
|
||||||
is_favorite = serializers.BooleanField(read_only=True)
|
|
||||||
total_members = serializers.IntegerField(read_only=True)
|
|
||||||
total_cycles = serializers.IntegerField(read_only=True)
|
|
||||||
total_modules = serializers.IntegerField(read_only=True)
|
|
||||||
is_member = serializers.BooleanField(read_only=True)
|
|
||||||
sort_order = serializers.FloatField(read_only=True)
|
|
||||||
member_role = serializers.IntegerField(read_only=True)
|
|
||||||
is_deployed = serializers.BooleanField(read_only=True)
|
|
||||||
members = serializers.SerializerMethodField()
|
|
||||||
|
|
||||||
def get_members(self, obj):
|
|
||||||
project_members = ProjectMember.objects.filter(project_id=obj.id).values(
|
|
||||||
"id",
|
|
||||||
"member_id",
|
|
||||||
"member__display_name",
|
|
||||||
"member__avatar",
|
|
||||||
)
|
|
||||||
return project_members
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Project
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectDetailSerializer(BaseSerializer):
|
|
||||||
# workspace = WorkSpaceSerializer(read_only=True)
|
|
||||||
default_assignee = UserLiteSerializer(read_only=True)
|
|
||||||
project_lead = UserLiteSerializer(read_only=True)
|
|
||||||
is_favorite = serializers.BooleanField(read_only=True)
|
|
||||||
total_members = serializers.IntegerField(read_only=True)
|
|
||||||
total_cycles = serializers.IntegerField(read_only=True)
|
|
||||||
total_modules = serializers.IntegerField(read_only=True)
|
|
||||||
is_member = serializers.BooleanField(read_only=True)
|
|
||||||
sort_order = serializers.FloatField(read_only=True)
|
|
||||||
member_role = serializers.IntegerField(read_only=True)
|
|
||||||
is_deployed = serializers.BooleanField(read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Project
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectMemberSerializer(BaseSerializer):
|
|
||||||
workspace = WorkspaceLiteSerializer(read_only=True)
|
|
||||||
project = ProjectLiteSerializer(read_only=True)
|
|
||||||
member = UserLiteSerializer(read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ProjectMember
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectMemberAdminSerializer(BaseSerializer):
|
|
||||||
workspace = WorkspaceLiteSerializer(read_only=True)
|
|
||||||
project = ProjectLiteSerializer(read_only=True)
|
|
||||||
member = UserAdminLiteSerializer(read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ProjectMember
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectMemberInviteSerializer(BaseSerializer):
|
|
||||||
project = ProjectLiteSerializer(read_only=True)
|
|
||||||
workspace = WorkspaceLiteSerializer(read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ProjectMemberInvite
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectIdentifierSerializer(BaseSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = ProjectIdentifier
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectFavoriteSerializer(BaseSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = ProjectFavorite
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"user",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectMemberLiteSerializer(BaseSerializer):
|
|
||||||
member = UserLiteSerializer(read_only=True)
|
|
||||||
is_subscribed = serializers.BooleanField(read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ProjectMember
|
|
||||||
fields = ["member", "id", "is_subscribed"]
|
|
||||||
read_only_fields = fields
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectDeployBoardSerializer(BaseSerializer):
|
|
||||||
project_details = ProjectLiteSerializer(read_only=True, source="project")
|
|
||||||
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ProjectDeployBoard
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
"anchor",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectPublicMemberSerializer(BaseSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = ProjectPublicMember
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
"member",
|
|
||||||
]
|
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
# Module imports
|
# Module imports
|
||||||
from .base import BaseSerializer
|
from .base import BaseSerializer
|
||||||
from .workspace import WorkspaceLiteSerializer
|
|
||||||
from .project import ProjectLiteSerializer
|
|
||||||
|
|
||||||
from plane.db.models import State
|
from plane.db.models import State
|
||||||
|
|
||||||
|
|
||||||
class StateSerializer(BaseSerializer):
|
class StateSerializer(BaseSerializer):
|
||||||
|
def validate(self, data):
|
||||||
|
# If the default is being provided then make all other states default False
|
||||||
|
if data.get("default", False):
|
||||||
|
State.objects.filter(project_id=self.context.get("project_id")).update(
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
return data
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = State
|
model = State
|
||||||
|
@ -1,111 +1,6 @@
|
|||||||
# Third party imports
|
# Module imports
|
||||||
from rest_framework import serializers
|
from plane.db.models import User
|
||||||
|
|
||||||
# Module import
|
|
||||||
from .base import BaseSerializer
|
from .base import BaseSerializer
|
||||||
from plane.db.models import User, Workspace, WorkspaceMemberInvite
|
|
||||||
|
|
||||||
|
|
||||||
class UserSerializer(BaseSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = User
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"id",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
"is_superuser",
|
|
||||||
"is_staff",
|
|
||||||
"last_active",
|
|
||||||
"last_login_time",
|
|
||||||
"last_logout_time",
|
|
||||||
"last_login_ip",
|
|
||||||
"last_logout_ip",
|
|
||||||
"last_login_uagent",
|
|
||||||
"token_updated_at",
|
|
||||||
"is_onboarded",
|
|
||||||
"is_bot",
|
|
||||||
]
|
|
||||||
extra_kwargs = {"password": {"write_only": True}}
|
|
||||||
|
|
||||||
# If the user has already filled first name or last name then he is onboarded
|
|
||||||
def get_is_onboarded(self, obj):
|
|
||||||
return bool(obj.first_name) or bool(obj.last_name)
|
|
||||||
|
|
||||||
|
|
||||||
class UserMeSerializer(BaseSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = User
|
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"avatar",
|
|
||||||
"cover_image",
|
|
||||||
"date_joined",
|
|
||||||
"display_name",
|
|
||||||
"email",
|
|
||||||
"first_name",
|
|
||||||
"last_name",
|
|
||||||
"is_active",
|
|
||||||
"is_bot",
|
|
||||||
"is_email_verified",
|
|
||||||
"is_managed",
|
|
||||||
"is_onboarded",
|
|
||||||
"is_tour_completed",
|
|
||||||
"mobile_number",
|
|
||||||
"role",
|
|
||||||
"onboarding_step",
|
|
||||||
"user_timezone",
|
|
||||||
"username",
|
|
||||||
"theme",
|
|
||||||
"last_workspace_id",
|
|
||||||
]
|
|
||||||
read_only_fields = fields
|
|
||||||
|
|
||||||
|
|
||||||
class UserMeSettingsSerializer(BaseSerializer):
|
|
||||||
workspace = serializers.SerializerMethodField()
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = User
|
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"email",
|
|
||||||
"workspace",
|
|
||||||
]
|
|
||||||
read_only_fields = fields
|
|
||||||
|
|
||||||
def get_workspace(self, obj):
|
|
||||||
workspace_invites = WorkspaceMemberInvite.objects.filter(
|
|
||||||
email=obj.email
|
|
||||||
).count()
|
|
||||||
if obj.last_workspace_id is not None:
|
|
||||||
workspace = Workspace.objects.filter(
|
|
||||||
pk=obj.last_workspace_id, workspace_member__member=obj.id
|
|
||||||
).first()
|
|
||||||
return {
|
|
||||||
"last_workspace_id": obj.last_workspace_id,
|
|
||||||
"last_workspace_slug": workspace.slug if workspace is not None else "",
|
|
||||||
"fallback_workspace_id": obj.last_workspace_id,
|
|
||||||
"fallback_workspace_slug": workspace.slug if workspace is not None else "",
|
|
||||||
"invites": workspace_invites,
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
fallback_workspace = (
|
|
||||||
Workspace.objects.filter(workspace_member__member_id=obj.id)
|
|
||||||
.order_by("created_at")
|
|
||||||
.first()
|
|
||||||
)
|
|
||||||
return {
|
|
||||||
"last_workspace_id": None,
|
|
||||||
"last_workspace_slug": None,
|
|
||||||
"fallback_workspace_id": fallback_workspace.id
|
|
||||||
if fallback_workspace is not None
|
|
||||||
else None,
|
|
||||||
"fallback_workspace_slug": fallback_workspace.slug
|
|
||||||
if fallback_workspace is not None
|
|
||||||
else None,
|
|
||||||
"invites": workspace_invites,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class UserLiteSerializer(BaseSerializer):
|
class UserLiteSerializer(BaseSerializer):
|
||||||
@ -123,41 +18,3 @@ class UserLiteSerializer(BaseSerializer):
|
|||||||
"id",
|
"id",
|
||||||
"is_bot",
|
"is_bot",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class UserAdminLiteSerializer(BaseSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = User
|
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"first_name",
|
|
||||||
"last_name",
|
|
||||||
"avatar",
|
|
||||||
"is_bot",
|
|
||||||
"display_name",
|
|
||||||
"email",
|
|
||||||
]
|
|
||||||
read_only_fields = [
|
|
||||||
"id",
|
|
||||||
"is_bot",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class ChangePasswordSerializer(serializers.Serializer):
|
|
||||||
model = User
|
|
||||||
|
|
||||||
"""
|
|
||||||
Serializer for password change endpoint.
|
|
||||||
"""
|
|
||||||
old_password = serializers.CharField(required=True)
|
|
||||||
new_password = serializers.CharField(required=True)
|
|
||||||
|
|
||||||
|
|
||||||
class ResetPasswordSerializer(serializers.Serializer):
|
|
||||||
model = User
|
|
||||||
|
|
||||||
"""
|
|
||||||
Serializer for password change endpoint.
|
|
||||||
"""
|
|
||||||
new_password = serializers.CharField(required=True)
|
|
||||||
confirm_password = serializers.CharField(required=True)
|
|
||||||
|
@ -1,39 +1,10 @@
|
|||||||
# Third party imports
|
|
||||||
from rest_framework import serializers
|
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
|
from plane.db.models import Workspace
|
||||||
from .base import BaseSerializer
|
from .base import BaseSerializer
|
||||||
from .user import UserLiteSerializer, UserAdminLiteSerializer
|
|
||||||
|
|
||||||
from plane.db.models import (
|
|
||||||
User,
|
|
||||||
Workspace,
|
|
||||||
WorkspaceMember,
|
|
||||||
Team,
|
|
||||||
TeamMember,
|
|
||||||
WorkspaceMemberInvite,
|
|
||||||
WorkspaceTheme,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class WorkSpaceSerializer(BaseSerializer):
|
|
||||||
owner = UserLiteSerializer(read_only=True)
|
|
||||||
total_members = serializers.IntegerField(read_only=True)
|
|
||||||
total_issues = serializers.IntegerField(read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Workspace
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"id",
|
|
||||||
"created_by",
|
|
||||||
"updated_by",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
"owner",
|
|
||||||
]
|
|
||||||
|
|
||||||
class WorkspaceLiteSerializer(BaseSerializer):
|
class WorkspaceLiteSerializer(BaseSerializer):
|
||||||
|
"""Lite serializer with only required fields"""
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Workspace
|
model = Workspace
|
||||||
fields = [
|
fields = [
|
||||||
@ -42,95 +13,3 @@ class WorkspaceLiteSerializer(BaseSerializer):
|
|||||||
"id",
|
"id",
|
||||||
]
|
]
|
||||||
read_only_fields = fields
|
read_only_fields = fields
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class WorkSpaceMemberSerializer(BaseSerializer):
|
|
||||||
member = UserLiteSerializer(read_only=True)
|
|
||||||
workspace = WorkspaceLiteSerializer(read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = WorkspaceMember
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class WorkspaceMemberMeSerializer(BaseSerializer):
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = WorkspaceMember
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class WorkspaceMemberAdminSerializer(BaseSerializer):
|
|
||||||
member = UserAdminLiteSerializer(read_only=True)
|
|
||||||
workspace = WorkspaceLiteSerializer(read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = WorkspaceMember
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class WorkSpaceMemberInviteSerializer(BaseSerializer):
|
|
||||||
workspace = WorkSpaceSerializer(read_only=True)
|
|
||||||
total_members = serializers.IntegerField(read_only=True)
|
|
||||||
created_by_detail = UserLiteSerializer(read_only=True, source="created_by")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = WorkspaceMemberInvite
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class TeamSerializer(BaseSerializer):
|
|
||||||
members_detail = UserLiteSerializer(read_only=True, source="members", many=True)
|
|
||||||
members = serializers.ListField(
|
|
||||||
child=serializers.PrimaryKeyRelatedField(queryset=User.objects.all()),
|
|
||||||
write_only=True,
|
|
||||||
required=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Team
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"created_by",
|
|
||||||
"updated_by",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
]
|
|
||||||
|
|
||||||
def create(self, validated_data, **kwargs):
|
|
||||||
if "members" in validated_data:
|
|
||||||
members = validated_data.pop("members")
|
|
||||||
workspace = self.context["workspace"]
|
|
||||||
team = Team.objects.create(**validated_data, workspace=workspace)
|
|
||||||
team_members = [
|
|
||||||
TeamMember(member=member, team=team, workspace=workspace)
|
|
||||||
for member in members
|
|
||||||
]
|
|
||||||
TeamMember.objects.bulk_create(team_members, batch_size=10)
|
|
||||||
return team
|
|
||||||
team = Team.objects.create(**validated_data)
|
|
||||||
return team
|
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
|
||||||
if "members" in validated_data:
|
|
||||||
members = validated_data.pop("members")
|
|
||||||
TeamMember.objects.filter(team=instance).delete()
|
|
||||||
team_members = [
|
|
||||||
TeamMember(member=member, team=instance, workspace=instance.workspace)
|
|
||||||
for member in members
|
|
||||||
]
|
|
||||||
TeamMember.objects.bulk_create(team_members, batch_size=10)
|
|
||||||
return super().update(instance, validated_data)
|
|
||||||
return super().update(instance, validated_data)
|
|
||||||
|
|
||||||
|
|
||||||
class WorkspaceThemeSerializer(BaseSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = WorkspaceTheme
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"actor",
|
|
||||||
]
|
|
||||||
|
@ -1,46 +1,15 @@
|
|||||||
from .analytic import urlpatterns as analytic_urls
|
from .project import urlpatterns as project_patterns
|
||||||
from .asset import urlpatterns as asset_urls
|
from .state import urlpatterns as state_patterns
|
||||||
from .authentication import urlpatterns as authentication_urls
|
from .issue import urlpatterns as issue_patterns
|
||||||
from .config import urlpatterns as configuration_urls
|
from .cycle import urlpatterns as cycle_patterns
|
||||||
from .cycle import urlpatterns as cycle_urls
|
from .module import urlpatterns as module_patterns
|
||||||
from .estimate import urlpatterns as estimate_urls
|
from .inbox import urlpatterns as inbox_patterns
|
||||||
from .external import urlpatterns as external_urls
|
|
||||||
from .importer import urlpatterns as importer_urls
|
|
||||||
from .inbox import urlpatterns as inbox_urls
|
|
||||||
from .integration import urlpatterns as integration_urls
|
|
||||||
from .issue import urlpatterns as issue_urls
|
|
||||||
from .module import urlpatterns as module_urls
|
|
||||||
from .notification import urlpatterns as notification_urls
|
|
||||||
from .page import urlpatterns as page_urls
|
|
||||||
from .project import urlpatterns as project_urls
|
|
||||||
from .public_board import urlpatterns as public_board_urls
|
|
||||||
from .search import urlpatterns as search_urls
|
|
||||||
from .state import urlpatterns as state_urls
|
|
||||||
from .user import urlpatterns as user_urls
|
|
||||||
from .views import urlpatterns as view_urls
|
|
||||||
from .workspace import urlpatterns as workspace_urls
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
*analytic_urls,
|
*project_patterns,
|
||||||
*asset_urls,
|
*state_patterns,
|
||||||
*authentication_urls,
|
*issue_patterns,
|
||||||
*configuration_urls,
|
*cycle_patterns,
|
||||||
*cycle_urls,
|
*module_patterns,
|
||||||
*estimate_urls,
|
*inbox_patterns,
|
||||||
*external_urls,
|
|
||||||
*importer_urls,
|
|
||||||
*inbox_urls,
|
|
||||||
*integration_urls,
|
|
||||||
*issue_urls,
|
|
||||||
*module_urls,
|
|
||||||
*notification_urls,
|
|
||||||
*page_urls,
|
|
||||||
*project_urls,
|
|
||||||
*public_board_urls,
|
|
||||||
*search_urls,
|
|
||||||
*state_urls,
|
|
||||||
*user_urls,
|
|
||||||
*view_urls,
|
|
||||||
*workspace_urls,
|
|
||||||
]
|
]
|
@ -1,87 +1,35 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
from plane.api.views.cycle import (
|
||||||
from plane.api.views import (
|
CycleAPIEndpoint,
|
||||||
CycleViewSet,
|
CycleIssueAPIEndpoint,
|
||||||
CycleIssueViewSet,
|
TransferCycleIssueAPIEndpoint,
|
||||||
CycleDateCheckEndpoint,
|
|
||||||
CycleFavoriteViewSet,
|
|
||||||
TransferCycleIssueEndpoint,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/",
|
||||||
CycleViewSet.as_view(
|
CycleAPIEndpoint.as_view(),
|
||||||
{
|
name="cycles",
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-cycle",
|
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/<uuid:pk>/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/<uuid:cycle_id>/",
|
||||||
CycleViewSet.as_view(
|
CycleAPIEndpoint.as_view(),
|
||||||
{
|
name="cycles",
|
||||||
"get": "retrieve",
|
|
||||||
"put": "update",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-cycle",
|
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/<uuid:cycle_id>/cycle-issues/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/<uuid:cycle_id>/cycle-issues/",
|
||||||
CycleIssueViewSet.as_view(
|
CycleIssueAPIEndpoint.as_view(),
|
||||||
{
|
name="cycle-issues",
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-cycle",
|
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/<uuid:cycle_id>/cycle-issues/<uuid:pk>/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/<uuid:cycle_id>/cycle-issues/<uuid:pk>/",
|
||||||
CycleIssueViewSet.as_view(
|
CycleIssueAPIEndpoint.as_view(),
|
||||||
{
|
name="cycle-issues",
|
||||||
"get": "retrieve",
|
|
||||||
"put": "update",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-cycle",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/date-check/",
|
|
||||||
CycleDateCheckEndpoint.as_view(),
|
|
||||||
name="project-cycle-date",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/user-favorite-cycles/",
|
|
||||||
CycleFavoriteViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="user-favorite-cycle",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/user-favorite-cycles/<uuid:cycle_id>/",
|
|
||||||
CycleFavoriteViewSet.as_view(
|
|
||||||
{
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="user-favorite-cycle",
|
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/<uuid:cycle_id>/transfer-issues/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/<uuid:cycle_id>/transfer-issues/",
|
||||||
TransferCycleIssueEndpoint.as_view(),
|
TransferCycleIssueAPIEndpoint.as_view(),
|
||||||
name="transfer-issues",
|
name="transfer-issues",
|
||||||
),
|
),
|
||||||
]
|
]
|
@ -1,53 +1,17 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
from plane.api.views import InboxIssueAPIEndpoint
|
||||||
from plane.api.views import (
|
|
||||||
InboxViewSet,
|
|
||||||
InboxIssueViewSet,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/inboxes/",
|
|
||||||
InboxViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="inbox",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/inboxes/<uuid:pk>/",
|
|
||||||
InboxViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "retrieve",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="inbox",
|
|
||||||
),
|
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/inboxes/<uuid:inbox_id>/inbox-issues/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/inboxes/<uuid:inbox_id>/inbox-issues/",
|
||||||
InboxIssueViewSet.as_view(
|
InboxIssueAPIEndpoint.as_view(),
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="inbox-issue",
|
name="inbox-issue",
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/inboxes/<uuid:inbox_id>/inbox-issues/<uuid:pk>/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/inboxes/<uuid:inbox_id>/inbox-issues/<uuid:pk>/",
|
||||||
InboxIssueViewSet.as_view(
|
InboxIssueAPIEndpoint.as_view(),
|
||||||
{
|
|
||||||
"get": "retrieve",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="inbox-issue",
|
name="inbox-issue",
|
||||||
),
|
),
|
||||||
]
|
]
|
@ -1,327 +1,62 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
from plane.api.views import (
|
from plane.api.views import (
|
||||||
IssueViewSet,
|
IssueAPIEndpoint,
|
||||||
IssueListEndpoint,
|
LabelAPIEndpoint,
|
||||||
IssueListGroupedEndpoint,
|
IssueLinkAPIEndpoint,
|
||||||
LabelViewSet,
|
IssueCommentAPIEndpoint,
|
||||||
BulkCreateIssueLabelsEndpoint,
|
IssueActivityAPIEndpoint,
|
||||||
BulkDeleteIssuesEndpoint,
|
|
||||||
BulkImportIssuesEndpoint,
|
|
||||||
UserWorkSpaceIssues,
|
|
||||||
SubIssuesEndpoint,
|
|
||||||
IssueLinkViewSet,
|
|
||||||
IssueAttachmentEndpoint,
|
|
||||||
ExportIssuesEndpoint,
|
|
||||||
IssueActivityEndpoint,
|
|
||||||
IssueCommentViewSet,
|
|
||||||
IssueSubscriberViewSet,
|
|
||||||
IssueReactionViewSet,
|
|
||||||
CommentReactionViewSet,
|
|
||||||
IssueUserDisplayPropertyEndpoint,
|
|
||||||
IssueArchiveViewSet,
|
|
||||||
IssueRelationViewSet,
|
|
||||||
IssueDraftViewSet,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/",
|
||||||
IssueViewSet.as_view(
|
IssueAPIEndpoint.as_view(),
|
||||||
{
|
name="issue",
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue",
|
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"v2/workspaces/<str:slug>/projects/<uuid:project_id>/issues/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/",
|
||||||
IssueListEndpoint.as_view(),
|
IssueAPIEndpoint.as_view(),
|
||||||
name="project-issue",
|
name="issue",
|
||||||
),
|
|
||||||
path(
|
|
||||||
"v3/workspaces/<str:slug>/projects/<uuid:project_id>/issues/",
|
|
||||||
IssueListGroupedEndpoint.as_view(),
|
|
||||||
name="project-issue",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:pk>/",
|
|
||||||
IssueViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "retrieve",
|
|
||||||
"put": "update",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue",
|
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issue-labels/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issue-labels/",
|
||||||
LabelViewSet.as_view(
|
LabelAPIEndpoint.as_view(),
|
||||||
{
|
name="label",
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-labels",
|
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issue-labels/<uuid:pk>/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issue-labels/<uuid:pk>/",
|
||||||
LabelViewSet.as_view(
|
LabelAPIEndpoint.as_view(),
|
||||||
{
|
name="label",
|
||||||
"get": "retrieve",
|
|
||||||
"put": "update",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-labels",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/bulk-create-labels/",
|
|
||||||
BulkCreateIssueLabelsEndpoint.as_view(),
|
|
||||||
name="project-bulk-labels",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/bulk-delete-issues/",
|
|
||||||
BulkDeleteIssuesEndpoint.as_view(),
|
|
||||||
name="project-issues-bulk",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/bulk-import-issues/<str:service>/",
|
|
||||||
BulkImportIssuesEndpoint.as_view(),
|
|
||||||
name="project-issues-bulk",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/my-issues/",
|
|
||||||
UserWorkSpaceIssues.as_view(),
|
|
||||||
name="workspace-issues",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/sub-issues/",
|
|
||||||
SubIssuesEndpoint.as_view(),
|
|
||||||
name="sub-issues",
|
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-links/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-links/",
|
||||||
IssueLinkViewSet.as_view(
|
IssueLinkAPIEndpoint.as_view(),
|
||||||
{
|
name="link",
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-links",
|
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-links/<uuid:pk>/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-links/<uuid:pk>/",
|
||||||
IssueLinkViewSet.as_view(
|
IssueLinkAPIEndpoint.as_view(),
|
||||||
{
|
name="link",
|
||||||
"get": "retrieve",
|
|
||||||
"put": "update",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
name="project-issue-links",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-attachments/",
|
|
||||||
IssueAttachmentEndpoint.as_view(),
|
|
||||||
name="project-issue-attachments",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-attachments/<uuid:pk>/",
|
|
||||||
IssueAttachmentEndpoint.as_view(),
|
|
||||||
name="project-issue-attachments",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/export-issues/",
|
|
||||||
ExportIssuesEndpoint.as_view(),
|
|
||||||
name="export-issues",
|
|
||||||
),
|
|
||||||
## End Issues
|
|
||||||
## Issue Activity
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/history/",
|
|
||||||
IssueActivityEndpoint.as_view(),
|
|
||||||
name="project-issue-history",
|
|
||||||
),
|
|
||||||
## Issue Activity
|
|
||||||
## IssueComments
|
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/comments/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/comments/",
|
||||||
IssueCommentViewSet.as_view(
|
IssueCommentAPIEndpoint.as_view(),
|
||||||
{
|
name="comment",
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-comment",
|
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/comments/<uuid:pk>/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/comments/<uuid:pk>/",
|
||||||
IssueCommentViewSet.as_view(
|
IssueCommentAPIEndpoint.as_view(),
|
||||||
{
|
name="comment",
|
||||||
"get": "retrieve",
|
|
||||||
"put": "update",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-comment",
|
|
||||||
),
|
|
||||||
## End IssueComments
|
|
||||||
# Issue Subscribers
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-subscribers/",
|
|
||||||
IssueSubscriberViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-subscribers",
|
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-subscribers/<uuid:subscriber_id>/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/activites/",
|
||||||
IssueSubscriberViewSet.as_view({"delete": "destroy"}),
|
IssueActivityAPIEndpoint.as_view(),
|
||||||
name="project-issue-subscribers",
|
name="activity",
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/subscribe/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/activites/<uuid:pk>/",
|
||||||
IssueSubscriberViewSet.as_view(
|
IssueActivityAPIEndpoint.as_view(),
|
||||||
{
|
name="activity",
|
||||||
"get": "subscription_status",
|
|
||||||
"post": "subscribe",
|
|
||||||
"delete": "unsubscribe",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-subscribers",
|
|
||||||
),
|
|
||||||
## End Issue Subscribers
|
|
||||||
# Issue Reactions
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/reactions/",
|
|
||||||
IssueReactionViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-reactions",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/reactions/<str:reaction_code>/",
|
|
||||||
IssueReactionViewSet.as_view(
|
|
||||||
{
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-reactions",
|
|
||||||
),
|
|
||||||
## End Issue Reactions
|
|
||||||
# Comment Reactions
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/comments/<uuid:comment_id>/reactions/",
|
|
||||||
CommentReactionViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-comment-reactions",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/comments/<uuid:comment_id>/reactions/<str:reaction_code>/",
|
|
||||||
CommentReactionViewSet.as_view(
|
|
||||||
{
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-comment-reactions",
|
|
||||||
),
|
|
||||||
## End Comment Reactions
|
|
||||||
## IssueProperty
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issue-display-properties/",
|
|
||||||
IssueUserDisplayPropertyEndpoint.as_view(),
|
|
||||||
name="project-issue-display-properties",
|
|
||||||
),
|
|
||||||
## IssueProperty End
|
|
||||||
## Issue Archives
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/archived-issues/",
|
|
||||||
IssueArchiveViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-archive",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/archived-issues/<uuid:pk>/",
|
|
||||||
IssueArchiveViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "retrieve",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-archive",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/unarchive/<uuid:pk>/",
|
|
||||||
IssueArchiveViewSet.as_view(
|
|
||||||
{
|
|
||||||
"post": "unarchive",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-archive",
|
|
||||||
),
|
|
||||||
## End Issue Archives
|
|
||||||
## Issue Relation
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-relation/",
|
|
||||||
IssueRelationViewSet.as_view(
|
|
||||||
{
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="issue-relation",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-relation/<uuid:pk>/",
|
|
||||||
IssueRelationViewSet.as_view(
|
|
||||||
{
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="issue-relation",
|
|
||||||
),
|
|
||||||
## End Issue Relation
|
|
||||||
## Issue Drafts
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issue-drafts/",
|
|
||||||
IssueDraftViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-draft",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issue-drafts/<uuid:pk>/",
|
|
||||||
IssueDraftViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "retrieve",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-draft",
|
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -1,104 +1,26 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
from plane.api.views import ModuleAPIEndpoint, ModuleIssueAPIEndpoint
|
||||||
from plane.api.views import (
|
|
||||||
ModuleViewSet,
|
|
||||||
ModuleIssueViewSet,
|
|
||||||
ModuleLinkViewSet,
|
|
||||||
ModuleFavoriteViewSet,
|
|
||||||
BulkImportModulesEndpoint,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/",
|
||||||
ModuleViewSet.as_view(
|
ModuleAPIEndpoint.as_view(),
|
||||||
{
|
name="modules",
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-modules",
|
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/<uuid:pk>/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/<uuid:pk>/",
|
||||||
ModuleViewSet.as_view(
|
ModuleAPIEndpoint.as_view(),
|
||||||
{
|
name="modules",
|
||||||
"get": "retrieve",
|
|
||||||
"put": "update",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-modules",
|
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/<uuid:module_id>/module-issues/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/<uuid:module_id>/module-issues/",
|
||||||
ModuleIssueViewSet.as_view(
|
ModuleIssueAPIEndpoint.as_view(),
|
||||||
{
|
name="module-issues",
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-module-issues",
|
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/<uuid:module_id>/module-issues/<uuid:pk>/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/<uuid:module_id>/module-issues/<uuid:pk>/",
|
||||||
ModuleIssueViewSet.as_view(
|
ModuleIssueAPIEndpoint.as_view(),
|
||||||
{
|
name="module-issues",
|
||||||
"get": "retrieve",
|
|
||||||
"put": "update",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-module-issues",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/<uuid:module_id>/module-links/",
|
|
||||||
ModuleLinkViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-module-links",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/<uuid:module_id>/module-links/<uuid:pk>/",
|
|
||||||
ModuleLinkViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "retrieve",
|
|
||||||
"put": "update",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-issue-module-links",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/user-favorite-modules/",
|
|
||||||
ModuleFavoriteViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="user-favorite-module",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/user-favorite-modules/<uuid:module_id>/",
|
|
||||||
ModuleFavoriteViewSet.as_view(
|
|
||||||
{
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="user-favorite-module",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/bulk-import-modules/<str:service>/",
|
|
||||||
BulkImportModulesEndpoint.as_view(),
|
|
||||||
name="bulk-modules-create",
|
|
||||||
),
|
),
|
||||||
]
|
]
|
@ -1,79 +0,0 @@
|
|||||||
from django.urls import path
|
|
||||||
|
|
||||||
|
|
||||||
from plane.api.views import (
|
|
||||||
PageViewSet,
|
|
||||||
PageBlockViewSet,
|
|
||||||
PageFavoriteViewSet,
|
|
||||||
CreateIssueFromPageBlockEndpoint,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/pages/",
|
|
||||||
PageViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-pages",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:pk>/",
|
|
||||||
PageViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "retrieve",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-pages",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:page_id>/page-blocks/",
|
|
||||||
PageBlockViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-page-blocks",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:page_id>/page-blocks/<uuid:pk>/",
|
|
||||||
PageBlockViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "retrieve",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-page-blocks",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/user-favorite-pages/",
|
|
||||||
PageFavoriteViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="user-favorite-pages",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/user-favorite-pages/<uuid:page_id>/",
|
|
||||||
PageFavoriteViewSet.as_view(
|
|
||||||
{
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="user-favorite-pages",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:page_id>/page-blocks/<uuid:page_block_id>/issues/",
|
|
||||||
CreateIssueFromPageBlockEndpoint.as_view(),
|
|
||||||
name="page-block-issues",
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,132 +1,16 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from plane.api.views import (
|
from plane.api.views import ProjectAPIEndpoint
|
||||||
ProjectViewSet,
|
|
||||||
InviteProjectEndpoint,
|
|
||||||
ProjectMemberViewSet,
|
|
||||||
ProjectMemberInvitationsViewset,
|
|
||||||
ProjectMemberUserEndpoint,
|
|
||||||
ProjectJoinEndpoint,
|
|
||||||
AddTeamToProjectEndpoint,
|
|
||||||
ProjectUserViewsEndpoint,
|
|
||||||
ProjectIdentifierEndpoint,
|
|
||||||
ProjectFavoritesViewSet,
|
|
||||||
LeaveProjectEndpoint,
|
|
||||||
ProjectPublicCoverImagesEndpoint,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/",
|
"workspaces/<str:slug>/projects/",
|
||||||
ProjectViewSet.as_view(
|
ProjectAPIEndpoint.as_view(),
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project",
|
name="project",
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:pk>/",
|
"workspaces/<str:slug>/projects/<uuid:pk>/",
|
||||||
ProjectViewSet.as_view(
|
ProjectAPIEndpoint.as_view(),
|
||||||
{
|
|
||||||
"get": "retrieve",
|
|
||||||
"put": "update",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project",
|
name="project",
|
||||||
),
|
),
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/project-identifiers/",
|
|
||||||
ProjectIdentifierEndpoint.as_view(),
|
|
||||||
name="project-identifiers",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/invite/",
|
|
||||||
InviteProjectEndpoint.as_view(),
|
|
||||||
name="invite-project",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/members/",
|
|
||||||
ProjectMemberViewSet.as_view({"get": "list", "post": "create"}),
|
|
||||||
name="project-member",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/members/<uuid:pk>/",
|
|
||||||
ProjectMemberViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "retrieve",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-member",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/join/",
|
|
||||||
ProjectJoinEndpoint.as_view(),
|
|
||||||
name="project-join",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/team-invite/",
|
|
||||||
AddTeamToProjectEndpoint.as_view(),
|
|
||||||
name="projects",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/invitations/",
|
|
||||||
ProjectMemberInvitationsViewset.as_view({"get": "list"}),
|
|
||||||
name="project-member-invite",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/invitations/<uuid:pk>/",
|
|
||||||
ProjectMemberInvitationsViewset.as_view(
|
|
||||||
{
|
|
||||||
"get": "retrieve",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-member-invite",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/project-views/",
|
|
||||||
ProjectUserViewsEndpoint.as_view(),
|
|
||||||
name="project-view",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/project-members/me/",
|
|
||||||
ProjectMemberUserEndpoint.as_view(),
|
|
||||||
name="project-member-view",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/user-favorite-projects/",
|
|
||||||
ProjectFavoritesViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-favorite",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/user-favorite-projects/<uuid:project_id>/",
|
|
||||||
ProjectFavoritesViewSet.as_view(
|
|
||||||
{
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-favorite",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/members/leave/",
|
|
||||||
LeaveProjectEndpoint.as_view(),
|
|
||||||
name="leave-project",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"project-covers/",
|
|
||||||
ProjectPublicCoverImagesEndpoint.as_view(),
|
|
||||||
name="project-covers",
|
|
||||||
),
|
|
||||||
]
|
]
|
@ -1,151 +0,0 @@
|
|||||||
from django.urls import path
|
|
||||||
|
|
||||||
|
|
||||||
from plane.api.views import (
|
|
||||||
ProjectDeployBoardViewSet,
|
|
||||||
ProjectDeployBoardPublicSettingsEndpoint,
|
|
||||||
ProjectIssuesPublicEndpoint,
|
|
||||||
IssueRetrievePublicEndpoint,
|
|
||||||
IssueCommentPublicViewSet,
|
|
||||||
IssueReactionPublicViewSet,
|
|
||||||
CommentReactionPublicViewSet,
|
|
||||||
InboxIssuePublicViewSet,
|
|
||||||
IssueVotePublicViewSet,
|
|
||||||
WorkspaceProjectDeployBoardEndpoint,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/project-deploy-boards/",
|
|
||||||
ProjectDeployBoardViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-deploy-board",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/project-deploy-boards/<uuid:pk>/",
|
|
||||||
ProjectDeployBoardViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "retrieve",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-deploy-board",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"public/workspaces/<str:slug>/project-boards/<uuid:project_id>/settings/",
|
|
||||||
ProjectDeployBoardPublicSettingsEndpoint.as_view(),
|
|
||||||
name="project-deploy-board-settings",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"public/workspaces/<str:slug>/project-boards/<uuid:project_id>/issues/",
|
|
||||||
ProjectIssuesPublicEndpoint.as_view(),
|
|
||||||
name="project-deploy-board",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"public/workspaces/<str:slug>/project-boards/<uuid:project_id>/issues/<uuid:issue_id>/",
|
|
||||||
IssueRetrievePublicEndpoint.as_view(),
|
|
||||||
name="workspace-project-boards",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"public/workspaces/<str:slug>/project-boards/<uuid:project_id>/issues/<uuid:issue_id>/comments/",
|
|
||||||
IssueCommentPublicViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="issue-comments-project-board",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"public/workspaces/<str:slug>/project-boards/<uuid:project_id>/issues/<uuid:issue_id>/comments/<uuid:pk>/",
|
|
||||||
IssueCommentPublicViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "retrieve",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="issue-comments-project-board",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"public/workspaces/<str:slug>/project-boards/<uuid:project_id>/issues/<uuid:issue_id>/reactions/",
|
|
||||||
IssueReactionPublicViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="issue-reactions-project-board",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"public/workspaces/<str:slug>/project-boards/<uuid:project_id>/issues/<uuid:issue_id>/reactions/<str:reaction_code>/",
|
|
||||||
IssueReactionPublicViewSet.as_view(
|
|
||||||
{
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="issue-reactions-project-board",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"public/workspaces/<str:slug>/project-boards/<uuid:project_id>/comments/<uuid:comment_id>/reactions/",
|
|
||||||
CommentReactionPublicViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="comment-reactions-project-board",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"public/workspaces/<str:slug>/project-boards/<uuid:project_id>/comments/<uuid:comment_id>/reactions/<str:reaction_code>/",
|
|
||||||
CommentReactionPublicViewSet.as_view(
|
|
||||||
{
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="comment-reactions-project-board",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"public/workspaces/<str:slug>/project-boards/<uuid:project_id>/inboxes/<uuid:inbox_id>/inbox-issues/",
|
|
||||||
InboxIssuePublicViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="inbox-issue",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"public/workspaces/<str:slug>/project-boards/<uuid:project_id>/inboxes/<uuid:inbox_id>/inbox-issues/<uuid:pk>/",
|
|
||||||
InboxIssuePublicViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "retrieve",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="inbox-issue",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"public/workspaces/<str:slug>/project-boards/<uuid:project_id>/issues/<uuid:issue_id>/votes/",
|
|
||||||
IssueVotePublicViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="issue-vote-project-board",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"public/workspaces/<str:slug>/project-boards/",
|
|
||||||
WorkspaceProjectDeployBoardEndpoint.as_view(),
|
|
||||||
name="workspace-project-boards",
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,38 +1,11 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
from plane.api.views import StateAPIEndpoint
|
||||||
from plane.api.views import StateViewSet
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/states/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/states/",
|
||||||
StateViewSet.as_view(
|
StateAPIEndpoint.as_view(),
|
||||||
{
|
name="states",
|
||||||
"get": "list",
|
|
||||||
"post": "create",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-states",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/states/<uuid:pk>/",
|
|
||||||
StateViewSet.as_view(
|
|
||||||
{
|
|
||||||
"get": "retrieve",
|
|
||||||
"patch": "partial_update",
|
|
||||||
"delete": "destroy",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-state",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/states/<uuid:pk>/mark-default/",
|
|
||||||
StateViewSet.as_view(
|
|
||||||
{
|
|
||||||
"post": "mark_as_default",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="project-state",
|
|
||||||
),
|
),
|
||||||
]
|
]
|
@ -1,180 +1,21 @@
|
|||||||
from .project import (
|
from .project import ProjectAPIEndpoint
|
||||||
ProjectViewSet,
|
|
||||||
ProjectMemberViewSet,
|
|
||||||
UserProjectInvitationsViewset,
|
|
||||||
InviteProjectEndpoint,
|
|
||||||
AddTeamToProjectEndpoint,
|
|
||||||
ProjectMemberInvitationsViewset,
|
|
||||||
ProjectMemberInviteDetailViewSet,
|
|
||||||
ProjectIdentifierEndpoint,
|
|
||||||
ProjectJoinEndpoint,
|
|
||||||
ProjectUserViewsEndpoint,
|
|
||||||
ProjectMemberUserEndpoint,
|
|
||||||
ProjectFavoritesViewSet,
|
|
||||||
ProjectDeployBoardViewSet,
|
|
||||||
ProjectDeployBoardPublicSettingsEndpoint,
|
|
||||||
WorkspaceProjectDeployBoardEndpoint,
|
|
||||||
LeaveProjectEndpoint,
|
|
||||||
ProjectPublicCoverImagesEndpoint,
|
|
||||||
)
|
|
||||||
from .user import (
|
|
||||||
UserEndpoint,
|
|
||||||
UpdateUserOnBoardedEndpoint,
|
|
||||||
UpdateUserTourCompletedEndpoint,
|
|
||||||
UserActivityEndpoint,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .oauth import OauthEndpoint
|
from .state import StateAPIEndpoint
|
||||||
|
|
||||||
from .base import BaseAPIView, BaseViewSet
|
|
||||||
|
|
||||||
from .workspace import (
|
|
||||||
WorkSpaceViewSet,
|
|
||||||
UserWorkSpacesEndpoint,
|
|
||||||
WorkSpaceAvailabilityCheckEndpoint,
|
|
||||||
InviteWorkspaceEndpoint,
|
|
||||||
JoinWorkspaceEndpoint,
|
|
||||||
WorkSpaceMemberViewSet,
|
|
||||||
TeamMemberViewSet,
|
|
||||||
WorkspaceInvitationsViewset,
|
|
||||||
UserWorkspaceInvitationsEndpoint,
|
|
||||||
UserWorkspaceInvitationEndpoint,
|
|
||||||
UserLastProjectWithWorkspaceEndpoint,
|
|
||||||
WorkspaceMemberUserEndpoint,
|
|
||||||
WorkspaceMemberUserViewsEndpoint,
|
|
||||||
UserActivityGraphEndpoint,
|
|
||||||
UserIssueCompletedGraphEndpoint,
|
|
||||||
UserWorkspaceDashboardEndpoint,
|
|
||||||
WorkspaceThemeViewSet,
|
|
||||||
WorkspaceUserProfileStatsEndpoint,
|
|
||||||
WorkspaceUserActivityEndpoint,
|
|
||||||
WorkspaceUserProfileEndpoint,
|
|
||||||
WorkspaceUserProfileIssuesEndpoint,
|
|
||||||
WorkspaceLabelsEndpoint,
|
|
||||||
LeaveWorkspaceEndpoint,
|
|
||||||
)
|
|
||||||
from .state import StateViewSet
|
|
||||||
from .view import (
|
|
||||||
GlobalViewViewSet,
|
|
||||||
GlobalViewIssuesViewSet,
|
|
||||||
IssueViewViewSet,
|
|
||||||
IssueViewFavoriteViewSet,
|
|
||||||
)
|
|
||||||
from .cycle import (
|
|
||||||
CycleViewSet,
|
|
||||||
CycleIssueViewSet,
|
|
||||||
CycleDateCheckEndpoint,
|
|
||||||
CycleFavoriteViewSet,
|
|
||||||
TransferCycleIssueEndpoint,
|
|
||||||
)
|
|
||||||
from .asset import FileAssetEndpoint, UserAssetsEndpoint
|
|
||||||
from .issue import (
|
from .issue import (
|
||||||
IssueViewSet,
|
IssueAPIEndpoint,
|
||||||
IssueListEndpoint,
|
LabelAPIEndpoint,
|
||||||
IssueListGroupedEndpoint,
|
IssueLinkAPIEndpoint,
|
||||||
WorkSpaceIssuesEndpoint,
|
IssueCommentAPIEndpoint,
|
||||||
IssueActivityEndpoint,
|
IssueActivityAPIEndpoint,
|
||||||
IssueCommentViewSet,
|
|
||||||
IssueUserDisplayPropertyEndpoint,
|
|
||||||
LabelViewSet,
|
|
||||||
BulkDeleteIssuesEndpoint,
|
|
||||||
UserWorkSpaceIssues,
|
|
||||||
SubIssuesEndpoint,
|
|
||||||
IssueLinkViewSet,
|
|
||||||
BulkCreateIssueLabelsEndpoint,
|
|
||||||
IssueAttachmentEndpoint,
|
|
||||||
IssueArchiveViewSet,
|
|
||||||
IssueSubscriberViewSet,
|
|
||||||
IssueCommentPublicViewSet,
|
|
||||||
CommentReactionViewSet,
|
|
||||||
IssueReactionViewSet,
|
|
||||||
IssueReactionPublicViewSet,
|
|
||||||
CommentReactionPublicViewSet,
|
|
||||||
IssueVotePublicViewSet,
|
|
||||||
IssueRelationViewSet,
|
|
||||||
IssueRetrievePublicEndpoint,
|
|
||||||
ProjectIssuesPublicEndpoint,
|
|
||||||
IssueDraftViewSet,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from .auth_extended import (
|
from .cycle import (
|
||||||
VerifyEmailEndpoint,
|
CycleAPIEndpoint,
|
||||||
RequestEmailVerificationEndpoint,
|
CycleIssueAPIEndpoint,
|
||||||
ForgotPasswordEndpoint,
|
TransferCycleIssueAPIEndpoint,
|
||||||
ResetPasswordEndpoint,
|
|
||||||
ChangePasswordEndpoint,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from .module import ModuleAPIEndpoint, ModuleIssueAPIEndpoint
|
||||||
|
|
||||||
from .authentication import (
|
from .inbox import InboxIssueAPIEndpoint
|
||||||
SignUpEndpoint,
|
|
||||||
SignInEndpoint,
|
|
||||||
SignOutEndpoint,
|
|
||||||
MagicSignInEndpoint,
|
|
||||||
MagicSignInGenerateEndpoint,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .module import (
|
|
||||||
ModuleViewSet,
|
|
||||||
ModuleIssueViewSet,
|
|
||||||
ModuleLinkViewSet,
|
|
||||||
ModuleFavoriteViewSet,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .api_token import ApiTokenEndpoint
|
|
||||||
|
|
||||||
from .integration import (
|
|
||||||
WorkspaceIntegrationViewSet,
|
|
||||||
IntegrationViewSet,
|
|
||||||
GithubIssueSyncViewSet,
|
|
||||||
GithubRepositorySyncViewSet,
|
|
||||||
GithubCommentSyncViewSet,
|
|
||||||
GithubRepositoriesEndpoint,
|
|
||||||
BulkCreateGithubIssueSyncEndpoint,
|
|
||||||
SlackProjectSyncViewSet,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .importer import (
|
|
||||||
ServiceIssueImportSummaryEndpoint,
|
|
||||||
ImportServiceEndpoint,
|
|
||||||
UpdateServiceImportStatusEndpoint,
|
|
||||||
BulkImportIssuesEndpoint,
|
|
||||||
BulkImportModulesEndpoint,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .page import (
|
|
||||||
PageViewSet,
|
|
||||||
PageBlockViewSet,
|
|
||||||
PageFavoriteViewSet,
|
|
||||||
CreateIssueFromPageBlockEndpoint,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .search import GlobalSearchEndpoint, IssueSearchEndpoint
|
|
||||||
|
|
||||||
|
|
||||||
from .external import GPTIntegrationEndpoint, ReleaseNotesEndpoint, UnsplashEndpoint
|
|
||||||
|
|
||||||
from .estimate import (
|
|
||||||
ProjectEstimatePointEndpoint,
|
|
||||||
BulkEstimatePointEndpoint,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .inbox import InboxViewSet, InboxIssueViewSet, InboxIssuePublicViewSet
|
|
||||||
|
|
||||||
from .analytic import (
|
|
||||||
AnalyticsEndpoint,
|
|
||||||
AnalyticViewViewset,
|
|
||||||
SavedAnalyticEndpoint,
|
|
||||||
ExportAnalyticsEndpoint,
|
|
||||||
DefaultAnalyticsEndpoint,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .notification import (
|
|
||||||
NotificationViewSet,
|
|
||||||
UnreadNotificationEndpoint,
|
|
||||||
MarkAllReadNotificationViewSet,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .exporter import ExportIssuesEndpoint
|
|
||||||
|
|
||||||
from .config import ConfigurationEndpoint
|
|
@ -1,47 +0,0 @@
|
|||||||
# Python import
|
|
||||||
from uuid import uuid4
|
|
||||||
|
|
||||||
# Third party
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from rest_framework import status
|
|
||||||
from sentry_sdk import capture_exception
|
|
||||||
|
|
||||||
# Module import
|
|
||||||
from .base import BaseAPIView
|
|
||||||
from plane.db.models import APIToken
|
|
||||||
from plane.api.serializers import APITokenSerializer
|
|
||||||
|
|
||||||
|
|
||||||
class ApiTokenEndpoint(BaseAPIView):
|
|
||||||
def post(self, request):
|
|
||||||
label = request.data.get("label", str(uuid4().hex))
|
|
||||||
workspace = request.data.get("workspace", False)
|
|
||||||
|
|
||||||
if not workspace:
|
|
||||||
return Response(
|
|
||||||
{"error": "Workspace is required"}, status=status.HTTP_200_OK
|
|
||||||
)
|
|
||||||
|
|
||||||
api_token = APIToken.objects.create(
|
|
||||||
label=label, user=request.user, workspace_id=workspace
|
|
||||||
)
|
|
||||||
|
|
||||||
serializer = APITokenSerializer(api_token)
|
|
||||||
# Token will be only vissible while creating
|
|
||||||
return Response(
|
|
||||||
{"api_token": serializer.data, "token": api_token.token},
|
|
||||||
status=status.HTTP_201_CREATED,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get(self, request):
|
|
||||||
api_tokens = APIToken.objects.filter(user=request.user)
|
|
||||||
serializer = APITokenSerializer(api_tokens, many=True)
|
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
|
|
||||||
def delete(self, request, pk):
|
|
||||||
api_token = APIToken.objects.get(pk=pk)
|
|
||||||
api_token.delete()
|
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
|
||||||
|
|
@ -1,397 +0,0 @@
|
|||||||
# Python imports
|
|
||||||
import uuid
|
|
||||||
import random
|
|
||||||
import string
|
|
||||||
import json
|
|
||||||
import requests
|
|
||||||
|
|
||||||
# Django imports
|
|
||||||
from django.utils import timezone
|
|
||||||
from django.core.exceptions import ValidationError
|
|
||||||
from django.core.validators import validate_email
|
|
||||||
from django.conf import settings
|
|
||||||
from django.contrib.auth.hashers import make_password
|
|
||||||
|
|
||||||
# Third party imports
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from rest_framework.permissions import AllowAny
|
|
||||||
from rest_framework import status
|
|
||||||
from rest_framework_simplejwt.tokens import RefreshToken
|
|
||||||
|
|
||||||
from sentry_sdk import capture_exception, capture_message
|
|
||||||
|
|
||||||
# Module imports
|
|
||||||
from . import BaseAPIView
|
|
||||||
from plane.db.models import User
|
|
||||||
from plane.api.serializers import UserSerializer
|
|
||||||
from plane.settings.redis import redis_instance
|
|
||||||
from plane.bgtasks.magic_link_code_task import magic_link
|
|
||||||
|
|
||||||
|
|
||||||
def get_tokens_for_user(user):
|
|
||||||
refresh = RefreshToken.for_user(user)
|
|
||||||
return (
|
|
||||||
str(refresh.access_token),
|
|
||||||
str(refresh),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class SignUpEndpoint(BaseAPIView):
|
|
||||||
permission_classes = (AllowAny,)
|
|
||||||
|
|
||||||
def post(self, request):
|
|
||||||
if not settings.ENABLE_SIGNUP:
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"error": "New account creation is disabled. Please contact your site administrator"
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
email = request.data.get("email", False)
|
|
||||||
password = request.data.get("password", False)
|
|
||||||
|
|
||||||
## Raise exception if any of the above are missing
|
|
||||||
if not email or not password:
|
|
||||||
return Response(
|
|
||||||
{"error": "Both email and password are required"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
email = email.strip().lower()
|
|
||||||
|
|
||||||
try:
|
|
||||||
validate_email(email)
|
|
||||||
except ValidationError as e:
|
|
||||||
return Response(
|
|
||||||
{"error": "Please provide a valid email address."},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check if the user already exists
|
|
||||||
if User.objects.filter(email=email).exists():
|
|
||||||
return Response(
|
|
||||||
{"error": "User with this email already exists"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
user = User.objects.create(email=email, username=uuid.uuid4().hex)
|
|
||||||
user.set_password(password)
|
|
||||||
|
|
||||||
# settings last actives for the user
|
|
||||||
user.last_active = timezone.now()
|
|
||||||
user.last_login_time = timezone.now()
|
|
||||||
user.last_login_ip = request.META.get("REMOTE_ADDR")
|
|
||||||
user.last_login_uagent = request.META.get("HTTP_USER_AGENT")
|
|
||||||
user.token_updated_at = timezone.now()
|
|
||||||
user.save()
|
|
||||||
|
|
||||||
access_token, refresh_token = get_tokens_for_user(user)
|
|
||||||
|
|
||||||
data = {
|
|
||||||
"access_token": access_token,
|
|
||||||
"refresh_token": refresh_token,
|
|
||||||
}
|
|
||||||
|
|
||||||
# Send Analytics
|
|
||||||
if settings.ANALYTICS_BASE_API:
|
|
||||||
_ = requests.post(
|
|
||||||
settings.ANALYTICS_BASE_API,
|
|
||||||
headers={
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"X-Auth-Token": settings.ANALYTICS_SECRET_KEY,
|
|
||||||
},
|
|
||||||
json={
|
|
||||||
"event_id": uuid.uuid4().hex,
|
|
||||||
"event_data": {
|
|
||||||
"medium": "email",
|
|
||||||
},
|
|
||||||
"user": {"email": email, "id": str(user.id)},
|
|
||||||
"device_ctx": {
|
|
||||||
"ip": request.META.get("REMOTE_ADDR"),
|
|
||||||
"user_agent": request.META.get("HTTP_USER_AGENT"),
|
|
||||||
},
|
|
||||||
"event_type": "SIGN_UP",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
return Response(data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
|
|
||||||
class SignInEndpoint(BaseAPIView):
|
|
||||||
permission_classes = (AllowAny,)
|
|
||||||
|
|
||||||
def post(self, request):
|
|
||||||
email = request.data.get("email", False)
|
|
||||||
password = request.data.get("password", False)
|
|
||||||
|
|
||||||
## Raise exception if any of the above are missing
|
|
||||||
if not email or not password:
|
|
||||||
return Response(
|
|
||||||
{"error": "Both email and password are required"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
email = email.strip().lower()
|
|
||||||
|
|
||||||
try:
|
|
||||||
validate_email(email)
|
|
||||||
except ValidationError as e:
|
|
||||||
return Response(
|
|
||||||
{"error": "Please provide a valid email address."},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
user = User.objects.filter(email=email).first()
|
|
||||||
|
|
||||||
if user is None:
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"error": "Sorry, we could not find a user with the provided credentials. Please try again."
|
|
||||||
},
|
|
||||||
status=status.HTTP_403_FORBIDDEN,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Sign up Process
|
|
||||||
if not user.check_password(password):
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"error": "Sorry, we could not find a user with the provided credentials. Please try again."
|
|
||||||
},
|
|
||||||
status=status.HTTP_403_FORBIDDEN,
|
|
||||||
)
|
|
||||||
if not user.is_active:
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"error": "Your account has been deactivated. Please contact your site administrator."
|
|
||||||
},
|
|
||||||
status=status.HTTP_403_FORBIDDEN,
|
|
||||||
)
|
|
||||||
|
|
||||||
# settings last active for the user
|
|
||||||
user.last_active = timezone.now()
|
|
||||||
user.last_login_time = timezone.now()
|
|
||||||
user.last_login_ip = request.META.get("REMOTE_ADDR")
|
|
||||||
user.last_login_uagent = request.META.get("HTTP_USER_AGENT")
|
|
||||||
user.token_updated_at = timezone.now()
|
|
||||||
user.save()
|
|
||||||
|
|
||||||
access_token, refresh_token = get_tokens_for_user(user)
|
|
||||||
# Send Analytics
|
|
||||||
if settings.ANALYTICS_BASE_API:
|
|
||||||
_ = requests.post(
|
|
||||||
settings.ANALYTICS_BASE_API,
|
|
||||||
headers={
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"X-Auth-Token": settings.ANALYTICS_SECRET_KEY,
|
|
||||||
},
|
|
||||||
json={
|
|
||||||
"event_id": uuid.uuid4().hex,
|
|
||||||
"event_data": {
|
|
||||||
"medium": "email",
|
|
||||||
},
|
|
||||||
"user": {"email": email, "id": str(user.id)},
|
|
||||||
"device_ctx": {
|
|
||||||
"ip": request.META.get("REMOTE_ADDR"),
|
|
||||||
"user_agent": request.META.get("HTTP_USER_AGENT"),
|
|
||||||
},
|
|
||||||
"event_type": "SIGN_IN",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
data = {
|
|
||||||
"access_token": access_token,
|
|
||||||
"refresh_token": refresh_token,
|
|
||||||
}
|
|
||||||
|
|
||||||
return Response(data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
|
|
||||||
class SignOutEndpoint(BaseAPIView):
|
|
||||||
def post(self, request):
|
|
||||||
refresh_token = request.data.get("refresh_token", False)
|
|
||||||
|
|
||||||
if not refresh_token:
|
|
||||||
capture_message("No refresh token provided")
|
|
||||||
return Response(
|
|
||||||
{"error": "No refresh token provided"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
user = User.objects.get(pk=request.user.id)
|
|
||||||
|
|
||||||
user.last_logout_time = timezone.now()
|
|
||||||
user.last_logout_ip = request.META.get("REMOTE_ADDR")
|
|
||||||
|
|
||||||
user.save()
|
|
||||||
|
|
||||||
token = RefreshToken(refresh_token)
|
|
||||||
token.blacklist()
|
|
||||||
return Response({"message": "success"}, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
|
|
||||||
class MagicSignInGenerateEndpoint(BaseAPIView):
|
|
||||||
permission_classes = [
|
|
||||||
AllowAny,
|
|
||||||
]
|
|
||||||
|
|
||||||
def post(self, request):
|
|
||||||
email = request.data.get("email", False)
|
|
||||||
|
|
||||||
if not email:
|
|
||||||
return Response(
|
|
||||||
{"error": "Please provide a valid email address"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Clean up
|
|
||||||
email = email.strip().lower()
|
|
||||||
validate_email(email)
|
|
||||||
|
|
||||||
## Generate a random token
|
|
||||||
token = (
|
|
||||||
"".join(random.choices(string.ascii_lowercase, k=4))
|
|
||||||
+ "-"
|
|
||||||
+ "".join(random.choices(string.ascii_lowercase, k=4))
|
|
||||||
+ "-"
|
|
||||||
+ "".join(random.choices(string.ascii_lowercase, k=4))
|
|
||||||
)
|
|
||||||
|
|
||||||
ri = redis_instance()
|
|
||||||
|
|
||||||
key = "magic_" + str(email)
|
|
||||||
|
|
||||||
# Check if the key already exists in python
|
|
||||||
if ri.exists(key):
|
|
||||||
data = json.loads(ri.get(key))
|
|
||||||
|
|
||||||
current_attempt = data["current_attempt"] + 1
|
|
||||||
|
|
||||||
if data["current_attempt"] > 2:
|
|
||||||
return Response(
|
|
||||||
{"error": "Max attempts exhausted. Please try again later."},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
value = {
|
|
||||||
"current_attempt": current_attempt,
|
|
||||||
"email": email,
|
|
||||||
"token": token,
|
|
||||||
}
|
|
||||||
expiry = 600
|
|
||||||
|
|
||||||
ri.set(key, json.dumps(value), ex=expiry)
|
|
||||||
|
|
||||||
else:
|
|
||||||
value = {"current_attempt": 0, "email": email, "token": token}
|
|
||||||
expiry = 600
|
|
||||||
|
|
||||||
ri.set(key, json.dumps(value), ex=expiry)
|
|
||||||
|
|
||||||
current_site = settings.WEB_URL
|
|
||||||
magic_link.delay(email, key, token, current_site)
|
|
||||||
|
|
||||||
return Response({"key": key}, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
|
|
||||||
class MagicSignInEndpoint(BaseAPIView):
|
|
||||||
permission_classes = [
|
|
||||||
AllowAny,
|
|
||||||
]
|
|
||||||
|
|
||||||
def post(self, request):
|
|
||||||
user_token = request.data.get("token", "").strip()
|
|
||||||
key = request.data.get("key", False).strip().lower()
|
|
||||||
|
|
||||||
if not key or user_token == "":
|
|
||||||
return Response(
|
|
||||||
{"error": "User token and key are required"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
ri = redis_instance()
|
|
||||||
|
|
||||||
if ri.exists(key):
|
|
||||||
data = json.loads(ri.get(key))
|
|
||||||
|
|
||||||
token = data["token"]
|
|
||||||
email = data["email"]
|
|
||||||
|
|
||||||
if str(token) == str(user_token):
|
|
||||||
if User.objects.filter(email=email).exists():
|
|
||||||
user = User.objects.get(email=email)
|
|
||||||
# Send event to Jitsu for tracking
|
|
||||||
if settings.ANALYTICS_BASE_API:
|
|
||||||
_ = requests.post(
|
|
||||||
settings.ANALYTICS_BASE_API,
|
|
||||||
headers={
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"X-Auth-Token": settings.ANALYTICS_SECRET_KEY,
|
|
||||||
},
|
|
||||||
json={
|
|
||||||
"event_id": uuid.uuid4().hex,
|
|
||||||
"event_data": {
|
|
||||||
"medium": "code",
|
|
||||||
},
|
|
||||||
"user": {"email": email, "id": str(user.id)},
|
|
||||||
"device_ctx": {
|
|
||||||
"ip": request.META.get("REMOTE_ADDR"),
|
|
||||||
"user_agent": request.META.get("HTTP_USER_AGENT"),
|
|
||||||
},
|
|
||||||
"event_type": "SIGN_IN",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
user = User.objects.create(
|
|
||||||
email=email,
|
|
||||||
username=uuid.uuid4().hex,
|
|
||||||
password=make_password(uuid.uuid4().hex),
|
|
||||||
is_password_autoset=True,
|
|
||||||
)
|
|
||||||
# Send event to Jitsu for tracking
|
|
||||||
if settings.ANALYTICS_BASE_API:
|
|
||||||
_ = requests.post(
|
|
||||||
settings.ANALYTICS_BASE_API,
|
|
||||||
headers={
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"X-Auth-Token": settings.ANALYTICS_SECRET_KEY,
|
|
||||||
},
|
|
||||||
json={
|
|
||||||
"event_id": uuid.uuid4().hex,
|
|
||||||
"event_data": {
|
|
||||||
"medium": "code",
|
|
||||||
},
|
|
||||||
"user": {"email": email, "id": str(user.id)},
|
|
||||||
"device_ctx": {
|
|
||||||
"ip": request.META.get("REMOTE_ADDR"),
|
|
||||||
"user_agent": request.META.get("HTTP_USER_AGENT"),
|
|
||||||
},
|
|
||||||
"event_type": "SIGN_UP",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
user.last_active = timezone.now()
|
|
||||||
user.last_login_time = timezone.now()
|
|
||||||
user.last_login_ip = request.META.get("REMOTE_ADDR")
|
|
||||||
user.last_login_uagent = request.META.get("HTTP_USER_AGENT")
|
|
||||||
user.token_updated_at = timezone.now()
|
|
||||||
user.save()
|
|
||||||
|
|
||||||
access_token, refresh_token = get_tokens_for_user(user)
|
|
||||||
data = {
|
|
||||||
"access_token": access_token,
|
|
||||||
"refresh_token": refresh_token,
|
|
||||||
}
|
|
||||||
|
|
||||||
return Response(data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
else:
|
|
||||||
return Response(
|
|
||||||
{"error": "Your login code was incorrect. Please try again."},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
|
||||||
return Response(
|
|
||||||
{"error": "The magic code/link has expired please try again"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
@ -1,27 +1,26 @@
|
|||||||
# Python imports
|
# Python imports
|
||||||
import zoneinfo
|
import zoneinfo
|
||||||
|
import json
|
||||||
|
|
||||||
# Django imports
|
# Django imports
|
||||||
from django.urls import resolve
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils import timezone
|
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
||||||
|
from django.utils import timezone
|
||||||
|
from django.core.serializers.json import DjangoJSONEncoder
|
||||||
|
|
||||||
# Third part imports
|
# Third party imports
|
||||||
from rest_framework import status
|
|
||||||
from rest_framework import status
|
|
||||||
from rest_framework.viewsets import ModelViewSet
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from rest_framework.exceptions import APIException
|
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework.filters import SearchFilter
|
from rest_framework.response import Response
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
from rest_framework import status
|
||||||
from sentry_sdk import capture_exception
|
from sentry_sdk import capture_exception
|
||||||
from django_filters.rest_framework import DjangoFilterBackend
|
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
|
from plane.api.middleware.api_authentication import APIKeyAuthentication
|
||||||
|
from plane.api.rate_limit import ApiKeyRateThrottle
|
||||||
from plane.utils.paginator import BasePaginator
|
from plane.utils.paginator import BasePaginator
|
||||||
|
from plane.bgtasks.webhook_task import send_webhook
|
||||||
|
|
||||||
|
|
||||||
class TimezoneMixin:
|
class TimezoneMixin:
|
||||||
@ -29,6 +28,7 @@ class TimezoneMixin:
|
|||||||
This enables timezone conversion according
|
This enables timezone conversion according
|
||||||
to the user set timezone
|
to the user set timezone
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def initial(self, request, *args, **kwargs):
|
def initial(self, request, *args, **kwargs):
|
||||||
super().initial(request, *args, **kwargs)
|
super().initial(request, *args, **kwargs)
|
||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
@ -36,110 +36,46 @@ class TimezoneMixin:
|
|||||||
else:
|
else:
|
||||||
timezone.deactivate()
|
timezone.deactivate()
|
||||||
|
|
||||||
|
class WebhookMixin:
|
||||||
|
webhook_event = None
|
||||||
|
|
||||||
class BaseViewSet(TimezoneMixin, ModelViewSet, BasePaginator):
|
def finalize_response(self, request, response, *args, **kwargs):
|
||||||
|
response = super().finalize_response(request, response, *args, **kwargs)
|
||||||
|
|
||||||
model = None
|
if (
|
||||||
|
self.webhook_event
|
||||||
permission_classes = [
|
and self.request.method in ["POST", "PATCH", "DELETE"]
|
||||||
IsAuthenticated,
|
and response.status_code in [200, 201, 204]
|
||||||
]
|
):
|
||||||
|
send_webhook.delay(
|
||||||
filter_backends = (
|
event=self.webhook_event,
|
||||||
DjangoFilterBackend,
|
event_data=json.dumps(response.data, cls=DjangoJSONEncoder),
|
||||||
SearchFilter,
|
action=self.request.method,
|
||||||
|
slug=self.workspace_slug,
|
||||||
)
|
)
|
||||||
|
|
||||||
filterset_fields = []
|
|
||||||
|
|
||||||
search_fields = []
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
try:
|
|
||||||
return self.model.objects.all()
|
|
||||||
except Exception as e:
|
|
||||||
capture_exception(e)
|
|
||||||
raise APIException("Please check the view", status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
def handle_exception(self, exc):
|
|
||||||
"""
|
|
||||||
Handle any exception that occurs, by returning an appropriate response,
|
|
||||||
or re-raising the error.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
response = super().handle_exception(exc)
|
|
||||||
return response
|
|
||||||
except Exception as e:
|
|
||||||
if isinstance(e, IntegrityError):
|
|
||||||
return Response({"error": "The payload is not valid"}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
if isinstance(e, ValidationError):
|
|
||||||
return Response({"error": "Please provide valid detail"}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
if isinstance(e, ObjectDoesNotExist):
|
|
||||||
model_name = str(exc).split(" matching query does not exist.")[0]
|
|
||||||
return Response({"error": f"{model_name} does not exist."}, status=status.HTTP_404_NOT_FOUND)
|
|
||||||
|
|
||||||
if isinstance(e, KeyError):
|
|
||||||
capture_exception(e)
|
|
||||||
return Response({"error": f"key {e} does not exist"}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
print(e) if settings.DEBUG else print("Server Error")
|
|
||||||
capture_exception(e)
|
|
||||||
return Response({"error": "Something went wrong please try again later"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
|
||||||
|
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
try:
|
|
||||||
response = super().dispatch(request, *args, **kwargs)
|
|
||||||
|
|
||||||
if settings.DEBUG:
|
|
||||||
from django.db import connection
|
|
||||||
|
|
||||||
print(
|
|
||||||
f"{request.method} - {request.get_full_path()} of Queries: {len(connection.queries)}"
|
|
||||||
)
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except Exception as exc:
|
|
||||||
response = self.handle_exception(exc)
|
|
||||||
return exc
|
|
||||||
|
|
||||||
@property
|
|
||||||
def workspace_slug(self):
|
|
||||||
return self.kwargs.get("slug", None)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def project_id(self):
|
|
||||||
project_id = self.kwargs.get("project_id", None)
|
|
||||||
if project_id:
|
|
||||||
return project_id
|
|
||||||
|
|
||||||
if resolve(self.request.path_info).url_name == "project":
|
|
||||||
return self.kwargs.get("pk", None)
|
|
||||||
|
|
||||||
|
|
||||||
class BaseAPIView(TimezoneMixin, APIView, BasePaginator):
|
class BaseAPIView(TimezoneMixin, APIView, BasePaginator):
|
||||||
|
authentication_classes = [
|
||||||
|
APIKeyAuthentication,
|
||||||
|
]
|
||||||
|
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
IsAuthenticated,
|
IsAuthenticated,
|
||||||
]
|
]
|
||||||
|
|
||||||
filter_backends = (
|
throttle_classes = [
|
||||||
DjangoFilterBackend,
|
ApiKeyRateThrottle,
|
||||||
SearchFilter,
|
]
|
||||||
)
|
|
||||||
|
|
||||||
filterset_fields = []
|
|
||||||
|
|
||||||
search_fields = []
|
|
||||||
|
|
||||||
def filter_queryset(self, queryset):
|
def filter_queryset(self, queryset):
|
||||||
for backend in list(self.filter_backends):
|
for backend in list(self.filter_backends):
|
||||||
queryset = backend().filter_queryset(self.request, queryset, self)
|
queryset = backend().filter_queryset(self.request, queryset, self)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
def handle_exception(self, exc):
|
def handle_exception(self, exc):
|
||||||
"""
|
"""
|
||||||
Handle any exception that occurs, by returning an appropriate response,
|
Handle any exception that occurs, by returning an appropriate response,
|
||||||
@ -150,27 +86,43 @@ class BaseAPIView(TimezoneMixin, APIView, BasePaginator):
|
|||||||
return response
|
return response
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, IntegrityError):
|
if isinstance(e, IntegrityError):
|
||||||
return Response({"error": "The payload is not valid"}, status=status.HTTP_400_BAD_REQUEST)
|
return Response(
|
||||||
|
{"error": "The payload is not valid"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
if isinstance(e, ValidationError):
|
if isinstance(e, ValidationError):
|
||||||
return Response({"error": "Please provide valid detail"}, status=status.HTTP_400_BAD_REQUEST)
|
return Response(
|
||||||
|
{
|
||||||
|
"error": "The provided payload is not valid please try with a valid payload"
|
||||||
|
},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
if isinstance(e, ObjectDoesNotExist):
|
if isinstance(e, ObjectDoesNotExist):
|
||||||
model_name = str(exc).split(" matching query does not exist.")[0]
|
model_name = str(exc).split(" matching query does not exist.")[0]
|
||||||
return Response({"error": f"{model_name} does not exist."}, status=status.HTTP_404_NOT_FOUND)
|
return Response(
|
||||||
|
{"error": f"{model_name} does not exist."},
|
||||||
|
status=status.HTTP_404_NOT_FOUND,
|
||||||
|
)
|
||||||
|
|
||||||
if isinstance(e, KeyError):
|
if isinstance(e, KeyError):
|
||||||
return Response({"error": f"key {e} does not exist"}, status=status.HTTP_400_BAD_REQUEST)
|
return Response(
|
||||||
|
{"error": f"key {e} does not exist"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
print(e) if settings.DEBUG else print("Server Error")
|
if settings.DEBUG:
|
||||||
|
print(e)
|
||||||
capture_exception(e)
|
capture_exception(e)
|
||||||
return Response({"error": "Something went wrong please try again later"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
return Response(
|
||||||
|
{"error": "Something went wrong please try again later"},
|
||||||
|
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
|
)
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
response = super().dispatch(request, *args, **kwargs)
|
response = super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
|
|
||||||
@ -178,11 +130,25 @@ class BaseAPIView(TimezoneMixin, APIView, BasePaginator):
|
|||||||
f"{request.method} - {request.get_full_path()} of Queries: {len(connection.queries)}"
|
f"{request.method} - {request.get_full_path()} of Queries: {len(connection.queries)}"
|
||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
response = self.handle_exception(exc)
|
response = self.handle_exception(exc)
|
||||||
return exc
|
return exc
|
||||||
|
|
||||||
|
def finalize_response(self, request, response, *args, **kwargs):
|
||||||
|
# Call super to get the default response
|
||||||
|
response = super().finalize_response(request, response, *args, **kwargs)
|
||||||
|
|
||||||
|
# Add custom headers if they exist in the request META
|
||||||
|
ratelimit_remaining = request.META.get('X-RateLimit-Remaining')
|
||||||
|
if ratelimit_remaining is not None:
|
||||||
|
response['X-RateLimit-Remaining'] = ratelimit_remaining
|
||||||
|
|
||||||
|
ratelimit_reset = request.META.get('X-RateLimit-Reset')
|
||||||
|
if ratelimit_reset is not None:
|
||||||
|
response['X-RateLimit-Reset'] = ratelimit_reset
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def workspace_slug(self):
|
def workspace_slug(self):
|
||||||
return self.kwargs.get("slug", None)
|
return self.kwargs.get("slug", None)
|
||||||
@ -190,3 +156,17 @@ class BaseAPIView(TimezoneMixin, APIView, BasePaginator):
|
|||||||
@property
|
@property
|
||||||
def project_id(self):
|
def project_id(self):
|
||||||
return self.kwargs.get("project_id", None)
|
return self.kwargs.get("project_id", None)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def fields(self):
|
||||||
|
fields = [
|
||||||
|
field for field in self.request.GET.get("fields", "").split(",") if field
|
||||||
|
]
|
||||||
|
return fields if fields else None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def expand(self):
|
||||||
|
expand = [
|
||||||
|
expand for expand in self.request.GET.get("expand", "").split(",") if expand
|
||||||
|
]
|
||||||
|
return expand if expand else None
|
@ -1,37 +0,0 @@
|
|||||||
# Python imports
|
|
||||||
import os
|
|
||||||
|
|
||||||
# Django imports
|
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
# Third party imports
|
|
||||||
from rest_framework.permissions import AllowAny
|
|
||||||
from rest_framework import status
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from sentry_sdk import capture_exception
|
|
||||||
|
|
||||||
# Module imports
|
|
||||||
from .base import BaseAPIView
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigurationEndpoint(BaseAPIView):
|
|
||||||
permission_classes = [
|
|
||||||
AllowAny,
|
|
||||||
]
|
|
||||||
|
|
||||||
def get(self, request):
|
|
||||||
data = {}
|
|
||||||
data["google_client_id"] = os.environ.get("GOOGLE_CLIENT_ID", None)
|
|
||||||
data["github_client_id"] = os.environ.get("GITHUB_CLIENT_ID", None)
|
|
||||||
data["github_app_name"] = os.environ.get("GITHUB_APP_NAME", None)
|
|
||||||
data["magic_login"] = (
|
|
||||||
bool(settings.EMAIL_HOST_USER) and bool(settings.EMAIL_HOST_PASSWORD)
|
|
||||||
) and os.environ.get("ENABLE_MAGIC_LINK_LOGIN", "0") == "1"
|
|
||||||
data["email_password_login"] = (
|
|
||||||
os.environ.get("ENABLE_EMAIL_PASSWORD", "0") == "1"
|
|
||||||
)
|
|
||||||
data["slack_client_id"] = os.environ.get("SLACK_CLIENT_ID", None)
|
|
||||||
data["posthog_api_key"] = os.environ.get("POSTHOG_API_KEY", None)
|
|
||||||
data["posthog_host"] = os.environ.get("POSTHOG_HOST", None)
|
|
||||||
data["has_unsplash_configured"] = bool(settings.UNSPLASH_ACCESS_KEY)
|
|
||||||
return Response(data, status=status.HTTP_200_OK)
|
|
@ -2,81 +2,48 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
# Django imports
|
# Django imports
|
||||||
from django.db.models import (
|
from django.db.models import Q, Count, Sum, Prefetch, F, OuterRef, Func
|
||||||
Func,
|
|
||||||
F,
|
|
||||||
Q,
|
|
||||||
Exists,
|
|
||||||
OuterRef,
|
|
||||||
Count,
|
|
||||||
Prefetch,
|
|
||||||
Sum,
|
|
||||||
)
|
|
||||||
from django.core import serializers
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.decorators import method_decorator
|
from django.core import serializers
|
||||||
from django.views.decorators.gzip import gzip_page
|
|
||||||
|
|
||||||
# Third party imports
|
# Third party imports
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from sentry_sdk import capture_exception
|
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from . import BaseViewSet, BaseAPIView
|
from .base import BaseAPIView, WebhookMixin
|
||||||
|
from plane.db.models import Cycle, Issue, CycleIssue, IssueLink, IssueAttachment
|
||||||
|
from plane.app.permissions import ProjectEntityPermission
|
||||||
from plane.api.serializers import (
|
from plane.api.serializers import (
|
||||||
CycleSerializer,
|
CycleSerializer,
|
||||||
CycleIssueSerializer,
|
CycleIssueSerializer,
|
||||||
CycleFavoriteSerializer,
|
IssueSerializer,
|
||||||
IssueStateSerializer,
|
|
||||||
CycleWriteSerializer,
|
|
||||||
)
|
|
||||||
from plane.api.permissions import ProjectEntityPermission
|
|
||||||
from plane.db.models import (
|
|
||||||
User,
|
|
||||||
Cycle,
|
|
||||||
CycleIssue,
|
|
||||||
Issue,
|
|
||||||
CycleFavorite,
|
|
||||||
IssueLink,
|
|
||||||
IssueAttachment,
|
|
||||||
Label,
|
|
||||||
)
|
)
|
||||||
from plane.bgtasks.issue_activites_task import issue_activity
|
from plane.bgtasks.issue_activites_task import issue_activity
|
||||||
from plane.utils.grouper import group_results
|
|
||||||
from plane.utils.issue_filters import issue_filters
|
|
||||||
from plane.utils.analytics_plot import burndown_plot
|
|
||||||
|
|
||||||
|
|
||||||
class CycleViewSet(BaseViewSet):
|
class CycleAPIEndpoint(WebhookMixin, BaseAPIView):
|
||||||
|
"""
|
||||||
|
This viewset automatically provides `list`, `create`, `retrieve`,
|
||||||
|
`update` and `destroy` actions related to cycle.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
serializer_class = CycleSerializer
|
serializer_class = CycleSerializer
|
||||||
model = Cycle
|
model = Cycle
|
||||||
|
webhook_event = "cycle"
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
ProjectEntityPermission,
|
ProjectEntityPermission,
|
||||||
]
|
]
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
|
||||||
serializer.save(
|
|
||||||
project_id=self.kwargs.get("project_id"), owned_by=self.request.user
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
subquery = CycleFavorite.objects.filter(
|
return (
|
||||||
user=self.request.user,
|
Cycle.objects.filter(workspace__slug=self.kwargs.get("slug"))
|
||||||
cycle_id=OuterRef("pk"),
|
|
||||||
project_id=self.kwargs.get("project_id"),
|
|
||||||
workspace__slug=self.kwargs.get("slug"),
|
|
||||||
)
|
|
||||||
return self.filter_queryset(
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"))
|
|
||||||
.filter(project_id=self.kwargs.get("project_id"))
|
.filter(project_id=self.kwargs.get("project_id"))
|
||||||
.filter(project__project_projectmember__member=self.request.user)
|
.filter(project__project_projectmember__member=self.request.user)
|
||||||
.select_related("project")
|
.select_related("project")
|
||||||
.select_related("workspace")
|
.select_related("workspace")
|
||||||
.select_related("owned_by")
|
.select_related("owned_by")
|
||||||
.annotate(is_favorite=Exists(subquery))
|
|
||||||
.annotate(
|
.annotate(
|
||||||
total_issues=Count(
|
total_issues=Count(
|
||||||
"issue_cycle",
|
"issue_cycle",
|
||||||
@ -157,27 +124,25 @@ class CycleViewSet(BaseViewSet):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.prefetch_related(
|
.order_by(self.kwargs.get("order_by", "-created_at"))
|
||||||
Prefetch(
|
|
||||||
"issue_cycle__issue__assignees",
|
|
||||||
queryset=User.objects.only("avatar", "first_name", "id").distinct(),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"issue_cycle__issue__labels",
|
|
||||||
queryset=Label.objects.only("name", "color", "id").distinct(),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.order_by("-is_favorite", "name")
|
|
||||||
.distinct()
|
.distinct()
|
||||||
)
|
)
|
||||||
|
|
||||||
def list(self, request, slug, project_id):
|
def get(self, request, slug, project_id, pk=None):
|
||||||
|
if pk:
|
||||||
|
queryset = self.get_queryset().get(pk=pk)
|
||||||
|
data = CycleSerializer(
|
||||||
|
queryset,
|
||||||
|
fields=self.fields,
|
||||||
|
expand=self.expand,
|
||||||
|
).data
|
||||||
|
return Response(
|
||||||
|
data,
|
||||||
|
status=status.HTTP_200_OK,
|
||||||
|
)
|
||||||
queryset = self.get_queryset()
|
queryset = self.get_queryset()
|
||||||
cycle_view = request.GET.get("cycle_view", "all")
|
cycle_view = request.GET.get("cycle_view", "all")
|
||||||
|
queryset = queryset.order_by("-is_favorite", "-created_at")
|
||||||
queryset = queryset.order_by("-is_favorite","-created_at")
|
|
||||||
|
|
||||||
# Current Cycle
|
# Current Cycle
|
||||||
if cycle_view == "current":
|
if cycle_view == "current":
|
||||||
@ -185,114 +150,37 @@ class CycleViewSet(BaseViewSet):
|
|||||||
start_date__lte=timezone.now(),
|
start_date__lte=timezone.now(),
|
||||||
end_date__gte=timezone.now(),
|
end_date__gte=timezone.now(),
|
||||||
)
|
)
|
||||||
|
data = CycleSerializer(
|
||||||
data = CycleSerializer(queryset, many=True).data
|
queryset, many=True, fields=self.fields, expand=self.expand
|
||||||
|
).data
|
||||||
if len(data):
|
|
||||||
assignee_distribution = (
|
|
||||||
Issue.objects.filter(
|
|
||||||
issue_cycle__cycle_id=data[0]["id"],
|
|
||||||
workspace__slug=slug,
|
|
||||||
project_id=project_id,
|
|
||||||
)
|
|
||||||
.annotate(display_name=F("assignees__display_name"))
|
|
||||||
.annotate(assignee_id=F("assignees__id"))
|
|
||||||
.annotate(avatar=F("assignees__avatar"))
|
|
||||||
.values("display_name", "assignee_id", "avatar")
|
|
||||||
.annotate(
|
|
||||||
total_issues=Count(
|
|
||||||
"assignee_id",
|
|
||||||
filter=Q(archived_at__isnull=True, is_draft=False),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
completed_issues=Count(
|
|
||||||
"assignee_id",
|
|
||||||
filter=Q(
|
|
||||||
completed_at__isnull=False,
|
|
||||||
archived_at__isnull=True,
|
|
||||||
is_draft=False,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
pending_issues=Count(
|
|
||||||
"assignee_id",
|
|
||||||
filter=Q(
|
|
||||||
completed_at__isnull=True,
|
|
||||||
archived_at__isnull=True,
|
|
||||||
is_draft=False,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.order_by("display_name")
|
|
||||||
)
|
|
||||||
|
|
||||||
label_distribution = (
|
|
||||||
Issue.objects.filter(
|
|
||||||
issue_cycle__cycle_id=data[0]["id"],
|
|
||||||
workspace__slug=slug,
|
|
||||||
project_id=project_id,
|
|
||||||
)
|
|
||||||
.annotate(label_name=F("labels__name"))
|
|
||||||
.annotate(color=F("labels__color"))
|
|
||||||
.annotate(label_id=F("labels__id"))
|
|
||||||
.values("label_name", "color", "label_id")
|
|
||||||
.annotate(
|
|
||||||
total_issues=Count(
|
|
||||||
"label_id",
|
|
||||||
filter=Q(archived_at__isnull=True, is_draft=False),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
completed_issues=Count(
|
|
||||||
"label_id",
|
|
||||||
filter=Q(
|
|
||||||
completed_at__isnull=False,
|
|
||||||
archived_at__isnull=True,
|
|
||||||
is_draft=False,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
pending_issues=Count(
|
|
||||||
"label_id",
|
|
||||||
filter=Q(
|
|
||||||
completed_at__isnull=True,
|
|
||||||
archived_at__isnull=True,
|
|
||||||
is_draft=False,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.order_by("label_name")
|
|
||||||
)
|
|
||||||
data[0]["distribution"] = {
|
|
||||||
"assignees": assignee_distribution,
|
|
||||||
"labels": label_distribution,
|
|
||||||
"completion_chart": {},
|
|
||||||
}
|
|
||||||
if data[0]["start_date"] and data[0]["end_date"]:
|
|
||||||
data[0]["distribution"]["completion_chart"] = burndown_plot(
|
|
||||||
queryset=queryset.first(),
|
|
||||||
slug=slug,
|
|
||||||
project_id=project_id,
|
|
||||||
cycle_id=data[0]["id"],
|
|
||||||
)
|
|
||||||
|
|
||||||
return Response(data, status=status.HTTP_200_OK)
|
return Response(data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
# Upcoming Cycles
|
# Upcoming Cycles
|
||||||
if cycle_view == "upcoming":
|
if cycle_view == "upcoming":
|
||||||
queryset = queryset.filter(start_date__gt=timezone.now())
|
queryset = queryset.filter(start_date__gt=timezone.now())
|
||||||
return Response(
|
return self.paginate(
|
||||||
CycleSerializer(queryset, many=True).data, status=status.HTTP_200_OK
|
request=request,
|
||||||
|
queryset=(queryset),
|
||||||
|
on_results=lambda cycles: CycleSerializer(
|
||||||
|
cycles,
|
||||||
|
many=True,
|
||||||
|
fields=self.fields,
|
||||||
|
expand=self.expand,
|
||||||
|
).data,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Completed Cycles
|
# Completed Cycles
|
||||||
if cycle_view == "completed":
|
if cycle_view == "completed":
|
||||||
queryset = queryset.filter(end_date__lt=timezone.now())
|
queryset = queryset.filter(end_date__lt=timezone.now())
|
||||||
return Response(
|
return self.paginate(
|
||||||
CycleSerializer(queryset, many=True).data, status=status.HTTP_200_OK
|
request=request,
|
||||||
|
queryset=(queryset),
|
||||||
|
on_results=lambda cycles: CycleSerializer(
|
||||||
|
cycles,
|
||||||
|
many=True,
|
||||||
|
fields=self.fields,
|
||||||
|
expand=self.expand,
|
||||||
|
).data,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Draft Cycles
|
# Draft Cycles
|
||||||
@ -301,9 +189,15 @@ class CycleViewSet(BaseViewSet):
|
|||||||
end_date=None,
|
end_date=None,
|
||||||
start_date=None,
|
start_date=None,
|
||||||
)
|
)
|
||||||
|
return self.paginate(
|
||||||
return Response(
|
request=request,
|
||||||
CycleSerializer(queryset, many=True).data, status=status.HTTP_200_OK
|
queryset=(queryset),
|
||||||
|
on_results=lambda cycles: CycleSerializer(
|
||||||
|
cycles,
|
||||||
|
many=True,
|
||||||
|
fields=self.fields,
|
||||||
|
expand=self.expand,
|
||||||
|
).data,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Incomplete Cycles
|
# Incomplete Cycles
|
||||||
@ -311,16 +205,28 @@ class CycleViewSet(BaseViewSet):
|
|||||||
queryset = queryset.filter(
|
queryset = queryset.filter(
|
||||||
Q(end_date__gte=timezone.now().date()) | Q(end_date__isnull=True),
|
Q(end_date__gte=timezone.now().date()) | Q(end_date__isnull=True),
|
||||||
)
|
)
|
||||||
return Response(
|
return self.paginate(
|
||||||
CycleSerializer(queryset, many=True).data, status=status.HTTP_200_OK
|
request=request,
|
||||||
|
queryset=(queryset),
|
||||||
|
on_results=lambda cycles: CycleSerializer(
|
||||||
|
cycles,
|
||||||
|
many=True,
|
||||||
|
fields=self.fields,
|
||||||
|
expand=self.expand,
|
||||||
|
).data,
|
||||||
|
)
|
||||||
|
return self.paginate(
|
||||||
|
request=request,
|
||||||
|
queryset=(queryset),
|
||||||
|
on_results=lambda cycles: CycleSerializer(
|
||||||
|
cycles,
|
||||||
|
many=True,
|
||||||
|
fields=self.fields,
|
||||||
|
expand=self.expand,
|
||||||
|
).data,
|
||||||
)
|
)
|
||||||
|
|
||||||
# If no matching view is found return all cycles
|
def post(self, request, slug, project_id):
|
||||||
return Response(
|
|
||||||
CycleSerializer(queryset, many=True).data, status=status.HTTP_200_OK
|
|
||||||
)
|
|
||||||
|
|
||||||
def create(self, request, slug, project_id):
|
|
||||||
if (
|
if (
|
||||||
request.data.get("start_date", None) is None
|
request.data.get("start_date", None) is None
|
||||||
and request.data.get("end_date", None) is None
|
and request.data.get("end_date", None) is None
|
||||||
@ -344,7 +250,7 @@ class CycleViewSet(BaseViewSet):
|
|||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
def partial_update(self, request, slug, project_id, pk):
|
def patch(self, request, slug, project_id, pk):
|
||||||
cycle = Cycle.objects.get(workspace__slug=slug, project_id=project_id, pk=pk)
|
cycle = Cycle.objects.get(workspace__slug=slug, project_id=project_id, pk=pk)
|
||||||
|
|
||||||
request_data = request.data
|
request_data = request.data
|
||||||
@ -363,115 +269,13 @@ class CycleViewSet(BaseViewSet):
|
|||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
serializer = CycleWriteSerializer(cycle, data=request.data, partial=True)
|
serializer = CycleSerializer(cycle, data=request.data, partial=True)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
serializer.save()
|
serializer.save()
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
def retrieve(self, request, slug, project_id, pk):
|
def delete(self, request, slug, project_id, pk):
|
||||||
queryset = self.get_queryset().get(pk=pk)
|
|
||||||
|
|
||||||
# Assignee Distribution
|
|
||||||
assignee_distribution = (
|
|
||||||
Issue.objects.filter(
|
|
||||||
issue_cycle__cycle_id=pk,
|
|
||||||
workspace__slug=slug,
|
|
||||||
project_id=project_id,
|
|
||||||
)
|
|
||||||
.annotate(first_name=F("assignees__first_name"))
|
|
||||||
.annotate(last_name=F("assignees__last_name"))
|
|
||||||
.annotate(assignee_id=F("assignees__id"))
|
|
||||||
.annotate(avatar=F("assignees__avatar"))
|
|
||||||
.annotate(display_name=F("assignees__display_name"))
|
|
||||||
.values("first_name", "last_name", "assignee_id", "avatar", "display_name")
|
|
||||||
.annotate(
|
|
||||||
total_issues=Count(
|
|
||||||
"assignee_id",
|
|
||||||
filter=Q(archived_at__isnull=True, is_draft=False),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
completed_issues=Count(
|
|
||||||
"assignee_id",
|
|
||||||
filter=Q(
|
|
||||||
completed_at__isnull=False,
|
|
||||||
archived_at__isnull=True,
|
|
||||||
is_draft=False,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
pending_issues=Count(
|
|
||||||
"assignee_id",
|
|
||||||
filter=Q(
|
|
||||||
completed_at__isnull=True,
|
|
||||||
archived_at__isnull=True,
|
|
||||||
is_draft=False,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.order_by("first_name", "last_name")
|
|
||||||
)
|
|
||||||
|
|
||||||
# Label Distribution
|
|
||||||
label_distribution = (
|
|
||||||
Issue.objects.filter(
|
|
||||||
issue_cycle__cycle_id=pk,
|
|
||||||
workspace__slug=slug,
|
|
||||||
project_id=project_id,
|
|
||||||
)
|
|
||||||
.annotate(label_name=F("labels__name"))
|
|
||||||
.annotate(color=F("labels__color"))
|
|
||||||
.annotate(label_id=F("labels__id"))
|
|
||||||
.values("label_name", "color", "label_id")
|
|
||||||
.annotate(
|
|
||||||
total_issues=Count(
|
|
||||||
"label_id",
|
|
||||||
filter=Q(archived_at__isnull=True, is_draft=False),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
completed_issues=Count(
|
|
||||||
"label_id",
|
|
||||||
filter=Q(
|
|
||||||
completed_at__isnull=False,
|
|
||||||
archived_at__isnull=True,
|
|
||||||
is_draft=False,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
pending_issues=Count(
|
|
||||||
"label_id",
|
|
||||||
filter=Q(
|
|
||||||
completed_at__isnull=True,
|
|
||||||
archived_at__isnull=True,
|
|
||||||
is_draft=False,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.order_by("label_name")
|
|
||||||
)
|
|
||||||
|
|
||||||
data = CycleSerializer(queryset).data
|
|
||||||
data["distribution"] = {
|
|
||||||
"assignees": assignee_distribution,
|
|
||||||
"labels": label_distribution,
|
|
||||||
"completion_chart": {},
|
|
||||||
}
|
|
||||||
|
|
||||||
if queryset.start_date and queryset.end_date:
|
|
||||||
data["distribution"]["completion_chart"] = burndown_plot(
|
|
||||||
queryset=queryset, slug=slug, project_id=project_id, cycle_id=pk
|
|
||||||
)
|
|
||||||
|
|
||||||
return Response(
|
|
||||||
data,
|
|
||||||
status=status.HTTP_200_OK,
|
|
||||||
)
|
|
||||||
|
|
||||||
def destroy(self, request, slug, project_id, pk):
|
|
||||||
cycle_issues = list(
|
cycle_issues = list(
|
||||||
CycleIssue.objects.filter(cycle_id=self.kwargs.get("pk")).values_list(
|
CycleIssue.objects.filter(cycle_id=self.kwargs.get("pk")).values_list(
|
||||||
"issue", flat=True
|
"issue", flat=True
|
||||||
@ -499,24 +303,23 @@ class CycleViewSet(BaseViewSet):
|
|||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class CycleIssueViewSet(BaseViewSet):
|
class CycleIssueAPIEndpoint(WebhookMixin, BaseAPIView):
|
||||||
|
"""
|
||||||
|
This viewset automatically provides `list`, `create`, `retrieve`,
|
||||||
|
`update` and `destroy` actions related to cycle issues.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
serializer_class = CycleIssueSerializer
|
serializer_class = CycleIssueSerializer
|
||||||
model = CycleIssue
|
model = CycleIssue
|
||||||
|
webhook_event = "cycle"
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
ProjectEntityPermission,
|
ProjectEntityPermission,
|
||||||
]
|
]
|
||||||
|
|
||||||
filterset_fields = [
|
|
||||||
"issue__labels__id",
|
|
||||||
"issue__assignees__id",
|
|
||||||
]
|
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return self.filter_queryset(
|
return (
|
||||||
super()
|
CycleIssue.objects.annotate(
|
||||||
.get_queryset()
|
|
||||||
.annotate(
|
|
||||||
sub_issues_count=Issue.issue_objects.filter(parent=OuterRef("issue_id"))
|
sub_issues_count=Issue.issue_objects.filter(parent=OuterRef("issue_id"))
|
||||||
.order_by()
|
.order_by()
|
||||||
.annotate(count=Func(F("id"), function="Count"))
|
.annotate(count=Func(F("id"), function="Count"))
|
||||||
@ -531,15 +334,12 @@ class CycleIssueViewSet(BaseViewSet):
|
|||||||
.select_related("cycle")
|
.select_related("cycle")
|
||||||
.select_related("issue", "issue__state", "issue__project")
|
.select_related("issue", "issue__state", "issue__project")
|
||||||
.prefetch_related("issue__assignees", "issue__labels")
|
.prefetch_related("issue__assignees", "issue__labels")
|
||||||
|
.order_by(self.kwargs.get("order_by", "-created_at"))
|
||||||
.distinct()
|
.distinct()
|
||||||
)
|
)
|
||||||
|
|
||||||
@method_decorator(gzip_page)
|
def get(self, request, slug, project_id, cycle_id):
|
||||||
def list(self, request, slug, project_id, cycle_id):
|
|
||||||
order_by = request.GET.get("order_by", "created_at")
|
order_by = request.GET.get("order_by", "created_at")
|
||||||
group_by = request.GET.get("group_by", False)
|
|
||||||
sub_group_by = request.GET.get("sub_group_by", False)
|
|
||||||
filters = issue_filters(request.query_params, "GET")
|
|
||||||
issues = (
|
issues = (
|
||||||
Issue.issue_objects.filter(issue_cycle__cycle_id=cycle_id)
|
Issue.issue_objects.filter(issue_cycle__cycle_id=cycle_id)
|
||||||
.annotate(
|
.annotate(
|
||||||
@ -558,7 +358,6 @@ class CycleIssueViewSet(BaseViewSet):
|
|||||||
.prefetch_related("assignees")
|
.prefetch_related("assignees")
|
||||||
.prefetch_related("labels")
|
.prefetch_related("labels")
|
||||||
.order_by(order_by)
|
.order_by(order_by)
|
||||||
.filter(**filters)
|
|
||||||
.annotate(
|
.annotate(
|
||||||
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
|
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
|
||||||
.order_by()
|
.order_by()
|
||||||
@ -573,29 +372,21 @@ class CycleIssueViewSet(BaseViewSet):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
issues_data = IssueStateSerializer(issues, many=True).data
|
return self.paginate(
|
||||||
|
request=request,
|
||||||
if sub_group_by and sub_group_by == group_by:
|
queryset=(issues),
|
||||||
return Response(
|
on_results=lambda issues: CycleSerializer(
|
||||||
{"error": "Group by and sub group by cannot be same"},
|
issues,
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
many=True,
|
||||||
|
fields=self.fields,
|
||||||
|
expand=self.expand,
|
||||||
|
).data,
|
||||||
)
|
)
|
||||||
|
|
||||||
if group_by:
|
def post(self, request, slug, project_id, cycle_id):
|
||||||
grouped_results = group_results(issues_data, group_by, sub_group_by)
|
|
||||||
return Response(
|
|
||||||
grouped_results,
|
|
||||||
status=status.HTTP_200_OK,
|
|
||||||
)
|
|
||||||
|
|
||||||
return Response(
|
|
||||||
issues_data, status=status.HTTP_200_OK
|
|
||||||
)
|
|
||||||
|
|
||||||
def create(self, request, slug, project_id, cycle_id):
|
|
||||||
issues = request.data.get("issues", [])
|
issues = request.data.get("issues", [])
|
||||||
|
|
||||||
if not len(issues):
|
if not issues:
|
||||||
return Response(
|
return Response(
|
||||||
{"error": "Issues are required"}, status=status.HTTP_400_BAD_REQUEST
|
{"error": "Issues are required"}, status=status.HTTP_400_BAD_REQUEST
|
||||||
)
|
)
|
||||||
@ -612,6 +403,10 @@ class CycleIssueViewSet(BaseViewSet):
|
|||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
issues = Issue.objects.filter(
|
||||||
|
pk__in=issues, workspace__slug=slug, project_id=project_id
|
||||||
|
).values_list("id", flat=True)
|
||||||
|
|
||||||
# Get all CycleIssues already created
|
# Get all CycleIssues already created
|
||||||
cycle_issues = list(CycleIssue.objects.filter(issue_id__in=issues))
|
cycle_issues = list(CycleIssue.objects.filter(issue_id__in=issues))
|
||||||
update_cycle_issue_activity = []
|
update_cycle_issue_activity = []
|
||||||
@ -683,7 +478,7 @@ class CycleIssueViewSet(BaseViewSet):
|
|||||||
status=status.HTTP_200_OK,
|
status=status.HTTP_200_OK,
|
||||||
)
|
)
|
||||||
|
|
||||||
def destroy(self, request, slug, project_id, cycle_id, pk):
|
def delete(self, request, slug, project_id, cycle_id, pk):
|
||||||
cycle_issue = CycleIssue.objects.get(
|
cycle_issue = CycleIssue.objects.get(
|
||||||
pk=pk, workspace__slug=slug, project_id=project_id, cycle_id=cycle_id
|
pk=pk, workspace__slug=slug, project_id=project_id, cycle_id=cycle_id
|
||||||
)
|
)
|
||||||
@ -706,74 +501,12 @@ class CycleIssueViewSet(BaseViewSet):
|
|||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class CycleDateCheckEndpoint(BaseAPIView):
|
class TransferCycleIssueAPIEndpoint(BaseAPIView):
|
||||||
permission_classes = [
|
"""
|
||||||
ProjectEntityPermission,
|
This viewset provides `create` actions for transfering the issues into a particular cycle.
|
||||||
]
|
|
||||||
|
|
||||||
def post(self, request, slug, project_id):
|
"""
|
||||||
start_date = request.data.get("start_date", False)
|
|
||||||
end_date = request.data.get("end_date", False)
|
|
||||||
cycle_id = request.data.get("cycle_id")
|
|
||||||
if not start_date or not end_date:
|
|
||||||
return Response(
|
|
||||||
{"error": "Start date and end date both are required"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
cycles = Cycle.objects.filter(
|
|
||||||
Q(workspace__slug=slug)
|
|
||||||
& Q(project_id=project_id)
|
|
||||||
& (
|
|
||||||
Q(start_date__lte=start_date, end_date__gte=start_date)
|
|
||||||
| Q(start_date__lte=end_date, end_date__gte=end_date)
|
|
||||||
| Q(start_date__gte=start_date, end_date__lte=end_date)
|
|
||||||
)
|
|
||||||
).exclude(pk=cycle_id)
|
|
||||||
|
|
||||||
if cycles.exists():
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"error": "You have a cycle already on the given dates, if you want to create a draft cycle you can do that by removing dates",
|
|
||||||
"status": False,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
return Response({"status": True}, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
|
|
||||||
class CycleFavoriteViewSet(BaseViewSet):
|
|
||||||
serializer_class = CycleFavoriteSerializer
|
|
||||||
model = CycleFavorite
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return self.filter_queryset(
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"))
|
|
||||||
.filter(user=self.request.user)
|
|
||||||
.select_related("cycle", "cycle__owned_by")
|
|
||||||
)
|
|
||||||
|
|
||||||
def create(self, request, slug, project_id):
|
|
||||||
serializer = CycleFavoriteSerializer(data=request.data)
|
|
||||||
if serializer.is_valid():
|
|
||||||
serializer.save(user=request.user, project_id=project_id)
|
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
def destroy(self, request, slug, project_id, cycle_id):
|
|
||||||
cycle_favorite = CycleFavorite.objects.get(
|
|
||||||
project=project_id,
|
|
||||||
user=request.user,
|
|
||||||
workspace__slug=slug,
|
|
||||||
cycle_id=cycle_id,
|
|
||||||
)
|
|
||||||
cycle_favorite.delete()
|
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
|
||||||
|
|
||||||
|
|
||||||
class TransferCycleIssueEndpoint(BaseAPIView):
|
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
ProjectEntityPermission,
|
ProjectEntityPermission,
|
||||||
]
|
]
|
||||||
|
@ -1,83 +1,30 @@
|
|||||||
# Python imports
|
# Python imports
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# Django import
|
# Django improts
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.db.models import Q, Count, OuterRef, Func, F, Prefetch
|
from django.db.models import Q
|
||||||
from django.core.serializers.json import DjangoJSONEncoder
|
from django.core.serializers.json import DjangoJSONEncoder
|
||||||
|
|
||||||
# Third party imports
|
# Third party imports
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from sentry_sdk import capture_exception
|
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from .base import BaseViewSet
|
from .base import BaseAPIView
|
||||||
from plane.api.permissions import ProjectBasePermission, ProjectLitePermission
|
from plane.app.permissions import ProjectLitePermission
|
||||||
from plane.db.models import (
|
from plane.api.serializers import InboxIssueSerializer, IssueSerializer
|
||||||
Inbox,
|
from plane.db.models import InboxIssue, Issue, State, ProjectMember
|
||||||
InboxIssue,
|
|
||||||
Issue,
|
|
||||||
State,
|
|
||||||
IssueLink,
|
|
||||||
IssueAttachment,
|
|
||||||
ProjectMember,
|
|
||||||
ProjectDeployBoard,
|
|
||||||
)
|
|
||||||
from plane.api.serializers import (
|
|
||||||
IssueSerializer,
|
|
||||||
InboxSerializer,
|
|
||||||
InboxIssueSerializer,
|
|
||||||
IssueCreateSerializer,
|
|
||||||
IssueStateInboxSerializer,
|
|
||||||
)
|
|
||||||
from plane.utils.issue_filters import issue_filters
|
|
||||||
from plane.bgtasks.issue_activites_task import issue_activity
|
from plane.bgtasks.issue_activites_task import issue_activity
|
||||||
|
|
||||||
|
|
||||||
class InboxViewSet(BaseViewSet):
|
class InboxIssueAPIEndpoint(BaseAPIView):
|
||||||
permission_classes = [
|
"""
|
||||||
ProjectBasePermission,
|
This viewset automatically provides `list`, `create`, `retrieve`,
|
||||||
]
|
`update` and `destroy` actions related to inbox issues.
|
||||||
|
|
||||||
serializer_class = InboxSerializer
|
"""
|
||||||
model = Inbox
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return (
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.filter(
|
|
||||||
workspace__slug=self.kwargs.get("slug"),
|
|
||||||
project_id=self.kwargs.get("project_id"),
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
pending_issue_count=Count(
|
|
||||||
"issue_inbox",
|
|
||||||
filter=Q(issue_inbox__status=-2),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.select_related("workspace", "project")
|
|
||||||
)
|
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
|
||||||
serializer.save(project_id=self.kwargs.get("project_id"))
|
|
||||||
|
|
||||||
def destroy(self, request, slug, project_id, pk):
|
|
||||||
inbox = Inbox.objects.get(
|
|
||||||
workspace__slug=slug, project_id=project_id, pk=pk
|
|
||||||
)
|
|
||||||
# Handle default inbox delete
|
|
||||||
if inbox.is_default:
|
|
||||||
return Response(
|
|
||||||
{"error": "You cannot delete the default inbox"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
inbox.delete()
|
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
|
||||||
|
|
||||||
|
|
||||||
class InboxIssueViewSet(BaseViewSet):
|
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
ProjectLitePermission,
|
ProjectLitePermission,
|
||||||
]
|
]
|
||||||
@ -100,58 +47,34 @@ class InboxIssueViewSet(BaseViewSet):
|
|||||||
inbox_id=self.kwargs.get("inbox_id"),
|
inbox_id=self.kwargs.get("inbox_id"),
|
||||||
)
|
)
|
||||||
.select_related("issue", "workspace", "project")
|
.select_related("issue", "workspace", "project")
|
||||||
|
.order_by(self.kwargs.get("order_by", "-created_at"))
|
||||||
)
|
)
|
||||||
|
|
||||||
def list(self, request, slug, project_id, inbox_id):
|
def get(self, request, slug, project_id, inbox_id, pk=None):
|
||||||
filters = issue_filters(request.query_params, "GET")
|
if pk:
|
||||||
issues = (
|
issue_queryset = self.get_queryset().get(pk=pk)
|
||||||
Issue.objects.filter(
|
issues_data = InboxIssueSerializer(
|
||||||
issue_inbox__inbox_id=inbox_id,
|
issue_queryset,
|
||||||
workspace__slug=slug,
|
fields=self.fields,
|
||||||
project_id=project_id,
|
expand=self.expand,
|
||||||
)
|
).data
|
||||||
.filter(**filters)
|
|
||||||
.annotate(bridge_id=F("issue_inbox__id"))
|
|
||||||
.select_related("workspace", "project", "state", "parent")
|
|
||||||
.prefetch_related("assignees", "labels")
|
|
||||||
.order_by("issue_inbox__snoozed_till", "issue_inbox__status")
|
|
||||||
.annotate(
|
|
||||||
sub_issues_count=Issue.issue_objects.filter(parent=OuterRef("id"))
|
|
||||||
.order_by()
|
|
||||||
.annotate(count=Func(F("id"), function="Count"))
|
|
||||||
.values("count")
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
|
|
||||||
.order_by()
|
|
||||||
.annotate(count=Func(F("id"), function="Count"))
|
|
||||||
.values("count")
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
attachment_count=IssueAttachment.objects.filter(
|
|
||||||
issue=OuterRef("id")
|
|
||||||
)
|
|
||||||
.order_by()
|
|
||||||
.annotate(count=Func(F("id"), function="Count"))
|
|
||||||
.values("count")
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"issue_inbox",
|
|
||||||
queryset=InboxIssue.objects.only(
|
|
||||||
"status", "duplicate_to", "snoozed_till", "source"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
issues_data = IssueStateInboxSerializer(issues, many=True).data
|
|
||||||
return Response(
|
return Response(
|
||||||
issues_data,
|
issues_data,
|
||||||
status=status.HTTP_200_OK,
|
status=status.HTTP_200_OK,
|
||||||
)
|
)
|
||||||
|
issue_queryset = self.get_queryset()
|
||||||
|
return self.paginate(
|
||||||
|
request=request,
|
||||||
|
queryset=(issue_queryset),
|
||||||
|
on_results=lambda inbox_issues: InboxIssueSerializer(
|
||||||
|
inbox_issues,
|
||||||
|
many=True,
|
||||||
|
fields=self.fields,
|
||||||
|
expand=self.expand,
|
||||||
|
).data,
|
||||||
|
)
|
||||||
|
|
||||||
|
def post(self, request, slug, project_id, inbox_id):
|
||||||
def create(self, request, slug, project_id, inbox_id):
|
|
||||||
if not request.data.get("issue", {}).get("name", False):
|
if not request.data.get("issue", {}).get("name", False):
|
||||||
return Response(
|
return Response(
|
||||||
{"error": "Name is required"}, status=status.HTTP_400_BAD_REQUEST
|
{"error": "Name is required"}, status=status.HTTP_400_BAD_REQUEST
|
||||||
@ -198,7 +121,7 @@ class InboxIssueViewSet(BaseViewSet):
|
|||||||
issue_id=str(issue.id),
|
issue_id=str(issue.id),
|
||||||
project_id=str(project_id),
|
project_id=str(project_id),
|
||||||
current_instance=None,
|
current_instance=None,
|
||||||
epoch=int(timezone.now().timestamp())
|
epoch=int(timezone.now().timestamp()),
|
||||||
)
|
)
|
||||||
# create an inbox issue
|
# create an inbox issue
|
||||||
InboxIssue.objects.create(
|
InboxIssue.objects.create(
|
||||||
@ -208,18 +131,28 @@ class InboxIssueViewSet(BaseViewSet):
|
|||||||
source=request.data.get("source", "in-app"),
|
source=request.data.get("source", "in-app"),
|
||||||
)
|
)
|
||||||
|
|
||||||
serializer = IssueStateInboxSerializer(issue)
|
serializer = IssueSerializer(issue)
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
def partial_update(self, request, slug, project_id, inbox_id, pk):
|
def patch(self, request, slug, project_id, inbox_id, pk):
|
||||||
inbox_issue = InboxIssue.objects.get(
|
inbox_issue = InboxIssue.objects.get(
|
||||||
pk=pk, workspace__slug=slug, project_id=project_id, inbox_id=inbox_id
|
pk=pk, workspace__slug=slug, project_id=project_id, inbox_id=inbox_id
|
||||||
)
|
)
|
||||||
# Get the project member
|
# Get the project member
|
||||||
project_member = ProjectMember.objects.get(workspace__slug=slug, project_id=project_id, member=request.user)
|
project_member = ProjectMember.objects.get(
|
||||||
|
workspace__slug=slug,
|
||||||
|
project_id=project_id,
|
||||||
|
member=request.user,
|
||||||
|
is_active=True,
|
||||||
|
)
|
||||||
# Only project members admins and created_by users can access this endpoint
|
# Only project members admins and created_by users can access this endpoint
|
||||||
if project_member.role <= 10 and str(inbox_issue.created_by_id) != str(request.user.id):
|
if project_member.role <= 10 and str(inbox_issue.created_by_id) != str(
|
||||||
return Response({"error": "You cannot edit inbox issues"}, status=status.HTTP_400_BAD_REQUEST)
|
request.user.id
|
||||||
|
):
|
||||||
|
return Response(
|
||||||
|
{"error": "You cannot edit inbox issues"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
# Get issue data
|
# Get issue data
|
||||||
issue_data = request.data.pop("issue", False)
|
issue_data = request.data.pop("issue", False)
|
||||||
@ -233,13 +166,13 @@ class InboxIssueViewSet(BaseViewSet):
|
|||||||
# viewers and guests since only viewers and guests
|
# viewers and guests since only viewers and guests
|
||||||
issue_data = {
|
issue_data = {
|
||||||
"name": issue_data.get("name", issue.name),
|
"name": issue_data.get("name", issue.name),
|
||||||
"description_html": issue_data.get("description_html", issue.description_html),
|
"description_html": issue_data.get(
|
||||||
"description": issue_data.get("description", issue.description)
|
"description_html", issue.description_html
|
||||||
|
),
|
||||||
|
"description": issue_data.get("description", issue.description),
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_serializer = IssueCreateSerializer(
|
issue_serializer = IssueSerializer(issue, data=issue_data, partial=True)
|
||||||
issue, data=issue_data, partial=True
|
|
||||||
)
|
|
||||||
|
|
||||||
if issue_serializer.is_valid():
|
if issue_serializer.is_valid():
|
||||||
current_instance = issue
|
current_instance = issue
|
||||||
@ -256,7 +189,7 @@ class InboxIssueViewSet(BaseViewSet):
|
|||||||
IssueSerializer(current_instance).data,
|
IssueSerializer(current_instance).data,
|
||||||
cls=DjangoJSONEncoder,
|
cls=DjangoJSONEncoder,
|
||||||
),
|
),
|
||||||
epoch=int(timezone.now().timestamp())
|
epoch=int(timezone.now().timestamp()),
|
||||||
)
|
)
|
||||||
issue_serializer.save()
|
issue_serializer.save()
|
||||||
else:
|
else:
|
||||||
@ -307,253 +240,36 @@ class InboxIssueViewSet(BaseViewSet):
|
|||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
else:
|
else:
|
||||||
return Response(InboxIssueSerializer(inbox_issue).data, status=status.HTTP_200_OK)
|
return Response(
|
||||||
|
InboxIssueSerializer(inbox_issue).data, status=status.HTTP_200_OK
|
||||||
def retrieve(self, request, slug, project_id, inbox_id, pk):
|
|
||||||
inbox_issue = InboxIssue.objects.get(
|
|
||||||
pk=pk, workspace__slug=slug, project_id=project_id, inbox_id=inbox_id
|
|
||||||
)
|
)
|
||||||
issue = Issue.objects.get(
|
|
||||||
pk=inbox_issue.issue_id, workspace__slug=slug, project_id=project_id
|
|
||||||
)
|
|
||||||
serializer = IssueStateInboxSerializer(issue)
|
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
def destroy(self, request, slug, project_id, inbox_id, pk):
|
def delete(self, request, slug, project_id, inbox_id, pk):
|
||||||
inbox_issue = InboxIssue.objects.get(
|
inbox_issue = InboxIssue.objects.get(
|
||||||
pk=pk, workspace__slug=slug, project_id=project_id, inbox_id=inbox_id
|
pk=pk, workspace__slug=slug, project_id=project_id, inbox_id=inbox_id
|
||||||
)
|
)
|
||||||
# Get the project member
|
# Get the project member
|
||||||
project_member = ProjectMember.objects.get(workspace__slug=slug, project_id=project_id, member=request.user)
|
project_member = ProjectMember.objects.get(
|
||||||
|
workspace__slug=slug,
|
||||||
|
project_id=project_id,
|
||||||
|
member=request.user,
|
||||||
|
is_active=True,
|
||||||
|
)
|
||||||
|
|
||||||
if project_member.role <= 10 and str(inbox_issue.created_by_id) != str(request.user.id):
|
if project_member.role <= 10 and str(inbox_issue.created_by_id) != str(
|
||||||
return Response({"error": "You cannot delete inbox issue"}, status=status.HTTP_400_BAD_REQUEST)
|
request.user.id
|
||||||
|
):
|
||||||
|
return Response(
|
||||||
|
{"error": "You cannot delete inbox issue"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
# Check the issue status
|
# Check the issue status
|
||||||
if inbox_issue.status in [-2, -1, 0, 2]:
|
if inbox_issue.status in [-2, -1, 0, 2]:
|
||||||
# Delete the issue also
|
# Delete the issue also
|
||||||
Issue.objects.filter(workspace__slug=slug, project_id=project_id, pk=inbox_issue.issue_id).delete()
|
|
||||||
|
|
||||||
inbox_issue.delete()
|
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
|
||||||
|
|
||||||
|
|
||||||
class InboxIssuePublicViewSet(BaseViewSet):
|
|
||||||
serializer_class = InboxIssueSerializer
|
|
||||||
model = InboxIssue
|
|
||||||
|
|
||||||
filterset_fields = [
|
|
||||||
"status",
|
|
||||||
]
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=self.kwargs.get("slug"), project_id=self.kwargs.get("project_id"))
|
|
||||||
if project_deploy_board is not None:
|
|
||||||
return self.filter_queryset(
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.filter(
|
|
||||||
Q(snoozed_till__gte=timezone.now()) | Q(snoozed_till__isnull=True),
|
|
||||||
project_id=self.kwargs.get("project_id"),
|
|
||||||
workspace__slug=self.kwargs.get("slug"),
|
|
||||||
inbox_id=self.kwargs.get("inbox_id"),
|
|
||||||
)
|
|
||||||
.select_related("issue", "workspace", "project")
|
|
||||||
)
|
|
||||||
return InboxIssue.objects.none()
|
|
||||||
|
|
||||||
def list(self, request, slug, project_id, inbox_id):
|
|
||||||
project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=slug, project_id=project_id)
|
|
||||||
if project_deploy_board.inbox is None:
|
|
||||||
return Response({"error": "Inbox is not enabled for this Project Board"}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
filters = issue_filters(request.query_params, "GET")
|
|
||||||
issues = (
|
|
||||||
Issue.objects.filter(
|
Issue.objects.filter(
|
||||||
issue_inbox__inbox_id=inbox_id,
|
workspace__slug=slug, project_id=project_id, pk=inbox_issue.issue_id
|
||||||
workspace__slug=slug,
|
).delete()
|
||||||
project_id=project_id,
|
|
||||||
)
|
|
||||||
.filter(**filters)
|
|
||||||
.annotate(bridge_id=F("issue_inbox__id"))
|
|
||||||
.select_related("workspace", "project", "state", "parent")
|
|
||||||
.prefetch_related("assignees", "labels")
|
|
||||||
.order_by("issue_inbox__snoozed_till", "issue_inbox__status")
|
|
||||||
.annotate(
|
|
||||||
sub_issues_count=Issue.issue_objects.filter(parent=OuterRef("id"))
|
|
||||||
.order_by()
|
|
||||||
.annotate(count=Func(F("id"), function="Count"))
|
|
||||||
.values("count")
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
|
|
||||||
.order_by()
|
|
||||||
.annotate(count=Func(F("id"), function="Count"))
|
|
||||||
.values("count")
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
attachment_count=IssueAttachment.objects.filter(
|
|
||||||
issue=OuterRef("id")
|
|
||||||
)
|
|
||||||
.order_by()
|
|
||||||
.annotate(count=Func(F("id"), function="Count"))
|
|
||||||
.values("count")
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"issue_inbox",
|
|
||||||
queryset=InboxIssue.objects.only(
|
|
||||||
"status", "duplicate_to", "snoozed_till", "source"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
issues_data = IssueStateInboxSerializer(issues, many=True).data
|
|
||||||
return Response(
|
|
||||||
issues_data,
|
|
||||||
status=status.HTTP_200_OK,
|
|
||||||
)
|
|
||||||
|
|
||||||
def create(self, request, slug, project_id, inbox_id):
|
|
||||||
project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=slug, project_id=project_id)
|
|
||||||
if project_deploy_board.inbox is None:
|
|
||||||
return Response({"error": "Inbox is not enabled for this Project Board"}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
if not request.data.get("issue", {}).get("name", False):
|
|
||||||
return Response(
|
|
||||||
{"error": "Name is required"}, status=status.HTTP_400_BAD_REQUEST
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check for valid priority
|
|
||||||
if not request.data.get("issue", {}).get("priority", "none") in [
|
|
||||||
"low",
|
|
||||||
"medium",
|
|
||||||
"high",
|
|
||||||
"urgent",
|
|
||||||
"none",
|
|
||||||
]:
|
|
||||||
return Response(
|
|
||||||
{"error": "Invalid priority"}, status=status.HTTP_400_BAD_REQUEST
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create or get state
|
|
||||||
state, _ = State.objects.get_or_create(
|
|
||||||
name="Triage",
|
|
||||||
group="backlog",
|
|
||||||
description="Default state for managing all Inbox Issues",
|
|
||||||
project_id=project_id,
|
|
||||||
color="#ff7700",
|
|
||||||
)
|
|
||||||
|
|
||||||
# create an issue
|
|
||||||
issue = Issue.objects.create(
|
|
||||||
name=request.data.get("issue", {}).get("name"),
|
|
||||||
description=request.data.get("issue", {}).get("description", {}),
|
|
||||||
description_html=request.data.get("issue", {}).get(
|
|
||||||
"description_html", "<p></p>"
|
|
||||||
),
|
|
||||||
priority=request.data.get("issue", {}).get("priority", "low"),
|
|
||||||
project_id=project_id,
|
|
||||||
state=state,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create an Issue Activity
|
|
||||||
issue_activity.delay(
|
|
||||||
type="issue.activity.created",
|
|
||||||
requested_data=json.dumps(request.data, cls=DjangoJSONEncoder),
|
|
||||||
actor_id=str(request.user.id),
|
|
||||||
issue_id=str(issue.id),
|
|
||||||
project_id=str(project_id),
|
|
||||||
current_instance=None,
|
|
||||||
epoch=int(timezone.now().timestamp())
|
|
||||||
)
|
|
||||||
# create an inbox issue
|
|
||||||
InboxIssue.objects.create(
|
|
||||||
inbox_id=inbox_id,
|
|
||||||
project_id=project_id,
|
|
||||||
issue=issue,
|
|
||||||
source=request.data.get("source", "in-app"),
|
|
||||||
)
|
|
||||||
|
|
||||||
serializer = IssueStateInboxSerializer(issue)
|
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
def partial_update(self, request, slug, project_id, inbox_id, pk):
|
|
||||||
project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=slug, project_id=project_id)
|
|
||||||
if project_deploy_board.inbox is None:
|
|
||||||
return Response({"error": "Inbox is not enabled for this Project Board"}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
inbox_issue = InboxIssue.objects.get(
|
|
||||||
pk=pk, workspace__slug=slug, project_id=project_id, inbox_id=inbox_id
|
|
||||||
)
|
|
||||||
# Get the project member
|
|
||||||
if str(inbox_issue.created_by_id) != str(request.user.id):
|
|
||||||
return Response({"error": "You cannot edit inbox issues"}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
# Get issue data
|
|
||||||
issue_data = request.data.pop("issue", False)
|
|
||||||
|
|
||||||
|
|
||||||
issue = Issue.objects.get(
|
|
||||||
pk=inbox_issue.issue_id, workspace__slug=slug, project_id=project_id
|
|
||||||
)
|
|
||||||
# viewers and guests since only viewers and guests
|
|
||||||
issue_data = {
|
|
||||||
"name": issue_data.get("name", issue.name),
|
|
||||||
"description_html": issue_data.get("description_html", issue.description_html),
|
|
||||||
"description": issue_data.get("description", issue.description)
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_serializer = IssueCreateSerializer(
|
|
||||||
issue, data=issue_data, partial=True
|
|
||||||
)
|
|
||||||
|
|
||||||
if issue_serializer.is_valid():
|
|
||||||
current_instance = issue
|
|
||||||
# Log all the updates
|
|
||||||
requested_data = json.dumps(issue_data, cls=DjangoJSONEncoder)
|
|
||||||
if issue is not None:
|
|
||||||
issue_activity.delay(
|
|
||||||
type="issue.activity.updated",
|
|
||||||
requested_data=requested_data,
|
|
||||||
actor_id=str(request.user.id),
|
|
||||||
issue_id=str(issue.id),
|
|
||||||
project_id=str(project_id),
|
|
||||||
current_instance=json.dumps(
|
|
||||||
IssueSerializer(current_instance).data,
|
|
||||||
cls=DjangoJSONEncoder,
|
|
||||||
),
|
|
||||||
epoch=int(timezone.now().timestamp())
|
|
||||||
)
|
|
||||||
issue_serializer.save()
|
|
||||||
return Response(issue_serializer.data, status=status.HTTP_200_OK)
|
|
||||||
return Response(issue_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
def retrieve(self, request, slug, project_id, inbox_id, pk):
|
|
||||||
project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=slug, project_id=project_id)
|
|
||||||
if project_deploy_board.inbox is None:
|
|
||||||
return Response({"error": "Inbox is not enabled for this Project Board"}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
inbox_issue = InboxIssue.objects.get(
|
|
||||||
pk=pk, workspace__slug=slug, project_id=project_id, inbox_id=inbox_id
|
|
||||||
)
|
|
||||||
issue = Issue.objects.get(
|
|
||||||
pk=inbox_issue.issue_id, workspace__slug=slug, project_id=project_id
|
|
||||||
)
|
|
||||||
serializer = IssueStateInboxSerializer(issue)
|
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
def destroy(self, request, slug, project_id, inbox_id, pk):
|
|
||||||
project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=slug, project_id=project_id)
|
|
||||||
if project_deploy_board.inbox is None:
|
|
||||||
return Response({"error": "Inbox is not enabled for this Project Board"}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
inbox_issue = InboxIssue.objects.get(
|
|
||||||
pk=pk, workspace__slug=slug, project_id=project_id, inbox_id=inbox_id
|
|
||||||
)
|
|
||||||
|
|
||||||
if str(inbox_issue.created_by_id) != str(request.user.id):
|
|
||||||
return Response({"error": "You cannot delete inbox issue"}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
inbox_issue.delete()
|
inbox_issue.delete()
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
File diff suppressed because it is too large
Load Diff
@ -1,73 +1,53 @@
|
|||||||
# Python imports
|
# Python imports
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# Django Imports
|
# Django imports
|
||||||
|
from django.db.models import Count, Prefetch, Q, F, Func, OuterRef
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.db import IntegrityError
|
|
||||||
from django.db.models import Prefetch, F, OuterRef, Func, Exists, Count, Q
|
|
||||||
from django.core import serializers
|
from django.core import serializers
|
||||||
from django.utils.decorators import method_decorator
|
|
||||||
from django.views.decorators.gzip import gzip_page
|
|
||||||
|
|
||||||
# Third party imports
|
# Third party imports
|
||||||
from rest_framework.response import Response
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from sentry_sdk import capture_exception
|
from rest_framework.response import Response
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from . import BaseViewSet
|
from .base import BaseAPIView, WebhookMixin
|
||||||
|
from plane.app.permissions import ProjectEntityPermission
|
||||||
|
from plane.db.models import (
|
||||||
|
Project,
|
||||||
|
Module,
|
||||||
|
ModuleLink,
|
||||||
|
Issue,
|
||||||
|
ModuleIssue,
|
||||||
|
IssueAttachment,
|
||||||
|
IssueLink,
|
||||||
|
)
|
||||||
from plane.api.serializers import (
|
from plane.api.serializers import (
|
||||||
ModuleWriteSerializer,
|
|
||||||
ModuleSerializer,
|
ModuleSerializer,
|
||||||
ModuleIssueSerializer,
|
ModuleIssueSerializer,
|
||||||
ModuleLinkSerializer,
|
IssueSerializer,
|
||||||
ModuleFavoriteSerializer,
|
|
||||||
IssueStateSerializer,
|
|
||||||
)
|
|
||||||
from plane.api.permissions import ProjectEntityPermission
|
|
||||||
from plane.db.models import (
|
|
||||||
Module,
|
|
||||||
ModuleIssue,
|
|
||||||
Project,
|
|
||||||
Issue,
|
|
||||||
ModuleLink,
|
|
||||||
ModuleFavorite,
|
|
||||||
IssueLink,
|
|
||||||
IssueAttachment,
|
|
||||||
)
|
)
|
||||||
from plane.bgtasks.issue_activites_task import issue_activity
|
from plane.bgtasks.issue_activites_task import issue_activity
|
||||||
from plane.utils.grouper import group_results
|
|
||||||
from plane.utils.issue_filters import issue_filters
|
|
||||||
from plane.utils.analytics_plot import burndown_plot
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleViewSet(BaseViewSet):
|
class ModuleAPIEndpoint(WebhookMixin, BaseAPIView):
|
||||||
|
"""
|
||||||
|
This viewset automatically provides `list`, `create`, `retrieve`,
|
||||||
|
`update` and `destroy` actions related to module.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
model = Module
|
model = Module
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
ProjectEntityPermission,
|
ProjectEntityPermission,
|
||||||
]
|
]
|
||||||
|
serializer_class = ModuleSerializer
|
||||||
def get_serializer_class(self):
|
webhook_event = "module"
|
||||||
return (
|
|
||||||
ModuleWriteSerializer
|
|
||||||
if self.action in ["create", "update", "partial_update"]
|
|
||||||
else ModuleSerializer
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
|
||||||
subquery = ModuleFavorite.objects.filter(
|
|
||||||
user=self.request.user,
|
|
||||||
module_id=OuterRef("pk"),
|
|
||||||
project_id=self.kwargs.get("project_id"),
|
|
||||||
workspace__slug=self.kwargs.get("slug"),
|
|
||||||
)
|
|
||||||
return (
|
return (
|
||||||
super()
|
Module.objects.filter(project_id=self.kwargs.get("project_id"))
|
||||||
.get_queryset()
|
|
||||||
.filter(project_id=self.kwargs.get("project_id"))
|
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"))
|
.filter(workspace__slug=self.kwargs.get("slug"))
|
||||||
.annotate(is_favorite=Exists(subquery))
|
|
||||||
.select_related("project")
|
.select_related("project")
|
||||||
.select_related("workspace")
|
.select_related("workspace")
|
||||||
.select_related("lead")
|
.select_related("lead")
|
||||||
@ -137,130 +117,43 @@ class ModuleViewSet(BaseViewSet):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.order_by("-is_favorite","-created_at")
|
.order_by(self.kwargs.get("order_by", "-created_at"))
|
||||||
)
|
)
|
||||||
|
|
||||||
def create(self, request, slug, project_id):
|
def post(self, request, slug, project_id):
|
||||||
project = Project.objects.get(workspace__slug=slug, pk=project_id)
|
project = Project.objects.get(workspace__slug=slug, pk=project_id)
|
||||||
serializer = ModuleWriteSerializer(
|
serializer = ModuleSerializer(data=request.data, context={"project": project})
|
||||||
data=request.data, context={"project": project}
|
|
||||||
)
|
|
||||||
|
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
serializer.save()
|
serializer.save()
|
||||||
|
|
||||||
module = Module.objects.get(pk=serializer.data["id"])
|
module = Module.objects.get(pk=serializer.data["id"])
|
||||||
serializer = ModuleSerializer(module)
|
serializer = ModuleSerializer(module)
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
def retrieve(self, request, slug, project_id, pk):
|
def get(self, request, slug, project_id, pk=None):
|
||||||
|
if pk:
|
||||||
queryset = self.get_queryset().get(pk=pk)
|
queryset = self.get_queryset().get(pk=pk)
|
||||||
|
data = ModuleSerializer(
|
||||||
assignee_distribution = (
|
queryset,
|
||||||
Issue.objects.filter(
|
fields=self.fields,
|
||||||
issue_module__module_id=pk,
|
expand=self.expand,
|
||||||
workspace__slug=slug,
|
).data
|
||||||
project_id=project_id,
|
|
||||||
)
|
|
||||||
.annotate(first_name=F("assignees__first_name"))
|
|
||||||
.annotate(last_name=F("assignees__last_name"))
|
|
||||||
.annotate(assignee_id=F("assignees__id"))
|
|
||||||
.annotate(display_name=F("assignees__display_name"))
|
|
||||||
.annotate(avatar=F("assignees__avatar"))
|
|
||||||
.values("first_name", "last_name", "assignee_id", "avatar", "display_name")
|
|
||||||
.annotate(
|
|
||||||
total_issues=Count(
|
|
||||||
"assignee_id",
|
|
||||||
filter=Q(
|
|
||||||
archived_at__isnull=True,
|
|
||||||
is_draft=False,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
completed_issues=Count(
|
|
||||||
"assignee_id",
|
|
||||||
filter=Q(
|
|
||||||
completed_at__isnull=False,
|
|
||||||
archived_at__isnull=True,
|
|
||||||
is_draft=False,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
pending_issues=Count(
|
|
||||||
"assignee_id",
|
|
||||||
filter=Q(
|
|
||||||
completed_at__isnull=True,
|
|
||||||
archived_at__isnull=True,
|
|
||||||
is_draft=False,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.order_by("first_name", "last_name")
|
|
||||||
)
|
|
||||||
|
|
||||||
label_distribution = (
|
|
||||||
Issue.objects.filter(
|
|
||||||
issue_module__module_id=pk,
|
|
||||||
workspace__slug=slug,
|
|
||||||
project_id=project_id,
|
|
||||||
)
|
|
||||||
.annotate(label_name=F("labels__name"))
|
|
||||||
.annotate(color=F("labels__color"))
|
|
||||||
.annotate(label_id=F("labels__id"))
|
|
||||||
.values("label_name", "color", "label_id")
|
|
||||||
.annotate(
|
|
||||||
total_issues=Count(
|
|
||||||
"label_id",
|
|
||||||
filter=Q(
|
|
||||||
archived_at__isnull=True,
|
|
||||||
is_draft=False,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
completed_issues=Count(
|
|
||||||
"label_id",
|
|
||||||
filter=Q(
|
|
||||||
completed_at__isnull=False,
|
|
||||||
archived_at__isnull=True,
|
|
||||||
is_draft=False,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.annotate(
|
|
||||||
pending_issues=Count(
|
|
||||||
"label_id",
|
|
||||||
filter=Q(
|
|
||||||
completed_at__isnull=True,
|
|
||||||
archived_at__isnull=True,
|
|
||||||
is_draft=False,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.order_by("label_name")
|
|
||||||
)
|
|
||||||
|
|
||||||
data = ModuleSerializer(queryset).data
|
|
||||||
data["distribution"] = {
|
|
||||||
"assignees": assignee_distribution,
|
|
||||||
"labels": label_distribution,
|
|
||||||
"completion_chart": {},
|
|
||||||
}
|
|
||||||
|
|
||||||
if queryset.start_date and queryset.target_date:
|
|
||||||
data["distribution"]["completion_chart"] = burndown_plot(
|
|
||||||
queryset=queryset, slug=slug, project_id=project_id, module_id=pk
|
|
||||||
)
|
|
||||||
|
|
||||||
return Response(
|
return Response(
|
||||||
data,
|
data,
|
||||||
status=status.HTTP_200_OK,
|
status=status.HTTP_200_OK,
|
||||||
)
|
)
|
||||||
|
return self.paginate(
|
||||||
|
request=request,
|
||||||
|
queryset=(self.get_queryset()),
|
||||||
|
on_results=lambda modules: ModuleSerializer(
|
||||||
|
modules,
|
||||||
|
many=True,
|
||||||
|
fields=self.fields,
|
||||||
|
expand=self.expand,
|
||||||
|
).data,
|
||||||
|
)
|
||||||
|
|
||||||
def destroy(self, request, slug, project_id, pk):
|
def delete(self, request, slug, project_id, pk):
|
||||||
module = Module.objects.get(workspace__slug=slug, project_id=project_id, pk=pk)
|
module = Module.objects.get(workspace__slug=slug, project_id=project_id, pk=pk)
|
||||||
module_issues = list(
|
module_issues = list(
|
||||||
ModuleIssue.objects.filter(module_id=pk).values_list("issue", flat=True)
|
ModuleIssue.objects.filter(module_id=pk).values_list("issue", flat=True)
|
||||||
@ -284,24 +177,24 @@ class ModuleViewSet(BaseViewSet):
|
|||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class ModuleIssueViewSet(BaseViewSet):
|
class ModuleIssueAPIEndpoint(WebhookMixin, BaseAPIView):
|
||||||
|
"""
|
||||||
|
This viewset automatically provides `list`, `create`, `retrieve`,
|
||||||
|
`update` and `destroy` actions related to module issues.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
serializer_class = ModuleIssueSerializer
|
serializer_class = ModuleIssueSerializer
|
||||||
model = ModuleIssue
|
model = ModuleIssue
|
||||||
|
webhook_event = "module"
|
||||||
filterset_fields = [
|
|
||||||
"issue__labels__id",
|
|
||||||
"issue__assignees__id",
|
|
||||||
]
|
|
||||||
|
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
ProjectEntityPermission,
|
ProjectEntityPermission,
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return self.filter_queryset(
|
return (
|
||||||
super()
|
ModuleIssue.objects.annotate(
|
||||||
.get_queryset()
|
|
||||||
.annotate(
|
|
||||||
sub_issues_count=Issue.issue_objects.filter(parent=OuterRef("issue"))
|
sub_issues_count=Issue.issue_objects.filter(parent=OuterRef("issue"))
|
||||||
.order_by()
|
.order_by()
|
||||||
.annotate(count=Func(F("id"), function="Count"))
|
.annotate(count=Func(F("id"), function="Count"))
|
||||||
@ -317,15 +210,12 @@ class ModuleIssueViewSet(BaseViewSet):
|
|||||||
.select_related("issue", "issue__state", "issue__project")
|
.select_related("issue", "issue__state", "issue__project")
|
||||||
.prefetch_related("issue__assignees", "issue__labels")
|
.prefetch_related("issue__assignees", "issue__labels")
|
||||||
.prefetch_related("module__members")
|
.prefetch_related("module__members")
|
||||||
|
.order_by(self.kwargs.get("order_by", "-created_at"))
|
||||||
.distinct()
|
.distinct()
|
||||||
)
|
)
|
||||||
|
|
||||||
@method_decorator(gzip_page)
|
def get(self, request, slug, project_id, module_id):
|
||||||
def list(self, request, slug, project_id, module_id):
|
|
||||||
order_by = request.GET.get("order_by", "created_at")
|
order_by = request.GET.get("order_by", "created_at")
|
||||||
group_by = request.GET.get("group_by", False)
|
|
||||||
sub_group_by = request.GET.get("sub_group_by", False)
|
|
||||||
filters = issue_filters(request.query_params, "GET")
|
|
||||||
issues = (
|
issues = (
|
||||||
Issue.issue_objects.filter(issue_module__module_id=module_id)
|
Issue.issue_objects.filter(issue_module__module_id=module_id)
|
||||||
.annotate(
|
.annotate(
|
||||||
@ -344,7 +234,6 @@ class ModuleIssueViewSet(BaseViewSet):
|
|||||||
.prefetch_related("assignees")
|
.prefetch_related("assignees")
|
||||||
.prefetch_related("labels")
|
.prefetch_related("labels")
|
||||||
.order_by(order_by)
|
.order_by(order_by)
|
||||||
.filter(**filters)
|
|
||||||
.annotate(
|
.annotate(
|
||||||
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
|
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
|
||||||
.order_by()
|
.order_by()
|
||||||
@ -358,26 +247,18 @@ class ModuleIssueViewSet(BaseViewSet):
|
|||||||
.values("count")
|
.values("count")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
issues_data = IssueStateSerializer(issues, many=True).data
|
return self.paginate(
|
||||||
|
request=request,
|
||||||
if sub_group_by and sub_group_by == group_by:
|
queryset=(issues),
|
||||||
return Response(
|
on_results=lambda issues: IssueSerializer(
|
||||||
{"error": "Group by and sub group by cannot be same"},
|
issues,
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
many=True,
|
||||||
|
fields=self.fields,
|
||||||
|
expand=self.expand,
|
||||||
|
).data,
|
||||||
)
|
)
|
||||||
|
|
||||||
if group_by:
|
def post(self, request, slug, project_id, module_id):
|
||||||
grouped_results = group_results(issues_data, group_by, sub_group_by)
|
|
||||||
return Response(
|
|
||||||
grouped_results,
|
|
||||||
status=status.HTTP_200_OK,
|
|
||||||
)
|
|
||||||
|
|
||||||
return Response(
|
|
||||||
issues_data, status=status.HTTP_200_OK
|
|
||||||
)
|
|
||||||
|
|
||||||
def create(self, request, slug, project_id, module_id):
|
|
||||||
issues = request.data.get("issues", [])
|
issues = request.data.get("issues", [])
|
||||||
if not len(issues):
|
if not len(issues):
|
||||||
return Response(
|
return Response(
|
||||||
@ -387,6 +268,10 @@ class ModuleIssueViewSet(BaseViewSet):
|
|||||||
workspace__slug=slug, project_id=project_id, pk=module_id
|
workspace__slug=slug, project_id=project_id, pk=module_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
issues = Issue.objects.filter(
|
||||||
|
workspace__slug=slug, project_id=project_id, pk__in=issues
|
||||||
|
).values_list("id", flat=True)
|
||||||
|
|
||||||
module_issues = list(ModuleIssue.objects.filter(issue_id__in=issues))
|
module_issues = list(ModuleIssue.objects.filter(issue_id__in=issues))
|
||||||
|
|
||||||
update_module_issue_activity = []
|
update_module_issue_activity = []
|
||||||
@ -458,7 +343,7 @@ class ModuleIssueViewSet(BaseViewSet):
|
|||||||
status=status.HTTP_200_OK,
|
status=status.HTTP_200_OK,
|
||||||
)
|
)
|
||||||
|
|
||||||
def destroy(self, request, slug, project_id, module_id, pk):
|
def delete(self, request, slug, project_id, module_id, pk):
|
||||||
module_issue = ModuleIssue.objects.get(
|
module_issue = ModuleIssue.objects.get(
|
||||||
workspace__slug=slug, project_id=project_id, module_id=module_id, pk=pk
|
workspace__slug=slug, project_id=project_id, module_id=module_id, pk=pk
|
||||||
)
|
)
|
||||||
@ -478,61 +363,3 @@ class ModuleIssueViewSet(BaseViewSet):
|
|||||||
epoch=int(timezone.now().timestamp()),
|
epoch=int(timezone.now().timestamp()),
|
||||||
)
|
)
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class ModuleLinkViewSet(BaseViewSet):
|
|
||||||
permission_classes = [
|
|
||||||
ProjectEntityPermission,
|
|
||||||
]
|
|
||||||
|
|
||||||
model = ModuleLink
|
|
||||||
serializer_class = ModuleLinkSerializer
|
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
|
||||||
serializer.save(
|
|
||||||
project_id=self.kwargs.get("project_id"),
|
|
||||||
module_id=self.kwargs.get("module_id"),
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return (
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"))
|
|
||||||
.filter(project_id=self.kwargs.get("project_id"))
|
|
||||||
.filter(module_id=self.kwargs.get("module_id"))
|
|
||||||
.filter(project__project_projectmember__member=self.request.user)
|
|
||||||
.order_by("-created_at")
|
|
||||||
.distinct()
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleFavoriteViewSet(BaseViewSet):
|
|
||||||
serializer_class = ModuleFavoriteSerializer
|
|
||||||
model = ModuleFavorite
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return self.filter_queryset(
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"))
|
|
||||||
.filter(user=self.request.user)
|
|
||||||
.select_related("module")
|
|
||||||
)
|
|
||||||
|
|
||||||
def create(self, request, slug, project_id):
|
|
||||||
serializer = ModuleFavoriteSerializer(data=request.data)
|
|
||||||
if serializer.is_valid():
|
|
||||||
serializer.save(user=request.user, project_id=project_id)
|
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
def destroy(self, request, slug, project_id, module_id):
|
|
||||||
module_favorite = ModuleFavorite.objects.get(
|
|
||||||
project=project_id,
|
|
||||||
user=request.user,
|
|
||||||
workspace__slug=slug,
|
|
||||||
module_id=module_id,
|
|
||||||
)
|
|
||||||
module_favorite.delete()
|
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
|
||||||
|
@ -1,255 +0,0 @@
|
|||||||
# Python imports
|
|
||||||
from datetime import timedelta, date
|
|
||||||
|
|
||||||
# Django imports
|
|
||||||
from django.db.models import Exists, OuterRef, Q, Prefetch
|
|
||||||
from django.utils import timezone
|
|
||||||
|
|
||||||
# Third party imports
|
|
||||||
from rest_framework import status
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from sentry_sdk import capture_exception
|
|
||||||
|
|
||||||
# Module imports
|
|
||||||
from .base import BaseViewSet, BaseAPIView
|
|
||||||
from plane.api.permissions import ProjectEntityPermission
|
|
||||||
from plane.db.models import (
|
|
||||||
Page,
|
|
||||||
PageBlock,
|
|
||||||
PageFavorite,
|
|
||||||
Issue,
|
|
||||||
IssueAssignee,
|
|
||||||
IssueActivity,
|
|
||||||
)
|
|
||||||
from plane.api.serializers import (
|
|
||||||
PageSerializer,
|
|
||||||
PageBlockSerializer,
|
|
||||||
PageFavoriteSerializer,
|
|
||||||
IssueLiteSerializer,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class PageViewSet(BaseViewSet):
|
|
||||||
serializer_class = PageSerializer
|
|
||||||
model = Page
|
|
||||||
permission_classes = [
|
|
||||||
ProjectEntityPermission,
|
|
||||||
]
|
|
||||||
search_fields = [
|
|
||||||
"name",
|
|
||||||
]
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
subquery = PageFavorite.objects.filter(
|
|
||||||
user=self.request.user,
|
|
||||||
page_id=OuterRef("pk"),
|
|
||||||
project_id=self.kwargs.get("project_id"),
|
|
||||||
workspace__slug=self.kwargs.get("slug"),
|
|
||||||
)
|
|
||||||
return self.filter_queryset(
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"))
|
|
||||||
.filter(project_id=self.kwargs.get("project_id"))
|
|
||||||
.filter(project__project_projectmember__member=self.request.user)
|
|
||||||
.filter(Q(owned_by=self.request.user) | Q(access=0))
|
|
||||||
.select_related("project")
|
|
||||||
.select_related("workspace")
|
|
||||||
.select_related("owned_by")
|
|
||||||
.annotate(is_favorite=Exists(subquery))
|
|
||||||
.order_by(self.request.GET.get("order_by", "-created_at"))
|
|
||||||
.prefetch_related("labels")
|
|
||||||
.order_by("name", "-is_favorite")
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"blocks",
|
|
||||||
queryset=PageBlock.objects.select_related(
|
|
||||||
"page", "issue", "workspace", "project"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.distinct()
|
|
||||||
)
|
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
|
||||||
serializer.save(
|
|
||||||
project_id=self.kwargs.get("project_id"), owned_by=self.request.user
|
|
||||||
)
|
|
||||||
|
|
||||||
def create(self, request, slug, project_id):
|
|
||||||
serializer = PageSerializer(
|
|
||||||
data=request.data,
|
|
||||||
context={"project_id": project_id, "owned_by_id": request.user.id},
|
|
||||||
)
|
|
||||||
|
|
||||||
if serializer.is_valid():
|
|
||||||
serializer.save()
|
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
def partial_update(self, request, slug, project_id, pk):
|
|
||||||
page = Page.objects.get(pk=pk, workspace__slug=slug, project_id=project_id)
|
|
||||||
# Only update access if the page owner is the requesting user
|
|
||||||
if (
|
|
||||||
page.access != request.data.get("access", page.access)
|
|
||||||
and page.owned_by_id != request.user.id
|
|
||||||
):
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"error": "Access cannot be updated since this page is owned by someone else"
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
serializer = PageSerializer(page, data=request.data, partial=True)
|
|
||||||
if serializer.is_valid():
|
|
||||||
serializer.save()
|
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
def list(self, request, slug, project_id):
|
|
||||||
queryset = self.get_queryset()
|
|
||||||
page_view = request.GET.get("page_view", False)
|
|
||||||
|
|
||||||
if not page_view:
|
|
||||||
return Response({"error": "Page View parameter is required"}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
# All Pages
|
|
||||||
if page_view == "all":
|
|
||||||
return Response(PageSerializer(queryset, many=True).data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
# Recent pages
|
|
||||||
if page_view == "recent":
|
|
||||||
current_time = date.today()
|
|
||||||
day_before = current_time - timedelta(days=1)
|
|
||||||
todays_pages = queryset.filter(updated_at__date=date.today())
|
|
||||||
yesterdays_pages = queryset.filter(updated_at__date=day_before)
|
|
||||||
earlier_this_week = queryset.filter( updated_at__date__range=(
|
|
||||||
(timezone.now() - timedelta(days=7)),
|
|
||||||
(timezone.now() - timedelta(days=2)),
|
|
||||||
))
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"today": PageSerializer(todays_pages, many=True).data,
|
|
||||||
"yesterday": PageSerializer(yesterdays_pages, many=True).data,
|
|
||||||
"earlier_this_week": PageSerializer(earlier_this_week, many=True).data,
|
|
||||||
},
|
|
||||||
status=status.HTTP_200_OK,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Favorite Pages
|
|
||||||
if page_view == "favorite":
|
|
||||||
queryset = queryset.filter(is_favorite=True)
|
|
||||||
return Response(PageSerializer(queryset, many=True).data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
# My pages
|
|
||||||
if page_view == "created_by_me":
|
|
||||||
queryset = queryset.filter(owned_by=request.user)
|
|
||||||
return Response(PageSerializer(queryset, many=True).data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
# Created by other Pages
|
|
||||||
if page_view == "created_by_other":
|
|
||||||
queryset = queryset.filter(~Q(owned_by=request.user), access=0)
|
|
||||||
return Response(PageSerializer(queryset, many=True).data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
return Response({"error": "No matching view found"}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
|
|
||||||
class PageBlockViewSet(BaseViewSet):
|
|
||||||
serializer_class = PageBlockSerializer
|
|
||||||
model = PageBlock
|
|
||||||
permission_classes = [
|
|
||||||
ProjectEntityPermission,
|
|
||||||
]
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return self.filter_queryset(
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"))
|
|
||||||
.filter(project_id=self.kwargs.get("project_id"))
|
|
||||||
.filter(page_id=self.kwargs.get("page_id"))
|
|
||||||
.filter(project__project_projectmember__member=self.request.user)
|
|
||||||
.select_related("project")
|
|
||||||
.select_related("workspace")
|
|
||||||
.select_related("page")
|
|
||||||
.select_related("issue")
|
|
||||||
.order_by("sort_order")
|
|
||||||
.distinct()
|
|
||||||
)
|
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
|
||||||
serializer.save(
|
|
||||||
project_id=self.kwargs.get("project_id"),
|
|
||||||
page_id=self.kwargs.get("page_id"),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class PageFavoriteViewSet(BaseViewSet):
|
|
||||||
permission_classes = [
|
|
||||||
ProjectEntityPermission,
|
|
||||||
]
|
|
||||||
|
|
||||||
serializer_class = PageFavoriteSerializer
|
|
||||||
model = PageFavorite
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return self.filter_queryset(
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"))
|
|
||||||
.filter(user=self.request.user)
|
|
||||||
.select_related("page", "page__owned_by")
|
|
||||||
)
|
|
||||||
|
|
||||||
def create(self, request, slug, project_id):
|
|
||||||
serializer = PageFavoriteSerializer(data=request.data)
|
|
||||||
if serializer.is_valid():
|
|
||||||
serializer.save(user=request.user, project_id=project_id)
|
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
def destroy(self, request, slug, project_id, page_id):
|
|
||||||
page_favorite = PageFavorite.objects.get(
|
|
||||||
project=project_id,
|
|
||||||
user=request.user,
|
|
||||||
workspace__slug=slug,
|
|
||||||
page_id=page_id,
|
|
||||||
)
|
|
||||||
page_favorite.delete()
|
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
|
||||||
|
|
||||||
class CreateIssueFromPageBlockEndpoint(BaseAPIView):
|
|
||||||
permission_classes = [
|
|
||||||
ProjectEntityPermission,
|
|
||||||
]
|
|
||||||
|
|
||||||
def post(self, request, slug, project_id, page_id, page_block_id):
|
|
||||||
page_block = PageBlock.objects.get(
|
|
||||||
pk=page_block_id,
|
|
||||||
workspace__slug=slug,
|
|
||||||
project_id=project_id,
|
|
||||||
page_id=page_id,
|
|
||||||
)
|
|
||||||
issue = Issue.objects.create(
|
|
||||||
name=page_block.name,
|
|
||||||
project_id=project_id,
|
|
||||||
description=page_block.description,
|
|
||||||
description_html=page_block.description_html,
|
|
||||||
description_stripped=page_block.description_stripped,
|
|
||||||
)
|
|
||||||
_ = IssueAssignee.objects.create(
|
|
||||||
issue=issue, assignee=request.user, project_id=project_id
|
|
||||||
)
|
|
||||||
|
|
||||||
_ = IssueActivity.objects.create(
|
|
||||||
issue=issue,
|
|
||||||
actor=request.user,
|
|
||||||
project_id=project_id,
|
|
||||||
comment=f"created the issue from {page_block.name} block",
|
|
||||||
verb="created",
|
|
||||||
)
|
|
||||||
|
|
||||||
page_block.issue = issue
|
|
||||||
page_block.save()
|
|
||||||
|
|
||||||
return Response(IssueLiteSerializer(issue).data, status=status.HTTP_200_OK)
|
|
@ -1,121 +1,63 @@
|
|||||||
# Python imports
|
|
||||||
import jwt
|
|
||||||
import boto3
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
# Django imports
|
# Django imports
|
||||||
from django.core.exceptions import ValidationError
|
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.db.models import (
|
from django.db.models import Exists, OuterRef, Q, F, Func, Subquery, Prefetch
|
||||||
Prefetch,
|
|
||||||
Q,
|
|
||||||
Exists,
|
|
||||||
OuterRef,
|
|
||||||
F,
|
|
||||||
Func,
|
|
||||||
Subquery,
|
|
||||||
)
|
|
||||||
from django.core.validators import validate_email
|
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
# Third Party imports
|
# Third party imports
|
||||||
from rest_framework.response import Response
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework import serializers
|
from rest_framework.response import Response
|
||||||
from rest_framework.permissions import AllowAny
|
from rest_framework.serializers import ValidationError
|
||||||
from sentry_sdk import capture_exception
|
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from .base import BaseViewSet, BaseAPIView
|
|
||||||
from plane.api.serializers import (
|
|
||||||
ProjectSerializer,
|
|
||||||
ProjectListSerializer,
|
|
||||||
ProjectMemberSerializer,
|
|
||||||
ProjectDetailSerializer,
|
|
||||||
ProjectMemberInviteSerializer,
|
|
||||||
ProjectFavoriteSerializer,
|
|
||||||
ProjectDeployBoardSerializer,
|
|
||||||
ProjectMemberAdminSerializer,
|
|
||||||
)
|
|
||||||
|
|
||||||
from plane.api.permissions import (
|
|
||||||
ProjectBasePermission,
|
|
||||||
ProjectEntityPermission,
|
|
||||||
ProjectMemberPermission,
|
|
||||||
ProjectLitePermission,
|
|
||||||
)
|
|
||||||
|
|
||||||
from plane.db.models import (
|
from plane.db.models import (
|
||||||
Project,
|
|
||||||
ProjectMember,
|
|
||||||
Workspace,
|
Workspace,
|
||||||
ProjectMemberInvite,
|
Project,
|
||||||
User,
|
|
||||||
WorkspaceMember,
|
|
||||||
State,
|
|
||||||
TeamMember,
|
|
||||||
ProjectFavorite,
|
ProjectFavorite,
|
||||||
ProjectIdentifier,
|
ProjectMember,
|
||||||
Module,
|
|
||||||
Cycle,
|
|
||||||
CycleFavorite,
|
|
||||||
ModuleFavorite,
|
|
||||||
PageFavorite,
|
|
||||||
IssueViewFavorite,
|
|
||||||
Page,
|
|
||||||
IssueAssignee,
|
|
||||||
ModuleMember,
|
|
||||||
Inbox,
|
|
||||||
ProjectDeployBoard,
|
ProjectDeployBoard,
|
||||||
|
State,
|
||||||
|
Cycle,
|
||||||
|
Module,
|
||||||
IssueProperty,
|
IssueProperty,
|
||||||
|
Inbox,
|
||||||
)
|
)
|
||||||
|
from plane.app.permissions import ProjectBasePermission
|
||||||
from plane.bgtasks.project_invitation_task import project_invitation
|
from plane.api.serializers import ProjectSerializer
|
||||||
|
from .base import BaseAPIView, WebhookMixin
|
||||||
|
|
||||||
|
|
||||||
class ProjectViewSet(BaseViewSet):
|
class ProjectAPIEndpoint(WebhookMixin, BaseAPIView):
|
||||||
|
"""Project Endpoints to create, update, list, retrieve and delete endpoint"""
|
||||||
|
|
||||||
serializer_class = ProjectSerializer
|
serializer_class = ProjectSerializer
|
||||||
model = Project
|
model = Project
|
||||||
|
webhook_event = "project"
|
||||||
|
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
ProjectBasePermission,
|
ProjectBasePermission,
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_serializer_class(self, *args, **kwargs):
|
|
||||||
if self.action in ["update", "partial_update"]:
|
|
||||||
return ProjectSerializer
|
|
||||||
return ProjectDetailSerializer
|
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return self.filter_queryset(
|
return (
|
||||||
super()
|
Project.objects.filter(workspace__slug=self.kwargs.get("slug"))
|
||||||
.get_queryset()
|
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"))
|
|
||||||
.filter(Q(project_projectmember__member=self.request.user) | Q(network=2))
|
.filter(Q(project_projectmember__member=self.request.user) | Q(network=2))
|
||||||
.select_related(
|
.select_related(
|
||||||
"workspace", "workspace__owner", "default_assignee", "project_lead"
|
"workspace", "workspace__owner", "default_assignee", "project_lead"
|
||||||
)
|
)
|
||||||
.annotate(
|
|
||||||
is_favorite=Exists(
|
|
||||||
ProjectFavorite.objects.filter(
|
|
||||||
user=self.request.user,
|
|
||||||
project_id=OuterRef("pk"),
|
|
||||||
workspace__slug=self.kwargs.get("slug"),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.annotate(
|
.annotate(
|
||||||
is_member=Exists(
|
is_member=Exists(
|
||||||
ProjectMember.objects.filter(
|
ProjectMember.objects.filter(
|
||||||
member=self.request.user,
|
member=self.request.user,
|
||||||
project_id=OuterRef("pk"),
|
project_id=OuterRef("pk"),
|
||||||
workspace__slug=self.kwargs.get("slug"),
|
workspace__slug=self.kwargs.get("slug"),
|
||||||
|
is_active=True,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.annotate(
|
.annotate(
|
||||||
total_members=ProjectMember.objects.filter(
|
total_members=ProjectMember.objects.filter(
|
||||||
project_id=OuterRef("id"), member__is_bot=False
|
project_id=OuterRef("id"),
|
||||||
|
member__is_bot=False,
|
||||||
|
is_active=True,
|
||||||
)
|
)
|
||||||
.order_by()
|
.order_by()
|
||||||
.annotate(count=Func(F("id"), function="Count"))
|
.annotate(count=Func(F("id"), function="Count"))
|
||||||
@ -137,6 +79,7 @@ class ProjectViewSet(BaseViewSet):
|
|||||||
member_role=ProjectMember.objects.filter(
|
member_role=ProjectMember.objects.filter(
|
||||||
project_id=OuterRef("pk"),
|
project_id=OuterRef("pk"),
|
||||||
member_id=self.request.user.id,
|
member_id=self.request.user.id,
|
||||||
|
is_active=True,
|
||||||
).values("role")
|
).values("role")
|
||||||
)
|
)
|
||||||
.annotate(
|
.annotate(
|
||||||
@ -147,16 +90,17 @@ class ProjectViewSet(BaseViewSet):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.order_by(self.kwargs.get("order_by", "-created_at"))
|
||||||
.distinct()
|
.distinct()
|
||||||
)
|
)
|
||||||
|
|
||||||
def list(self, request, slug):
|
def get(self, request, slug, pk=None):
|
||||||
fields = [field for field in request.GET.get("fields", "").split(",") if field]
|
if pk is None:
|
||||||
|
|
||||||
sort_order_query = ProjectMember.objects.filter(
|
sort_order_query = ProjectMember.objects.filter(
|
||||||
member=request.user,
|
member=request.user,
|
||||||
project_id=OuterRef("pk"),
|
project_id=OuterRef("pk"),
|
||||||
workspace__slug=self.kwargs.get("slug"),
|
workspace__slug=self.kwargs.get("slug"),
|
||||||
|
is_active=True,
|
||||||
).values("sort_order")
|
).values("sort_order")
|
||||||
projects = (
|
projects = (
|
||||||
self.get_queryset()
|
self.get_queryset()
|
||||||
@ -166,27 +110,25 @@ class ProjectViewSet(BaseViewSet):
|
|||||||
"project_projectmember",
|
"project_projectmember",
|
||||||
queryset=ProjectMember.objects.filter(
|
queryset=ProjectMember.objects.filter(
|
||||||
workspace__slug=slug,
|
workspace__slug=slug,
|
||||||
|
is_active=True,
|
||||||
).select_related("member"),
|
).select_related("member"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.order_by("sort_order", "name")
|
.order_by("sort_order", "name")
|
||||||
)
|
)
|
||||||
if request.GET.get("per_page", False) and request.GET.get("cursor", False):
|
|
||||||
return self.paginate(
|
return self.paginate(
|
||||||
request=request,
|
request=request,
|
||||||
queryset=(projects),
|
queryset=(projects),
|
||||||
on_results=lambda projects: ProjectListSerializer(
|
on_results=lambda projects: ProjectSerializer(
|
||||||
projects, many=True
|
projects, many=True, fields=self.fields, expand=self.expand,
|
||||||
).data,
|
).data,
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
project = self.get_queryset().get(workspace__slug=slug, pk=pk)
|
||||||
|
serializer = ProjectSerializer(project, fields=self.fields, expand=self.expand,)
|
||||||
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
return Response(
|
def post(self, request, slug):
|
||||||
ProjectListSerializer(
|
|
||||||
projects, many=True, fields=fields if fields else None
|
|
||||||
).data
|
|
||||||
)
|
|
||||||
|
|
||||||
def create(self, request, slug):
|
|
||||||
try:
|
try:
|
||||||
workspace = Workspace.objects.get(slug=slug)
|
workspace = Workspace.objects.get(slug=slug)
|
||||||
|
|
||||||
@ -272,7 +214,7 @@ class ProjectViewSet(BaseViewSet):
|
|||||||
)
|
)
|
||||||
|
|
||||||
project = self.get_queryset().filter(pk=serializer.data["id"]).first()
|
project = self.get_queryset().filter(pk=serializer.data["id"]).first()
|
||||||
serializer = ProjectListSerializer(project)
|
serializer = ProjectSerializer(project)
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
return Response(
|
return Response(
|
||||||
serializer.errors,
|
serializer.errors,
|
||||||
@ -288,16 +230,15 @@ class ProjectViewSet(BaseViewSet):
|
|||||||
return Response(
|
return Response(
|
||||||
{"error": "Workspace does not exist"}, status=status.HTTP_404_NOT_FOUND
|
{"error": "Workspace does not exist"}, status=status.HTTP_404_NOT_FOUND
|
||||||
)
|
)
|
||||||
except serializers.ValidationError as e:
|
except ValidationError as e:
|
||||||
return Response(
|
return Response(
|
||||||
{"identifier": "The project identifier is already taken"},
|
{"identifier": "The project identifier is already taken"},
|
||||||
status=status.HTTP_410_GONE,
|
status=status.HTTP_410_GONE,
|
||||||
)
|
)
|
||||||
|
|
||||||
def partial_update(self, request, slug, pk=None):
|
def patch(self, request, slug, pk=None):
|
||||||
try:
|
try:
|
||||||
workspace = Workspace.objects.get(slug=slug)
|
workspace = Workspace.objects.get(slug=slug)
|
||||||
|
|
||||||
project = Project.objects.get(pk=pk)
|
project = Project.objects.get(pk=pk)
|
||||||
|
|
||||||
serializer = ProjectSerializer(
|
serializer = ProjectSerializer(
|
||||||
@ -324,10 +265,9 @@ class ProjectViewSet(BaseViewSet):
|
|||||||
)
|
)
|
||||||
|
|
||||||
project = self.get_queryset().filter(pk=serializer.data["id"]).first()
|
project = self.get_queryset().filter(pk=serializer.data["id"]).first()
|
||||||
serializer = ProjectListSerializer(project)
|
serializer = ProjectSerializer(project)
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
except IntegrityError as e:
|
except IntegrityError as e:
|
||||||
if "already exists" in str(e):
|
if "already exists" in str(e):
|
||||||
return Response(
|
return Response(
|
||||||
@ -338,710 +278,8 @@ class ProjectViewSet(BaseViewSet):
|
|||||||
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
|
||||||
)
|
)
|
||||||
except serializers.ValidationError as e:
|
except ValidationError as e:
|
||||||
return Response(
|
return Response(
|
||||||
{"identifier": "The project identifier is already taken"},
|
{"identifier": "The project identifier is already taken"},
|
||||||
status=status.HTTP_410_GONE,
|
status=status.HTTP_410_GONE,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class InviteProjectEndpoint(BaseAPIView):
|
|
||||||
permission_classes = [
|
|
||||||
ProjectBasePermission,
|
|
||||||
]
|
|
||||||
|
|
||||||
def post(self, request, slug, project_id):
|
|
||||||
email = request.data.get("email", False)
|
|
||||||
role = request.data.get("role", False)
|
|
||||||
|
|
||||||
# Check if email is provided
|
|
||||||
if not email:
|
|
||||||
return Response(
|
|
||||||
{"error": "Email is required"}, status=status.HTTP_400_BAD_REQUEST
|
|
||||||
)
|
|
||||||
|
|
||||||
validate_email(email)
|
|
||||||
# Check if user is already a member of workspace
|
|
||||||
if ProjectMember.objects.filter(
|
|
||||||
project_id=project_id,
|
|
||||||
member__email=email,
|
|
||||||
member__is_bot=False,
|
|
||||||
).exists():
|
|
||||||
return Response(
|
|
||||||
{"error": "User is already member of workspace"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
user = User.objects.filter(email=email).first()
|
|
||||||
|
|
||||||
if user is None:
|
|
||||||
token = jwt.encode(
|
|
||||||
{"email": email, "timestamp": datetime.now().timestamp()},
|
|
||||||
settings.SECRET_KEY,
|
|
||||||
algorithm="HS256",
|
|
||||||
)
|
|
||||||
project_invitation_obj = ProjectMemberInvite.objects.create(
|
|
||||||
email=email.strip().lower(),
|
|
||||||
project_id=project_id,
|
|
||||||
token=token,
|
|
||||||
role=role,
|
|
||||||
)
|
|
||||||
domain = settings.WEB_URL
|
|
||||||
project_invitation.delay(email, project_id, token, domain)
|
|
||||||
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"message": "Email sent successfully",
|
|
||||||
"id": project_invitation_obj.id,
|
|
||||||
},
|
|
||||||
status=status.HTTP_200_OK,
|
|
||||||
)
|
|
||||||
|
|
||||||
project_member = ProjectMember.objects.create(
|
|
||||||
member=user, project_id=project_id, role=role
|
|
||||||
)
|
|
||||||
|
|
||||||
_ = IssueProperty.objects.create(user=user, project_id=project_id)
|
|
||||||
|
|
||||||
return Response(
|
|
||||||
ProjectMemberSerializer(project_member).data, status=status.HTTP_200_OK
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class UserProjectInvitationsViewset(BaseViewSet):
|
|
||||||
serializer_class = ProjectMemberInviteSerializer
|
|
||||||
model = ProjectMemberInvite
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return self.filter_queryset(
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.filter(email=self.request.user.email)
|
|
||||||
.select_related("workspace", "workspace__owner", "project")
|
|
||||||
)
|
|
||||||
|
|
||||||
def create(self, request):
|
|
||||||
invitations = request.data.get("invitations")
|
|
||||||
project_invitations = ProjectMemberInvite.objects.filter(
|
|
||||||
pk__in=invitations, accepted=True
|
|
||||||
)
|
|
||||||
ProjectMember.objects.bulk_create(
|
|
||||||
[
|
|
||||||
ProjectMember(
|
|
||||||
project=invitation.project,
|
|
||||||
workspace=invitation.project.workspace,
|
|
||||||
member=request.user,
|
|
||||||
role=invitation.role,
|
|
||||||
created_by=request.user,
|
|
||||||
)
|
|
||||||
for invitation in project_invitations
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
IssueProperty.objects.bulk_create(
|
|
||||||
[
|
|
||||||
ProjectMember(
|
|
||||||
project=invitation.project,
|
|
||||||
workspace=invitation.project.workspace,
|
|
||||||
user=request.user,
|
|
||||||
created_by=request.user,
|
|
||||||
)
|
|
||||||
for invitation in project_invitations
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
# Delete joined project invites
|
|
||||||
project_invitations.delete()
|
|
||||||
|
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectMemberViewSet(BaseViewSet):
|
|
||||||
serializer_class = ProjectMemberAdminSerializer
|
|
||||||
model = ProjectMember
|
|
||||||
permission_classes = [
|
|
||||||
ProjectMemberPermission,
|
|
||||||
]
|
|
||||||
|
|
||||||
search_fields = [
|
|
||||||
"member__display_name",
|
|
||||||
"member__first_name",
|
|
||||||
]
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return self.filter_queryset(
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"))
|
|
||||||
.filter(project_id=self.kwargs.get("project_id"))
|
|
||||||
.filter(member__is_bot=False)
|
|
||||||
.select_related("project")
|
|
||||||
.select_related("member")
|
|
||||||
.select_related("workspace", "workspace__owner")
|
|
||||||
)
|
|
||||||
|
|
||||||
def create(self, request, slug, project_id):
|
|
||||||
members = request.data.get("members", [])
|
|
||||||
|
|
||||||
# get the project
|
|
||||||
project = Project.objects.get(pk=project_id, workspace__slug=slug)
|
|
||||||
|
|
||||||
if not len(members):
|
|
||||||
return Response(
|
|
||||||
{"error": "Atleast one member is required"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
bulk_project_members = []
|
|
||||||
bulk_issue_props = []
|
|
||||||
|
|
||||||
project_members = (
|
|
||||||
ProjectMember.objects.filter(
|
|
||||||
workspace__slug=slug,
|
|
||||||
member_id__in=[member.get("member_id") for member in members],
|
|
||||||
)
|
|
||||||
.values("member_id", "sort_order")
|
|
||||||
.order_by("sort_order")
|
|
||||||
)
|
|
||||||
|
|
||||||
for member in members:
|
|
||||||
sort_order = [
|
|
||||||
project_member.get("sort_order")
|
|
||||||
for project_member in project_members
|
|
||||||
if str(project_member.get("member_id")) == str(member.get("member_id"))
|
|
||||||
]
|
|
||||||
bulk_project_members.append(
|
|
||||||
ProjectMember(
|
|
||||||
member_id=member.get("member_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,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
bulk_issue_props.append(
|
|
||||||
IssueProperty(
|
|
||||||
user_id=member.get("member_id"),
|
|
||||||
project_id=project_id,
|
|
||||||
workspace_id=project.workspace_id,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
project_members = ProjectMember.objects.bulk_create(
|
|
||||||
bulk_project_members,
|
|
||||||
batch_size=10,
|
|
||||||
ignore_conflicts=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
_ = IssueProperty.objects.bulk_create(
|
|
||||||
bulk_issue_props, batch_size=10, ignore_conflicts=True
|
|
||||||
)
|
|
||||||
|
|
||||||
serializer = ProjectMemberSerializer(project_members, many=True)
|
|
||||||
|
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
|
||||||
|
|
||||||
def list(self, request, slug, project_id):
|
|
||||||
project_member = ProjectMember.objects.get(
|
|
||||||
member=request.user, workspace__slug=slug, project_id=project_id
|
|
||||||
)
|
|
||||||
|
|
||||||
project_members = ProjectMember.objects.filter(
|
|
||||||
project_id=project_id,
|
|
||||||
workspace__slug=slug,
|
|
||||||
member__is_bot=False,
|
|
||||||
).select_related("project", "member", "workspace")
|
|
||||||
|
|
||||||
if project_member.role > 10:
|
|
||||||
serializer = ProjectMemberAdminSerializer(project_members, many=True)
|
|
||||||
else:
|
|
||||||
serializer = ProjectMemberSerializer(project_members, many=True)
|
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
def partial_update(self, request, slug, project_id, pk):
|
|
||||||
project_member = ProjectMember.objects.get(
|
|
||||||
pk=pk, workspace__slug=slug, project_id=project_id
|
|
||||||
)
|
|
||||||
if request.user.id == project_member.member_id:
|
|
||||||
return Response(
|
|
||||||
{"error": "You cannot update your own role"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
# Check while updating user roles
|
|
||||||
requested_project_member = ProjectMember.objects.get(
|
|
||||||
project_id=project_id, workspace__slug=slug, member=request.user
|
|
||||||
)
|
|
||||||
if (
|
|
||||||
"role" in request.data
|
|
||||||
and int(request.data.get("role", project_member.role))
|
|
||||||
> requested_project_member.role
|
|
||||||
):
|
|
||||||
return Response(
|
|
||||||
{"error": "You cannot update a role that is higher than your own role"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
serializer = ProjectMemberSerializer(
|
|
||||||
project_member, data=request.data, partial=True
|
|
||||||
)
|
|
||||||
|
|
||||||
if serializer.is_valid():
|
|
||||||
serializer.save()
|
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
def destroy(self, request, slug, project_id, pk):
|
|
||||||
project_member = ProjectMember.objects.get(
|
|
||||||
workspace__slug=slug, project_id=project_id, pk=pk
|
|
||||||
)
|
|
||||||
# check requesting user role
|
|
||||||
requesting_project_member = ProjectMember.objects.get(
|
|
||||||
workspace__slug=slug, member=request.user, project_id=project_id
|
|
||||||
)
|
|
||||||
if requesting_project_member.role < project_member.role:
|
|
||||||
return Response(
|
|
||||||
{"error": "You cannot remove a user having role higher than yourself"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Remove all favorites
|
|
||||||
ProjectFavorite.objects.filter(
|
|
||||||
workspace__slug=slug, project_id=project_id, user=project_member.member
|
|
||||||
).delete()
|
|
||||||
CycleFavorite.objects.filter(
|
|
||||||
workspace__slug=slug, project_id=project_id, user=project_member.member
|
|
||||||
).delete()
|
|
||||||
ModuleFavorite.objects.filter(
|
|
||||||
workspace__slug=slug, project_id=project_id, user=project_member.member
|
|
||||||
).delete()
|
|
||||||
PageFavorite.objects.filter(
|
|
||||||
workspace__slug=slug, project_id=project_id, user=project_member.member
|
|
||||||
).delete()
|
|
||||||
IssueViewFavorite.objects.filter(
|
|
||||||
workspace__slug=slug, project_id=project_id, user=project_member.member
|
|
||||||
).delete()
|
|
||||||
# Also remove issue from issue assigned
|
|
||||||
IssueAssignee.objects.filter(
|
|
||||||
workspace__slug=slug,
|
|
||||||
project_id=project_id,
|
|
||||||
assignee=project_member.member,
|
|
||||||
).delete()
|
|
||||||
|
|
||||||
# Remove if module member
|
|
||||||
ModuleMember.objects.filter(
|
|
||||||
workspace__slug=slug,
|
|
||||||
project_id=project_id,
|
|
||||||
member=project_member.member,
|
|
||||||
).delete()
|
|
||||||
# Delete owned Pages
|
|
||||||
Page.objects.filter(
|
|
||||||
workspace__slug=slug,
|
|
||||||
project_id=project_id,
|
|
||||||
owned_by=project_member.member,
|
|
||||||
).delete()
|
|
||||||
project_member.delete()
|
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
|
||||||
|
|
||||||
|
|
||||||
class AddTeamToProjectEndpoint(BaseAPIView):
|
|
||||||
permission_classes = [
|
|
||||||
ProjectBasePermission,
|
|
||||||
]
|
|
||||||
|
|
||||||
def post(self, request, slug, project_id):
|
|
||||||
team_members = TeamMember.objects.filter(
|
|
||||||
workspace__slug=slug, team__in=request.data.get("teams", [])
|
|
||||||
).values_list("member", flat=True)
|
|
||||||
|
|
||||||
if len(team_members) == 0:
|
|
||||||
return Response(
|
|
||||||
{"error": "No such team exists"}, status=status.HTTP_400_BAD_REQUEST
|
|
||||||
)
|
|
||||||
|
|
||||||
workspace = Workspace.objects.get(slug=slug)
|
|
||||||
|
|
||||||
project_members = []
|
|
||||||
issue_props = []
|
|
||||||
for member in team_members:
|
|
||||||
project_members.append(
|
|
||||||
ProjectMember(
|
|
||||||
project_id=project_id,
|
|
||||||
member_id=member,
|
|
||||||
workspace=workspace,
|
|
||||||
created_by=request.user,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
issue_props.append(
|
|
||||||
IssueProperty(
|
|
||||||
project_id=project_id,
|
|
||||||
user_id=member,
|
|
||||||
workspace=workspace,
|
|
||||||
created_by=request.user,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
ProjectMember.objects.bulk_create(
|
|
||||||
project_members, batch_size=10, ignore_conflicts=True
|
|
||||||
)
|
|
||||||
|
|
||||||
_ = IssueProperty.objects.bulk_create(
|
|
||||||
issue_props, batch_size=10, ignore_conflicts=True
|
|
||||||
)
|
|
||||||
|
|
||||||
serializer = ProjectMemberSerializer(project_members, many=True)
|
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectMemberInvitationsViewset(BaseViewSet):
|
|
||||||
serializer_class = ProjectMemberInviteSerializer
|
|
||||||
model = ProjectMemberInvite
|
|
||||||
|
|
||||||
search_fields = []
|
|
||||||
|
|
||||||
permission_classes = [
|
|
||||||
ProjectBasePermission,
|
|
||||||
]
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return self.filter_queryset(
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"))
|
|
||||||
.filter(project_id=self.kwargs.get("project_id"))
|
|
||||||
.select_related("project")
|
|
||||||
.select_related("workspace", "workspace__owner")
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectMemberInviteDetailViewSet(BaseViewSet):
|
|
||||||
serializer_class = ProjectMemberInviteSerializer
|
|
||||||
model = ProjectMemberInvite
|
|
||||||
|
|
||||||
search_fields = []
|
|
||||||
|
|
||||||
permission_classes = [
|
|
||||||
ProjectBasePermission,
|
|
||||||
]
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return self.filter_queryset(
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.select_related("project")
|
|
||||||
.select_related("workspace", "workspace__owner")
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectIdentifierEndpoint(BaseAPIView):
|
|
||||||
permission_classes = [
|
|
||||||
ProjectBasePermission,
|
|
||||||
]
|
|
||||||
|
|
||||||
def get(self, request, slug):
|
|
||||||
name = request.GET.get("name", "").strip().upper()
|
|
||||||
|
|
||||||
if name == "":
|
|
||||||
return Response(
|
|
||||||
{"error": "Name is required"}, status=status.HTTP_400_BAD_REQUEST
|
|
||||||
)
|
|
||||||
|
|
||||||
exists = ProjectIdentifier.objects.filter(
|
|
||||||
name=name, workspace__slug=slug
|
|
||||||
).values("id", "name", "project")
|
|
||||||
|
|
||||||
return Response(
|
|
||||||
{"exists": len(exists), "identifiers": exists},
|
|
||||||
status=status.HTTP_200_OK,
|
|
||||||
)
|
|
||||||
|
|
||||||
def delete(self, request, slug):
|
|
||||||
name = request.data.get("name", "").strip().upper()
|
|
||||||
|
|
||||||
if name == "":
|
|
||||||
return Response(
|
|
||||||
{"error": "Name is required"}, status=status.HTTP_400_BAD_REQUEST
|
|
||||||
)
|
|
||||||
|
|
||||||
if Project.objects.filter(identifier=name, workspace__slug=slug).exists():
|
|
||||||
return Response(
|
|
||||||
{"error": "Cannot delete an identifier of an existing project"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
ProjectIdentifier.objects.filter(name=name, workspace__slug=slug).delete()
|
|
||||||
|
|
||||||
return Response(
|
|
||||||
status=status.HTTP_204_NO_CONTENT,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectJoinEndpoint(BaseAPIView):
|
|
||||||
def post(self, request, slug):
|
|
||||||
project_ids = request.data.get("project_ids", [])
|
|
||||||
|
|
||||||
# Get the workspace user role
|
|
||||||
workspace_member = WorkspaceMember.objects.get(
|
|
||||||
member=request.user, workspace__slug=slug
|
|
||||||
)
|
|
||||||
|
|
||||||
workspace_role = workspace_member.role
|
|
||||||
workspace = workspace_member.workspace
|
|
||||||
|
|
||||||
ProjectMember.objects.bulk_create(
|
|
||||||
[
|
|
||||||
ProjectMember(
|
|
||||||
project_id=project_id,
|
|
||||||
member=request.user,
|
|
||||||
role=20
|
|
||||||
if workspace_role >= 15
|
|
||||||
else (15 if workspace_role == 10 else workspace_role),
|
|
||||||
workspace=workspace,
|
|
||||||
created_by=request.user,
|
|
||||||
)
|
|
||||||
for project_id in project_ids
|
|
||||||
],
|
|
||||||
ignore_conflicts=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
IssueProperty.objects.bulk_create(
|
|
||||||
[
|
|
||||||
IssueProperty(
|
|
||||||
project_id=project_id,
|
|
||||||
user=request.user,
|
|
||||||
workspace=workspace,
|
|
||||||
created_by=request.user,
|
|
||||||
)
|
|
||||||
for project_id in project_ids
|
|
||||||
],
|
|
||||||
ignore_conflicts=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
return Response(
|
|
||||||
{"message": "Projects joined successfully"},
|
|
||||||
status=status.HTTP_201_CREATED,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectUserViewsEndpoint(BaseAPIView):
|
|
||||||
def post(self, request, slug, project_id):
|
|
||||||
project = Project.objects.get(pk=project_id, workspace__slug=slug)
|
|
||||||
|
|
||||||
project_member = ProjectMember.objects.filter(
|
|
||||||
member=request.user, project=project
|
|
||||||
).first()
|
|
||||||
|
|
||||||
if project_member is None:
|
|
||||||
return Response({"error": "Forbidden"}, status=status.HTTP_403_FORBIDDEN)
|
|
||||||
|
|
||||||
view_props = project_member.view_props
|
|
||||||
default_props = project_member.default_props
|
|
||||||
preferences = project_member.preferences
|
|
||||||
sort_order = project_member.sort_order
|
|
||||||
|
|
||||||
project_member.view_props = request.data.get("view_props", view_props)
|
|
||||||
project_member.default_props = request.data.get("default_props", default_props)
|
|
||||||
project_member.preferences = request.data.get("preferences", preferences)
|
|
||||||
project_member.sort_order = request.data.get("sort_order", sort_order)
|
|
||||||
|
|
||||||
project_member.save()
|
|
||||||
|
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectMemberUserEndpoint(BaseAPIView):
|
|
||||||
def get(self, request, slug, project_id):
|
|
||||||
project_member = ProjectMember.objects.get(
|
|
||||||
project_id=project_id, workspace__slug=slug, member=request.user
|
|
||||||
)
|
|
||||||
serializer = ProjectMemberSerializer(project_member)
|
|
||||||
|
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectFavoritesViewSet(BaseViewSet):
|
|
||||||
serializer_class = ProjectFavoriteSerializer
|
|
||||||
model = ProjectFavorite
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return self.filter_queryset(
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"))
|
|
||||||
.filter(user=self.request.user)
|
|
||||||
.select_related(
|
|
||||||
"project", "project__project_lead", "project__default_assignee"
|
|
||||||
)
|
|
||||||
.select_related("workspace", "workspace__owner")
|
|
||||||
)
|
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
|
||||||
serializer.save(user=self.request.user)
|
|
||||||
|
|
||||||
def create(self, request, slug):
|
|
||||||
serializer = ProjectFavoriteSerializer(data=request.data)
|
|
||||||
if serializer.is_valid():
|
|
||||||
serializer.save(user=request.user)
|
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
def destroy(self, request, slug, project_id):
|
|
||||||
project_favorite = ProjectFavorite.objects.get(
|
|
||||||
project=project_id, user=request.user, workspace__slug=slug
|
|
||||||
)
|
|
||||||
project_favorite.delete()
|
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectDeployBoardViewSet(BaseViewSet):
|
|
||||||
permission_classes = [
|
|
||||||
ProjectMemberPermission,
|
|
||||||
]
|
|
||||||
serializer_class = ProjectDeployBoardSerializer
|
|
||||||
model = ProjectDeployBoard
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return (
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.filter(
|
|
||||||
workspace__slug=self.kwargs.get("slug"),
|
|
||||||
project_id=self.kwargs.get("project_id"),
|
|
||||||
)
|
|
||||||
.select_related("project")
|
|
||||||
)
|
|
||||||
|
|
||||||
def create(self, request, slug, project_id):
|
|
||||||
comments = request.data.get("comments", False)
|
|
||||||
reactions = request.data.get("reactions", False)
|
|
||||||
inbox = request.data.get("inbox", None)
|
|
||||||
votes = request.data.get("votes", False)
|
|
||||||
views = request.data.get(
|
|
||||||
"views",
|
|
||||||
{
|
|
||||||
"list": True,
|
|
||||||
"kanban": True,
|
|
||||||
"calendar": True,
|
|
||||||
"gantt": True,
|
|
||||||
"spreadsheet": True,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
project_deploy_board, _ = ProjectDeployBoard.objects.get_or_create(
|
|
||||||
anchor=f"{slug}/{project_id}",
|
|
||||||
project_id=project_id,
|
|
||||||
)
|
|
||||||
project_deploy_board.comments = comments
|
|
||||||
project_deploy_board.reactions = reactions
|
|
||||||
project_deploy_board.inbox = inbox
|
|
||||||
project_deploy_board.votes = votes
|
|
||||||
project_deploy_board.views = views
|
|
||||||
|
|
||||||
project_deploy_board.save()
|
|
||||||
|
|
||||||
serializer = ProjectDeployBoardSerializer(project_deploy_board)
|
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectDeployBoardPublicSettingsEndpoint(BaseAPIView):
|
|
||||||
permission_classes = [
|
|
||||||
AllowAny,
|
|
||||||
]
|
|
||||||
|
|
||||||
def get(self, request, slug, project_id):
|
|
||||||
project_deploy_board = ProjectDeployBoard.objects.get(
|
|
||||||
workspace__slug=slug, project_id=project_id
|
|
||||||
)
|
|
||||||
serializer = ProjectDeployBoardSerializer(project_deploy_board)
|
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
|
|
||||||
class WorkspaceProjectDeployBoardEndpoint(BaseAPIView):
|
|
||||||
permission_classes = [
|
|
||||||
AllowAny,
|
|
||||||
]
|
|
||||||
|
|
||||||
def get(self, request, slug):
|
|
||||||
projects = (
|
|
||||||
Project.objects.filter(workspace__slug=slug)
|
|
||||||
.annotate(
|
|
||||||
is_public=Exists(
|
|
||||||
ProjectDeployBoard.objects.filter(
|
|
||||||
workspace__slug=slug, project_id=OuterRef("pk")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.filter(is_public=True)
|
|
||||||
).values(
|
|
||||||
"id",
|
|
||||||
"identifier",
|
|
||||||
"name",
|
|
||||||
"description",
|
|
||||||
"emoji",
|
|
||||||
"icon_prop",
|
|
||||||
"cover_image",
|
|
||||||
)
|
|
||||||
|
|
||||||
return Response(projects, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
|
|
||||||
class LeaveProjectEndpoint(BaseAPIView):
|
|
||||||
permission_classes = [
|
|
||||||
ProjectLitePermission,
|
|
||||||
]
|
|
||||||
|
|
||||||
def delete(self, request, slug, project_id):
|
|
||||||
project_member = ProjectMember.objects.get(
|
|
||||||
workspace__slug=slug,
|
|
||||||
member=request.user,
|
|
||||||
project_id=project_id,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Only Admin case
|
|
||||||
if (
|
|
||||||
project_member.role == 20
|
|
||||||
and ProjectMember.objects.filter(
|
|
||||||
workspace__slug=slug,
|
|
||||||
role=20,
|
|
||||||
project_id=project_id,
|
|
||||||
).count()
|
|
||||||
== 1
|
|
||||||
):
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"error": "You cannot leave the project since you are the only admin of the project you should delete the project"
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
# Delete the member from workspace
|
|
||||||
project_member.delete()
|
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectPublicCoverImagesEndpoint(BaseAPIView):
|
|
||||||
permission_classes = [
|
|
||||||
AllowAny,
|
|
||||||
]
|
|
||||||
|
|
||||||
def get(self, request):
|
|
||||||
files = []
|
|
||||||
s3 = boto3.client(
|
|
||||||
"s3",
|
|
||||||
aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
|
|
||||||
aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
|
|
||||||
)
|
|
||||||
params = {
|
|
||||||
"Bucket": settings.AWS_S3_BUCKET_NAME,
|
|
||||||
"Prefix": "static/project-cover/",
|
|
||||||
}
|
|
||||||
|
|
||||||
response = s3.list_objects_v2(**params)
|
|
||||||
# Extracting file keys from the response
|
|
||||||
if "Contents" in response:
|
|
||||||
for content in response["Contents"]:
|
|
||||||
if not content["Key"].endswith(
|
|
||||||
"/"
|
|
||||||
): # This line ensures we're only getting files, not "sub-folders"
|
|
||||||
files.append(
|
|
||||||
f"https://{settings.AWS_S3_BUCKET_NAME}.s3.{settings.AWS_REGION}.amazonaws.com/{content['Key']}"
|
|
||||||
)
|
|
||||||
|
|
||||||
return Response(files, status=status.HTTP_200_OK)
|
|
||||||
|
@ -7,25 +7,21 @@ from django.db.models import Q
|
|||||||
# Third party imports
|
# Third party imports
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from sentry_sdk import capture_exception
|
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from . import BaseViewSet, BaseAPIView
|
from .base import BaseAPIView
|
||||||
from plane.api.serializers import StateSerializer
|
from plane.api.serializers import StateSerializer
|
||||||
from plane.api.permissions import ProjectEntityPermission
|
from plane.app.permissions import ProjectEntityPermission
|
||||||
from plane.db.models import State, Issue
|
from plane.db.models import State, Issue
|
||||||
|
|
||||||
|
|
||||||
class StateViewSet(BaseViewSet):
|
class StateAPIEndpoint(BaseAPIView):
|
||||||
serializer_class = StateSerializer
|
serializer_class = StateSerializer
|
||||||
model = State
|
model = State
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
ProjectEntityPermission,
|
ProjectEntityPermission,
|
||||||
]
|
]
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
|
||||||
serializer.save(project_id=self.kwargs.get("project_id"))
|
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return self.filter_queryset(
|
return self.filter_queryset(
|
||||||
super()
|
super()
|
||||||
@ -39,37 +35,29 @@ class StateViewSet(BaseViewSet):
|
|||||||
.distinct()
|
.distinct()
|
||||||
)
|
)
|
||||||
|
|
||||||
def create(self, request, slug, project_id):
|
def post(self, request, slug, project_id):
|
||||||
serializer = StateSerializer(data=request.data)
|
serializer = StateSerializer(data=request.data, context={"project_id": project_id})
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
serializer.save(project_id=project_id)
|
serializer.save(project_id=project_id)
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
def list(self, request, slug, project_id):
|
def get(self, request, slug, project_id, pk=None):
|
||||||
states = StateSerializer(self.get_queryset(), many=True).data
|
if pk:
|
||||||
grouped = request.GET.get("grouped", False)
|
serializer = StateSerializer(self.get_queryset().get(pk=pk))
|
||||||
if grouped == "true":
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
state_dict = {}
|
return self.paginate(
|
||||||
for key, value in groupby(
|
request=request,
|
||||||
sorted(states, key=lambda state: state["group"]),
|
queryset=(self.get_queryset()),
|
||||||
lambda state: state.get("group"),
|
on_results=lambda states: StateSerializer(
|
||||||
):
|
states,
|
||||||
state_dict[str(key)] = list(value)
|
many=True,
|
||||||
return Response(state_dict, status=status.HTTP_200_OK)
|
fields=self.fields,
|
||||||
return Response(states, status=status.HTTP_200_OK)
|
expand=self.expand,
|
||||||
|
).data,
|
||||||
|
)
|
||||||
|
|
||||||
def mark_as_default(self, request, slug, project_id, pk):
|
def delete(self, request, slug, project_id, pk):
|
||||||
# Select all the states which are marked as default
|
|
||||||
_ = State.objects.filter(
|
|
||||||
workspace__slug=slug, project_id=project_id, default=True
|
|
||||||
).update(default=False)
|
|
||||||
_ = State.objects.filter(
|
|
||||||
workspace__slug=slug, project_id=project_id, pk=pk
|
|
||||||
).update(default=True)
|
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
|
||||||
|
|
||||||
def destroy(self, request, slug, project_id, pk):
|
|
||||||
state = State.objects.get(
|
state = State.objects.get(
|
||||||
~Q(name="Triage"),
|
~Q(name="Triage"),
|
||||||
pk=pk,
|
pk=pk,
|
||||||
@ -91,3 +79,11 @@ class StateViewSet(BaseViewSet):
|
|||||||
|
|
||||||
state.delete()
|
state.delete()
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
def patch(self, request, slug, project_id, pk=None):
|
||||||
|
state = State.objects.filter(workspace__slug=slug, project_id=project_id, pk=pk)
|
||||||
|
serializer = StateSerializer(state, data=request.data, partial=True)
|
||||||
|
if serializer.is_valid():
|
||||||
|
serializer.save()
|
||||||
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
0
apiserver/plane/app/__init__.py
Normal file
0
apiserver/plane/app/__init__.py
Normal file
5
apiserver/plane/app/apps.py
Normal file
5
apiserver/plane/app/apps.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class AppApiConfig(AppConfig):
|
||||||
|
name = "plane.app"
|
0
apiserver/plane/app/middleware/__init__.py
Normal file
0
apiserver/plane/app/middleware/__init__.py
Normal file
47
apiserver/plane/app/middleware/api_authentication.py
Normal file
47
apiserver/plane/app/middleware/api_authentication.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# Django imports
|
||||||
|
from django.utils import timezone
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
|
# Third party imports
|
||||||
|
from rest_framework import authentication
|
||||||
|
from rest_framework.exceptions import AuthenticationFailed
|
||||||
|
|
||||||
|
# Module imports
|
||||||
|
from plane.db.models import APIToken
|
||||||
|
|
||||||
|
|
||||||
|
class APIKeyAuthentication(authentication.BaseAuthentication):
|
||||||
|
"""
|
||||||
|
Authentication with an API Key
|
||||||
|
"""
|
||||||
|
|
||||||
|
www_authenticate_realm = "api"
|
||||||
|
media_type = "application/json"
|
||||||
|
auth_header_name = "X-Api-Key"
|
||||||
|
|
||||||
|
def get_api_token(self, request):
|
||||||
|
return request.headers.get(self.auth_header_name)
|
||||||
|
|
||||||
|
def validate_api_token(self, token):
|
||||||
|
try:
|
||||||
|
api_token = APIToken.objects.get(
|
||||||
|
Q(Q(expired_at__gt=timezone.now()) | Q(expired_at__isnull=True)),
|
||||||
|
token=token,
|
||||||
|
is_active=True,
|
||||||
|
)
|
||||||
|
except APIToken.DoesNotExist:
|
||||||
|
raise AuthenticationFailed("Given API token is not valid")
|
||||||
|
|
||||||
|
# save api token last used
|
||||||
|
api_token.last_used = timezone.now()
|
||||||
|
api_token.save(update_fields=["last_used"])
|
||||||
|
return (api_token.user, api_token.token)
|
||||||
|
|
||||||
|
def authenticate(self, request):
|
||||||
|
token = self.get_api_token(request=request)
|
||||||
|
if not token:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Validate the API token
|
||||||
|
user, token = self.validate_api_token(token)
|
||||||
|
return user, token
|
17
apiserver/plane/app/permissions/__init__.py
Normal file
17
apiserver/plane/app/permissions/__init__.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
from .workspace import (
|
||||||
|
WorkSpaceBasePermission,
|
||||||
|
WorkspaceOwnerPermission,
|
||||||
|
WorkSpaceAdminPermission,
|
||||||
|
WorkspaceEntityPermission,
|
||||||
|
WorkspaceViewerPermission,
|
||||||
|
WorkspaceUserPermission,
|
||||||
|
)
|
||||||
|
from .project import (
|
||||||
|
ProjectBasePermission,
|
||||||
|
ProjectEntityPermission,
|
||||||
|
ProjectMemberPermission,
|
||||||
|
ProjectLitePermission,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
@ -13,14 +13,15 @@ Guest = 5
|
|||||||
|
|
||||||
class ProjectBasePermission(BasePermission):
|
class ProjectBasePermission(BasePermission):
|
||||||
def has_permission(self, request, view):
|
def has_permission(self, request, view):
|
||||||
|
|
||||||
if request.user.is_anonymous:
|
if request.user.is_anonymous:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
## Safe Methods -> Handle the filtering logic in queryset
|
## Safe Methods -> Handle the filtering logic in queryset
|
||||||
if request.method in SAFE_METHODS:
|
if request.method in SAFE_METHODS:
|
||||||
return WorkspaceMember.objects.filter(
|
return WorkspaceMember.objects.filter(
|
||||||
workspace__slug=view.workspace_slug, member=request.user
|
workspace__slug=view.workspace_slug,
|
||||||
|
member=request.user,
|
||||||
|
is_active=True,
|
||||||
).exists()
|
).exists()
|
||||||
|
|
||||||
## Only workspace owners or admins can create the projects
|
## Only workspace owners or admins can create the projects
|
||||||
@ -29,6 +30,7 @@ class ProjectBasePermission(BasePermission):
|
|||||||
workspace__slug=view.workspace_slug,
|
workspace__slug=view.workspace_slug,
|
||||||
member=request.user,
|
member=request.user,
|
||||||
role__in=[Admin, Member],
|
role__in=[Admin, Member],
|
||||||
|
is_active=True,
|
||||||
).exists()
|
).exists()
|
||||||
|
|
||||||
## Only Project Admins can update project attributes
|
## Only Project Admins can update project attributes
|
||||||
@ -37,19 +39,21 @@ class ProjectBasePermission(BasePermission):
|
|||||||
member=request.user,
|
member=request.user,
|
||||||
role=Admin,
|
role=Admin,
|
||||||
project_id=view.project_id,
|
project_id=view.project_id,
|
||||||
|
is_active=True,
|
||||||
).exists()
|
).exists()
|
||||||
|
|
||||||
|
|
||||||
class ProjectMemberPermission(BasePermission):
|
class ProjectMemberPermission(BasePermission):
|
||||||
def has_permission(self, request, view):
|
def has_permission(self, request, view):
|
||||||
|
|
||||||
if request.user.is_anonymous:
|
if request.user.is_anonymous:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
## Safe Methods -> Handle the filtering logic in queryset
|
## Safe Methods -> Handle the filtering logic in queryset
|
||||||
if request.method in SAFE_METHODS:
|
if request.method in SAFE_METHODS:
|
||||||
return ProjectMember.objects.filter(
|
return ProjectMember.objects.filter(
|
||||||
workspace__slug=view.workspace_slug, member=request.user
|
workspace__slug=view.workspace_slug,
|
||||||
|
member=request.user,
|
||||||
|
is_active=True,
|
||||||
).exists()
|
).exists()
|
||||||
## Only workspace owners or admins can create the projects
|
## Only workspace owners or admins can create the projects
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
@ -57,6 +61,7 @@ class ProjectMemberPermission(BasePermission):
|
|||||||
workspace__slug=view.workspace_slug,
|
workspace__slug=view.workspace_slug,
|
||||||
member=request.user,
|
member=request.user,
|
||||||
role__in=[Admin, Member],
|
role__in=[Admin, Member],
|
||||||
|
is_active=True,
|
||||||
).exists()
|
).exists()
|
||||||
|
|
||||||
## Only Project Admins can update project attributes
|
## Only Project Admins can update project attributes
|
||||||
@ -65,12 +70,12 @@ class ProjectMemberPermission(BasePermission):
|
|||||||
member=request.user,
|
member=request.user,
|
||||||
role__in=[Admin, Member],
|
role__in=[Admin, Member],
|
||||||
project_id=view.project_id,
|
project_id=view.project_id,
|
||||||
|
is_active=True,
|
||||||
).exists()
|
).exists()
|
||||||
|
|
||||||
|
|
||||||
class ProjectEntityPermission(BasePermission):
|
class ProjectEntityPermission(BasePermission):
|
||||||
def has_permission(self, request, view):
|
def has_permission(self, request, view):
|
||||||
|
|
||||||
if request.user.is_anonymous:
|
if request.user.is_anonymous:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -80,6 +85,7 @@ class ProjectEntityPermission(BasePermission):
|
|||||||
workspace__slug=view.workspace_slug,
|
workspace__slug=view.workspace_slug,
|
||||||
member=request.user,
|
member=request.user,
|
||||||
project_id=view.project_id,
|
project_id=view.project_id,
|
||||||
|
is_active=True,
|
||||||
).exists()
|
).exists()
|
||||||
|
|
||||||
## Only project members or admins can create and edit the project attributes
|
## Only project members or admins can create and edit the project attributes
|
||||||
@ -88,11 +94,11 @@ class ProjectEntityPermission(BasePermission):
|
|||||||
member=request.user,
|
member=request.user,
|
||||||
role__in=[Admin, Member],
|
role__in=[Admin, Member],
|
||||||
project_id=view.project_id,
|
project_id=view.project_id,
|
||||||
|
is_active=True,
|
||||||
).exists()
|
).exists()
|
||||||
|
|
||||||
|
|
||||||
class ProjectLitePermission(BasePermission):
|
class ProjectLitePermission(BasePermission):
|
||||||
|
|
||||||
def has_permission(self, request, view):
|
def has_permission(self, request, view):
|
||||||
if request.user.is_anonymous:
|
if request.user.is_anonymous:
|
||||||
return False
|
return False
|
||||||
@ -101,4 +107,5 @@ class ProjectLitePermission(BasePermission):
|
|||||||
workspace__slug=view.workspace_slug,
|
workspace__slug=view.workspace_slug,
|
||||||
member=request.user,
|
member=request.user,
|
||||||
project_id=view.project_id,
|
project_id=view.project_id,
|
||||||
|
is_active=True,
|
||||||
).exists()
|
).exists()
|
@ -32,12 +32,28 @@ class WorkSpaceBasePermission(BasePermission):
|
|||||||
member=request.user,
|
member=request.user,
|
||||||
workspace__slug=view.workspace_slug,
|
workspace__slug=view.workspace_slug,
|
||||||
role__in=[Owner, Admin],
|
role__in=[Owner, Admin],
|
||||||
|
is_active=True,
|
||||||
).exists()
|
).exists()
|
||||||
|
|
||||||
# allow only owner to delete the workspace
|
# allow only owner to delete the workspace
|
||||||
if request.method == "DELETE":
|
if request.method == "DELETE":
|
||||||
return WorkspaceMember.objects.filter(
|
return WorkspaceMember.objects.filter(
|
||||||
member=request.user, workspace__slug=view.workspace_slug, role=Owner
|
member=request.user,
|
||||||
|
workspace__slug=view.workspace_slug,
|
||||||
|
role=Owner,
|
||||||
|
is_active=True,
|
||||||
|
).exists()
|
||||||
|
|
||||||
|
|
||||||
|
class WorkspaceOwnerPermission(BasePermission):
|
||||||
|
def has_permission(self, request, view):
|
||||||
|
if request.user.is_anonymous:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return WorkspaceMember.objects.filter(
|
||||||
|
workspace__slug=view.workspace_slug,
|
||||||
|
member=request.user,
|
||||||
|
role=Owner,
|
||||||
).exists()
|
).exists()
|
||||||
|
|
||||||
|
|
||||||
@ -50,6 +66,7 @@ class WorkSpaceAdminPermission(BasePermission):
|
|||||||
member=request.user,
|
member=request.user,
|
||||||
workspace__slug=view.workspace_slug,
|
workspace__slug=view.workspace_slug,
|
||||||
role__in=[Owner, Admin],
|
role__in=[Owner, Admin],
|
||||||
|
is_active=True,
|
||||||
).exists()
|
).exists()
|
||||||
|
|
||||||
|
|
||||||
@ -63,12 +80,14 @@ class WorkspaceEntityPermission(BasePermission):
|
|||||||
return WorkspaceMember.objects.filter(
|
return WorkspaceMember.objects.filter(
|
||||||
workspace__slug=view.workspace_slug,
|
workspace__slug=view.workspace_slug,
|
||||||
member=request.user,
|
member=request.user,
|
||||||
|
is_active=True,
|
||||||
).exists()
|
).exists()
|
||||||
|
|
||||||
return WorkspaceMember.objects.filter(
|
return WorkspaceMember.objects.filter(
|
||||||
member=request.user,
|
member=request.user,
|
||||||
workspace__slug=view.workspace_slug,
|
workspace__slug=view.workspace_slug,
|
||||||
role__in=[Owner, Admin],
|
role__in=[Owner, Admin],
|
||||||
|
is_active=True,
|
||||||
).exists()
|
).exists()
|
||||||
|
|
||||||
|
|
||||||
@ -78,5 +97,20 @@ class WorkspaceViewerPermission(BasePermission):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
return WorkspaceMember.objects.filter(
|
return WorkspaceMember.objects.filter(
|
||||||
member=request.user, workspace__slug=view.workspace_slug, role__gte=10
|
member=request.user,
|
||||||
|
workspace__slug=view.workspace_slug,
|
||||||
|
role__gte=10,
|
||||||
|
is_active=True,
|
||||||
|
).exists()
|
||||||
|
|
||||||
|
|
||||||
|
class WorkspaceUserPermission(BasePermission):
|
||||||
|
def has_permission(self, request, view):
|
||||||
|
if request.user.is_anonymous:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return WorkspaceMember.objects.filter(
|
||||||
|
member=request.user,
|
||||||
|
workspace__slug=view.workspace_slug,
|
||||||
|
is_active=True,
|
||||||
).exists()
|
).exists()
|
45
apiserver/plane/app/rate_limit.py
Normal file
45
apiserver/plane/app/rate_limit.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
from django.utils import timezone
|
||||||
|
from rest_framework.throttling import SimpleRateThrottle
|
||||||
|
|
||||||
|
|
||||||
|
class ApiKeyRateThrottle(SimpleRateThrottle):
|
||||||
|
scope = 'api_key'
|
||||||
|
|
||||||
|
def get_cache_key(self, request, view):
|
||||||
|
# Retrieve the API key from the request header
|
||||||
|
api_key = request.headers.get('X-Api-Key')
|
||||||
|
if not api_key:
|
||||||
|
return None # Allow the request if there's no API key
|
||||||
|
|
||||||
|
# Use the API key as part of the cache key
|
||||||
|
return f'{self.scope}:{api_key}'
|
||||||
|
|
||||||
|
def allow_request(self, request, view):
|
||||||
|
# Calculate the current time as a Unix timestamp
|
||||||
|
now = timezone.now().timestamp()
|
||||||
|
|
||||||
|
# Use the parent class's method to check if the request is allowed
|
||||||
|
allowed = super().allow_request(request, view)
|
||||||
|
|
||||||
|
if allowed:
|
||||||
|
# Calculate the remaining limit and reset time
|
||||||
|
history = self.cache.get(self.key, [])
|
||||||
|
|
||||||
|
# Remove old histories
|
||||||
|
while history and history[-1] <= now - self.duration:
|
||||||
|
history.pop()
|
||||||
|
|
||||||
|
# Calculate the requests
|
||||||
|
num_requests = len(history)
|
||||||
|
|
||||||
|
# Check available requests
|
||||||
|
available = self.num_requests - num_requests
|
||||||
|
|
||||||
|
# Unix timestamp for when the rate limit will reset
|
||||||
|
reset_time = int(now + self.duration)
|
||||||
|
|
||||||
|
# Add headers
|
||||||
|
request.META['X-RateLimit-Remaining'] = max(0, available)
|
||||||
|
request.META['X-RateLimit-Reset'] = reset_time
|
||||||
|
|
||||||
|
return allowed
|
104
apiserver/plane/app/serializers/__init__.py
Normal file
104
apiserver/plane/app/serializers/__init__.py
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
from .base import BaseSerializer
|
||||||
|
from .user import (
|
||||||
|
UserSerializer,
|
||||||
|
UserLiteSerializer,
|
||||||
|
ChangePasswordSerializer,
|
||||||
|
ResetPasswordSerializer,
|
||||||
|
UserAdminLiteSerializer,
|
||||||
|
UserMeSerializer,
|
||||||
|
UserMeSettingsSerializer,
|
||||||
|
)
|
||||||
|
from .workspace import (
|
||||||
|
WorkSpaceSerializer,
|
||||||
|
WorkSpaceMemberSerializer,
|
||||||
|
TeamSerializer,
|
||||||
|
WorkSpaceMemberInviteSerializer,
|
||||||
|
WorkspaceLiteSerializer,
|
||||||
|
WorkspaceThemeSerializer,
|
||||||
|
WorkspaceMemberAdminSerializer,
|
||||||
|
WorkspaceMemberMeSerializer,
|
||||||
|
)
|
||||||
|
from .project import (
|
||||||
|
ProjectSerializer,
|
||||||
|
ProjectListSerializer,
|
||||||
|
ProjectDetailSerializer,
|
||||||
|
ProjectMemberSerializer,
|
||||||
|
ProjectMemberInviteSerializer,
|
||||||
|
ProjectIdentifierSerializer,
|
||||||
|
ProjectFavoriteSerializer,
|
||||||
|
ProjectLiteSerializer,
|
||||||
|
ProjectMemberLiteSerializer,
|
||||||
|
ProjectDeployBoardSerializer,
|
||||||
|
ProjectMemberAdminSerializer,
|
||||||
|
ProjectPublicMemberSerializer,
|
||||||
|
)
|
||||||
|
from .state import StateSerializer, StateLiteSerializer
|
||||||
|
from .view import GlobalViewSerializer, IssueViewSerializer, IssueViewFavoriteSerializer
|
||||||
|
from .cycle import (
|
||||||
|
CycleSerializer,
|
||||||
|
CycleIssueSerializer,
|
||||||
|
CycleFavoriteSerializer,
|
||||||
|
CycleWriteSerializer,
|
||||||
|
)
|
||||||
|
from .asset import FileAssetSerializer
|
||||||
|
from .issue import (
|
||||||
|
IssueCreateSerializer,
|
||||||
|
IssueActivitySerializer,
|
||||||
|
IssueCommentSerializer,
|
||||||
|
IssuePropertySerializer,
|
||||||
|
IssueAssigneeSerializer,
|
||||||
|
LabelSerializer,
|
||||||
|
IssueSerializer,
|
||||||
|
IssueFlatSerializer,
|
||||||
|
IssueStateSerializer,
|
||||||
|
IssueLinkSerializer,
|
||||||
|
IssueLiteSerializer,
|
||||||
|
IssueAttachmentSerializer,
|
||||||
|
IssueSubscriberSerializer,
|
||||||
|
IssueReactionSerializer,
|
||||||
|
CommentReactionSerializer,
|
||||||
|
IssueVoteSerializer,
|
||||||
|
IssueRelationSerializer,
|
||||||
|
RelatedIssueSerializer,
|
||||||
|
IssuePublicSerializer,
|
||||||
|
)
|
||||||
|
|
||||||
|
from .module import (
|
||||||
|
ModuleWriteSerializer,
|
||||||
|
ModuleSerializer,
|
||||||
|
ModuleIssueSerializer,
|
||||||
|
ModuleLinkSerializer,
|
||||||
|
ModuleFavoriteSerializer,
|
||||||
|
)
|
||||||
|
|
||||||
|
from .api import APITokenSerializer, APITokenReadSerializer
|
||||||
|
|
||||||
|
from .integration import (
|
||||||
|
IntegrationSerializer,
|
||||||
|
WorkspaceIntegrationSerializer,
|
||||||
|
GithubIssueSyncSerializer,
|
||||||
|
GithubRepositorySerializer,
|
||||||
|
GithubRepositorySyncSerializer,
|
||||||
|
GithubCommentSyncSerializer,
|
||||||
|
SlackProjectSyncSerializer,
|
||||||
|
)
|
||||||
|
|
||||||
|
from .importer import ImporterSerializer
|
||||||
|
|
||||||
|
from .page import PageSerializer, PageLogSerializer, SubPageSerializer, PageFavoriteSerializer
|
||||||
|
|
||||||
|
from .estimate import (
|
||||||
|
EstimateSerializer,
|
||||||
|
EstimatePointSerializer,
|
||||||
|
EstimateReadSerializer,
|
||||||
|
)
|
||||||
|
|
||||||
|
from .inbox import InboxSerializer, InboxIssueSerializer, IssueStateInboxSerializer
|
||||||
|
|
||||||
|
from .analytic import AnalyticViewSerializer
|
||||||
|
|
||||||
|
from .notification import NotificationSerializer
|
||||||
|
|
||||||
|
from .exporter import ExporterHistorySerializer
|
||||||
|
|
||||||
|
from .webhook import WebhookSerializer, WebhookLogSerializer
|
31
apiserver/plane/app/serializers/api.py
Normal file
31
apiserver/plane/app/serializers/api.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
from .base import BaseSerializer
|
||||||
|
from plane.db.models import APIToken, APIActivityLog
|
||||||
|
|
||||||
|
|
||||||
|
class APITokenSerializer(BaseSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = APIToken
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"token",
|
||||||
|
"expired_at",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
"workspace",
|
||||||
|
"user",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class APITokenReadSerializer(BaseSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = APIToken
|
||||||
|
exclude = ('token',)
|
||||||
|
|
||||||
|
|
||||||
|
class APIActivityLogSerializer(BaseSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = APIActivityLog
|
||||||
|
fields = "__all__"
|
58
apiserver/plane/app/serializers/base.py
Normal file
58
apiserver/plane/app/serializers/base.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
|
||||||
|
class BaseSerializer(serializers.ModelSerializer):
|
||||||
|
id = serializers.PrimaryKeyRelatedField(read_only=True)
|
||||||
|
|
||||||
|
class DynamicBaseSerializer(BaseSerializer):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
# If 'fields' is provided in the arguments, remove it and store it separately.
|
||||||
|
# This is done so as not to pass this custom argument up to the superclass.
|
||||||
|
fields = kwargs.pop("fields", None)
|
||||||
|
|
||||||
|
# Call the initialization of the superclass.
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# If 'fields' was provided, filter the fields of the serializer accordingly.
|
||||||
|
if fields is not None:
|
||||||
|
self.fields = self._filter_fields(fields)
|
||||||
|
|
||||||
|
def _filter_fields(self, fields):
|
||||||
|
"""
|
||||||
|
Adjust the serializer's fields based on the provided 'fields' list.
|
||||||
|
|
||||||
|
:param fields: List or dictionary specifying which fields to include in the serializer.
|
||||||
|
:return: The updated fields for the serializer.
|
||||||
|
"""
|
||||||
|
# Check each field_name in the provided fields.
|
||||||
|
for field_name in fields:
|
||||||
|
# If the field is a dictionary (indicating nested fields),
|
||||||
|
# loop through its keys and values.
|
||||||
|
if isinstance(field_name, dict):
|
||||||
|
for key, value in field_name.items():
|
||||||
|
# If the value of this nested field is a list,
|
||||||
|
# perform a recursive filter on it.
|
||||||
|
if isinstance(value, list):
|
||||||
|
self._filter_fields(self.fields[key], value)
|
||||||
|
|
||||||
|
# Create a list to store allowed fields.
|
||||||
|
allowed = []
|
||||||
|
for item in fields:
|
||||||
|
# If the item is a string, it directly represents a field's name.
|
||||||
|
if isinstance(item, str):
|
||||||
|
allowed.append(item)
|
||||||
|
# If the item is a dictionary, it represents a nested field.
|
||||||
|
# Add the key of this dictionary to the allowed list.
|
||||||
|
elif isinstance(item, dict):
|
||||||
|
allowed.append(list(item.keys())[0])
|
||||||
|
|
||||||
|
# Convert the current serializer's fields and the allowed fields to sets.
|
||||||
|
existing = set(self.fields)
|
||||||
|
allowed = set(allowed)
|
||||||
|
|
||||||
|
# Remove fields from the serializer that aren't in the 'allowed' list.
|
||||||
|
for field_name in (existing - allowed):
|
||||||
|
self.fields.pop(field_name)
|
||||||
|
|
||||||
|
return self.fields
|
107
apiserver/plane/app/serializers/cycle.py
Normal file
107
apiserver/plane/app/serializers/cycle.py
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
# Third party imports
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
# Module imports
|
||||||
|
from .base import BaseSerializer
|
||||||
|
from .user import UserLiteSerializer
|
||||||
|
from .issue import IssueStateSerializer
|
||||||
|
from .workspace import WorkspaceLiteSerializer
|
||||||
|
from .project import ProjectLiteSerializer
|
||||||
|
from plane.db.models import Cycle, CycleIssue, CycleFavorite
|
||||||
|
|
||||||
|
|
||||||
|
class CycleWriteSerializer(BaseSerializer):
|
||||||
|
def validate(self, data):
|
||||||
|
if (
|
||||||
|
data.get("start_date", None) is not None
|
||||||
|
and data.get("end_date", None) is not None
|
||||||
|
and data.get("start_date", None) > data.get("end_date", None)
|
||||||
|
):
|
||||||
|
raise serializers.ValidationError("Start date cannot exceed end date")
|
||||||
|
return data
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Cycle
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class CycleSerializer(BaseSerializer):
|
||||||
|
owned_by = UserLiteSerializer(read_only=True)
|
||||||
|
is_favorite = serializers.BooleanField(read_only=True)
|
||||||
|
total_issues = serializers.IntegerField(read_only=True)
|
||||||
|
cancelled_issues = serializers.IntegerField(read_only=True)
|
||||||
|
completed_issues = serializers.IntegerField(read_only=True)
|
||||||
|
started_issues = serializers.IntegerField(read_only=True)
|
||||||
|
unstarted_issues = serializers.IntegerField(read_only=True)
|
||||||
|
backlog_issues = serializers.IntegerField(read_only=True)
|
||||||
|
assignees = serializers.SerializerMethodField(read_only=True)
|
||||||
|
total_estimates = serializers.IntegerField(read_only=True)
|
||||||
|
completed_estimates = serializers.IntegerField(read_only=True)
|
||||||
|
started_estimates = serializers.IntegerField(read_only=True)
|
||||||
|
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
||||||
|
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||||
|
|
||||||
|
def validate(self, data):
|
||||||
|
if (
|
||||||
|
data.get("start_date", None) is not None
|
||||||
|
and data.get("end_date", None) is not None
|
||||||
|
and data.get("start_date", None) > data.get("end_date", None)
|
||||||
|
):
|
||||||
|
raise serializers.ValidationError("Start date cannot exceed end date")
|
||||||
|
return data
|
||||||
|
|
||||||
|
def get_assignees(self, obj):
|
||||||
|
members = [
|
||||||
|
{
|
||||||
|
"avatar": assignee.avatar,
|
||||||
|
"display_name": assignee.display_name,
|
||||||
|
"id": assignee.id,
|
||||||
|
}
|
||||||
|
for issue_cycle in obj.issue_cycle.prefetch_related(
|
||||||
|
"issue__assignees"
|
||||||
|
).all()
|
||||||
|
for assignee in issue_cycle.issue.assignees.all()
|
||||||
|
]
|
||||||
|
# Use a set comprehension to return only the unique objects
|
||||||
|
unique_objects = {frozenset(item.items()) for item in members}
|
||||||
|
|
||||||
|
# Convert the set back to a list of dictionaries
|
||||||
|
unique_list = [dict(item) for item in unique_objects]
|
||||||
|
|
||||||
|
return unique_list
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Cycle
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"owned_by",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class CycleIssueSerializer(BaseSerializer):
|
||||||
|
issue_detail = IssueStateSerializer(read_only=True, source="issue")
|
||||||
|
sub_issues_count = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = CycleIssue
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"cycle",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class CycleFavoriteSerializer(BaseSerializer):
|
||||||
|
cycle_detail = CycleSerializer(source="cycle", read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = CycleFavorite
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"user",
|
||||||
|
]
|
@ -2,7 +2,7 @@
|
|||||||
from .base import BaseSerializer
|
from .base import BaseSerializer
|
||||||
|
|
||||||
from plane.db.models import Estimate, EstimatePoint
|
from plane.db.models import Estimate, EstimatePoint
|
||||||
from plane.api.serializers import WorkspaceLiteSerializer, ProjectLiteSerializer
|
from plane.app.serializers import WorkspaceLiteSerializer, ProjectLiteSerializer
|
||||||
|
|
||||||
|
|
||||||
class EstimateSerializer(BaseSerializer):
|
class EstimateSerializer(BaseSerializer):
|
57
apiserver/plane/app/serializers/inbox.py
Normal file
57
apiserver/plane/app/serializers/inbox.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# Third party frameworks
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
# Module imports
|
||||||
|
from .base import BaseSerializer
|
||||||
|
from .issue import IssueFlatSerializer, LabelLiteSerializer
|
||||||
|
from .project import ProjectLiteSerializer
|
||||||
|
from .state import StateLiteSerializer
|
||||||
|
from .user import UserLiteSerializer
|
||||||
|
from plane.db.models import Inbox, InboxIssue, Issue
|
||||||
|
|
||||||
|
|
||||||
|
class InboxSerializer(BaseSerializer):
|
||||||
|
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
||||||
|
pending_issue_count = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Inbox
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"project",
|
||||||
|
"workspace",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class InboxIssueSerializer(BaseSerializer):
|
||||||
|
issue_detail = IssueFlatSerializer(source="issue", read_only=True)
|
||||||
|
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = InboxIssue
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"project",
|
||||||
|
"workspace",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class InboxIssueLiteSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = InboxIssue
|
||||||
|
fields = ["id", "status", "duplicate_to", "snoozed_till", "source"]
|
||||||
|
read_only_fields = fields
|
||||||
|
|
||||||
|
|
||||||
|
class IssueStateInboxSerializer(BaseSerializer):
|
||||||
|
state_detail = StateLiteSerializer(read_only=True, source="state")
|
||||||
|
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||||
|
label_details = LabelLiteSerializer(read_only=True, source="labels", many=True)
|
||||||
|
assignee_details = UserLiteSerializer(read_only=True, source="assignees", many=True)
|
||||||
|
sub_issues_count = serializers.IntegerField(read_only=True)
|
||||||
|
bridge_id = serializers.UUIDField(read_only=True)
|
||||||
|
issue_inbox = InboxIssueLiteSerializer(read_only=True, many=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Issue
|
||||||
|
fields = "__all__"
|
@ -1,5 +1,5 @@
|
|||||||
# Module imports
|
# Module imports
|
||||||
from plane.api.serializers import BaseSerializer
|
from plane.app.serializers import BaseSerializer
|
||||||
from plane.db.models import Integration, WorkspaceIntegration
|
from plane.db.models import Integration, WorkspaceIntegration
|
||||||
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
# Module imports
|
# Module imports
|
||||||
from plane.api.serializers import BaseSerializer
|
from plane.app.serializers import BaseSerializer
|
||||||
from plane.db.models import (
|
from plane.db.models import (
|
||||||
GithubIssueSync,
|
GithubIssueSync,
|
||||||
GithubRepository,
|
GithubRepository,
|
@ -1,5 +1,5 @@
|
|||||||
# Module imports
|
# Module imports
|
||||||
from plane.api.serializers import BaseSerializer
|
from plane.app.serializers import BaseSerializer
|
||||||
from plane.db.models import SlackProjectSync
|
from plane.db.models import SlackProjectSync
|
||||||
|
|
||||||
|
|
615
apiserver/plane/app/serializers/issue.py
Normal file
615
apiserver/plane/app/serializers/issue.py
Normal file
@ -0,0 +1,615 @@
|
|||||||
|
# Django imports
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
# Third Party imports
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
# Module imports
|
||||||
|
from .base import BaseSerializer, DynamicBaseSerializer
|
||||||
|
from .user import UserLiteSerializer
|
||||||
|
from .state import StateSerializer, StateLiteSerializer
|
||||||
|
from .project import ProjectLiteSerializer
|
||||||
|
from .workspace import WorkspaceLiteSerializer
|
||||||
|
from plane.db.models import (
|
||||||
|
User,
|
||||||
|
Issue,
|
||||||
|
IssueActivity,
|
||||||
|
IssueComment,
|
||||||
|
IssueProperty,
|
||||||
|
IssueAssignee,
|
||||||
|
IssueSubscriber,
|
||||||
|
IssueLabel,
|
||||||
|
Label,
|
||||||
|
CycleIssue,
|
||||||
|
Cycle,
|
||||||
|
Module,
|
||||||
|
ModuleIssue,
|
||||||
|
IssueLink,
|
||||||
|
IssueAttachment,
|
||||||
|
IssueReaction,
|
||||||
|
CommentReaction,
|
||||||
|
IssueVote,
|
||||||
|
IssueRelation,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class IssueFlatSerializer(BaseSerializer):
|
||||||
|
## Contain only flat fields
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Issue
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"description",
|
||||||
|
"description_html",
|
||||||
|
"priority",
|
||||||
|
"start_date",
|
||||||
|
"target_date",
|
||||||
|
"sequence_id",
|
||||||
|
"sort_order",
|
||||||
|
"is_draft",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class IssueProjectLiteSerializer(BaseSerializer):
|
||||||
|
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Issue
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"project_detail",
|
||||||
|
"name",
|
||||||
|
"sequence_id",
|
||||||
|
]
|
||||||
|
read_only_fields = fields
|
||||||
|
|
||||||
|
|
||||||
|
##TODO: Find a better way to write this serializer
|
||||||
|
## Find a better approach to save manytomany?
|
||||||
|
class IssueCreateSerializer(BaseSerializer):
|
||||||
|
state_detail = StateSerializer(read_only=True, source="state")
|
||||||
|
created_by_detail = UserLiteSerializer(read_only=True, source="created_by")
|
||||||
|
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||||
|
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
||||||
|
|
||||||
|
assignees = serializers.ListField(
|
||||||
|
child=serializers.PrimaryKeyRelatedField(queryset=User.objects.all()),
|
||||||
|
write_only=True,
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
labels = serializers.ListField(
|
||||||
|
child=serializers.PrimaryKeyRelatedField(queryset=Label.objects.all()),
|
||||||
|
write_only=True,
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Issue
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
|
||||||
|
def to_representation(self, instance):
|
||||||
|
data = super().to_representation(instance)
|
||||||
|
data['assignees'] = [str(assignee.id) for assignee in instance.assignees.all()]
|
||||||
|
data['labels'] = [str(label.id) for label in instance.labels.all()]
|
||||||
|
return data
|
||||||
|
|
||||||
|
def validate(self, data):
|
||||||
|
if (
|
||||||
|
data.get("start_date", None) is not None
|
||||||
|
and data.get("target_date", None) is not None
|
||||||
|
and data.get("start_date", None) > data.get("target_date", None)
|
||||||
|
):
|
||||||
|
raise serializers.ValidationError("Start date cannot exceed target date")
|
||||||
|
return data
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
assignees = validated_data.pop("assignees", None)
|
||||||
|
labels = validated_data.pop("labels", None)
|
||||||
|
|
||||||
|
project_id = self.context["project_id"]
|
||||||
|
workspace_id = self.context["workspace_id"]
|
||||||
|
default_assignee_id = self.context["default_assignee_id"]
|
||||||
|
|
||||||
|
issue = Issue.objects.create(**validated_data, project_id=project_id)
|
||||||
|
|
||||||
|
# Issue Audit Users
|
||||||
|
created_by_id = issue.created_by_id
|
||||||
|
updated_by_id = issue.updated_by_id
|
||||||
|
|
||||||
|
if assignees is not None and len(assignees):
|
||||||
|
IssueAssignee.objects.bulk_create(
|
||||||
|
[
|
||||||
|
IssueAssignee(
|
||||||
|
assignee=user,
|
||||||
|
issue=issue,
|
||||||
|
project_id=project_id,
|
||||||
|
workspace_id=workspace_id,
|
||||||
|
created_by_id=created_by_id,
|
||||||
|
updated_by_id=updated_by_id,
|
||||||
|
)
|
||||||
|
for user in assignees
|
||||||
|
],
|
||||||
|
batch_size=10,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# Then assign it to default assignee
|
||||||
|
if default_assignee_id is not None:
|
||||||
|
IssueAssignee.objects.create(
|
||||||
|
assignee_id=default_assignee_id,
|
||||||
|
issue=issue,
|
||||||
|
project_id=project_id,
|
||||||
|
workspace_id=workspace_id,
|
||||||
|
created_by_id=created_by_id,
|
||||||
|
updated_by_id=updated_by_id,
|
||||||
|
)
|
||||||
|
|
||||||
|
if labels is not None and len(labels):
|
||||||
|
IssueLabel.objects.bulk_create(
|
||||||
|
[
|
||||||
|
IssueLabel(
|
||||||
|
label=label,
|
||||||
|
issue=issue,
|
||||||
|
project_id=project_id,
|
||||||
|
workspace_id=workspace_id,
|
||||||
|
created_by_id=created_by_id,
|
||||||
|
updated_by_id=updated_by_id,
|
||||||
|
)
|
||||||
|
for label in labels
|
||||||
|
],
|
||||||
|
batch_size=10,
|
||||||
|
)
|
||||||
|
|
||||||
|
return issue
|
||||||
|
|
||||||
|
def update(self, instance, validated_data):
|
||||||
|
assignees = validated_data.pop("assignees", None)
|
||||||
|
labels = validated_data.pop("labels", None)
|
||||||
|
|
||||||
|
# Related models
|
||||||
|
project_id = instance.project_id
|
||||||
|
workspace_id = instance.workspace_id
|
||||||
|
created_by_id = instance.created_by_id
|
||||||
|
updated_by_id = instance.updated_by_id
|
||||||
|
|
||||||
|
if assignees is not None:
|
||||||
|
IssueAssignee.objects.filter(issue=instance).delete()
|
||||||
|
IssueAssignee.objects.bulk_create(
|
||||||
|
[
|
||||||
|
IssueAssignee(
|
||||||
|
assignee=user,
|
||||||
|
issue=instance,
|
||||||
|
project_id=project_id,
|
||||||
|
workspace_id=workspace_id,
|
||||||
|
created_by_id=created_by_id,
|
||||||
|
updated_by_id=updated_by_id,
|
||||||
|
)
|
||||||
|
for user in assignees
|
||||||
|
],
|
||||||
|
batch_size=10,
|
||||||
|
)
|
||||||
|
|
||||||
|
if labels is not None:
|
||||||
|
IssueLabel.objects.filter(issue=instance).delete()
|
||||||
|
IssueLabel.objects.bulk_create(
|
||||||
|
[
|
||||||
|
IssueLabel(
|
||||||
|
label=label,
|
||||||
|
issue=instance,
|
||||||
|
project_id=project_id,
|
||||||
|
workspace_id=workspace_id,
|
||||||
|
created_by_id=created_by_id,
|
||||||
|
updated_by_id=updated_by_id,
|
||||||
|
)
|
||||||
|
for label in labels
|
||||||
|
],
|
||||||
|
batch_size=10,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Time updation occues even when other related models are updated
|
||||||
|
instance.updated_at = timezone.now()
|
||||||
|
return super().update(instance, validated_data)
|
||||||
|
|
||||||
|
|
||||||
|
class IssueActivitySerializer(BaseSerializer):
|
||||||
|
actor_detail = UserLiteSerializer(read_only=True, source="actor")
|
||||||
|
issue_detail = IssueFlatSerializer(read_only=True, source="issue")
|
||||||
|
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = IssueActivity
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class IssuePropertySerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = IssueProperty
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"user",
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class LabelSerializer(BaseSerializer):
|
||||||
|
workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True)
|
||||||
|
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Label
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class LabelLiteSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Label
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"color",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class IssueLabelSerializer(BaseSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = IssueLabel
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class IssueRelationSerializer(BaseSerializer):
|
||||||
|
issue_detail = IssueProjectLiteSerializer(read_only=True, source="related_issue")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = IssueRelation
|
||||||
|
fields = [
|
||||||
|
"issue_detail",
|
||||||
|
"relation_type",
|
||||||
|
"related_issue",
|
||||||
|
"issue",
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
]
|
||||||
|
|
||||||
|
class RelatedIssueSerializer(BaseSerializer):
|
||||||
|
issue_detail = IssueProjectLiteSerializer(read_only=True, source="issue")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = IssueRelation
|
||||||
|
fields = [
|
||||||
|
"issue_detail",
|
||||||
|
"relation_type",
|
||||||
|
"related_issue",
|
||||||
|
"issue",
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class IssueAssigneeSerializer(BaseSerializer):
|
||||||
|
assignee_details = UserLiteSerializer(read_only=True, source="assignee")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = IssueAssignee
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class CycleBaseSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Cycle
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class IssueCycleDetailSerializer(BaseSerializer):
|
||||||
|
cycle_detail = CycleBaseSerializer(read_only=True, source="cycle")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = CycleIssue
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleBaseSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Module
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class IssueModuleDetailSerializer(BaseSerializer):
|
||||||
|
module_detail = ModuleBaseSerializer(read_only=True, source="module")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ModuleIssue
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class IssueLinkSerializer(BaseSerializer):
|
||||||
|
created_by_detail = UserLiteSerializer(read_only=True, source="created_by")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = IssueLink
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
"issue",
|
||||||
|
]
|
||||||
|
|
||||||
|
# Validation if url already exists
|
||||||
|
def create(self, validated_data):
|
||||||
|
if IssueLink.objects.filter(
|
||||||
|
url=validated_data.get("url"), issue_id=validated_data.get("issue_id")
|
||||||
|
).exists():
|
||||||
|
raise serializers.ValidationError(
|
||||||
|
{"error": "URL already exists for this Issue"}
|
||||||
|
)
|
||||||
|
return IssueLink.objects.create(**validated_data)
|
||||||
|
|
||||||
|
|
||||||
|
class IssueAttachmentSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = IssueAttachment
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"issue",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class IssueReactionSerializer(BaseSerializer):
|
||||||
|
|
||||||
|
actor_detail = UserLiteSerializer(read_only=True, source="actor")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = IssueReaction
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"issue",
|
||||||
|
"actor",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class CommentReactionLiteSerializer(BaseSerializer):
|
||||||
|
actor_detail = UserLiteSerializer(read_only=True, source="actor")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = CommentReaction
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"reaction",
|
||||||
|
"comment",
|
||||||
|
"actor_detail",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class CommentReactionSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = CommentReaction
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = ["workspace", "project", "comment", "actor"]
|
||||||
|
|
||||||
|
|
||||||
|
class IssueVoteSerializer(BaseSerializer):
|
||||||
|
|
||||||
|
actor_detail = UserLiteSerializer(read_only=True, source="actor")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = IssueVote
|
||||||
|
fields = ["issue", "vote", "workspace", "project", "actor", "actor_detail"]
|
||||||
|
read_only_fields = fields
|
||||||
|
|
||||||
|
|
||||||
|
class IssueCommentSerializer(BaseSerializer):
|
||||||
|
actor_detail = UserLiteSerializer(read_only=True, source="actor")
|
||||||
|
issue_detail = IssueFlatSerializer(read_only=True, source="issue")
|
||||||
|
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||||
|
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
||||||
|
comment_reactions = CommentReactionLiteSerializer(read_only=True, many=True)
|
||||||
|
is_member = serializers.BooleanField(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = IssueComment
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"issue",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class IssueStateFlatSerializer(BaseSerializer):
|
||||||
|
state_detail = StateLiteSerializer(read_only=True, source="state")
|
||||||
|
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Issue
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"sequence_id",
|
||||||
|
"name",
|
||||||
|
"state_detail",
|
||||||
|
"project_detail",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# Issue Serializer with state details
|
||||||
|
class IssueStateSerializer(DynamicBaseSerializer):
|
||||||
|
label_details = LabelLiteSerializer(read_only=True, source="labels", many=True)
|
||||||
|
state_detail = StateLiteSerializer(read_only=True, source="state")
|
||||||
|
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||||
|
assignee_details = UserLiteSerializer(read_only=True, source="assignees", many=True)
|
||||||
|
sub_issues_count = serializers.IntegerField(read_only=True)
|
||||||
|
bridge_id = serializers.UUIDField(read_only=True)
|
||||||
|
attachment_count = serializers.IntegerField(read_only=True)
|
||||||
|
link_count = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Issue
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class IssueSerializer(BaseSerializer):
|
||||||
|
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||||
|
state_detail = StateSerializer(read_only=True, source="state")
|
||||||
|
parent_detail = IssueStateFlatSerializer(read_only=True, source="parent")
|
||||||
|
label_details = LabelSerializer(read_only=True, source="labels", many=True)
|
||||||
|
assignee_details = UserLiteSerializer(read_only=True, source="assignees", many=True)
|
||||||
|
related_issues = IssueRelationSerializer(read_only=True, source="issue_relation", many=True)
|
||||||
|
issue_relations = RelatedIssueSerializer(read_only=True, source="issue_related", many=True)
|
||||||
|
issue_cycle = IssueCycleDetailSerializer(read_only=True)
|
||||||
|
issue_module = IssueModuleDetailSerializer(read_only=True)
|
||||||
|
issue_link = IssueLinkSerializer(read_only=True, many=True)
|
||||||
|
issue_attachment = IssueAttachmentSerializer(read_only=True, many=True)
|
||||||
|
sub_issues_count = serializers.IntegerField(read_only=True)
|
||||||
|
issue_reactions = IssueReactionSerializer(read_only=True, many=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Issue
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class IssueLiteSerializer(DynamicBaseSerializer):
|
||||||
|
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
||||||
|
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||||
|
state_detail = StateLiteSerializer(read_only=True, source="state")
|
||||||
|
label_details = LabelLiteSerializer(read_only=True, source="labels", many=True)
|
||||||
|
assignee_details = UserLiteSerializer(read_only=True, source="assignees", many=True)
|
||||||
|
sub_issues_count = serializers.IntegerField(read_only=True)
|
||||||
|
cycle_id = serializers.UUIDField(read_only=True)
|
||||||
|
module_id = serializers.UUIDField(read_only=True)
|
||||||
|
attachment_count = serializers.IntegerField(read_only=True)
|
||||||
|
link_count = serializers.IntegerField(read_only=True)
|
||||||
|
issue_reactions = IssueReactionSerializer(read_only=True, many=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Issue
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"start_date",
|
||||||
|
"target_date",
|
||||||
|
"completed_at",
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class IssuePublicSerializer(BaseSerializer):
|
||||||
|
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||||
|
state_detail = StateLiteSerializer(read_only=True, source="state")
|
||||||
|
reactions = IssueReactionSerializer(read_only=True, many=True, source="issue_reactions")
|
||||||
|
votes = IssueVoteSerializer(read_only=True, many=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Issue
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"description_html",
|
||||||
|
"sequence_id",
|
||||||
|
"state",
|
||||||
|
"state_detail",
|
||||||
|
"project",
|
||||||
|
"project_detail",
|
||||||
|
"workspace",
|
||||||
|
"priority",
|
||||||
|
"target_date",
|
||||||
|
"reactions",
|
||||||
|
"votes",
|
||||||
|
]
|
||||||
|
read_only_fields = fields
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class IssueSubscriberSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = IssueSubscriber
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"issue",
|
||||||
|
]
|
198
apiserver/plane/app/serializers/module.py
Normal file
198
apiserver/plane/app/serializers/module.py
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
# Third Party imports
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
# Module imports
|
||||||
|
from .base import BaseSerializer
|
||||||
|
from .user import UserLiteSerializer
|
||||||
|
from .project import ProjectLiteSerializer
|
||||||
|
from .workspace import WorkspaceLiteSerializer
|
||||||
|
|
||||||
|
from plane.db.models import (
|
||||||
|
User,
|
||||||
|
Module,
|
||||||
|
ModuleMember,
|
||||||
|
ModuleIssue,
|
||||||
|
ModuleLink,
|
||||||
|
ModuleFavorite,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleWriteSerializer(BaseSerializer):
|
||||||
|
members = serializers.ListField(
|
||||||
|
child=serializers.PrimaryKeyRelatedField(queryset=User.objects.all()),
|
||||||
|
write_only=True,
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
||||||
|
workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Module
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
|
||||||
|
def to_representation(self, instance):
|
||||||
|
data = super().to_representation(instance)
|
||||||
|
data['members'] = [str(member.id) for member in instance.members.all()]
|
||||||
|
return data
|
||||||
|
|
||||||
|
def validate(self, data):
|
||||||
|
if data.get("start_date", None) is not None and data.get("target_date", None) is not None and data.get("start_date", None) > data.get("target_date", None):
|
||||||
|
raise serializers.ValidationError("Start date cannot exceed target date")
|
||||||
|
return data
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
members = validated_data.pop("members", None)
|
||||||
|
|
||||||
|
project = self.context["project"]
|
||||||
|
|
||||||
|
module = Module.objects.create(**validated_data, project=project)
|
||||||
|
|
||||||
|
if members is not None:
|
||||||
|
ModuleMember.objects.bulk_create(
|
||||||
|
[
|
||||||
|
ModuleMember(
|
||||||
|
module=module,
|
||||||
|
member=member,
|
||||||
|
project=project,
|
||||||
|
workspace=project.workspace,
|
||||||
|
created_by=module.created_by,
|
||||||
|
updated_by=module.updated_by,
|
||||||
|
)
|
||||||
|
for member in members
|
||||||
|
],
|
||||||
|
batch_size=10,
|
||||||
|
ignore_conflicts=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
return module
|
||||||
|
|
||||||
|
def update(self, instance, validated_data):
|
||||||
|
members = validated_data.pop("members", None)
|
||||||
|
|
||||||
|
if members is not None:
|
||||||
|
ModuleMember.objects.filter(module=instance).delete()
|
||||||
|
ModuleMember.objects.bulk_create(
|
||||||
|
[
|
||||||
|
ModuleMember(
|
||||||
|
module=instance,
|
||||||
|
member=member,
|
||||||
|
project=instance.project,
|
||||||
|
workspace=instance.project.workspace,
|
||||||
|
created_by=instance.created_by,
|
||||||
|
updated_by=instance.updated_by,
|
||||||
|
)
|
||||||
|
for member in members
|
||||||
|
],
|
||||||
|
batch_size=10,
|
||||||
|
ignore_conflicts=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
return super().update(instance, validated_data)
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleFlatSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Module
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleIssueSerializer(BaseSerializer):
|
||||||
|
module_detail = ModuleFlatSerializer(read_only=True, source="module")
|
||||||
|
issue_detail = ProjectLiteSerializer(read_only=True, source="issue")
|
||||||
|
sub_issues_count = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ModuleIssue
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
"module",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleLinkSerializer(BaseSerializer):
|
||||||
|
created_by_detail = UserLiteSerializer(read_only=True, source="created_by")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ModuleLink
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
"module",
|
||||||
|
]
|
||||||
|
|
||||||
|
# Validation if url already exists
|
||||||
|
def create(self, validated_data):
|
||||||
|
if ModuleLink.objects.filter(
|
||||||
|
url=validated_data.get("url"), module_id=validated_data.get("module_id")
|
||||||
|
).exists():
|
||||||
|
raise serializers.ValidationError(
|
||||||
|
{"error": "URL already exists for this Issue"}
|
||||||
|
)
|
||||||
|
return ModuleLink.objects.create(**validated_data)
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleSerializer(BaseSerializer):
|
||||||
|
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||||
|
lead_detail = UserLiteSerializer(read_only=True, source="lead")
|
||||||
|
members_detail = UserLiteSerializer(read_only=True, many=True, source="members")
|
||||||
|
link_module = ModuleLinkSerializer(read_only=True, many=True)
|
||||||
|
is_favorite = serializers.BooleanField(read_only=True)
|
||||||
|
total_issues = serializers.IntegerField(read_only=True)
|
||||||
|
cancelled_issues = serializers.IntegerField(read_only=True)
|
||||||
|
completed_issues = serializers.IntegerField(read_only=True)
|
||||||
|
started_issues = serializers.IntegerField(read_only=True)
|
||||||
|
unstarted_issues = serializers.IntegerField(read_only=True)
|
||||||
|
backlog_issues = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Module
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleFavoriteSerializer(BaseSerializer):
|
||||||
|
module_detail = ModuleFlatSerializer(source="module", read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ModuleFavorite
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"user",
|
||||||
|
]
|
@ -6,28 +6,7 @@ from .base import BaseSerializer
|
|||||||
from .issue import IssueFlatSerializer, LabelLiteSerializer
|
from .issue import IssueFlatSerializer, LabelLiteSerializer
|
||||||
from .workspace import WorkspaceLiteSerializer
|
from .workspace import WorkspaceLiteSerializer
|
||||||
from .project import ProjectLiteSerializer
|
from .project import ProjectLiteSerializer
|
||||||
from plane.db.models import Page, PageBlock, PageFavorite, PageLabel, Label
|
from plane.db.models import Page, PageLog, PageFavorite, PageLabel, Label, Issue, Module
|
||||||
|
|
||||||
|
|
||||||
class PageBlockSerializer(BaseSerializer):
|
|
||||||
issue_detail = IssueFlatSerializer(source="issue", read_only=True)
|
|
||||||
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
|
||||||
workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = PageBlock
|
|
||||||
fields = "__all__"
|
|
||||||
read_only_fields = [
|
|
||||||
"workspace",
|
|
||||||
"project",
|
|
||||||
"page",
|
|
||||||
]
|
|
||||||
|
|
||||||
class PageBlockLiteSerializer(BaseSerializer):
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = PageBlock
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class PageSerializer(BaseSerializer):
|
class PageSerializer(BaseSerializer):
|
||||||
@ -38,7 +17,6 @@ class PageSerializer(BaseSerializer):
|
|||||||
write_only=True,
|
write_only=True,
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
blocks = PageBlockLiteSerializer(read_only=True, many=True)
|
|
||||||
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
||||||
workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True)
|
workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True)
|
||||||
|
|
||||||
@ -102,6 +80,41 @@ class PageSerializer(BaseSerializer):
|
|||||||
return super().update(instance, validated_data)
|
return super().update(instance, validated_data)
|
||||||
|
|
||||||
|
|
||||||
|
class SubPageSerializer(BaseSerializer):
|
||||||
|
entity_details = serializers.SerializerMethodField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = PageLog
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"page",
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_entity_details(self, obj):
|
||||||
|
entity_name = obj.entity_name
|
||||||
|
if entity_name == 'forward_link' or entity_name == 'back_link':
|
||||||
|
try:
|
||||||
|
page = Page.objects.get(pk=obj.entity_identifier)
|
||||||
|
return PageSerializer(page).data
|
||||||
|
except Page.DoesNotExist:
|
||||||
|
return None
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class PageLogSerializer(BaseSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = PageLog
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"page",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class PageFavoriteSerializer(BaseSerializer):
|
class PageFavoriteSerializer(BaseSerializer):
|
||||||
page_detail = PageSerializer(source="page", read_only=True)
|
page_detail = PageSerializer(source="page", read_only=True)
|
||||||
|
|
217
apiserver/plane/app/serializers/project.py
Normal file
217
apiserver/plane/app/serializers/project.py
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
# Third party imports
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
# Module imports
|
||||||
|
from .base import BaseSerializer, DynamicBaseSerializer
|
||||||
|
from plane.app.serializers.workspace import WorkspaceLiteSerializer
|
||||||
|
from plane.app.serializers.user import UserLiteSerializer, UserAdminLiteSerializer
|
||||||
|
from plane.db.models import (
|
||||||
|
Project,
|
||||||
|
ProjectMember,
|
||||||
|
ProjectMemberInvite,
|
||||||
|
ProjectIdentifier,
|
||||||
|
ProjectFavorite,
|
||||||
|
ProjectDeployBoard,
|
||||||
|
ProjectPublicMember,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectSerializer(BaseSerializer):
|
||||||
|
workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Project
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
]
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
identifier = validated_data.get("identifier", "").strip().upper()
|
||||||
|
if identifier == "":
|
||||||
|
raise serializers.ValidationError(detail="Project Identifier is required")
|
||||||
|
|
||||||
|
if ProjectIdentifier.objects.filter(
|
||||||
|
name=identifier, workspace_id=self.context["workspace_id"]
|
||||||
|
).exists():
|
||||||
|
raise serializers.ValidationError(detail="Project Identifier is taken")
|
||||||
|
project = Project.objects.create(
|
||||||
|
**validated_data, workspace_id=self.context["workspace_id"]
|
||||||
|
)
|
||||||
|
_ = ProjectIdentifier.objects.create(
|
||||||
|
name=project.identifier,
|
||||||
|
project=project,
|
||||||
|
workspace_id=self.context["workspace_id"],
|
||||||
|
)
|
||||||
|
return project
|
||||||
|
|
||||||
|
def update(self, instance, validated_data):
|
||||||
|
identifier = validated_data.get("identifier", "").strip().upper()
|
||||||
|
|
||||||
|
# If identifier is not passed update the project and return
|
||||||
|
if identifier == "":
|
||||||
|
project = super().update(instance, validated_data)
|
||||||
|
return project
|
||||||
|
|
||||||
|
# If no Project Identifier is found create it
|
||||||
|
project_identifier = ProjectIdentifier.objects.filter(
|
||||||
|
name=identifier, workspace_id=instance.workspace_id
|
||||||
|
).first()
|
||||||
|
if project_identifier is None:
|
||||||
|
project = super().update(instance, validated_data)
|
||||||
|
project_identifier = ProjectIdentifier.objects.filter(
|
||||||
|
project=project
|
||||||
|
).first()
|
||||||
|
if project_identifier is not None:
|
||||||
|
project_identifier.name = identifier
|
||||||
|
project_identifier.save()
|
||||||
|
return project
|
||||||
|
# If found check if the project_id to be updated and identifier project id is same
|
||||||
|
if project_identifier.project_id == instance.id:
|
||||||
|
# If same pass update
|
||||||
|
project = super().update(instance, validated_data)
|
||||||
|
return project
|
||||||
|
|
||||||
|
# If not same fail update
|
||||||
|
raise serializers.ValidationError(detail="Project Identifier is already taken")
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectLiteSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Project
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"identifier",
|
||||||
|
"name",
|
||||||
|
"cover_image",
|
||||||
|
"icon_prop",
|
||||||
|
"emoji",
|
||||||
|
"description",
|
||||||
|
]
|
||||||
|
read_only_fields = fields
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectListSerializer(DynamicBaseSerializer):
|
||||||
|
is_favorite = serializers.BooleanField(read_only=True)
|
||||||
|
total_members = serializers.IntegerField(read_only=True)
|
||||||
|
total_cycles = serializers.IntegerField(read_only=True)
|
||||||
|
total_modules = serializers.IntegerField(read_only=True)
|
||||||
|
is_member = serializers.BooleanField(read_only=True)
|
||||||
|
sort_order = serializers.FloatField(read_only=True)
|
||||||
|
member_role = serializers.IntegerField(read_only=True)
|
||||||
|
is_deployed = serializers.BooleanField(read_only=True)
|
||||||
|
members = serializers.SerializerMethodField()
|
||||||
|
|
||||||
|
def get_members(self, obj):
|
||||||
|
project_members = ProjectMember.objects.filter(
|
||||||
|
project_id=obj.id,
|
||||||
|
is_active=True,
|
||||||
|
).values(
|
||||||
|
"id",
|
||||||
|
"member_id",
|
||||||
|
"member__display_name",
|
||||||
|
"member__avatar",
|
||||||
|
)
|
||||||
|
return list(project_members)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Project
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectDetailSerializer(BaseSerializer):
|
||||||
|
# workspace = WorkSpaceSerializer(read_only=True)
|
||||||
|
default_assignee = UserLiteSerializer(read_only=True)
|
||||||
|
project_lead = UserLiteSerializer(read_only=True)
|
||||||
|
is_favorite = serializers.BooleanField(read_only=True)
|
||||||
|
total_members = serializers.IntegerField(read_only=True)
|
||||||
|
total_cycles = serializers.IntegerField(read_only=True)
|
||||||
|
total_modules = serializers.IntegerField(read_only=True)
|
||||||
|
is_member = serializers.BooleanField(read_only=True)
|
||||||
|
sort_order = serializers.FloatField(read_only=True)
|
||||||
|
member_role = serializers.IntegerField(read_only=True)
|
||||||
|
is_deployed = serializers.BooleanField(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Project
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectMemberSerializer(BaseSerializer):
|
||||||
|
workspace = WorkspaceLiteSerializer(read_only=True)
|
||||||
|
project = ProjectLiteSerializer(read_only=True)
|
||||||
|
member = UserLiteSerializer(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ProjectMember
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectMemberAdminSerializer(BaseSerializer):
|
||||||
|
workspace = WorkspaceLiteSerializer(read_only=True)
|
||||||
|
project = ProjectLiteSerializer(read_only=True)
|
||||||
|
member = UserAdminLiteSerializer(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ProjectMember
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectMemberInviteSerializer(BaseSerializer):
|
||||||
|
project = ProjectLiteSerializer(read_only=True)
|
||||||
|
workspace = WorkspaceLiteSerializer(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ProjectMemberInvite
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectIdentifierSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = ProjectIdentifier
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectFavoriteSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = ProjectFavorite
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"user",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectMemberLiteSerializer(BaseSerializer):
|
||||||
|
member = UserLiteSerializer(read_only=True)
|
||||||
|
is_subscribed = serializers.BooleanField(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ProjectMember
|
||||||
|
fields = ["member", "id", "is_subscribed"]
|
||||||
|
read_only_fields = fields
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectDeployBoardSerializer(BaseSerializer):
|
||||||
|
project_details = ProjectLiteSerializer(read_only=True, source="project")
|
||||||
|
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ProjectDeployBoard
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"anchor",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectPublicMemberSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = ProjectPublicMember
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"member",
|
||||||
|
]
|
28
apiserver/plane/app/serializers/state.py
Normal file
28
apiserver/plane/app/serializers/state.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Module imports
|
||||||
|
from .base import BaseSerializer
|
||||||
|
|
||||||
|
|
||||||
|
from plane.db.models import State
|
||||||
|
|
||||||
|
|
||||||
|
class StateSerializer(BaseSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = State
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class StateLiteSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = State
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"color",
|
||||||
|
"group",
|
||||||
|
]
|
||||||
|
read_only_fields = fields
|
167
apiserver/plane/app/serializers/user.py
Normal file
167
apiserver/plane/app/serializers/user.py
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
# Third party imports
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
# Module import
|
||||||
|
from .base import BaseSerializer
|
||||||
|
from plane.db.models import User, Workspace, WorkspaceMemberInvite
|
||||||
|
from plane.license.models import InstanceAdmin, Instance
|
||||||
|
|
||||||
|
|
||||||
|
class UserSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"id",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
"is_superuser",
|
||||||
|
"is_staff",
|
||||||
|
"last_active",
|
||||||
|
"last_login_time",
|
||||||
|
"last_logout_time",
|
||||||
|
"last_login_ip",
|
||||||
|
"last_logout_ip",
|
||||||
|
"last_login_uagent",
|
||||||
|
"token_updated_at",
|
||||||
|
"is_onboarded",
|
||||||
|
"is_bot",
|
||||||
|
]
|
||||||
|
extra_kwargs = {"password": {"write_only": True}}
|
||||||
|
|
||||||
|
# If the user has already filled first name or last name then he is onboarded
|
||||||
|
def get_is_onboarded(self, obj):
|
||||||
|
return bool(obj.first_name) or bool(obj.last_name)
|
||||||
|
|
||||||
|
|
||||||
|
class UserMeSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"avatar",
|
||||||
|
"cover_image",
|
||||||
|
"date_joined",
|
||||||
|
"display_name",
|
||||||
|
"email",
|
||||||
|
"first_name",
|
||||||
|
"last_name",
|
||||||
|
"is_active",
|
||||||
|
"is_bot",
|
||||||
|
"is_email_verified",
|
||||||
|
"is_managed",
|
||||||
|
"is_onboarded",
|
||||||
|
"is_tour_completed",
|
||||||
|
"mobile_number",
|
||||||
|
"role",
|
||||||
|
"onboarding_step",
|
||||||
|
"user_timezone",
|
||||||
|
"username",
|
||||||
|
"theme",
|
||||||
|
"last_workspace_id",
|
||||||
|
"use_case",
|
||||||
|
]
|
||||||
|
read_only_fields = fields
|
||||||
|
|
||||||
|
|
||||||
|
class UserMeSettingsSerializer(BaseSerializer):
|
||||||
|
workspace = serializers.SerializerMethodField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"email",
|
||||||
|
"workspace",
|
||||||
|
]
|
||||||
|
read_only_fields = fields
|
||||||
|
|
||||||
|
def get_workspace(self, obj):
|
||||||
|
workspace_invites = WorkspaceMemberInvite.objects.filter(
|
||||||
|
email=obj.email
|
||||||
|
).count()
|
||||||
|
if obj.last_workspace_id is not None:
|
||||||
|
workspace = Workspace.objects.filter(
|
||||||
|
pk=obj.last_workspace_id, workspace_member__member=obj.id
|
||||||
|
).first()
|
||||||
|
return {
|
||||||
|
"last_workspace_id": obj.last_workspace_id,
|
||||||
|
"last_workspace_slug": workspace.slug if workspace is not None else "",
|
||||||
|
"fallback_workspace_id": obj.last_workspace_id,
|
||||||
|
"fallback_workspace_slug": workspace.slug
|
||||||
|
if workspace is not None
|
||||||
|
else "",
|
||||||
|
"invites": workspace_invites,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
fallback_workspace = (
|
||||||
|
Workspace.objects.filter(workspace_member__member_id=obj.id)
|
||||||
|
.order_by("created_at")
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
"last_workspace_id": None,
|
||||||
|
"last_workspace_slug": None,
|
||||||
|
"fallback_workspace_id": fallback_workspace.id
|
||||||
|
if fallback_workspace is not None
|
||||||
|
else None,
|
||||||
|
"fallback_workspace_slug": fallback_workspace.slug
|
||||||
|
if fallback_workspace is not None
|
||||||
|
else None,
|
||||||
|
"invites": workspace_invites,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class UserLiteSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"first_name",
|
||||||
|
"last_name",
|
||||||
|
"avatar",
|
||||||
|
"is_bot",
|
||||||
|
"display_name",
|
||||||
|
]
|
||||||
|
read_only_fields = [
|
||||||
|
"id",
|
||||||
|
"is_bot",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class UserAdminLiteSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"first_name",
|
||||||
|
"last_name",
|
||||||
|
"avatar",
|
||||||
|
"is_bot",
|
||||||
|
"display_name",
|
||||||
|
"email",
|
||||||
|
]
|
||||||
|
read_only_fields = [
|
||||||
|
"id",
|
||||||
|
"is_bot",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ChangePasswordSerializer(serializers.Serializer):
|
||||||
|
model = User
|
||||||
|
|
||||||
|
"""
|
||||||
|
Serializer for password change endpoint.
|
||||||
|
"""
|
||||||
|
old_password = serializers.CharField(required=True)
|
||||||
|
new_password = serializers.CharField(required=True)
|
||||||
|
|
||||||
|
|
||||||
|
class ResetPasswordSerializer(serializers.Serializer):
|
||||||
|
model = User
|
||||||
|
|
||||||
|
"""
|
||||||
|
Serializer for password change endpoint.
|
||||||
|
"""
|
||||||
|
new_password = serializers.CharField(required=True)
|
||||||
|
confirm_password = serializers.CharField(required=True)
|
30
apiserver/plane/app/serializers/webhook.py
Normal file
30
apiserver/plane/app/serializers/webhook.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Third party imports
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
# Module imports
|
||||||
|
from .base import DynamicBaseSerializer
|
||||||
|
from plane.db.models import Webhook, WebhookLog
|
||||||
|
from plane.db.models.webhook import validate_domain, validate_schema
|
||||||
|
|
||||||
|
class WebhookSerializer(DynamicBaseSerializer):
|
||||||
|
url = serializers.URLField(validators=[validate_schema, validate_domain])
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Webhook
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"secret_key",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class WebhookLogSerializer(DynamicBaseSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = WebhookLog
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"webhook"
|
||||||
|
]
|
||||||
|
|
136
apiserver/plane/app/serializers/workspace.py
Normal file
136
apiserver/plane/app/serializers/workspace.py
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
# Third party imports
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
# Module imports
|
||||||
|
from .base import BaseSerializer
|
||||||
|
from .user import UserLiteSerializer, UserAdminLiteSerializer
|
||||||
|
|
||||||
|
from plane.db.models import (
|
||||||
|
User,
|
||||||
|
Workspace,
|
||||||
|
WorkspaceMember,
|
||||||
|
Team,
|
||||||
|
TeamMember,
|
||||||
|
WorkspaceMemberInvite,
|
||||||
|
WorkspaceTheme,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class WorkSpaceSerializer(BaseSerializer):
|
||||||
|
owner = UserLiteSerializer(read_only=True)
|
||||||
|
total_members = serializers.IntegerField(read_only=True)
|
||||||
|
total_issues = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Workspace
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"id",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
"owner",
|
||||||
|
]
|
||||||
|
|
||||||
|
class WorkspaceLiteSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Workspace
|
||||||
|
fields = [
|
||||||
|
"name",
|
||||||
|
"slug",
|
||||||
|
"id",
|
||||||
|
]
|
||||||
|
read_only_fields = fields
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class WorkSpaceMemberSerializer(BaseSerializer):
|
||||||
|
member = UserLiteSerializer(read_only=True)
|
||||||
|
workspace = WorkspaceLiteSerializer(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = WorkspaceMember
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class WorkspaceMemberMeSerializer(BaseSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = WorkspaceMember
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class WorkspaceMemberAdminSerializer(BaseSerializer):
|
||||||
|
member = UserAdminLiteSerializer(read_only=True)
|
||||||
|
workspace = WorkspaceLiteSerializer(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = WorkspaceMember
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class WorkSpaceMemberInviteSerializer(BaseSerializer):
|
||||||
|
workspace = WorkSpaceSerializer(read_only=True)
|
||||||
|
total_members = serializers.IntegerField(read_only=True)
|
||||||
|
created_by_detail = UserLiteSerializer(read_only=True, source="created_by")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = WorkspaceMemberInvite
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class TeamSerializer(BaseSerializer):
|
||||||
|
members_detail = UserLiteSerializer(read_only=True, source="members", many=True)
|
||||||
|
members = serializers.ListField(
|
||||||
|
child=serializers.PrimaryKeyRelatedField(queryset=User.objects.all()),
|
||||||
|
write_only=True,
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Team
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
|
||||||
|
def create(self, validated_data, **kwargs):
|
||||||
|
if "members" in validated_data:
|
||||||
|
members = validated_data.pop("members")
|
||||||
|
workspace = self.context["workspace"]
|
||||||
|
team = Team.objects.create(**validated_data, workspace=workspace)
|
||||||
|
team_members = [
|
||||||
|
TeamMember(member=member, team=team, workspace=workspace)
|
||||||
|
for member in members
|
||||||
|
]
|
||||||
|
TeamMember.objects.bulk_create(team_members, batch_size=10)
|
||||||
|
return team
|
||||||
|
team = Team.objects.create(**validated_data)
|
||||||
|
return team
|
||||||
|
|
||||||
|
def update(self, instance, validated_data):
|
||||||
|
if "members" in validated_data:
|
||||||
|
members = validated_data.pop("members")
|
||||||
|
TeamMember.objects.filter(team=instance).delete()
|
||||||
|
team_members = [
|
||||||
|
TeamMember(member=member, team=instance, workspace=instance.workspace)
|
||||||
|
for member in members
|
||||||
|
]
|
||||||
|
TeamMember.objects.bulk_create(team_members, batch_size=10)
|
||||||
|
return super().update(instance, validated_data)
|
||||||
|
return super().update(instance, validated_data)
|
||||||
|
|
||||||
|
|
||||||
|
class WorkspaceThemeSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = WorkspaceTheme
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"actor",
|
||||||
|
]
|
48
apiserver/plane/app/urls/__init__.py
Normal file
48
apiserver/plane/app/urls/__init__.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
from .analytic import urlpatterns as analytic_urls
|
||||||
|
from .asset import urlpatterns as asset_urls
|
||||||
|
from .authentication import urlpatterns as authentication_urls
|
||||||
|
from .config import urlpatterns as configuration_urls
|
||||||
|
from .cycle import urlpatterns as cycle_urls
|
||||||
|
from .estimate import urlpatterns as estimate_urls
|
||||||
|
from .external import urlpatterns as external_urls
|
||||||
|
from .importer import urlpatterns as importer_urls
|
||||||
|
from .inbox import urlpatterns as inbox_urls
|
||||||
|
from .integration import urlpatterns as integration_urls
|
||||||
|
from .issue import urlpatterns as issue_urls
|
||||||
|
from .module import urlpatterns as module_urls
|
||||||
|
from .notification import urlpatterns as notification_urls
|
||||||
|
from .page import urlpatterns as page_urls
|
||||||
|
from .project import urlpatterns as project_urls
|
||||||
|
from .search import urlpatterns as search_urls
|
||||||
|
from .state import urlpatterns as state_urls
|
||||||
|
from .user import urlpatterns as user_urls
|
||||||
|
from .views import urlpatterns as view_urls
|
||||||
|
from .workspace import urlpatterns as workspace_urls
|
||||||
|
from .api import urlpatterns as api_urls
|
||||||
|
from .webhook import urlpatterns as webhook_urls
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
*analytic_urls,
|
||||||
|
*asset_urls,
|
||||||
|
*authentication_urls,
|
||||||
|
*configuration_urls,
|
||||||
|
*cycle_urls,
|
||||||
|
*estimate_urls,
|
||||||
|
*external_urls,
|
||||||
|
*importer_urls,
|
||||||
|
*inbox_urls,
|
||||||
|
*integration_urls,
|
||||||
|
*issue_urls,
|
||||||
|
*module_urls,
|
||||||
|
*notification_urls,
|
||||||
|
*page_urls,
|
||||||
|
*project_urls,
|
||||||
|
*search_urls,
|
||||||
|
*state_urls,
|
||||||
|
*user_urls,
|
||||||
|
*view_urls,
|
||||||
|
*workspace_urls,
|
||||||
|
*api_urls,
|
||||||
|
*webhook_urls,
|
||||||
|
]
|
@ -1,7 +1,7 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
from plane.api.views import (
|
from plane.app.views import (
|
||||||
AnalyticsEndpoint,
|
AnalyticsEndpoint,
|
||||||
AnalyticViewViewset,
|
AnalyticViewViewset,
|
||||||
SavedAnalyticEndpoint,
|
SavedAnalyticEndpoint,
|
17
apiserver/plane/app/urls/api.py
Normal file
17
apiserver/plane/app/urls/api.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from django.urls import path
|
||||||
|
from plane.app.views import ApiTokenEndpoint
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
# API Tokens
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/api-tokens/",
|
||||||
|
ApiTokenEndpoint.as_view(),
|
||||||
|
name="api-tokens",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/api-tokens/<uuid:pk>/",
|
||||||
|
ApiTokenEndpoint.as_view(),
|
||||||
|
name="api-tokens",
|
||||||
|
),
|
||||||
|
## End API Tokens
|
||||||
|
]
|
@ -1,7 +1,7 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
from plane.api.views import (
|
from plane.app.views import (
|
||||||
FileAssetEndpoint,
|
FileAssetEndpoint,
|
||||||
UserAssetsEndpoint,
|
UserAssetsEndpoint,
|
||||||
)
|
)
|
@ -3,7 +3,7 @@ from django.urls import path
|
|||||||
from rest_framework_simplejwt.views import TokenRefreshView
|
from rest_framework_simplejwt.views import TokenRefreshView
|
||||||
|
|
||||||
|
|
||||||
from plane.api.views import (
|
from plane.app.views import (
|
||||||
# Authentication
|
# Authentication
|
||||||
SignUpEndpoint,
|
SignUpEndpoint,
|
||||||
SignInEndpoint,
|
SignInEndpoint,
|
@ -1,7 +1,7 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
from plane.api.views import ConfigurationEndpoint
|
from plane.app.views import ConfigurationEndpoint
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(
|
path(
|
93
apiserver/plane/app/urls/cycle.py
Normal file
93
apiserver/plane/app/urls/cycle.py
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
|
from plane.app.views import (
|
||||||
|
CycleViewSet,
|
||||||
|
CycleIssueViewSet,
|
||||||
|
CycleDateCheckEndpoint,
|
||||||
|
CycleFavoriteViewSet,
|
||||||
|
TransferCycleIssueEndpoint,
|
||||||
|
CycleIssueGroupedEndpoint,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/",
|
||||||
|
CycleViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-cycle",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/<uuid:pk>/",
|
||||||
|
CycleViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"put": "update",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-cycle",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/<uuid:cycle_id>/cycle-issues/",
|
||||||
|
CycleIssueViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-cycle",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"v3/workspaces/<str:slug>/projects/<uuid:project_id>/cycles/<uuid:cycle_id>/cycle-issues/",
|
||||||
|
CycleIssueGroupedEndpoint.as_view(),
|
||||||
|
name="project-issue-cycle",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/<uuid:cycle_id>/cycle-issues/<uuid:pk>/",
|
||||||
|
CycleIssueViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"put": "update",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-cycle",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/date-check/",
|
||||||
|
CycleDateCheckEndpoint.as_view(),
|
||||||
|
name="project-cycle-date",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/user-favorite-cycles/",
|
||||||
|
CycleFavoriteViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="user-favorite-cycle",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/user-favorite-cycles/<uuid:cycle_id>/",
|
||||||
|
CycleFavoriteViewSet.as_view(
|
||||||
|
{
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="user-favorite-cycle",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/<uuid:cycle_id>/transfer-issues/",
|
||||||
|
TransferCycleIssueEndpoint.as_view(),
|
||||||
|
name="transfer-issues",
|
||||||
|
),
|
||||||
|
]
|
@ -1,7 +1,7 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
from plane.api.views import (
|
from plane.app.views import (
|
||||||
ProjectEstimatePointEndpoint,
|
ProjectEstimatePointEndpoint,
|
||||||
BulkEstimatePointEndpoint,
|
BulkEstimatePointEndpoint,
|
||||||
)
|
)
|
@ -1,9 +1,9 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
from plane.api.views import UnsplashEndpoint
|
from plane.app.views import UnsplashEndpoint
|
||||||
from plane.api.views import ReleaseNotesEndpoint
|
from plane.app.views import ReleaseNotesEndpoint
|
||||||
from plane.api.views import GPTIntegrationEndpoint
|
from plane.app.views import GPTIntegrationEndpoint
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
@ -1,7 +1,7 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
from plane.api.views import (
|
from plane.app.views import (
|
||||||
ServiceIssueImportSummaryEndpoint,
|
ServiceIssueImportSummaryEndpoint,
|
||||||
ImportServiceEndpoint,
|
ImportServiceEndpoint,
|
||||||
UpdateServiceImportStatusEndpoint,
|
UpdateServiceImportStatusEndpoint,
|
53
apiserver/plane/app/urls/inbox.py
Normal file
53
apiserver/plane/app/urls/inbox.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
|
from plane.app.views import (
|
||||||
|
InboxViewSet,
|
||||||
|
InboxIssueViewSet,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/inboxes/",
|
||||||
|
InboxViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="inbox",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/inboxes/<uuid:pk>/",
|
||||||
|
InboxViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="inbox",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/inboxes/<uuid:inbox_id>/inbox-issues/",
|
||||||
|
InboxIssueViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="inbox-issue",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/inboxes/<uuid:inbox_id>/inbox-issues/<uuid:pk>/",
|
||||||
|
InboxIssueViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="inbox-issue",
|
||||||
|
),
|
||||||
|
]
|
@ -1,7 +1,7 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
from plane.api.views import (
|
from plane.app.views import (
|
||||||
IntegrationViewSet,
|
IntegrationViewSet,
|
||||||
WorkspaceIntegrationViewSet,
|
WorkspaceIntegrationViewSet,
|
||||||
GithubRepositoriesEndpoint,
|
GithubRepositoriesEndpoint,
|
327
apiserver/plane/app/urls/issue.py
Normal file
327
apiserver/plane/app/urls/issue.py
Normal file
@ -0,0 +1,327 @@
|
|||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
|
from plane.app.views import (
|
||||||
|
IssueViewSet,
|
||||||
|
IssueListEndpoint,
|
||||||
|
IssueListGroupedEndpoint,
|
||||||
|
LabelViewSet,
|
||||||
|
BulkCreateIssueLabelsEndpoint,
|
||||||
|
BulkDeleteIssuesEndpoint,
|
||||||
|
BulkImportIssuesEndpoint,
|
||||||
|
UserWorkSpaceIssues,
|
||||||
|
SubIssuesEndpoint,
|
||||||
|
IssueLinkViewSet,
|
||||||
|
IssueAttachmentEndpoint,
|
||||||
|
ExportIssuesEndpoint,
|
||||||
|
IssueActivityEndpoint,
|
||||||
|
IssueCommentViewSet,
|
||||||
|
IssueSubscriberViewSet,
|
||||||
|
IssueReactionViewSet,
|
||||||
|
CommentReactionViewSet,
|
||||||
|
IssueUserDisplayPropertyEndpoint,
|
||||||
|
IssueArchiveViewSet,
|
||||||
|
IssueRelationViewSet,
|
||||||
|
IssueDraftViewSet,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/",
|
||||||
|
IssueViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"v2/workspaces/<str:slug>/projects/<uuid:project_id>/issues/",
|
||||||
|
IssueListEndpoint.as_view(),
|
||||||
|
name="project-issue",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"v3/workspaces/<str:slug>/projects/<uuid:project_id>/issues/",
|
||||||
|
IssueListGroupedEndpoint.as_view(),
|
||||||
|
name="project-issue",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:pk>/",
|
||||||
|
IssueViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"put": "update",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issue-labels/",
|
||||||
|
LabelViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-labels",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issue-labels/<uuid:pk>/",
|
||||||
|
LabelViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"put": "update",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-labels",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/bulk-create-labels/",
|
||||||
|
BulkCreateIssueLabelsEndpoint.as_view(),
|
||||||
|
name="project-bulk-labels",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/bulk-delete-issues/",
|
||||||
|
BulkDeleteIssuesEndpoint.as_view(),
|
||||||
|
name="project-issues-bulk",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/bulk-import-issues/<str:service>/",
|
||||||
|
BulkImportIssuesEndpoint.as_view(),
|
||||||
|
name="project-issues-bulk",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/my-issues/",
|
||||||
|
UserWorkSpaceIssues.as_view(),
|
||||||
|
name="workspace-issues",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/sub-issues/",
|
||||||
|
SubIssuesEndpoint.as_view(),
|
||||||
|
name="sub-issues",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-links/",
|
||||||
|
IssueLinkViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-links",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-links/<uuid:pk>/",
|
||||||
|
IssueLinkViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"put": "update",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-links",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-attachments/",
|
||||||
|
IssueAttachmentEndpoint.as_view(),
|
||||||
|
name="project-issue-attachments",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-attachments/<uuid:pk>/",
|
||||||
|
IssueAttachmentEndpoint.as_view(),
|
||||||
|
name="project-issue-attachments",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/export-issues/",
|
||||||
|
ExportIssuesEndpoint.as_view(),
|
||||||
|
name="export-issues",
|
||||||
|
),
|
||||||
|
## End Issues
|
||||||
|
## Issue Activity
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/history/",
|
||||||
|
IssueActivityEndpoint.as_view(),
|
||||||
|
name="project-issue-history",
|
||||||
|
),
|
||||||
|
## Issue Activity
|
||||||
|
## IssueComments
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/comments/",
|
||||||
|
IssueCommentViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-comment",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/comments/<uuid:pk>/",
|
||||||
|
IssueCommentViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"put": "update",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-comment",
|
||||||
|
),
|
||||||
|
## End IssueComments
|
||||||
|
# Issue Subscribers
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-subscribers/",
|
||||||
|
IssueSubscriberViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-subscribers",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-subscribers/<uuid:subscriber_id>/",
|
||||||
|
IssueSubscriberViewSet.as_view({"delete": "destroy"}),
|
||||||
|
name="project-issue-subscribers",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/subscribe/",
|
||||||
|
IssueSubscriberViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "subscription_status",
|
||||||
|
"post": "subscribe",
|
||||||
|
"delete": "unsubscribe",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-subscribers",
|
||||||
|
),
|
||||||
|
## End Issue Subscribers
|
||||||
|
# Issue Reactions
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/reactions/",
|
||||||
|
IssueReactionViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-reactions",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/reactions/<str:reaction_code>/",
|
||||||
|
IssueReactionViewSet.as_view(
|
||||||
|
{
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-reactions",
|
||||||
|
),
|
||||||
|
## End Issue Reactions
|
||||||
|
# Comment Reactions
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/comments/<uuid:comment_id>/reactions/",
|
||||||
|
CommentReactionViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-comment-reactions",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/comments/<uuid:comment_id>/reactions/<str:reaction_code>/",
|
||||||
|
CommentReactionViewSet.as_view(
|
||||||
|
{
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-comment-reactions",
|
||||||
|
),
|
||||||
|
## End Comment Reactions
|
||||||
|
## IssueProperty
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issue-display-properties/",
|
||||||
|
IssueUserDisplayPropertyEndpoint.as_view(),
|
||||||
|
name="project-issue-display-properties",
|
||||||
|
),
|
||||||
|
## IssueProperty End
|
||||||
|
## Issue Archives
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/archived-issues/",
|
||||||
|
IssueArchiveViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-archive",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/archived-issues/<uuid:pk>/",
|
||||||
|
IssueArchiveViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-archive",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/unarchive/<uuid:pk>/",
|
||||||
|
IssueArchiveViewSet.as_view(
|
||||||
|
{
|
||||||
|
"post": "unarchive",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-archive",
|
||||||
|
),
|
||||||
|
## End Issue Archives
|
||||||
|
## Issue Relation
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-relation/",
|
||||||
|
IssueRelationViewSet.as_view(
|
||||||
|
{
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="issue-relation",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-relation/<uuid:pk>/",
|
||||||
|
IssueRelationViewSet.as_view(
|
||||||
|
{
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="issue-relation",
|
||||||
|
),
|
||||||
|
## End Issue Relation
|
||||||
|
## Issue Drafts
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issue-drafts/",
|
||||||
|
IssueDraftViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-draft",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issue-drafts/<uuid:pk>/",
|
||||||
|
IssueDraftViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-draft",
|
||||||
|
),
|
||||||
|
]
|
110
apiserver/plane/app/urls/module.py
Normal file
110
apiserver/plane/app/urls/module.py
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
|
from plane.app.views import (
|
||||||
|
ModuleViewSet,
|
||||||
|
ModuleIssueViewSet,
|
||||||
|
ModuleLinkViewSet,
|
||||||
|
ModuleFavoriteViewSet,
|
||||||
|
BulkImportModulesEndpoint,
|
||||||
|
ModuleIssueGroupedEndpoint,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/",
|
||||||
|
ModuleViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-modules",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/<uuid:pk>/",
|
||||||
|
ModuleViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"put": "update",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-modules",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/<uuid:module_id>/module-issues/",
|
||||||
|
ModuleIssueViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-module-issues",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"v3/workspaces/<str:slug>/projects/<uuid:project_id>/modules/<uuid:module_id>/module-issues/",
|
||||||
|
ModuleIssueGroupedEndpoint.as_view(),
|
||||||
|
name="project-issue-cycle",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/<uuid:module_id>/module-issues/<uuid:pk>/",
|
||||||
|
ModuleIssueViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"put": "update",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-module-issues",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/<uuid:module_id>/module-links/",
|
||||||
|
ModuleLinkViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-module-links",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/modules/<uuid:module_id>/module-links/<uuid:pk>/",
|
||||||
|
ModuleLinkViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"put": "update",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-module-links",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/user-favorite-modules/",
|
||||||
|
ModuleFavoriteViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="user-favorite-module",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/user-favorite-modules/<uuid:module_id>/",
|
||||||
|
ModuleFavoriteViewSet.as_view(
|
||||||
|
{
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="user-favorite-module",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/bulk-import-modules/<str:service>/",
|
||||||
|
BulkImportModulesEndpoint.as_view(),
|
||||||
|
name="bulk-modules-create",
|
||||||
|
),
|
||||||
|
]
|
@ -1,7 +1,7 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
from plane.api.views import (
|
from plane.app.views import (
|
||||||
NotificationViewSet,
|
NotificationViewSet,
|
||||||
UnreadNotificationEndpoint,
|
UnreadNotificationEndpoint,
|
||||||
MarkAllReadNotificationViewSet,
|
MarkAllReadNotificationViewSet,
|
133
apiserver/plane/app/urls/page.py
Normal file
133
apiserver/plane/app/urls/page.py
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
|
from plane.app.views import (
|
||||||
|
PageViewSet,
|
||||||
|
PageFavoriteViewSet,
|
||||||
|
PageLogEndpoint,
|
||||||
|
SubPagesEndpoint,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/pages/",
|
||||||
|
PageViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-pages",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:pk>/",
|
||||||
|
PageViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-pages",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/user-favorite-pages/",
|
||||||
|
PageFavoriteViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="user-favorite-pages",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/user-favorite-pages/<uuid:page_id>/",
|
||||||
|
PageFavoriteViewSet.as_view(
|
||||||
|
{
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="user-favorite-pages",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/pages/",
|
||||||
|
PageViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-pages",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:pk>/",
|
||||||
|
PageViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-pages",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:page_id>/archive/",
|
||||||
|
PageViewSet.as_view(
|
||||||
|
{
|
||||||
|
"post": "archive",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-page-archive",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:page_id>/unarchive/",
|
||||||
|
PageViewSet.as_view(
|
||||||
|
{
|
||||||
|
"post": "unarchive",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-page-unarchive",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/archived-pages/",
|
||||||
|
PageViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "archive_list",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-pages",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:page_id>/lock/",
|
||||||
|
PageViewSet.as_view(
|
||||||
|
{
|
||||||
|
"post": "lock",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-pages",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:page_id>/unlock/",
|
||||||
|
PageViewSet.as_view(
|
||||||
|
{
|
||||||
|
"post": "unlock",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:page_id>/transactions/",
|
||||||
|
PageLogEndpoint.as_view(),
|
||||||
|
name="page-transactions",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:page_id>/transactions/<uuid:transaction>/",
|
||||||
|
PageLogEndpoint.as_view(),
|
||||||
|
name="page-transactions",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:page_id>/sub-pages/",
|
||||||
|
SubPagesEndpoint.as_view(),
|
||||||
|
name="sub-page",
|
||||||
|
),
|
||||||
|
]
|
172
apiserver/plane/app/urls/project.py
Normal file
172
apiserver/plane/app/urls/project.py
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from plane.app.views import (
|
||||||
|
ProjectViewSet,
|
||||||
|
ProjectInvitationsViewset,
|
||||||
|
ProjectMemberViewSet,
|
||||||
|
ProjectMemberUserEndpoint,
|
||||||
|
ProjectJoinEndpoint,
|
||||||
|
AddTeamToProjectEndpoint,
|
||||||
|
ProjectUserViewsEndpoint,
|
||||||
|
ProjectIdentifierEndpoint,
|
||||||
|
ProjectFavoritesViewSet,
|
||||||
|
UserProjectInvitationsViewset,
|
||||||
|
ProjectPublicCoverImagesEndpoint,
|
||||||
|
ProjectDeployBoardViewSet,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/",
|
||||||
|
ProjectViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:pk>/",
|
||||||
|
ProjectViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"put": "update",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/project-identifiers/",
|
||||||
|
ProjectIdentifierEndpoint.as_view(),
|
||||||
|
name="project-identifiers",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/invitations/",
|
||||||
|
ProjectInvitationsViewset.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
name="project-member-invite",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/invitations/<uuid:pk>/",
|
||||||
|
ProjectInvitationsViewset.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-member-invite",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"users/me/invitations/projects/",
|
||||||
|
UserProjectInvitationsViewset.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
name="user-project-invitations",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/join/",
|
||||||
|
ProjectJoinEndpoint.as_view(),
|
||||||
|
name="project-join",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/members/",
|
||||||
|
ProjectMemberViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-member",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/members/<uuid:pk>/",
|
||||||
|
ProjectMemberViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-member",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/members/leave/",
|
||||||
|
ProjectMemberViewSet.as_view(
|
||||||
|
{
|
||||||
|
"post": "leave",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-member",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/team-invite/",
|
||||||
|
AddTeamToProjectEndpoint.as_view(),
|
||||||
|
name="projects",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/project-views/",
|
||||||
|
ProjectUserViewsEndpoint.as_view(),
|
||||||
|
name="project-view",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/project-members/me/",
|
||||||
|
ProjectMemberUserEndpoint.as_view(),
|
||||||
|
name="project-member-view",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/user-favorite-projects/",
|
||||||
|
ProjectFavoritesViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-favorite",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/user-favorite-projects/<uuid:project_id>/",
|
||||||
|
ProjectFavoritesViewSet.as_view(
|
||||||
|
{
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-favorite",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"project-covers/",
|
||||||
|
ProjectPublicCoverImagesEndpoint.as_view(),
|
||||||
|
name="project-covers",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/project-deploy-boards/",
|
||||||
|
ProjectDeployBoardViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-deploy-board",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/project-deploy-boards/<uuid:pk>/",
|
||||||
|
ProjectDeployBoardViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-deploy-board",
|
||||||
|
),
|
||||||
|
]
|
@ -1,7 +1,7 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
from plane.api.views import (
|
from plane.app.views import (
|
||||||
GlobalSearchEndpoint,
|
GlobalSearchEndpoint,
|
||||||
IssueSearchEndpoint,
|
IssueSearchEndpoint,
|
||||||
)
|
)
|
38
apiserver/plane/app/urls/state.py
Normal file
38
apiserver/plane/app/urls/state.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
|
from plane.app.views import StateViewSet
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/states/",
|
||||||
|
StateViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-states",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/states/<uuid:pk>/",
|
||||||
|
StateViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "destroy",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-state",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/states/<uuid:pk>/mark-default/",
|
||||||
|
StateViewSet.as_view(
|
||||||
|
{
|
||||||
|
"post": "mark_as_default",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-state",
|
||||||
|
),
|
||||||
|
]
|
@ -1,6 +1,6 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from plane.api.views import (
|
from plane.app.views import (
|
||||||
## User
|
## User
|
||||||
UserEndpoint,
|
UserEndpoint,
|
||||||
UpdateUserOnBoardedEndpoint,
|
UpdateUserOnBoardedEndpoint,
|
||||||
@ -9,15 +9,10 @@ from plane.api.views import (
|
|||||||
ChangePasswordEndpoint,
|
ChangePasswordEndpoint,
|
||||||
## End User
|
## End User
|
||||||
## Workspaces
|
## Workspaces
|
||||||
UserWorkspaceInvitationsEndpoint,
|
|
||||||
UserWorkSpacesEndpoint,
|
UserWorkSpacesEndpoint,
|
||||||
JoinWorkspaceEndpoint,
|
|
||||||
UserWorkspaceInvitationsEndpoint,
|
|
||||||
UserWorkspaceInvitationEndpoint,
|
|
||||||
UserActivityGraphEndpoint,
|
UserActivityGraphEndpoint,
|
||||||
UserIssueCompletedGraphEndpoint,
|
UserIssueCompletedGraphEndpoint,
|
||||||
UserWorkspaceDashboardEndpoint,
|
UserWorkspaceDashboardEndpoint,
|
||||||
UserProjectInvitationsViewset,
|
|
||||||
## End Workspaces
|
## End Workspaces
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,7 +21,11 @@ urlpatterns = [
|
|||||||
path(
|
path(
|
||||||
"users/me/",
|
"users/me/",
|
||||||
UserEndpoint.as_view(
|
UserEndpoint.as_view(
|
||||||
{"get": "retrieve", "patch": "partial_update", "delete": "destroy"}
|
{
|
||||||
|
"get": "retrieve",
|
||||||
|
"patch": "partial_update",
|
||||||
|
"delete": "deactivate",
|
||||||
|
}
|
||||||
),
|
),
|
||||||
name="users",
|
name="users",
|
||||||
),
|
),
|
||||||
@ -39,6 +38,15 @@ urlpatterns = [
|
|||||||
),
|
),
|
||||||
name="users",
|
name="users",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"users/me/instance-admin/",
|
||||||
|
UserEndpoint.as_view(
|
||||||
|
{
|
||||||
|
"get": "retrieve_instance_admin",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="users",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"users/me/change-password/",
|
"users/me/change-password/",
|
||||||
ChangePasswordEndpoint.as_view(),
|
ChangePasswordEndpoint.as_view(),
|
||||||
@ -65,23 +73,6 @@ urlpatterns = [
|
|||||||
UserWorkSpacesEndpoint.as_view(),
|
UserWorkSpacesEndpoint.as_view(),
|
||||||
name="user-workspace",
|
name="user-workspace",
|
||||||
),
|
),
|
||||||
# user workspace invitations
|
|
||||||
path(
|
|
||||||
"users/me/invitations/workspaces/",
|
|
||||||
UserWorkspaceInvitationsEndpoint.as_view({"get": "list", "post": "create"}),
|
|
||||||
name="user-workspace-invitations",
|
|
||||||
),
|
|
||||||
# user workspace invitation
|
|
||||||
path(
|
|
||||||
"users/me/invitations/<uuid:pk>/",
|
|
||||||
UserWorkspaceInvitationEndpoint.as_view(
|
|
||||||
{
|
|
||||||
"get": "retrieve",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
name="user-workspace-invitation",
|
|
||||||
),
|
|
||||||
# user join workspace
|
|
||||||
# User Graphs
|
# User Graphs
|
||||||
path(
|
path(
|
||||||
"users/me/workspaces/<str:slug>/activity-graph/",
|
"users/me/workspaces/<str:slug>/activity-graph/",
|
||||||
@ -99,15 +90,4 @@ urlpatterns = [
|
|||||||
name="user-workspace-dashboard",
|
name="user-workspace-dashboard",
|
||||||
),
|
),
|
||||||
## End User Graph
|
## End User Graph
|
||||||
path(
|
|
||||||
"users/me/invitations/workspaces/<str:slug>/<uuid:pk>/join/",
|
|
||||||
JoinWorkspaceEndpoint.as_view(),
|
|
||||||
name="user-join-workspace",
|
|
||||||
),
|
|
||||||
# user project invitations
|
|
||||||
path(
|
|
||||||
"users/me/invitations/projects/",
|
|
||||||
UserProjectInvitationsViewset.as_view({"get": "list", "post": "create"}),
|
|
||||||
name="user-project-invitations",
|
|
||||||
),
|
|
||||||
]
|
]
|
@ -1,7 +1,7 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
from plane.api.views import (
|
from plane.app.views import (
|
||||||
IssueViewViewSet,
|
IssueViewViewSet,
|
||||||
GlobalViewViewSet,
|
GlobalViewViewSet,
|
||||||
GlobalViewIssuesViewSet,
|
GlobalViewIssuesViewSet,
|
31
apiserver/plane/app/urls/webhook.py
Normal file
31
apiserver/plane/app/urls/webhook.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from plane.app.views import (
|
||||||
|
WebhookEndpoint,
|
||||||
|
WebhookLogsEndpoint,
|
||||||
|
WebhookSecretRegenerateEndpoint,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/webhooks/",
|
||||||
|
WebhookEndpoint.as_view(),
|
||||||
|
name="webhooks",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/webhooks/<uuid:pk>/",
|
||||||
|
WebhookEndpoint.as_view(),
|
||||||
|
name="webhooks",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/webhooks/<uuid:pk>/regenerate/",
|
||||||
|
WebhookSecretRegenerateEndpoint.as_view(),
|
||||||
|
name="webhooks",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/webhook-logs/<uuid:webhook_id>/",
|
||||||
|
WebhookLogsEndpoint.as_view(),
|
||||||
|
name="webhooks",
|
||||||
|
),
|
||||||
|
]
|
@ -1,9 +1,10 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
from plane.api.views import (
|
from plane.app.views import (
|
||||||
|
UserWorkspaceInvitationsViewSet,
|
||||||
WorkSpaceViewSet,
|
WorkSpaceViewSet,
|
||||||
InviteWorkspaceEndpoint,
|
WorkspaceJoinEndpoint,
|
||||||
WorkSpaceMemberViewSet,
|
WorkSpaceMemberViewSet,
|
||||||
WorkspaceInvitationsViewset,
|
WorkspaceInvitationsViewset,
|
||||||
WorkspaceMemberUserEndpoint,
|
WorkspaceMemberUserEndpoint,
|
||||||
@ -17,7 +18,6 @@ from plane.api.views import (
|
|||||||
WorkspaceUserProfileEndpoint,
|
WorkspaceUserProfileEndpoint,
|
||||||
WorkspaceUserProfileIssuesEndpoint,
|
WorkspaceUserProfileIssuesEndpoint,
|
||||||
WorkspaceLabelsEndpoint,
|
WorkspaceLabelsEndpoint,
|
||||||
LeaveWorkspaceEndpoint,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -49,14 +49,14 @@ urlpatterns = [
|
|||||||
),
|
),
|
||||||
name="workspace",
|
name="workspace",
|
||||||
),
|
),
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/invite/",
|
|
||||||
InviteWorkspaceEndpoint.as_view(),
|
|
||||||
name="invite-workspace",
|
|
||||||
),
|
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/invitations/",
|
"workspaces/<str:slug>/invitations/",
|
||||||
WorkspaceInvitationsViewset.as_view({"get": "list"}),
|
WorkspaceInvitationsViewset.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
},
|
||||||
|
),
|
||||||
name="workspace-invitations",
|
name="workspace-invitations",
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
@ -69,6 +69,23 @@ urlpatterns = [
|
|||||||
),
|
),
|
||||||
name="workspace-invitations",
|
name="workspace-invitations",
|
||||||
),
|
),
|
||||||
|
# user workspace invitations
|
||||||
|
path(
|
||||||
|
"users/me/workspaces/invitations/",
|
||||||
|
UserWorkspaceInvitationsViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
name="user-workspace-invitations",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/invitations/<uuid:pk>/join/",
|
||||||
|
WorkspaceJoinEndpoint.as_view(),
|
||||||
|
name="workspace-join",
|
||||||
|
),
|
||||||
|
# user join workspace
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/members/",
|
"workspaces/<str:slug>/members/",
|
||||||
WorkSpaceMemberViewSet.as_view({"get": "list"}),
|
WorkSpaceMemberViewSet.as_view({"get": "list"}),
|
||||||
@ -85,6 +102,15 @@ urlpatterns = [
|
|||||||
),
|
),
|
||||||
name="workspace-member",
|
name="workspace-member",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/members/leave/",
|
||||||
|
WorkSpaceMemberViewSet.as_view(
|
||||||
|
{
|
||||||
|
"post": "leave",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
name="leave-workspace-members",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/teams/",
|
"workspaces/<str:slug>/teams/",
|
||||||
TeamMemberViewSet.as_view(
|
TeamMemberViewSet.as_view(
|
||||||
@ -168,9 +194,4 @@ urlpatterns = [
|
|||||||
WorkspaceLabelsEndpoint.as_view(),
|
WorkspaceLabelsEndpoint.as_view(),
|
||||||
name="workspace-labels",
|
name="workspace-labels",
|
||||||
),
|
),
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/members/leave/",
|
|
||||||
LeaveWorkspaceEndpoint.as_view(),
|
|
||||||
name="leave-workspace-members",
|
|
||||||
),
|
|
||||||
]
|
]
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user