Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: configuration endpoint for frontend client #2355

Merged
merged 6 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apiserver/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,13 @@ DEFAULT_PASSWORD="password123"
# SignUps
ENABLE_SIGNUP="1"


# Enable Email/Password Signup
ENABLE_EMAIL_PASSWORD="1"

# Enable Magic link Login
ENABLE_MAGIC_LINK_LOGIN="0"

# Email redirections and minio domain settings
WEB_URL="http://localhost"

28 changes: 20 additions & 8 deletions apiserver/plane/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,11 @@
GlobalSearchEndpoint,
IssueSearchEndpoint,
## End Search
# Gpt
# External
GPTIntegrationEndpoint,
## End Gpt
# Release Notes
ReleaseNotesEndpoint,
## End Release Notes
UnsplashEndpoint,
## End External
# Inbox
InboxViewSet,
InboxIssueViewSet,
Expand Down Expand Up @@ -186,6 +185,9 @@
## Exporter
ExportIssuesEndpoint,
## End Exporter
# Configuration
ConfigurationEndpoint,
## End Configuration
)


Expand Down Expand Up @@ -1446,20 +1448,23 @@
name="project-issue-search",
),
## End Search
# Gpt
# External
path(
"workspaces/<str:slug>/projects/<uuid:project_id>/ai-assistant/",
GPTIntegrationEndpoint.as_view(),
name="importer",
),
## End Gpt
# Release Notes
path(
"release-notes/",
ReleaseNotesEndpoint.as_view(),
name="release-notes",
),
## End Release Notes
path(
"unsplash/",
UnsplashEndpoint.as_view(),
name="release-notes",
),
## End External
# Inbox
path(
"workspaces/<str:slug>/projects/<uuid:project_id>/inboxes/",
Expand Down Expand Up @@ -1728,4 +1733,11 @@
name="workspace-project-boards",
),
## End Public Boards
# Configuration
path(
"configs/",
ConfigurationEndpoint.as_view(),
name="configuration",
),
## End Configuration
]
9 changes: 4 additions & 5 deletions apiserver/plane/api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,13 @@
from .search import GlobalSearchEndpoint, IssueSearchEndpoint


from .gpt import GPTIntegrationEndpoint
from .external import GPTIntegrationEndpoint, ReleaseNotesEndpoint, UnsplashEndpoint

from .estimate import (
ProjectEstimatePointEndpoint,
BulkEstimatePointEndpoint,
)


from .release import ReleaseNotesEndpoint

from .inbox import InboxViewSet, InboxIssueViewSet, InboxIssuePublicViewSet

from .analytic import (
Expand All @@ -169,4 +166,6 @@

from .notification import NotificationViewSet, UnreadNotificationEndpoint, MarkAllReadNotificationViewSet

from .exporter import ExportIssuesEndpoint
from .exporter import ExportIssuesEndpoint

from .config import ConfigurationEndpoint
40 changes: 40 additions & 0 deletions apiserver/plane/api/views/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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):
try:
data = {}
data["google"] = os.environ.get("GOOGLE_CLIENT_ID", None)
data["github"] = 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"
)
return Response(data, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import requests

# Third party imports
import openai
from rest_framework.response import Response
from rest_framework import status
import openai
from rest_framework.permissions import AllowAny
from sentry_sdk import capture_exception

# Django imports
Expand All @@ -15,6 +16,7 @@
from plane.api.permissions import ProjectEntityPermission
from plane.db.models import Workspace, Project
from plane.api.serializers import ProjectLiteSerializer, WorkspaceLiteSerializer
from plane.utils.integrations.github import get_release_notes


class GPTIntegrationEndpoint(BaseAPIView):
Expand Down Expand Up @@ -73,3 +75,44 @@ def post(self, request, slug, project_id):
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)


class ReleaseNotesEndpoint(BaseAPIView):
def get(self, request):
try:
release_notes = get_release_notes()
return Response(release_notes, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)


class UnsplashEndpoint(BaseAPIView):

def get(self, request):
try:
query = request.GET.get("query", False)
page = request.GET.get("page", 1)
per_page = request.GET.get("per_page", 20)

url = (
f"https://api.unsplash.com/search/photos/?client_id={settings.UNSPLASH_ACCESS_KEY}&query={query}&page=${page}&per_page={per_page}"
if query
else f"https://api.unsplash.com/photos/?client_id={settings.UNSPLASH_ACCESS_KEY}&page={page}&per_page={per_page}"
)

headers = {
"Content-Type": "application/json",
}

resp = requests.get(url=url, headers=headers)
return Response(resp.json(), status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
21 changes: 0 additions & 21 deletions apiserver/plane/api/views/release.py

This file was deleted.

3 changes: 3 additions & 0 deletions apiserver/plane/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,6 @@
GITHUB_ACCESS_TOKEN = os.environ.get("GITHUB_ACCESS_TOKEN", False)

ENABLE_SIGNUP = os.environ.get("ENABLE_SIGNUP", "1") == "1"

# Unsplash Access key
UNSPLASH_ACCESS_KEY = os.environ.get("UNSPLASH_ACCESS_KEY")
4 changes: 4 additions & 0 deletions apiserver/plane/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,7 @@
SCOUT_MONITOR = os.environ.get("SCOUT_MONITOR", False)
SCOUT_KEY = os.environ.get("SCOUT_KEY", "")
SCOUT_NAME = "Plane"

# Unsplash Access key
UNSPLASH_ACCESS_KEY = os.environ.get("UNSPLASH_ACCESS_KEY")

1 change: 1 addition & 0 deletions apiserver/plane/settings/selfhosted.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,4 @@
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")

4 changes: 4 additions & 0 deletions apiserver/plane/settings/staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,7 @@
GITHUB_ACCESS_TOKEN = os.environ.get("GITHUB_ACCESS_TOKEN", False)

ENABLE_SIGNUP = os.environ.get("ENABLE_SIGNUP", "1") == "1"


# Unsplash Access key
UNSPLASH_ACCESS_KEY = os.environ.get("UNSPLASH_ACCESS_KEY")