diff --git a/apps/app/.eslintrc.json b/.eslintrc.json similarity index 100% rename from apps/app/.eslintrc.json rename to .eslintrc.json diff --git a/.github/workflows/test_runner.yml b/.github/workflows/test_runner.yml deleted file mode 100644 index 5780c9f63de..00000000000 --- a/.github/workflows/test_runner.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Plane Tests - -on: - push: - pull_request: - branches: - - master - -jobs: - test: - runs-on: ubuntu-latest - - services: - postgres: - image: postgres:latest - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: github_actions - ports: - - 5432:5432 - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 - - redis: - image: redis:latest - env: - REDIS_HOST: localhost - REDIS_PORT: 6379 - ports: - - 6379:6379 - options: --health-cmd "redis-cli ping" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - - steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.9 - uses: actions/setup-python@v4 - with: - python-version: 3.9 - - name: psycopg2 prerequisites - run: sudo apt-get install libpq-dev - - name: Install dependencies - working-directory: ./apiserver - run: | - python -m pip install --upgrade pip - pip install -r requirements/test.txt - - name: Run Tests - working-directory: ./apiserver - env: - SECRET_KEY: ${{ secrets.SECRET_KEY }} - run: coverage run --source='.' manage.py test --settings=plane.settings.test diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000000..294dc1c0eb9 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +hello@plane.so. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000000..75ccb884c29 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,59 @@ +# Contributing to Plane + +Thank you for showing an interest in contributing to Plane! All kinds of contributions are valuable to us. In this guide, we will cover how you can quickly onboard and make your first contribution. + +## Submitting an issue + +Before submitting a new issue, please search the [issues](https://github.com/makeplane/plane/issues) tab. Maybe an issue or discussion already exists and might inform you of workarounds. Otherwise, you can give new informplaneation. + +While we want to fix all the [issues](https://github.com/makeplane/plane/issues), before fixing a bug we need to be able to reproduce and confirm it. Please provide us with a minimal reproduction scenario using a repository or [Gist](https://gist.github.com/). Having a live, reproducible scenario gives us the information without asking questions back & forth with additional questions like: + +- 3rd-party libraries being used and their versions +- a use-case that fails + +Without said minimal reproduction, we won't be able to investigate all [issues](https://github.com/makeplane/plane/issues), and the issue might not be resolved. + +You can open a new issue with this [issue form](https://github.com/makeplane/plane/issues/new). + +## Projects setup and Architecture + +### Requirements + +- Node.js version v16.18.0 +- Python version 3.8+ +- Postgres version v14 +- Redis version v6.2.7 +- pnpm version 7.22.0 + +### Setup the project + +The project is a monorepo, with backend api and frontend in a single repo. + +The backend is a django project which is kept inside apiserver + +## Missing a Feature? + +If a feature is missing, you can directly _request_ a new one [here](https://github.com/makeplane/plane/issues/new?assignees=&labels=feature&template=feature_request.yml&title=%F0%9F%9A%80+Feature%3A+). You also can do the same by choosing "🚀 Feature" when raising a [New Issue](https://github.com/makeplane/plane/issues/new/choose) on our GitHub Repository. +If you would like to _implement_ it, an issue with your proposal must be submitted first, to be sure that we can use it. Please consider the guidelines given below. + +## Coding guidelines + +To ensure consistency throughout the source code, please keep these rules in mind as you are working: + +- All features or bug fixes must be tested by one or more specs (unit-tests). +- We use [Eslint default rule guide](https://eslint.org/docs/rules/), with minor changes. An automated formatter is available using prettier. + +## Need help? Questions and suggestions + +Questions, suggestions, and thoughts are most welcome. We can also be reached in our [Discord Server](https://discord.com/invite/A92xrEGCge). + +## Ways to contribute + +- Try Plane Cloud and the self hosting platform and give feedback +- Add new integrations +- Help with open [issues](https://github.com/makeplane/plane/issues) or [create your own](https://github.com/makeplane/plane/issues/new/choose) +- Share your thoughts and suggestions with us +- Help create tutorials and blog posts +- Request a feature by submitting a proposal +- Report a bug +- **Improve documentation** - fix incomplete or missing [docs](https://docs.plane.so/), bad wording, examples or explanations. diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index abb8505cd70..00000000000 --- a/Dockerfile +++ /dev/null @@ -1,138 +0,0 @@ -FROM node:18-alpine AS builder -RUN apk add --no-cache libc6-compat -RUN apk update -# Set working directory -WORKDIR /app - -RUN apk add curl - -COPY ./apps ./apps -COPY ./package.json ./package.json -COPY ./.eslintrc.json ./.eslintrc.json -COPY ./yarn.lock ./yarn.lock - -RUN yarn global add turbo -RUN turbo prune --scope=app --docker - -# Add lockfile and package.json's of isolated subworkspace -FROM node:18-alpine AS installer - -RUN apk add --no-cache libc6-compat -RUN apk update -WORKDIR /app - -# First install the dependencies (as they change less often) -COPY .gitignore .gitignore -COPY --from=builder /app/out/json/ . -COPY --from=builder /app/out/yarn.lock ./yarn.lock -RUN yarn install - -# Build the project -COPY --from=builder /app/out/full/ . -COPY turbo.json turbo.json - -RUN yarn turbo run build --filter=app... - -FROM python:3.8.14-alpine3.16 AS runner - -ENV SECRET_KEY ${SECRET_KEY} -ENV DATABASE_URL ${DATABASE_URL} -ENV REDIS_URL ${REDIS_URL} -ENV EMAIL_HOST ${EMAIL_HOST} -ENV EMAIL_HOST_USER ${EMAIL_HOST_USER} -ENV EMAIL_HOST_PASSWORD ${EMAIL_HOST_PASSWORD} - -ENV AWS_REGION ${AWS_REGION} -ENV AWS_ACCESS_KEY_ID ${AWS_ACCESS_KEY_ID} -ENV AWS_SECRET_ACCESS_KEY ${AWS_SECRET_ACCESS_KEY} -ENV AWS_S3_BUCKET_NAME ${AWS_S3_BUCKET_NAME} - - -ENV SENTRY_DSN ${SENTRY_DSN} -ENV WEB_URL ${WEB_URL} - -ENV DISABLE_COLLECTSTATIC ${DISABLE_COLLECTSTATIC} - -ENV GITHUB_CLIENT_SECRET ${GITHUB_CLIENT_SECRET} -ENV NEXT_PUBLIC_GITHUB_ID ${NEXT_PUBLIC_GITHUB_ID} -ENV NEXT_PUBLIC_GOOGLE_CLIENTID ${NEXT_PUBLIC_GOOGLE_CLIENTID} -ENV NEXT_PUBLIC_API_BASE_URL ${NEXT_PUBLIC_API_BASE_URL} - -# Frontend - -RUN apk --update --no-cache add \ - "libpq~=14" \ - "libxslt~=1.1" \ - "nodejs-current~=18" \ - "xmlsec~=1.2" - -WORKDIR /app - -# Don't run production as root -RUN addgroup -S plane && \ - adduser -S captain -G plane - -USER captain - -COPY --from=installer /app/apps/app/next.config.js . -COPY --from=installer /app/apps/app/package.json . - -# Automatically leverage output traces to reduce image size -# https://nextjs.org/docs/advanced-features/output-file-tracing -COPY --from=installer --chown=captain:plane /app/apps/app/.next/standalone ./ -COPY --from=installer --chown=captain:plane /app/apps/app/.next/static ./apps/app/.next/static - -EXPOSE 3000 - -# Backend - -USER root - - -ENV PYTHONDONTWRITEBYTECODE 1 -ENV PYTHONUNBUFFERED 1 -ENV PIP_DISABLE_PIP_VERSION_CHECK=1 - - -COPY ./apiserver/requirements.txt ./ -COPY ./apiserver/requirements ./requirements -RUN apk add libffi-dev -RUN apk --update --no-cache --virtual .build-deps add \ - "bash~=5.1" \ - "g++~=11.2" \ - "gcc~=11.2" \ - "cargo~=1.60" \ - "git~=2" \ - "make~=4.3" \ - "postgresql13-dev~=13" \ - "libc-dev" \ - "linux-headers" \ - && \ - pip install -r requirements.txt --compile --no-cache-dir \ - && \ - apk del .build-deps - - -RUN chown captain.plane /app - -# Add in Django deps and generate Django's static files -COPY ./apiserver/manage.py manage.py -COPY ./apiserver/plane plane/ -COPY ./apiserver/templates templates/ - -COPY ./apiserver/gunicorn.config.py ./ -USER root -RUN apk --update --no-cache add "bash~=5.1" -COPY ./bin ./bin/ -USER captain - -# Expose container port and run entry point script -EXPOSE 8000 - -USER root - -RUN apk --update add supervisor - -ADD /supervisor /src/supervisor - -CMD ["supervisord","-c","/src/supervisor/service_script.conf"] \ No newline at end of file diff --git a/apiserver/.env.example b/apiserver/.env.example new file mode 100644 index 00000000000..0595770fa7a --- /dev/null +++ b/apiserver/.env.example @@ -0,0 +1,18 @@ +# Backend +SECRET_KEY="<-- django secret -->" +EMAIL_HOST="<-- email smtp -->" +EMAIL_HOST_USER="<-- email host user -->" +EMAIL_HOST_PASSWORD="<-- email host password -->" + +AWS_REGION="<-- aws region -->" +AWS_ACCESS_KEY_ID="<-- aws access key -->" +AWS_SECRET_ACCESS_KEY="<-- aws secret acess key -->" +AWS_S3_BUCKET_NAME="<-- aws s3 bucket name -->" + +SENTRY_DSN="<-- sentry dsn -->" +WEB_URL="<-- frontend web url -->" + +GITHUB_CLIENT_SECRET="<-- github secret -->" + +DISABLE_COLLECTSTATIC=1 +DOCKERIZED=0 //True if running docker compose else 0 diff --git a/apiserver/Dockerfile.api b/apiserver/Dockerfile.api index f2aa59e51c2..e39f91f6f67 100644 --- a/apiserver/Dockerfile.api +++ b/apiserver/Dockerfile.api @@ -48,6 +48,9 @@ COPY gunicorn.config.py ./ USER root RUN apk --update --no-cache add "bash~=5.1" COPY ./bin ./bin/ + +RUN chmod +x ./bin/channel-worker ./bin/takeoff ./bin/worker + USER captain # Expose container port and run entry point script diff --git a/apiserver/Procfile b/apiserver/Procfile index f5b7e7897ae..026a3f95342 100644 --- a/apiserver/Procfile +++ b/apiserver/Procfile @@ -1,2 +1,3 @@ -web: gunicorn plane.wsgi -k gthread --workers 8 --bind 0.0.0.0:$PORT --config gunicorn.config.py --max-requests 10000 --max-requests-jitter 1000 --access-logfile - -worker: python manage.py rqworker \ No newline at end of file +web: gunicorn -w 4 -k uvicorn.workers.UvicornWorker plane.asgi:application --bind 0.0.0.0:$PORT --config gunicorn.config.py --max-requests 10000 --max-requests-jitter 1000 --access-logfile - +worker: python manage.py rqworker +channel-worker: python manage.py runworker issue-activites \ No newline at end of file diff --git a/apiserver/back_migration.py b/apiserver/back_migration.py new file mode 100644 index 00000000000..98f1947532c --- /dev/null +++ b/apiserver/back_migration.py @@ -0,0 +1,42 @@ +# All the python scripts that are used for back migrations + +from plane.db.models import Issue, IssueComment + +# Update description and description html values for old descriptions +def update_description(): + try: + + issues = Issue.objects.all() + updated_issues = [] + + for issue in issues: + issue.description_html = f"
{issue.description}
" + issue.description_stripped = issue.description + updated_issues.append(issue) + + Issue.objects.bulk_update( + updated_issues, ["description_html", "description_stripped"], batch_size=100 + ) + print("Success") + except Exception as e: + print(e) + print("Failed") + + +def update_comments(): + try: + + issue_comments = IssueComment.objects.all() + updated_issue_comments = [] + + for issue_comment in issue_comments: + issue_comment.comment_html = f"{issue_comment.comment_stripped}
" + updated_issue_comments.append(issue_comment) + + Issue.objects.bulk_update( + updated_issue_comments, ["comment_html"], batch_size=100 + ) + print("Success") + except Exception as e: + print(e) + print("Failed") diff --git a/apiserver/bin/channel-worker b/apiserver/bin/channel-worker new file mode 100755 index 00000000000..90ba63d5030 --- /dev/null +++ b/apiserver/bin/channel-worker @@ -0,0 +1,6 @@ +#!/bin/bash +set -e + +python manage.py wait_for_db +python manage.py migrate +python manage.py runworker issue-activites \ No newline at end of file diff --git a/apiserver/bin/takeoff b/apiserver/bin/takeoff index b76a9fd3b4c..8340f16c704 100755 --- a/apiserver/bin/takeoff +++ b/apiserver/bin/takeoff @@ -2,4 +2,4 @@ set -e python manage.py wait_for_db python manage.py migrate -exec gunicorn plane.wsgi -k gthread --workers 8 --bind 0.0.0.0:8000 --config gunicorn.config.py --max-requests 10000 --max-requests-jitter 1000 --access-logfile - +exec gunicorn -w 8 -k uvicorn.workers.UvicornWorker plane.asgi:application --bind 0.0.0.0:8000 --config gunicorn.config.py --max-requests 1200 --max-requests-jitter 1000 --access-logfile - diff --git a/apiserver/plane/api/consumers/__init__.py b/apiserver/plane/api/consumers/__init__.py new file mode 100644 index 00000000000..cbf41cdfaee --- /dev/null +++ b/apiserver/plane/api/consumers/__init__.py @@ -0,0 +1 @@ +from .issue_consumer import IssueConsumer \ No newline at end of file diff --git a/apiserver/plane/api/consumers/issue_consumer.py b/apiserver/plane/api/consumers/issue_consumer.py new file mode 100644 index 00000000000..38eb69967a7 --- /dev/null +++ b/apiserver/plane/api/consumers/issue_consumer.py @@ -0,0 +1,547 @@ +from channels.generic.websocket import SyncConsumer +import json +from plane.db.models import IssueActivity, Project, User, Issue, State, Label + + +class IssueConsumer(SyncConsumer): + + # Track Chnages in name + def track_name( + self, + requested_data, + current_instance, + issue_id, + project, + actor, + issue_activities, + ): + if current_instance.get("name") != requested_data.get("name"): + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value=current_instance.get("name"), + new_value=requested_data.get("name"), + field="name", + project=project, + workspace=project.workspace, + comment=f"{actor.email} updated the start date to {requested_data.get('name')}", + ) + ) + + # Track changes in parent issue + def track_parent( + self, + requested_data, + current_instance, + issue_id, + project, + actor, + issue_activities, + ): + if current_instance.get("parent") != requested_data.get("parent"): + + if requested_data.get("parent") == None: + old_parent = Issue.objects.get(pk=current_instance.get("parent")) + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value=f"{project.identifier}-{old_parent.sequence_id}", + new_value=None, + field="parent", + project=project, + workspace=project.workspace, + comment=f"{actor.email} updated the parent issue to None", + old_identifier=old_parent.id, + new_identifier=None, + ) + ) + else: + new_parent = Issue.objects.get(pk=requested_data.get("parent")) + old_parent = Issue.objects.filter( + pk=current_instance.get("parent") + ).first() + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value=f"{project.identifier}-{old_parent.sequence_id}" + if old_parent is not None + else None, + new_value=f"{project.identifier}-{new_parent.sequence_id}", + field="parent", + project=project, + workspace=project.workspace, + comment=f"{actor.email} updated the parent issue to {new_parent.name}", + old_identifier=old_parent.id + if old_parent is not None + else None, + new_identifier=new_parent.id, + ) + ) + + # Track changes in priority + def track_priority( + self, + requested_data, + current_instance, + issue_id, + project, + actor, + issue_activities, + ): + if current_instance.get("priority") != requested_data.get("priority"): + if requested_data.get("priority") == None: + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value=current_instance.get("parent"), + new_value=requested_data.get("parent"), + field="priority", + project=project, + workspace=project.workspace, + comment=f"{actor.email} updated the priority to None", + ) + ) + else: + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value=current_instance.get("priority"), + new_value=requested_data.get("priority"), + field="priority", + project=project, + workspace=project.workspace, + comment=f"{actor.email} updated the priority to {requested_data.get('priority')}", + ) + ) + + # Track chnages in state of the issue + def track_state( + self, + requested_data, + current_instance, + issue_id, + project, + actor, + issue_activities, + ): + if current_instance.get("state") != requested_data.get("state"): + + new_state = State.objects.get(pk=requested_data.get("state", None)) + old_state = State.objects.get(pk=current_instance.get("state", None)) + + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value=old_state.name, + new_value=new_state.name, + field="state", + project=project, + workspace=project.workspace, + comment=f"{actor.email} updated the state to {new_state.name}", + old_identifier=old_state.id, + new_identifier=new_state.id, + ) + ) + + # Track issue description + def track_description( + self, + requested_data, + current_instance, + issue_id, + project, + actor, + issue_activities, + ): + if current_instance.get("description_html") != requested_data.get("description_html"): + + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value=current_instance.get("description_html"), + new_value=requested_data.get("description_html"), + field="description", + project=project, + workspace=project.workspace, + comment=f"{actor.email} updated the description to {requested_data.get('description_html')}", + ) + ) + + # Track changes in issue target date + def track_target_date( + self, + requested_data, + current_instance, + issue_id, + project, + actor, + issue_activities, + ): + if current_instance.get("target_date") != requested_data.get("target_date"): + if requested_data.get("target_date") == None: + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value=current_instance.get("target_date"), + new_value=requested_data.get("target_date"), + field="target_date", + project=project, + workspace=project.workspace, + comment=f"{actor.email} updated the target date to None", + ) + ) + else: + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value=current_instance.get("target_date"), + new_value=requested_data.get("target_date"), + field="target_date", + project=project, + workspace=project.workspace, + comment=f"{actor.email} updated the target date to {requested_data.get('target_date')}", + ) + ) + + # Track changes in issue start date + def track_start_date( + self, + requested_data, + current_instance, + issue_id, + project, + actor, + issue_activities, + ): + if current_instance.get("start_date") != requested_data.get("start_date"): + if requested_data.get("start_date") == None: + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value=current_instance.get("start_date"), + new_value=requested_data.get("start_date"), + field="start_date", + project=project, + workspace=project.workspace, + comment=f"{actor.email} updated the start date to None", + ) + ) + else: + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value=current_instance.get("start_date"), + new_value=requested_data.get("start_date"), + field="start_date", + project=project, + workspace=project.workspace, + comment=f"{actor.email} updated the start date to {requested_data.get('start_date')}", + ) + ) + + # Track changes in issue labels + def track_labels( + self, + requested_data, + current_instance, + issue_id, + project, + actor, + issue_activities, + ): + # Label Addition + if len(requested_data.get("labels_list")) > len(current_instance.get("labels")): + + for label in requested_data.get("labels_list"): + if label not in current_instance.get("labels"): + label = Label.objects.get(pk=label) + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value="", + new_value=label.name, + field="labels", + project=project, + workspace=project.workspace, + comment=f"{actor.email} added label {label.name}", + new_identifier=label.id, + old_identifier=None, + ) + ) + + # Label Removal + if len(requested_data.get("labels_list")) < len(current_instance.get("labels")): + + for label in current_instance.get("labels"): + if label not in requested_data.get("labels_list"): + label = Label.objects.get(pk=label) + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value=label.name, + new_value="", + field="labels", + project=project, + workspace=project.workspace, + comment=f"{actor.email} removed label {label.name}", + old_identifier=label.id, + new_identifier=None, + ) + ) + + # Track changes in issue assignees + def track_assignees( + self, + requested_data, + current_instance, + issue_id, + project, + actor, + issue_activities, + ): + + # Assignee Addition + if len(requested_data.get("assignees_list")) > len( + current_instance.get("assignees") + ): + + for assignee in requested_data.get("assignees_list"): + if assignee not in current_instance.get("assignees"): + assignee = User.objects.get(pk=assignee) + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value="", + new_value=assignee.email, + field="assignees", + project=project, + workspace=project.workspace, + comment=f"{actor.email} added assignee {assignee.email}", + new_identifier=actor.id, + ) + ) + + # Assignee Removal + if len(requested_data.get("assignees_list")) < len( + current_instance.get("assignees") + ): + + for assignee in current_instance.get("assignees"): + if assignee not in requested_data.get("assignees_list"): + assignee = User.objects.get(pk=assignee) + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value=assignee.email, + new_value="", + field="assignee", + project=project, + workspace=project.workspace, + comment=f"{actor.email} removed assignee {assignee.email}", + old_identifier=actor.id, + ) + ) + + # Track changes in blocking issues + def track_blocks( + self, + requested_data, + current_instance, + issue_id, + project, + actor, + issue_activities, + ): + if len(requested_data.get("blocks_list")) > len( + current_instance.get("blocked_issues") + ): + + for block in requested_data.get("blocks_list"): + if ( + len( + [ + blocked + for blocked in current_instance.get("blocked_issues") + if blocked.get("block") == block + ] + ) + == 0 + ): + issue = Issue.objects.get(pk=block) + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value="", + new_value=f"{project.identifier}-{issue.sequence_id}", + field="blocks", + project=project, + workspace=project.workspace, + comment=f"{actor.email} added blocking issue {project.identifier}-{issue.sequence_id}", + new_identifier=issue.id, + ) + ) + + # Blocked Issue Removal + if len(requested_data.get("blocks_list")) < len( + current_instance.get("blocked_issues") + ): + + for blocked in current_instance.get("blocked_issues"): + if blocked.get("block") not in requested_data.get("blocks_list"): + issue = Issue.objects.get(pk=blocked.get("block")) + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value=f"{project.identifier}-{issue.sequence_id}", + new_value="", + field="blocks", + project=project, + workspace=project.workspace, + comment=f"{actor.email} removed blocking issue {project.identifier}-{issue.sequence_id}", + old_identifier=issue.id, + ) + ) + + # Track changes in blocked_by issues + def track_blockings( + self, + requested_data, + current_instance, + issue_id, + project, + actor, + issue_activities, + ): + if len(requested_data.get("blockers_list")) > len( + current_instance.get("blocker_issues") + ): + + for block in requested_data.get("blockers_list"): + if ( + len( + [ + blocked + for blocked in current_instance.get("blocker_issues") + if blocked.get("blocked_by") == block + ] + ) + == 0 + ): + issue = Issue.objects.get(pk=block) + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value="", + new_value=f"{project.identifier}-{issue.sequence_id}", + field="blocking", + project=project, + workspace=project.workspace, + comment=f"{actor.email} added blocked by issue {project.identifier}-{issue.sequence_id}", + new_identifier=issue.id, + ) + ) + + # Blocked Issue Removal + if len(requested_data.get("blockers_list")) < len( + current_instance.get("blocker_issues") + ): + + for blocked in current_instance.get("blocker_issues"): + if blocked.get("blocked_by") not in requested_data.get("blockers_list"): + issue = Issue.objects.get(pk=blocked.get("blocked_by")) + issue_activities.append( + IssueActivity( + issue_id=issue_id, + actor=actor, + verb="updated", + old_value=f"{project.identifier}-{issue.sequence_id}", + new_value="", + field="blocking", + project=project, + workspace=project.workspace, + comment=f"{actor.email} removed blocked by issue {project.identifier}-{issue.sequence_id}", + old_identifier=issue.id, + ) + ) + + # Receive message from room group + def issue_activity(self, event): + + issue_activities = [] + # Remove event type: + event.pop("type") + + requested_data = json.loads(event.get("requested_data")) + current_instance = json.loads(event.get("current_instance")) + issue_id = event.get("issue_id") + actor_id = event.get("actor_id") + project_id = event.get("project_id") + + actor = User.objects.get(pk=actor_id) + + project = Project.objects.get(pk=project_id) + + ISSUE_ACTIVITY_MAPPER = { + "name": self.track_name, + "parent": self.track_parent, + "priority": self.track_priority, + "state": self.track_state, + "description": self.track_description, + "target_date": self.track_target_date, + "start_date": self.track_start_date, + "labels_list": self.track_labels, + "assignees_list": self.track_assignees, + "blocks_list": self.track_blocks, + "blockers_list": self.track_blockings, + } + + for key in requested_data: + func = ISSUE_ACTIVITY_MAPPER.get(key, None) + if func is not None: + func( + requested_data, + current_instance, + issue_id, + project, + actor, + issue_activities, + ) + + # Save all the values to database + IssueActivity.objects.bulk_create(issue_activities) diff --git a/apiserver/plane/api/serializers/issue.py b/apiserver/plane/api/serializers/issue.py index 06795fd772b..569eef88c71 100644 --- a/apiserver/plane/api/serializers/issue.py +++ b/apiserver/plane/api/serializers/issue.py @@ -47,6 +47,7 @@ class Meta: class IssueStateSerializer(BaseSerializer): state_detail = StateSerializer(read_only=True, source="state") + project_detail = ProjectSerializer(read_only=True, source="project") class Meta: model = Issue @@ -67,6 +68,8 @@ class IssueCreateSerializer(BaseSerializer): write_only=True, required=False, ) + + # List of issues that are blocking this issue blockers_list = serializers.ListField( child=serializers.PrimaryKeyRelatedField(queryset=Issue.objects.all()), write_only=True, @@ -77,6 +80,8 @@ class IssueCreateSerializer(BaseSerializer): write_only=True, required=False, ) + + # List of issues that are blocked by this issue blocks_list = serializers.ListField( child=serializers.PrimaryKeyRelatedField(queryset=Issue.objects.all()), write_only=True, @@ -421,10 +426,12 @@ class IssueSerializer(BaseSerializer): parent_detail = IssueFlatSerializer(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) + # List of issues blocked by this issue blocked_issues = BlockedIssueSerializer(read_only=True, many=True) + # List of issues that block this issue blocker_issues = BlockerIssueSerializer(read_only=True, many=True) issue_cycle = IssueCycleDetailSerializer(read_only=True) - issue_module = IssueModuleDetailSerializer(read_only=True, many=True) + issue_module = IssueModuleDetailSerializer(read_only=True) class Meta: model = Issue diff --git a/apiserver/plane/api/serializers/module.py b/apiserver/plane/api/serializers/module.py index 989802c8b50..1d3748f8d6f 100644 --- a/apiserver/plane/api/serializers/module.py +++ b/apiserver/plane/api/serializers/module.py @@ -7,7 +7,13 @@ from .project import ProjectSerializer from .issue import IssueStateSerializer -from plane.db.models import User, Module, ModuleMember, ModuleIssue +from plane.db.models import User, Module, ModuleMember, ModuleIssue, ModuleLink + + +class LinkCreateSerializer(serializers.Serializer): + + url = serializers.CharField(required=True) + title = serializers.CharField(required=False) class ModuleWriteSerializer(BaseSerializer): @@ -17,6 +23,11 @@ class ModuleWriteSerializer(BaseSerializer): write_only=True, required=False, ) + links_list = serializers.ListField( + child=LinkCreateSerializer(), + write_only=True, + required=False, + ) class Meta: model = Module @@ -33,6 +44,7 @@ class Meta: def create(self, validated_data): members = validated_data.pop("members_list", None) + links = validated_data.pop("links_list", None) project = self.context["project"] @@ -55,11 +67,31 @@ def create(self, validated_data): ignore_conflicts=True, ) + if links is not None: + ModuleLink.objects.bulk_create( + [ + ModuleLink( + module=module, + project=project, + workspace=project.workspace, + created_by=module.created_by, + updated_by=module.updated_by, + title=link.get("title", None), + url=link.get("url", None), + ) + for link in links + ], + batch_size=10, + ignore_conflicts=True, + ) + return module def update(self, instance, validated_data): members = validated_data.pop("members_list", None) + links = validated_data.pop("links_list", None) + if members is not None: ModuleIssue.objects.filter(module=instance).delete() ModuleMember.objects.bulk_create( @@ -75,7 +107,26 @@ def update(self, instance, validated_data): for member in members ], batch_size=10, - ignore_conflicts=True + ignore_conflicts=True, + ) + + if links is not None: + ModuleLink.objects.filter(module=instance).delete() + ModuleLink.objects.bulk_create( + [ + ModuleLink( + module=instance, + project=instance.project, + workspace=instance.project.workspace, + created_by=instance.created_by, + updated_by=instance.updated_by, + title=link.get("title", None), + url=link.get("url", None), + ) + for link in links + ], + batch_size=10, + ignore_conflicts=True, ) return super().update(instance, validated_data) @@ -114,12 +165,30 @@ class Meta: ] +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", + ] + + class ModuleSerializer(BaseSerializer): project_detail = ProjectSerializer(read_only=True, source="project") lead_detail = UserLiteSerializer(read_only=True, source="lead") members_detail = UserLiteSerializer(read_only=True, many=True, source="members") - module_issues = ModuleIssueSerializer(read_only=True, many=True) + issue_module = ModuleIssueSerializer(read_only=True, many=True) + link_module = ModuleLinkSerializer(read_only=True, many=True) class Meta: model = Module @@ -131,4 +200,4 @@ class Meta: "updated_by", "created_at", "updated_at", - ] + ] \ No newline at end of file diff --git a/apiserver/plane/api/serializers/workspace.py b/apiserver/plane/api/serializers/workspace.py index 15f9b1dbf26..fe180bbd82b 100644 --- a/apiserver/plane/api/serializers/workspace.py +++ b/apiserver/plane/api/serializers/workspace.py @@ -18,18 +18,12 @@ class Meta: fields = "__all__" read_only_fields = [ "id", - "slug", "created_by", "updated_by", "created_at", "updated_at", "owner", ] - extra_kwargs = { - "slug": { - "required": False, - }, - } class WorkSpaceMemberSerializer(BaseSerializer): diff --git a/apiserver/plane/api/urls.py b/apiserver/plane/api/urls.py index b04f9dc3a39..872f5953f7c 100644 --- a/apiserver/plane/api/urls.py +++ b/apiserver/plane/api/urls.py @@ -58,6 +58,9 @@ UserLastProjectWithWorkspaceEndpoint, UserWorkSpaceIssues, ProjectMemberUserEndpoint, + WorkspaceMemberUserEndpoint, + WorkspaceMemberUserViewsEndpoint, + WorkSpaceAvailabilityCheckEndpoint, ) from plane.api.views.project import AddTeamToProjectEndpoint @@ -147,6 +150,11 @@ name="user-project-invitaions", ), ## Workspaces ## + path( + "workspace-slug-check/", + WorkSpaceAvailabilityCheckEndpoint.as_view(), + name="workspace-availability", + ), path( "workspaces/", WorkSpaceViewSet.as_view( @@ -234,6 +242,16 @@ UserLastProjectWithWorkspaceEndpoint.as_view(), name="workspace-project-details", ), + path( + "workspaces/
- Login,
- Welcome! Login with the link below
- {{magic_url}}
or enter the code.
- {{code}}
-
-
+
|
+
|