mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
* [WEB-1404] fix: redirection to web app and issue with telemetry checkbox in setup form. * chore: add scrollbar in admin app. * chore: fix `workspaces_exist` logic in instance api.
185 lines
5.8 KiB
Python
185 lines
5.8 KiB
Python
# Python imports
|
|
import os
|
|
|
|
# Django imports
|
|
from django.conf import settings
|
|
|
|
# Third party imports
|
|
from rest_framework import status
|
|
from rest_framework.permissions import AllowAny
|
|
from rest_framework.response import Response
|
|
|
|
# Module imports
|
|
from plane.app.views import BaseAPIView
|
|
from plane.db.models import Workspace
|
|
from plane.license.api.permissions import (
|
|
InstanceAdminPermission,
|
|
)
|
|
from plane.license.api.serializers import (
|
|
InstanceSerializer,
|
|
)
|
|
from plane.license.models import Instance
|
|
from plane.license.utils.instance_value import (
|
|
get_configuration_value,
|
|
)
|
|
from plane.utils.cache import cache_response, invalidate_cache
|
|
|
|
|
|
class InstanceEndpoint(BaseAPIView):
|
|
def get_permissions(self):
|
|
if self.request.method == "PATCH":
|
|
return [
|
|
InstanceAdminPermission(),
|
|
]
|
|
return [
|
|
AllowAny(),
|
|
]
|
|
|
|
@cache_response(60 * 60 * 2, user=False)
|
|
def get(self, request):
|
|
instance = Instance.objects.first()
|
|
|
|
# get the instance
|
|
if instance is None:
|
|
return Response(
|
|
{"is_activated": False, "is_setup_done": False},
|
|
status=status.HTTP_200_OK,
|
|
)
|
|
# Return instance
|
|
serializer = InstanceSerializer(instance)
|
|
data = serializer.data
|
|
data["is_activated"] = True
|
|
# Get all the configuration
|
|
(
|
|
IS_GOOGLE_ENABLED,
|
|
IS_GITHUB_ENABLED,
|
|
GITHUB_APP_NAME,
|
|
EMAIL_HOST,
|
|
ENABLE_MAGIC_LINK_LOGIN,
|
|
ENABLE_EMAIL_PASSWORD,
|
|
SLACK_CLIENT_ID,
|
|
POSTHOG_API_KEY,
|
|
POSTHOG_HOST,
|
|
UNSPLASH_ACCESS_KEY,
|
|
OPENAI_API_KEY,
|
|
) = get_configuration_value(
|
|
[
|
|
{
|
|
"key": "IS_GOOGLE_ENABLED",
|
|
"default": os.environ.get("IS_GOOGLE_ENABLED", "0"),
|
|
},
|
|
{
|
|
"key": "IS_GITHUB_ENABLED",
|
|
"default": os.environ.get("IS_GITHUB_ENABLED", "0"),
|
|
},
|
|
{
|
|
"key": "GITHUB_APP_NAME",
|
|
"default": os.environ.get("GITHUB_APP_NAME", ""),
|
|
},
|
|
{
|
|
"key": "EMAIL_HOST",
|
|
"default": os.environ.get("EMAIL_HOST", ""),
|
|
},
|
|
{
|
|
"key": "ENABLE_MAGIC_LINK_LOGIN",
|
|
"default": os.environ.get("ENABLE_MAGIC_LINK_LOGIN", "1"),
|
|
},
|
|
{
|
|
"key": "ENABLE_EMAIL_PASSWORD",
|
|
"default": os.environ.get("ENABLE_EMAIL_PASSWORD", "1"),
|
|
},
|
|
{
|
|
"key": "SLACK_CLIENT_ID",
|
|
"default": os.environ.get("SLACK_CLIENT_ID", None),
|
|
},
|
|
{
|
|
"key": "POSTHOG_API_KEY",
|
|
"default": os.environ.get("POSTHOG_API_KEY", None),
|
|
},
|
|
{
|
|
"key": "POSTHOG_HOST",
|
|
"default": os.environ.get("POSTHOG_HOST", None),
|
|
},
|
|
{
|
|
"key": "UNSPLASH_ACCESS_KEY",
|
|
"default": os.environ.get("UNSPLASH_ACCESS_KEY", ""),
|
|
},
|
|
{
|
|
"key": "OPENAI_API_KEY",
|
|
"default": os.environ.get("OPENAI_API_KEY", ""),
|
|
},
|
|
]
|
|
)
|
|
|
|
data = {}
|
|
# Authentication
|
|
data["is_google_enabled"] = IS_GOOGLE_ENABLED == "1"
|
|
data["is_github_enabled"] = IS_GITHUB_ENABLED == "1"
|
|
data["is_magic_login_enabled"] = ENABLE_MAGIC_LINK_LOGIN == "1"
|
|
data["is_email_password_enabled"] = ENABLE_EMAIL_PASSWORD == "1"
|
|
|
|
# Github app name
|
|
data["github_app_name"] = str(GITHUB_APP_NAME)
|
|
|
|
# Slack client
|
|
data["slack_client_id"] = SLACK_CLIENT_ID
|
|
|
|
# Posthog
|
|
data["posthog_api_key"] = POSTHOG_API_KEY
|
|
data["posthog_host"] = POSTHOG_HOST
|
|
|
|
# Unsplash
|
|
data["has_unsplash_configured"] = bool(UNSPLASH_ACCESS_KEY)
|
|
|
|
# Open AI settings
|
|
data["has_openai_configured"] = bool(OPENAI_API_KEY)
|
|
|
|
# File size settings
|
|
data["file_size_limit"] = float(
|
|
os.environ.get("FILE_SIZE_LIMIT", 5242880)
|
|
)
|
|
|
|
# is smtp configured
|
|
data["is_smtp_configured"] = bool(EMAIL_HOST)
|
|
|
|
# Base URL
|
|
data["admin_base_url"] = settings.ADMIN_BASE_URL
|
|
data["space_base_url"] = settings.SPACE_BASE_URL
|
|
data["app_base_url"] = settings.APP_BASE_URL
|
|
|
|
instance_data = serializer.data
|
|
instance_data["workspaces_exist"] = Workspace.objects.count() >= 1
|
|
|
|
response_data = {"config": data, "instance": instance_data}
|
|
return Response(response_data, status=status.HTTP_200_OK)
|
|
|
|
@invalidate_cache(path="/api/instances/", user=False)
|
|
def patch(self, request):
|
|
# Get the instance
|
|
instance = Instance.objects.first()
|
|
serializer = InstanceSerializer(
|
|
instance, 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)
|
|
|
|
|
|
class SignUpScreenVisitedEndpoint(BaseAPIView):
|
|
permission_classes = [
|
|
AllowAny,
|
|
]
|
|
|
|
@invalidate_cache(path="/api/instances/", user=False)
|
|
def post(self, request):
|
|
instance = Instance.objects.first()
|
|
if instance is None:
|
|
return Response(
|
|
{"error": "Instance is not configured"},
|
|
status=status.HTTP_400_BAD_REQUEST,
|
|
)
|
|
instance.is_signup_screen_visited = True
|
|
instance.save()
|
|
return Response(status=status.HTTP_204_NO_CONTENT)
|