forked from github/plane
dev: instance configuration values
This commit is contained in:
parent
fea812f1b1
commit
d05b63fc51
@ -12,7 +12,8 @@ from sentry_sdk import capture_exception
|
||||
|
||||
# Module imports
|
||||
from .base import BaseAPIView
|
||||
|
||||
from plane.license.models import Instance
|
||||
from plane.license.utils.instance_value import get_configuration_value
|
||||
|
||||
class ConfigurationEndpoint(BaseAPIView):
|
||||
permission_classes = [
|
||||
@ -20,18 +21,27 @@ class ConfigurationEndpoint(BaseAPIView):
|
||||
]
|
||||
|
||||
def get(self, request):
|
||||
instance_configuration = Instance.objects.values("key", "value")
|
||||
|
||||
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)
|
||||
# Authentication
|
||||
data["google_client_id"] = get_configuration_value(instance_configuration, "GOOGLE_CLIENT_ID")
|
||||
data["github_client_id"] = get_configuration_value(instance_configuration,"GITHUB_CLIENT_ID")
|
||||
data["github_app_name"] = get_configuration_value(instance_configuration, "GITHUB_APP_NAME")
|
||||
data["magic_login"] = (
|
||||
bool(settings.EMAIL_HOST_USER) and bool(settings.EMAIL_HOST_PASSWORD)
|
||||
) and os.environ.get("ENABLE_MAGIC_LINK_LOGIN", "0") == "1"
|
||||
bool(get_configuration_value(instance_configuration, "EMAIL_HOST_USER")) and bool(get_configuration_value(instance_configuration, "EMAIL_HOST_PASSWORD"))
|
||||
) and get_configuration_value(instance_configuration, "ENABLE_MAGIC_LINK_LOGIN", "0") == "1"
|
||||
data["email_password_login"] = (
|
||||
os.environ.get("ENABLE_EMAIL_PASSWORD", "0") == "1"
|
||||
get_configuration_value(instance_configuration, "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)
|
||||
# Slack client
|
||||
data["slack_client_id"] = get_configuration_value(instance_configuration, "SLACK_CLIENT_ID")
|
||||
|
||||
# Posthog
|
||||
data["posthog_api_key"] = get_configuration_value(instance_configuration, "POSTHOG_API_KEY")
|
||||
data["posthog_host"] = get_configuration_value(instance_configuration, "POSTHOG_HOST")
|
||||
|
||||
# Unsplash
|
||||
data["has_unsplash_configured"] = bool(get_configuration_value(instance_configuration, "UNSPLASH_ACCESS_KEY"))
|
||||
|
||||
return Response(data, status=status.HTTP_200_OK)
|
||||
|
@ -2,7 +2,7 @@
|
||||
import requests
|
||||
|
||||
# Third party imports
|
||||
import openai
|
||||
from openai import OpenAI
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from rest_framework.permissions import AllowAny
|
||||
@ -17,7 +17,8 @@ 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
|
||||
|
||||
from plane.license.models import InstanceConfiguration
|
||||
from plane.license.utils.instance_value import get_configuration_value
|
||||
|
||||
class GPTIntegrationEndpoint(BaseAPIView):
|
||||
permission_classes = [
|
||||
@ -25,7 +26,14 @@ class GPTIntegrationEndpoint(BaseAPIView):
|
||||
]
|
||||
|
||||
def post(self, request, slug, project_id):
|
||||
if not settings.OPENAI_API_KEY or not settings.GPT_ENGINE:
|
||||
|
||||
# Get the configuration value
|
||||
instance_configuration = InstanceConfiguration.objects.values("key", "value")
|
||||
api_key = get_configuration_value(instance_configuration, "OPENAI_API_KEY")
|
||||
gpt_engine = get_configuration_value(instance_configuration, "GPT_ENGINE")
|
||||
|
||||
# Check the keys
|
||||
if not api_key or not gpt_engine:
|
||||
return Response(
|
||||
{"error": "OpenAI API key and engine is required"},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
@ -41,12 +49,17 @@ class GPTIntegrationEndpoint(BaseAPIView):
|
||||
|
||||
final_text = task + "\n" + prompt
|
||||
|
||||
openai.api_key = settings.OPENAI_API_KEY
|
||||
response = openai.ChatCompletion.create(
|
||||
model=settings.GPT_ENGINE,
|
||||
instance_configuration = InstanceConfiguration.objects.values("key", "value")
|
||||
|
||||
gpt_engine = get_configuration_value(instance_configuration, "GPT_ENGINE")
|
||||
|
||||
client = OpenAI(
|
||||
api_key=api_key,
|
||||
)
|
||||
|
||||
response = client.chat.completions.create(
|
||||
model=gpt_engine,
|
||||
messages=[{"role": "user", "content": final_text}],
|
||||
temperature=0.7,
|
||||
max_tokens=1024,
|
||||
)
|
||||
|
||||
workspace = Workspace.objects.get(slug=slug)
|
||||
|
@ -17,6 +17,7 @@ from plane.db.models import Issue
|
||||
from plane.utils.analytics_plot import build_graph_plot
|
||||
from plane.utils.issue_filters import issue_filters
|
||||
from plane.license.models import InstanceConfiguration
|
||||
from plane.license.utils.instance_value import get_configuration_value
|
||||
|
||||
row_mapping = {
|
||||
"state__name": "State",
|
||||
@ -50,14 +51,14 @@ def send_export_email(email, slug, csv_buffer):
|
||||
csv_buffer.seek(0)
|
||||
|
||||
# Configure email connection from the database
|
||||
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values()
|
||||
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values("key", "value")
|
||||
connection = get_connection(
|
||||
host=instance_configuration.get("EMAIL_HOST", ""),
|
||||
port=int(instance_configuration.get("EMAIL_PORT", "587")),
|
||||
username=instance_configuration.get("EMAIL_HOST_USER", ""),
|
||||
password=instance_configuration.get("EMAIL_HOST_PASSWORD", ""),
|
||||
use_tls=bool(instance_configuration.get("EMAIL_USE_TLS", "")),
|
||||
use_ssl=bool(instance_configuration.get("EMAIL_USE_SSL", ""))
|
||||
host=get_configuration_value(instance_configuration, "EMAIL_HOST"),
|
||||
port=int(get_configuration_value(instance_configuration, "EMAIL_PORT", "587")),
|
||||
username=get_configuration_value(instance_configuration, "EMAIL_HOST_USER"),
|
||||
password=get_configuration_value(instance_configuration, "EMAIL_HOST_PASSWORD"),
|
||||
use_tls=bool(get_configuration_value(instance_configuration, "EMAIL_USE_TLS", "1")),
|
||||
use_ssl=bool(get_configuration_value(instance_configuration, "EMAIL_USE_SSL", "0")),
|
||||
)
|
||||
|
||||
msg = EmailMultiAlternatives(subject=subject, text_content=text_content, from_email=settings.EMAIL_FROM, to=[email], connection=connection)
|
||||
|
@ -12,6 +12,7 @@ from sentry_sdk import capture_exception
|
||||
|
||||
# Module imports
|
||||
from plane.license.models import InstanceConfiguration
|
||||
from plane.license.utils.instance_value import get_configuration_value
|
||||
|
||||
@shared_task
|
||||
def email_verification(first_name, email, token, current_site):
|
||||
@ -34,15 +35,16 @@ def email_verification(first_name, email, token, current_site):
|
||||
text_content = strip_tags(html_content)
|
||||
|
||||
# Configure email connection from the database
|
||||
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values()
|
||||
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values("key", "value")
|
||||
connection = get_connection(
|
||||
host=instance_configuration.get("EMAIL_HOST", ""),
|
||||
port=int(instance_configuration.get("EMAIL_PORT", "587")),
|
||||
username=instance_configuration.get("EMAIL_HOST_USER", ""),
|
||||
password=instance_configuration.get("EMAIL_HOST_PASSWORD", ""),
|
||||
use_tls=bool(instance_configuration.get("EMAIL_USE_TLS", "")),
|
||||
use_ssl=bool(instance_configuration.get("EMAIL_USE_SSL", ""))
|
||||
host=get_configuration_value(instance_configuration, "EMAIL_HOST"),
|
||||
port=int(get_configuration_value(instance_configuration, "EMAIL_PORT", "587")),
|
||||
username=get_configuration_value(instance_configuration, "EMAIL_HOST_USER"),
|
||||
password=get_configuration_value(instance_configuration, "EMAIL_HOST_PASSWORD"),
|
||||
use_tls=bool(get_configuration_value(instance_configuration, "EMAIL_USE_TLS", "1")),
|
||||
use_ssl=bool(get_configuration_value(instance_configuration, "EMAIL_USE_SSL", "0")),
|
||||
)
|
||||
|
||||
# Initiate email alternatives
|
||||
msg = EmailMultiAlternatives(subject=subject, text_content=text_content, from_email=settings.EMAIL_FROM, to=[email], connection=connection)
|
||||
msg.attach_alternative(html_content, "text/html")
|
||||
|
@ -10,7 +10,7 @@ from sentry_sdk import capture_exception
|
||||
|
||||
# Module imports
|
||||
from plane.license.models import InstanceConfiguration
|
||||
|
||||
from plane.license.utils.instance_value import get_configuration_value
|
||||
|
||||
@shared_task
|
||||
def forgot_password(first_name, email, uidb64, token, current_site):
|
||||
@ -32,15 +32,14 @@ def forgot_password(first_name, email, uidb64, token, current_site):
|
||||
|
||||
text_content = strip_tags(html_content)
|
||||
|
||||
# Configure email connection from the database
|
||||
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values()
|
||||
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values("key", "value")
|
||||
connection = get_connection(
|
||||
host=instance_configuration.get("EMAIL_HOST", ""),
|
||||
port=int(instance_configuration.get("EMAIL_PORT", "587")),
|
||||
username=instance_configuration.get("EMAIL_HOST_USER", ""),
|
||||
password=instance_configuration.get("EMAIL_HOST_PASSWORD", ""),
|
||||
use_tls=bool(instance_configuration.get("EMAIL_USE_TLS", "")),
|
||||
use_ssl=bool(instance_configuration.get("EMAIL_USE_SSL", ""))
|
||||
host=get_configuration_value(instance_configuration, "EMAIL_HOST"),
|
||||
port=int(get_configuration_value(instance_configuration, "EMAIL_PORT", "587")),
|
||||
username=get_configuration_value(instance_configuration, "EMAIL_HOST_USER"),
|
||||
password=get_configuration_value(instance_configuration, "EMAIL_HOST_PASSWORD"),
|
||||
use_tls=bool(get_configuration_value(instance_configuration, "EMAIL_USE_TLS", "1")),
|
||||
use_ssl=bool(get_configuration_value(instance_configuration, "EMAIL_USE_SSL", "0")),
|
||||
)
|
||||
# Initiate email alternatives
|
||||
msg = EmailMultiAlternatives(subject=subject, text_content=text_content, from_email=settings.EMAIL_FROM, to=[email], connection=connection)
|
||||
|
@ -10,6 +10,7 @@ from sentry_sdk import capture_exception
|
||||
|
||||
# Module imports
|
||||
from plane.license.models import InstanceConfiguration
|
||||
from plane.license.utils.instance_value import get_configuration_value
|
||||
|
||||
@shared_task
|
||||
def magic_link(email, key, token, current_site):
|
||||
@ -27,15 +28,14 @@ def magic_link(email, key, token, current_site):
|
||||
|
||||
text_content = strip_tags(html_content)
|
||||
|
||||
# Configure email connection from the database
|
||||
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values()
|
||||
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values("key", "value")
|
||||
connection = get_connection(
|
||||
host=instance_configuration.get("EMAIL_HOST", ""),
|
||||
port=int(instance_configuration.get("EMAIL_PORT", "587")),
|
||||
username=instance_configuration.get("EMAIL_HOST_USER", ""),
|
||||
password=instance_configuration.get("EMAIL_HOST_PASSWORD", ""),
|
||||
use_tls=bool(instance_configuration.get("EMAIL_USE_TLS", "")),
|
||||
use_ssl=bool(instance_configuration.get("EMAIL_USE_SSL", ""))
|
||||
host=get_configuration_value(instance_configuration, "EMAIL_HOST"),
|
||||
port=int(get_configuration_value(instance_configuration, "EMAIL_PORT", "587")),
|
||||
username=get_configuration_value(instance_configuration, "EMAIL_HOST_USER"),
|
||||
password=get_configuration_value(instance_configuration, "EMAIL_HOST_PASSWORD"),
|
||||
use_tls=bool(get_configuration_value(instance_configuration, "EMAIL_USE_TLS", "1")),
|
||||
use_ssl=bool(get_configuration_value(instance_configuration, "EMAIL_USE_SSL", "0")),
|
||||
)
|
||||
# Initiate email alternatives
|
||||
msg = EmailMultiAlternatives(subject=subject, text_content=text_content, from_email=settings.EMAIL_FROM, to=[email], connection=connection)
|
||||
|
@ -11,7 +11,7 @@ from sentry_sdk import capture_exception
|
||||
# Module imports
|
||||
from plane.db.models import Project, User, ProjectMemberInvite
|
||||
from plane.license.models import InstanceConfiguration
|
||||
|
||||
from plane.license.utils.instance_value import get_configuration_value
|
||||
|
||||
@shared_task
|
||||
def project_invitation(email, project_id, token, current_site):
|
||||
@ -45,14 +45,14 @@ def project_invitation(email, project_id, token, current_site):
|
||||
project_member_invite.save()
|
||||
|
||||
# Configure email connection from the database
|
||||
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values()
|
||||
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values("key", "value")
|
||||
connection = get_connection(
|
||||
host=instance_configuration.get("EMAIL_HOST", ""),
|
||||
port=int(instance_configuration.get("EMAIL_PORT", "587")),
|
||||
username=instance_configuration.get("EMAIL_HOST_USER", ""),
|
||||
password=instance_configuration.get("EMAIL_HOST_PASSWORD", ""),
|
||||
use_tls=bool(instance_configuration.get("EMAIL_USE_TLS", "")),
|
||||
use_ssl=bool(instance_configuration.get("EMAIL_USE_SSL", ""))
|
||||
host=get_configuration_value(instance_configuration, "EMAIL_HOST"),
|
||||
port=int(get_configuration_value(instance_configuration, "EMAIL_PORT", "587")),
|
||||
username=get_configuration_value(instance_configuration, "EMAIL_HOST_USER"),
|
||||
password=get_configuration_value(instance_configuration, "EMAIL_HOST_PASSWORD"),
|
||||
use_tls=bool(get_configuration_value(instance_configuration, "EMAIL_USE_TLS", "1")),
|
||||
use_ssl=bool(get_configuration_value(instance_configuration, "EMAIL_USE_SSL", "0")),
|
||||
)
|
||||
# Initiate email alternatives
|
||||
msg = EmailMultiAlternatives(subject=subject, text_content=text_content, from_email=settings.EMAIL_FROM, to=[email], connection=connection)
|
||||
|
@ -13,6 +13,7 @@ from slack_sdk.errors import SlackApiError
|
||||
# Module imports
|
||||
from plane.db.models import Workspace, WorkspaceMemberInvite
|
||||
from plane.license.models import InstanceConfiguration
|
||||
from plane.license.utils.instance_value import get_configuration_value
|
||||
|
||||
@shared_task
|
||||
def workspace_invitation(email, workspace_id, token, current_site, invitor):
|
||||
@ -47,15 +48,14 @@ def workspace_invitation(email, workspace_id, token, current_site, invitor):
|
||||
workspace_member_invite.message = text_content
|
||||
workspace_member_invite.save()
|
||||
|
||||
# Configure email connection from the database
|
||||
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values()
|
||||
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values("key", "value")
|
||||
connection = get_connection(
|
||||
host=instance_configuration.get("EMAIL_HOST", ""),
|
||||
port=int(instance_configuration.get("EMAIL_PORT", "587")),
|
||||
username=instance_configuration.get("EMAIL_HOST_USER", ""),
|
||||
password=instance_configuration.get("EMAIL_HOST_PASSWORD", ""),
|
||||
use_tls=bool(instance_configuration.get("EMAIL_USE_TLS", "")),
|
||||
use_ssl=bool(instance_configuration.get("EMAIL_USE_SSL", ""))
|
||||
host=get_configuration_value(instance_configuration, "EMAIL_HOST"),
|
||||
port=int(get_configuration_value(instance_configuration, "EMAIL_PORT", "587")),
|
||||
username=get_configuration_value(instance_configuration, "EMAIL_HOST_USER"),
|
||||
password=get_configuration_value(instance_configuration, "EMAIL_HOST_PASSWORD"),
|
||||
use_tls=bool(get_configuration_value(instance_configuration, "EMAIL_USE_TLS", "1")),
|
||||
use_ssl=bool(get_configuration_value(instance_configuration, "EMAIL_USE_SSL", "0")),
|
||||
)
|
||||
# Initiate email alternatives
|
||||
msg = EmailMultiAlternatives(subject=subject, text_content=text_content, from_email=settings.EMAIL_FROM, to=[email], connection=connection)
|
||||
|
0
apiserver/plane/license/utils/__init__.py
Normal file
0
apiserver/plane/license/utils/__init__.py
Normal file
6
apiserver/plane/license/utils/instance_value.py
Normal file
6
apiserver/plane/license/utils/instance_value.py
Normal file
@ -0,0 +1,6 @@
|
||||
# Helper function to return value from the passed key
|
||||
def get_configuration_value(query, key, default=None):
|
||||
for item in query:
|
||||
if item['key'] == key:
|
||||
return item.get("value", default)
|
||||
return default
|
@ -26,7 +26,7 @@ google-api-python-client==2.97.0
|
||||
django-redis==5.3.0
|
||||
uvicorn==0.23.2
|
||||
channels==4.0.0
|
||||
openai==0.28.0
|
||||
openai==1.2.4
|
||||
slack-sdk==3.21.3
|
||||
celery==5.3.4
|
||||
django_celery_beat==2.5.0
|
||||
|
Loading…
Reference in New Issue
Block a user