forked from github/plane
Merge branch 'dev/license_engine' of github.com:makeplane/plane into dev/license_engine
This commit is contained in:
commit
58ac2955fa
@ -387,7 +387,6 @@ class EmailCheckEndpoint(BaseAPIView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Send event
|
# Send event
|
||||||
if settings.POSTHOG_API_KEY and settings.POSTHOG_HOST:
|
|
||||||
auth_events.delay(
|
auth_events.delay(
|
||||||
user=user.id,
|
user=user.id,
|
||||||
email=email,
|
email=email,
|
||||||
@ -420,7 +419,6 @@ class EmailCheckEndpoint(BaseAPIView):
|
|||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
if settings.POSTHOG_API_KEY and settings.POSTHOG_HOST:
|
|
||||||
auth_events.delay(
|
auth_events.delay(
|
||||||
user=user.id,
|
user=user.id,
|
||||||
email=email,
|
email=email,
|
||||||
@ -449,7 +447,6 @@ class EmailCheckEndpoint(BaseAPIView):
|
|||||||
status=status.HTTP_200_OK,
|
status=status.HTTP_200_OK,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if settings.POSTHOG_API_KEY and settings.POSTHOG_HOST:
|
|
||||||
auth_events.delay(
|
auth_events.delay(
|
||||||
user=user.id,
|
user=user.id,
|
||||||
email=email,
|
email=email,
|
||||||
|
@ -73,7 +73,7 @@ class SignUpEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
# get configuration values
|
# get configuration values
|
||||||
# Get configuration values
|
# Get configuration values
|
||||||
ENABLE_SIGNUP = get_configuration_value(
|
ENABLE_SIGNUP, = get_configuration_value(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"key": "ENABLE_SIGNUP",
|
"key": "ENABLE_SIGNUP",
|
||||||
@ -173,7 +173,7 @@ class SignInEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
# Create the user
|
# Create the user
|
||||||
else:
|
else:
|
||||||
ENABLE_SIGNUP = get_configuration_value(
|
ENABLE_SIGNUP, = get_configuration_value(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"key": "ENABLE_SIGNUP",
|
"key": "ENABLE_SIGNUP",
|
||||||
@ -269,7 +269,6 @@ class SignInEndpoint(BaseAPIView):
|
|||||||
workspace_member_invites.delete()
|
workspace_member_invites.delete()
|
||||||
project_member_invites.delete()
|
project_member_invites.delete()
|
||||||
# Send event
|
# Send event
|
||||||
if settings.POSTHOG_API_KEY and settings.POSTHOG_HOST:
|
|
||||||
auth_events.delay(
|
auth_events.delay(
|
||||||
user=user.id,
|
user=user.id,
|
||||||
email=email,
|
email=email,
|
||||||
@ -352,7 +351,6 @@ class MagicSignInEndpoint(BaseAPIView):
|
|||||||
status=status.HTTP_403_FORBIDDEN,
|
status=status.HTTP_403_FORBIDDEN,
|
||||||
)
|
)
|
||||||
# Send event
|
# Send event
|
||||||
if settings.POSTHOG_API_KEY and settings.POSTHOG_HOST:
|
|
||||||
auth_events.delay(
|
auth_events.delay(
|
||||||
user=user.id,
|
user=user.id,
|
||||||
email=email,
|
email=email,
|
||||||
|
@ -20,60 +20,6 @@ class ConfigurationEndpoint(BaseAPIView):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
print(
|
|
||||||
get_configuration_value(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"key": "GOOGLE_CLIENT_ID",
|
|
||||||
"default": os.environ.get("GOOGLE_CLIENT_ID", None),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "GITHUB_CLIENT_ID",
|
|
||||||
"default": os.environ.get("GITHUB_CLIENT_ID", None),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "GITHUB_APP_NAME",
|
|
||||||
"default": os.environ.get("GITHUB_APP_NAME", None),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "EMAIL_HOST_USER",
|
|
||||||
"default": os.environ.get("EMAIL_HOST_USER", None),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "EMAIL_HOST_PASSWORD",
|
|
||||||
"default": os.environ.get("EMAIL_HOST_PASSWORD", None),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"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", "1"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "POSTHOG_API_KEY",
|
|
||||||
"default": os.environ.get("POSTHOG_API_KEY", "1"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "POSTHOG_HOST",
|
|
||||||
"default": os.environ.get("POSTHOG_HOST", "1"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "UNSPLASH_ACCESS_KEY",
|
|
||||||
"default": os.environ.get("UNSPLASH_ACCESS_KEY", "1"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "OPENAI_API_KEY",
|
|
||||||
"default": os.environ.get("OPENAI_API_KEY", "1"),
|
|
||||||
},
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Get all the configuration
|
# Get all the configuration
|
||||||
(
|
(
|
||||||
@ -141,7 +87,7 @@ class ConfigurationEndpoint(BaseAPIView):
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
print("hewllo")
|
|
||||||
data = {}
|
data = {}
|
||||||
# Authentication
|
# Authentication
|
||||||
data["google_client_id"] = GOOGLE_CLIENT_ID
|
data["google_client_id"] = GOOGLE_CLIENT_ID
|
||||||
|
@ -89,16 +89,16 @@ class ReleaseNotesEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
class UnsplashEndpoint(BaseAPIView):
|
class UnsplashEndpoint(BaseAPIView):
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
UNSPLASH_ACESS_KEY = get_configuration_value(
|
UNSPLASH_ACCESS_KEY, = get_configuration_value(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"key": "UNSPLASH_ACESS_KEY",
|
"key": "UNSPLASH_ACCESS_KEY",
|
||||||
"default": os.environ.get("UNSPLASH_ACCESS_KEY"),
|
"default": os.environ.get("UNSPLASH_ACCESS_KEY"),
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
# Check unsplash access key
|
# Check unsplash access key
|
||||||
if not UNSPLASH_ACESS_KEY:
|
if not UNSPLASH_ACCESS_KEY:
|
||||||
return Response([], status=status.HTTP_200_OK)
|
return Response([], status=status.HTTP_200_OK)
|
||||||
|
|
||||||
# Query parameters
|
# Query parameters
|
||||||
@ -107,9 +107,9 @@ class UnsplashEndpoint(BaseAPIView):
|
|||||||
per_page = request.GET.get("per_page", 20)
|
per_page = request.GET.get("per_page", 20)
|
||||||
|
|
||||||
url = (
|
url = (
|
||||||
f"https://api.unsplash.com/search/photos/?client_id={UNSPLASH_ACESS_KEY}&query={query}&page=${page}&per_page={per_page}"
|
f"https://api.unsplash.com/search/photos/?client_id={UNSPLASH_ACCESS_KEY}&query={query}&page=${page}&per_page={per_page}"
|
||||||
if query
|
if query
|
||||||
else f"https://api.unsplash.com/photos/?client_id={UNSPLASH_ACESS_KEY}&page={page}&per_page={per_page}"
|
else f"https://api.unsplash.com/photos/?client_id={UNSPLASH_ACCESS_KEY}&page={page}&per_page={per_page}"
|
||||||
)
|
)
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
|
@ -280,7 +280,6 @@ class OauthEndpoint(BaseAPIView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Send event
|
# Send event
|
||||||
if settings.POSTHOG_API_KEY and settings.POSTHOG_HOST:
|
|
||||||
auth_events.delay(
|
auth_events.delay(
|
||||||
user=user.id,
|
user=user.id,
|
||||||
email=email,
|
email=email,
|
||||||
@ -300,7 +299,7 @@ class OauthEndpoint(BaseAPIView):
|
|||||||
return Response(data, status=status.HTTP_200_OK)
|
return Response(data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
ENABLE_SIGNUP = get_configuration_value(
|
ENABLE_SIGNUP, = get_configuration_value(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"key": "ENABLE_SIGNUP",
|
"key": "ENABLE_SIGNUP",
|
||||||
@ -412,7 +411,6 @@ class OauthEndpoint(BaseAPIView):
|
|||||||
project_member_invites.delete()
|
project_member_invites.delete()
|
||||||
|
|
||||||
# Send event
|
# Send event
|
||||||
if settings.POSTHOG_API_KEY and settings.POSTHOG_HOST:
|
|
||||||
auth_events.delay(
|
auth_events.delay(
|
||||||
user=user.id,
|
user=user.id,
|
||||||
email=email,
|
email=email,
|
||||||
|
@ -408,7 +408,6 @@ class WorkspaceJoinEndpoint(BaseAPIView):
|
|||||||
workspace_invite.delete()
|
workspace_invite.delete()
|
||||||
|
|
||||||
# Send event
|
# Send event
|
||||||
if settings.POSTHOG_API_KEY and settings.POSTHOG_HOST:
|
|
||||||
workspace_invite_event.delay(
|
workspace_invite_event.delay(
|
||||||
user=user.id if user is not None else None,
|
user=user.id if user is not None else None,
|
||||||
email=email,
|
email=email,
|
||||||
|
@ -1,17 +1,41 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
import os
|
||||||
|
|
||||||
from posthog import Posthog
|
# third party imports
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
#third party imports
|
|
||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
from sentry_sdk import capture_exception
|
from sentry_sdk import capture_exception
|
||||||
|
from posthog import Posthog
|
||||||
|
|
||||||
|
# module imports
|
||||||
|
from plane.license.utils.instance_value import get_configuration_value
|
||||||
|
|
||||||
|
|
||||||
|
def posthogConfiguration():
|
||||||
|
POSTHOG_API_KEY, POSTHOG_HOST = get_configuration_value(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"key": "POSTHOG_API_KEY",
|
||||||
|
"default": os.environ.get("POSTHOG_API_KEY", None),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "POSTHOG_HOST",
|
||||||
|
"default": os.environ.get("POSTHOG_HOST", None),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
if POSTHOG_API_KEY and POSTHOG_HOST:
|
||||||
|
return POSTHOG_API_KEY, POSTHOG_HOST
|
||||||
|
else:
|
||||||
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def auth_events(user, email, user_agent, ip, event_name, medium, first_time):
|
def auth_events(user, email, user_agent, ip, event_name, medium, first_time):
|
||||||
try:
|
try:
|
||||||
posthog = Posthog(settings.POSTHOG_API_KEY, host=settings.POSTHOG_HOST)
|
POSTHOG_API_KEY, POSTHOG_HOST = posthogConfiguration()
|
||||||
|
|
||||||
|
if POSTHOG_API_KEY and POSTHOG_HOST:
|
||||||
|
posthog = Posthog(POSTHOG_API_KEY, host=POSTHOG_HOST)
|
||||||
posthog.capture(
|
posthog.capture(
|
||||||
email,
|
email,
|
||||||
event=event_name,
|
event=event_name,
|
||||||
@ -29,10 +53,14 @@ def auth_events(user, email, user_agent, ip, event_name, medium, first_time):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
capture_exception(e)
|
capture_exception(e)
|
||||||
|
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def workspace_invite_event(user, email, user_agent, ip, event_name, accepted_from):
|
def workspace_invite_event(user, email, user_agent, ip, event_name, accepted_from):
|
||||||
try:
|
try:
|
||||||
posthog = Posthog(settings.POSTHOG_API_KEY, host=settings.POSTHOG_HOST)
|
POSTHOG_API_KEY, POSTHOG_HOST = posthogConfiguration()
|
||||||
|
|
||||||
|
if POSTHOG_API_KEY and POSTHOG_HOST:
|
||||||
|
posthog = Posthog(POSTHOG_API_KEY, host=POSTHOG_HOST)
|
||||||
posthog.capture(
|
posthog.capture(
|
||||||
email,
|
email,
|
||||||
event=event_name,
|
event=event_name,
|
||||||
|
@ -9,12 +9,6 @@ from plane.license.models import InstanceConfiguration
|
|||||||
from plane.license.utils.encryption import decrypt_data
|
from plane.license.utils.encryption import decrypt_data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def create_lookup_dict(list_of_dicts):
|
|
||||||
return {item['key']: item for item in list_of_dicts}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Helper function to return value from the passed key
|
# Helper function to return value from the passed key
|
||||||
def get_configuration_value(keys):
|
def get_configuration_value(keys):
|
||||||
environment_list = []
|
environment_list = []
|
||||||
@ -35,20 +29,17 @@ def get_configuration_value(keys):
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
environment_list.append(key.get("default"))
|
environment_list.append(key.get("default"))
|
||||||
|
else:
|
||||||
|
# Get the configuration from os
|
||||||
|
for key in keys:
|
||||||
|
environment_list.append(os.environ.get(key.get("key"), key.get("default")))
|
||||||
|
|
||||||
return tuple(environment_list)
|
return tuple(environment_list)
|
||||||
|
|
||||||
|
|
||||||
def get_email_configuration():
|
def get_email_configuration():
|
||||||
if settings.SKIP_ENV_VAR:
|
return (
|
||||||
(
|
get_configuration_value(
|
||||||
EMAIL_HOST_USER,
|
|
||||||
EMAIL_HOST_PASSWORD,
|
|
||||||
EMAIL_HOST,
|
|
||||||
EMAIL_FROM,
|
|
||||||
EMAIL_USE_TLS,
|
|
||||||
EMAIL_PORT,
|
|
||||||
) = get_configuration_value(
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"key": "EMAIL_HOST_USER",
|
"key": "EMAIL_HOST_USER",
|
||||||
@ -63,42 +54,18 @@ def get_email_configuration():
|
|||||||
"default": os.environ.get("EMAIL_HOST", None),
|
"default": os.environ.get("EMAIL_HOST", None),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "EMAIL_FROM",
|
"key": "EMAIL_PORT",
|
||||||
"default": os.environ.get("EMAIL_FROM", None),
|
"default": os.environ.get("EMAIL_PORT", 587),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "EMAIL_USE_TLS",
|
"key": "EMAIL_USE_TLS",
|
||||||
"default": os.environ.get("EMAIL_USE_TLS", "1"),
|
"default": os.environ.get("EMAIL_USE_TLS", "1"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "EMAIL_PORT",
|
"key": "EMAIL_FROM",
|
||||||
"default": os.environ.get("EMAIL_PORT", 587),
|
"default": os.environ.get("EMAIL_FROM", "Team Plane <team@mailer.plane.so>"),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
return (
|
|
||||||
EMAIL_HOST,
|
|
||||||
EMAIL_HOST_USER,
|
|
||||||
EMAIL_HOST_PASSWORD,
|
|
||||||
EMAIL_PORT,
|
|
||||||
EMAIL_USE_TLS,
|
|
||||||
EMAIL_FROM,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
|
||||||
# Get email configuration directly from os
|
|
||||||
EMAIL_HOST = os.environ.get("EMAIL_HOST")
|
|
||||||
EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER")
|
|
||||||
EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD")
|
|
||||||
EMAIL_PORT = os.environ.get("EMAIL_PORT", 587)
|
|
||||||
EMAIL_USE_TLS = os.environ.get("EMAIL_USE_TLS", "1")
|
|
||||||
EMAIL_FROM = os.environ.get("EMAIL_FROM", "Team Plane <team@mailer.plane.so>")
|
|
||||||
|
|
||||||
return (
|
|
||||||
EMAIL_HOST,
|
|
||||||
EMAIL_HOST_USER,
|
|
||||||
EMAIL_HOST_PASSWORD,
|
|
||||||
EMAIL_PORT,
|
|
||||||
EMAIL_USE_TLS,
|
|
||||||
EMAIL_FROM,
|
|
||||||
)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user