From 2aee62761611ccb7bb17843e6036ba3a309a568d Mon Sep 17 00:00:00 2001 From: pablohashescobar Date: Wed, 15 Nov 2023 17:54:33 +0530 Subject: [PATCH 1/3] dev: remove deprecated variables --- .env.example | 9 ++------- Dockerfile | 1 - ENV_SETUP.md | 7 +++---- apiserver/.env.example | 6 ------ apiserver/plane/api/urls/__init__.py | 8 ++------ apiserver/plane/api/views/base.py | 1 - apiserver/plane/settings/common.py | 16 +++++----------- apiserver/plane/urls.py | 3 +-- deploy/selfhost/docker-compose.yml | 8 ++------ deploy/selfhost/variables.env | 6 +----- 10 files changed, 16 insertions(+), 49 deletions(-) diff --git a/.env.example b/.env.example index b98adf171..44bf9ecd6 100644 --- a/.env.example +++ b/.env.example @@ -26,15 +26,10 @@ OPENAI_API_KEY="sk-" # add your openai key here GPT_ENGINE="gpt-3.5-turbo" # use "gpt-4" if you have access # Settings related to Docker -DOCKERIZED=1 +DOCKERIZED=1 # deprecated + # set to 1 If using the pre-configured minio setup USE_MINIO=1 # Nginx Configuration NGINX_PORT=80 - -# Set it to 0, to disable it -ENABLE_WEBHOOK=1 - -# Set it to 0, to disable it -ENABLE_API=1 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 388c5a4ef..880b9ee56 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,7 +44,6 @@ ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 ENV PIP_DISABLE_PIP_VERSION_CHECK=1 ENV DJANGO_SETTINGS_MODULE plane.settings.production -ENV DOCKERIZED 1 WORKDIR /code diff --git a/ENV_SETUP.md b/ENV_SETUP.md index 23faf83f7..0dd6c4373 100644 --- a/ENV_SETUP.md +++ b/ENV_SETUP.md @@ -35,8 +35,6 @@ OPENAI_API_BASE="https://api.openai.com/v1" # change if using a custom endpoint OPENAI_API_KEY="sk-" # add your openai key here GPT_ENGINE="gpt-3.5-turbo" # use "gpt-4" if you have access ​ -# Settings related to Docker -DOCKERIZED=1 # set to 1 If using the pre-configured minio setup USE_MINIO=1 ​ @@ -119,11 +117,12 @@ OPENAI_API_BASE="https://api.openai.com/v1" # change if using a custom endpoint OPENAI_API_KEY="sk-" # add your openai key here GPT_ENGINE="gpt-3.5-turbo" # use "gpt-4" if you have access ​ +# Settings related to Docker +DOCKERIZED=1 # Deprecated + # Github GITHUB_CLIENT_SECRET="" # For fetching release notes ​ -# Settings related to Docker -DOCKERIZED=1 # set to 1 If using the pre-configured minio setup USE_MINIO=1 ​ diff --git a/apiserver/.env.example b/apiserver/.env.example index d0b4013a8..cc4c7d47f 100644 --- a/apiserver/.env.example +++ b/apiserver/.env.example @@ -70,12 +70,6 @@ ENABLE_MAGIC_LINK_LOGIN="0" # Email redirections and minio domain settings WEB_URL="http://localhost" -# Set it to 0, to disable it -ENABLE_WEBHOOK=1 - -# Set it to 0, to disable it -ENABLE_API=1 - # Gunicorn Workers GUNICORN_WORKERS=2 diff --git a/apiserver/plane/api/urls/__init__.py b/apiserver/plane/api/urls/__init__.py index 1e3c1cbca..e6088cb14 100644 --- a/apiserver/plane/api/urls/__init__.py +++ b/apiserver/plane/api/urls/__init__.py @@ -49,10 +49,6 @@ urlpatterns = [ *user_urls, *view_urls, *workspace_urls, + *api_urls, + *webhook_urls, ] - -if settings.ENABLE_WEBHOOK: - urlpatterns += webhook_urls - -if settings.ENABLE_API: - urlpatterns += api_urls diff --git a/apiserver/plane/api/views/base.py b/apiserver/plane/api/views/base.py index 71f9c1842..de7bafd57 100644 --- a/apiserver/plane/api/views/base.py +++ b/apiserver/plane/api/views/base.py @@ -51,7 +51,6 @@ class WebhookMixin: self.webhook_event and self.request.method in ["POST", "PATCH", "DELETE"] and response.status_code in [200, 201, 204] - and settings.ENABLE_WEBHOOK ): send_webhook.delay( event=self.webhook_event, diff --git a/apiserver/plane/settings/common.py b/apiserver/plane/settings/common.py index 74bf59be3..b55293297 100644 --- a/apiserver/plane/settings/common.py +++ b/apiserver/plane/settings/common.py @@ -5,6 +5,7 @@ import ssl import certifi from datetime import timedelta from urllib.parse import urlparse + # Django imports from django.core.management.utils import get_random_secret_key @@ -26,12 +27,6 @@ DEBUG = False # Allowed Hosts ALLOWED_HOSTS = ["*"] -# To access webhook -ENABLE_WEBHOOK = os.environ.get("ENABLE_WEBHOOK", "1") == "1" - -# To access plane api through api tokens -ENABLE_API = os.environ.get("ENABLE_API", "1") == "1" - # Redirect if / is not present APPEND_SLASH = True @@ -229,7 +224,9 @@ STORAGES = { "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", }, } -STORAGES["default"] = {"BACKEND": "storages.backends.s3boto3.S3Boto3Storage"} +STORAGES["default"] = { + "BACKEND": "storages.backends.s3boto3.S3Boto3Storage", +} AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY_ID", "access-key") AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY", "secret-key") AWS_STORAGE_BUCKET_NAME = os.environ.get("AWS_S3_BUCKET_NAME", "uploads") @@ -245,7 +242,6 @@ if AWS_S3_ENDPOINT_URL: AWS_S3_URL_PROTOCOL = f"{parsed_url.scheme}:" - # JWT Auth Configuration SIMPLE_JWT = { "ACCESS_TOKEN_LIFETIME": timedelta(minutes=10080), @@ -338,7 +334,5 @@ SCOUT_MONITOR = os.environ.get("SCOUT_MONITOR", False) SCOUT_KEY = os.environ.get("SCOUT_KEY", "") SCOUT_NAME = "Plane" -# Set the variable true if running in docker environment -DOCKERIZED = int(os.environ.get("DOCKERIZED", 1)) == 1 +# Use Minio settings USE_MINIO = int(os.environ.get("USE_MINIO", 0)) == 1 - diff --git a/apiserver/plane/urls.py b/apiserver/plane/urls.py index aabc6a75a..25055833c 100644 --- a/apiserver/plane/urls.py +++ b/apiserver/plane/urls.py @@ -11,11 +11,10 @@ from django.conf import settings urlpatterns = [ path("", TemplateView.as_view(template_name="index.html")), path("api/", include("plane.api.urls")), + path("api/v1/", include("plane.proxy.urls")), path("", include("plane.web.urls")), ] -if settings.ENABLE_API: - urlpatterns += path("api/v1/", include("plane.proxy.urls")), if settings.DEBUG: import debug_toolbar diff --git a/deploy/selfhost/docker-compose.yml b/deploy/selfhost/docker-compose.yml index 03e136ba1..ddf211fb3 100644 --- a/deploy/selfhost/docker-compose.yml +++ b/deploy/selfhost/docker-compose.yml @@ -9,13 +9,9 @@ x-app-env : &app-env - NEXT_PUBLIC_DEPLOY_URL=${NEXT_PUBLIC_DEPLOY_URL:-http://localhost/spaces} - SENTRY_DSN=${SENTRY_DSN:-""} - GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET:-""} - - DOCKERIZED=${DOCKERIZED:-1} - # BASE WEBHOOK - - ENABLE_WEBHOOK=${ENABLE_WEBHOOK:-1} - # BASE API - - ENABLE_API=${ENABLE_API:-1} + - DOCKERIZED=${DOCKERIZED:-1} # deprecated - CORS_ALLOWED_ORIGINS=${CORS_ALLOWED_ORIGINS:-http://localhost} - # Gunicorn Workers + # Gunicorn Workers - GUNICORN_WORKERS=${GUNICORN_WORKERS:-2} #DB SETTINGS - PGHOST=${PGHOST:-plane-db} diff --git a/deploy/selfhost/variables.env b/deploy/selfhost/variables.env index 7581dfdc1..c71b335ee 100644 --- a/deploy/selfhost/variables.env +++ b/deploy/selfhost/variables.env @@ -11,13 +11,9 @@ NEXT_PUBLIC_ENABLE_OAUTH=0 NEXT_PUBLIC_DEPLOY_URL=http://localhost/spaces SENTRY_DSN="" GITHUB_CLIENT_SECRET="" -DOCKERIZED=1 +DOCKERIZED=1 # deprecated CORS_ALLOWED_ORIGINS="http://localhost" -# Webhook -ENABLE_WEBHOOK=1 -# API -ENABLE_API=1 #DB SETTINGS PGHOST=plane-db From 9789757d2d90cdb492c839ea2f4b719b745bea52 Mon Sep 17 00:00:00 2001 From: pablohashescobar Date: Wed, 15 Nov 2023 18:18:00 +0530 Subject: [PATCH 2/3] dev: fix current site domain registration --- apiserver/plane/api/views/project.py | 2 +- apiserver/plane/api/views/workspace.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apiserver/plane/api/views/project.py b/apiserver/plane/api/views/project.py index 08c7fee4d..ce7750105 100644 --- a/apiserver/plane/api/views/project.py +++ b/apiserver/plane/api/views/project.py @@ -427,7 +427,7 @@ class ProjectInvitationsViewset(BaseViewSet): project_invitations = ProjectMemberInvite.objects.bulk_create( project_invitations, batch_size=10, ignore_conflicts=True ) - current_site = f"{request.scheme}://{request.get_host()}", + current_site = request.META.get('HTTP_ORIGIN') # Send invitations for invitation in project_invitations: diff --git a/apiserver/plane/api/views/workspace.py b/apiserver/plane/api/views/workspace.py index 3fc9b7bde..8804d48ef 100644 --- a/apiserver/plane/api/views/workspace.py +++ b/apiserver/plane/api/views/workspace.py @@ -319,7 +319,7 @@ class WorkspaceInvitationsViewset(BaseViewSet): workspace_invitations, batch_size=10, ignore_conflicts=True ) - current_site = f"{request.scheme}://{request.get_host()}", + current_site = request.META.get('HTTP_ORIGIN') # Send invitations for invitation in workspace_invitations: From 89a5088f31d5acd9086b486fce2b34eede63bd7f Mon Sep 17 00:00:00 2001 From: pablohashescobar Date: Wed, 15 Nov 2023 19:22:56 +0530 Subject: [PATCH 3/3] dev: update cors setup and local settings --- .env.example | 6 +++--- ENV_SETUP.md | 12 ++++++------ apiserver/.env.example | 8 ++++---- apiserver/plane/settings/common.py | 18 +++++++----------- apiserver/plane/settings/local.py | 8 -------- apiserver/plane/settings/production.py | 5 +++++ deploy/selfhost/docker-compose.yml | 4 ++-- deploy/selfhost/variables.env | 8 ++++---- 8 files changed, 31 insertions(+), 38 deletions(-) diff --git a/.env.example b/.env.example index 44bf9ecd6..90070de19 100644 --- a/.env.example +++ b/.env.example @@ -21,9 +21,9 @@ AWS_S3_BUCKET_NAME="uploads" FILE_SIZE_LIMIT=5242880 # GPT settings -OPENAI_API_BASE="https://api.openai.com/v1" # change if using a custom endpoint -OPENAI_API_KEY="sk-" # add your openai key here -GPT_ENGINE="gpt-3.5-turbo" # use "gpt-4" if you have access +OPENAI_API_BASE="https://api.openai.com/v1" # deprecated +OPENAI_API_KEY="sk-" # deprecated +GPT_ENGINE="gpt-3.5-turbo" # deprecated # Settings related to Docker DOCKERIZED=1 # deprecated diff --git a/ENV_SETUP.md b/ENV_SETUP.md index 0dd6c4373..a062bfefb 100644 --- a/ENV_SETUP.md +++ b/ENV_SETUP.md @@ -31,9 +31,9 @@ AWS_S3_BUCKET_NAME="uploads" FILE_SIZE_LIMIT=5242880 ​ # GPT settings -OPENAI_API_BASE="https://api.openai.com/v1" # change if using a custom endpoint -OPENAI_API_KEY="sk-" # add your openai key here -GPT_ENGINE="gpt-3.5-turbo" # use "gpt-4" if you have access +OPENAI_API_BASE="https://api.openai.com/v1" # deprecated +OPENAI_API_KEY="sk-" # deprecated +GPT_ENGINE="gpt-3.5-turbo" # deprecated ​ # set to 1 If using the pre-configured minio setup USE_MINIO=1 @@ -113,9 +113,9 @@ AWS_S3_BUCKET_NAME="uploads" FILE_SIZE_LIMIT=5242880 ​ # GPT settings -OPENAI_API_BASE="https://api.openai.com/v1" # change if using a custom endpoint -OPENAI_API_KEY="sk-" # add your openai key here -GPT_ENGINE="gpt-3.5-turbo" # use "gpt-4" if you have access +OPENAI_API_BASE="https://api.openai.com/v1" # deprecated +OPENAI_API_KEY="sk-" # deprecated +GPT_ENGINE="gpt-3.5-turbo" # deprecated ​ # Settings related to Docker DOCKERIZED=1 # Deprecated diff --git a/apiserver/.env.example b/apiserver/.env.example index cc4c7d47f..29d95ee77 100644 --- a/apiserver/.env.example +++ b/apiserver/.env.example @@ -1,7 +1,7 @@ # Backend # Debug value for api server use it as 0 for production use DEBUG=0 -CORS_ALLOWED_ORIGINS="http://localhost" +CORS_ALLOWED_ORIGINS="" # Error logs SENTRY_DSN="" @@ -38,9 +38,9 @@ AWS_S3_BUCKET_NAME="uploads" FILE_SIZE_LIMIT=5242880 # GPT settings -OPENAI_API_BASE="https://api.openai.com/v1" # change if using a custom endpoint -OPENAI_API_KEY="sk-" # add your openai key here -GPT_ENGINE="gpt-3.5-turbo" # use "gpt-4" if you have access +OPENAI_API_BASE="https://api.openai.com/v1" # deprecated +OPENAI_API_KEY="sk-" # deprecated +GPT_ENGINE="gpt-3.5-turbo" # deprecated # Github GITHUB_CLIENT_SECRET="" # For fetching release notes diff --git a/apiserver/plane/settings/common.py b/apiserver/plane/settings/common.py index b55293297..1d5b217d2 100644 --- a/apiserver/plane/settings/common.py +++ b/apiserver/plane/settings/common.py @@ -113,7 +113,13 @@ CSRF_COOKIE_SECURE = True # CORS Settings CORS_ALLOW_CREDENTIALS = True -CORS_ALLOWED_ORIGINS = os.environ.get("CORS_ALLOWED_ORIGINS", "").split(",") +cors_origins_raw = os.environ.get("CORS_ALLOWED_ORIGINS", "") +# filter out empty strings +cors_allowed_origins = [origin.strip() for origin in cors_origins_raw.split(",") if origin.strip()] +if cors_allowed_origins: + CORS_ALLOWED_ORIGINS = cors_allowed_origins +else: + CORS_ALLOW_ALL_ORIGINS = True # Application Settings WSGI_APPLICATION = "plane.wsgi.application" @@ -324,15 +330,5 @@ GITHUB_ACCESS_TOKEN = os.environ.get("GITHUB_ACCESS_TOKEN", False) ANALYTICS_SECRET_KEY = os.environ.get("ANALYTICS_SECRET_KEY", False) ANALYTICS_BASE_API = os.environ.get("ANALYTICS_BASE_API", False) -# Open AI Settings -OPENAI_API_BASE = os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1") -OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY", False) -GPT_ENGINE = os.environ.get("GPT_ENGINE", "gpt-3.5-turbo") - -# Scout Settings -SCOUT_MONITOR = os.environ.get("SCOUT_MONITOR", False) -SCOUT_KEY = os.environ.get("SCOUT_KEY", "") -SCOUT_NAME = "Plane" - # Use Minio settings USE_MINIO = int(os.environ.get("USE_MINIO", 0)) == 1 diff --git a/apiserver/plane/settings/local.py b/apiserver/plane/settings/local.py index 9fa5ed0aa..8f27d4234 100644 --- a/apiserver/plane/settings/local.py +++ b/apiserver/plane/settings/local.py @@ -3,10 +3,6 @@ from .common import * # noqa DEBUG = True -ALLOWED_HOSTS = [ - "*", -] - # Debug Toolbar settings INSTALLED_APPS += ("debug_toolbar",) MIDDLEWARE += ("debug_toolbar.middleware.DebugToolbarMiddleware",) @@ -24,13 +20,9 @@ CACHES = { INTERNAL_IPS = ("127.0.0.1",) -CORS_ORIGIN_ALLOW_ALL = True - MEDIA_URL = "/uploads/" MEDIA_ROOT = os.path.join(BASE_DIR, "uploads") -# For local settings -CORS_ALLOW_ALL_ORIGINS = True CORS_ALLOWED_ORIGINS = [ "http://localhost:3000", "http://127.0.0.1:3000", diff --git a/apiserver/plane/settings/production.py b/apiserver/plane/settings/production.py index b230bbc32..90eb04dd5 100644 --- a/apiserver/plane/settings/production.py +++ b/apiserver/plane/settings/production.py @@ -11,3 +11,8 @@ INSTALLED_APPS += ("scout_apm.django",) # Honor the 'X-Forwarded-Proto' header for request.is_secure() SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") + +# Scout Settings +SCOUT_MONITOR = os.environ.get("SCOUT_MONITOR", False) +SCOUT_KEY = os.environ.get("SCOUT_KEY", "") +SCOUT_NAME = "Plane" diff --git a/deploy/selfhost/docker-compose.yml b/deploy/selfhost/docker-compose.yml index ddf211fb3..afcb4ae37 100644 --- a/deploy/selfhost/docker-compose.yml +++ b/deploy/selfhost/docker-compose.yml @@ -10,7 +10,7 @@ x-app-env : &app-env - SENTRY_DSN=${SENTRY_DSN:-""} - GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET:-""} - DOCKERIZED=${DOCKERIZED:-1} # deprecated - - CORS_ALLOWED_ORIGINS=${CORS_ALLOWED_ORIGINS:-http://localhost} + - CORS_ALLOWED_ORIGINS=${CORS_ALLOWED_ORIGINS:-""} # Gunicorn Workers - GUNICORN_WORKERS=${GUNICORN_WORKERS:-2} #DB SETTINGS @@ -35,7 +35,7 @@ x-app-env : &app-env - EMAIL_USE_SSL=${EMAIL_USE_SSL:-0} - DEFAULT_EMAIL=${DEFAULT_EMAIL:-captain@plane.so} - DEFAULT_PASSWORD=${DEFAULT_PASSWORD:-password123} - # OPENAI SETTINGS + # OPENAI SETTINGS - Deprecated can be configured through admin panel - OPENAI_API_BASE=${OPENAI_API_BASE:-https://api.openai.com/v1} - OPENAI_API_KEY=${OPENAI_API_KEY:-"sk-"} - GPT_ENGINE=${GPT_ENGINE:-"gpt-3.5-turbo"} diff --git a/deploy/selfhost/variables.env b/deploy/selfhost/variables.env index c71b335ee..ae8a045e8 100644 --- a/deploy/selfhost/variables.env +++ b/deploy/selfhost/variables.env @@ -12,7 +12,7 @@ NEXT_PUBLIC_DEPLOY_URL=http://localhost/spaces SENTRY_DSN="" GITHUB_CLIENT_SECRET="" DOCKERIZED=1 # deprecated -CORS_ALLOWED_ORIGINS="http://localhost" +CORS_ALLOWED_ORIGINS="" #DB SETTINGS @@ -41,9 +41,9 @@ DEFAULT_EMAIL=captain@plane.so DEFAULT_PASSWORD=password123 # OPENAI SETTINGS -OPENAI_API_BASE=https://api.openai.com/v1 -OPENAI_API_KEY="sk-" -GPT_ENGINE="gpt-3.5-turbo" +OPENAI_API_BASE=https://api.openai.com/v1 # deprecated +OPENAI_API_KEY="sk-" # deprecated +GPT_ENGINE="gpt-3.5-turbo" # deprecated # LOGIN/SIGNUP SETTINGS ENABLE_SIGNUP=1