diff --git a/apiserver/plane/api/serializers/issue.py b/apiserver/plane/api/serializers/issue.py index 2dafaa7e6..6fe5ddec1 100644 --- a/apiserver/plane/api/serializers/issue.py +++ b/apiserver/plane/api/serializers/issue.py @@ -61,7 +61,6 @@ class IssueSerializer(BaseSerializer): # Validate assignees are from project if data.get("assignees", []): - print(data.get("assignees")) data["assignees"] = ProjectMember.objects.filter( project_id=self.context.get("project_id"), is_active=True, diff --git a/apiserver/plane/api/views/issue.py b/apiserver/plane/api/views/issue.py index 41745010f..18393b677 100644 --- a/apiserver/plane/api/views/issue.py +++ b/apiserver/plane/api/views/issue.py @@ -450,7 +450,7 @@ class IssueCommentAPIEndpoint(WebhookMixin, BaseAPIView): serializer_class = IssueCommentSerializer model = IssueComment - webhook_event = "issue_comment" + webhook_event = "issue-comment" permission_classes = [ ProjectLitePermission, ] diff --git a/apiserver/plane/api/views/project.py b/apiserver/plane/api/views/project.py index 812a0072e..e8dc9f5a9 100644 --- a/apiserver/plane/api/views/project.py +++ b/apiserver/plane/api/views/project.py @@ -123,10 +123,9 @@ class ProjectAPIEndpoint(WebhookMixin, BaseAPIView): projects, many=True, fields=self.fields, expand=self.expand, ).data, ) - else: - project = self.get_queryset().get(workspace__slug=slug, pk=project_id) - serializer = ProjectSerializer(project, fields=self.fields, expand=self.expand,) - return Response(serializer.data, status=status.HTTP_200_OK) + project = self.get_queryset().get(workspace__slug=slug, pk=project_id) + serializer = ProjectSerializer(project, fields=self.fields, expand=self.expand,) + return Response(serializer.data, status=status.HTTP_200_OK) def post(self, request, slug): try: diff --git a/apiserver/plane/app/views/external.py b/apiserver/plane/app/views/external.py index 34f21d00e..b9f8a0cf0 100644 --- a/apiserver/plane/app/views/external.py +++ b/apiserver/plane/app/views/external.py @@ -27,8 +27,8 @@ class GPTIntegrationEndpoint(BaseAPIView): # 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") + api_key = get_configuration_value(instance_configuration, "OPENAI_API_KEY", os.environ.get("OPENAI_API_KEY")) + gpt_engine = get_configuration_value(instance_configuration, "GPT_ENGINE", os.environ.get("GPT_ENGINE", "gpt-3.5-turbo")) # Check the keys if not api_key or not gpt_engine: @@ -47,10 +47,6 @@ class GPTIntegrationEndpoint(BaseAPIView): final_text = task + "\n" + prompt - instance_configuration = InstanceConfiguration.objects.values("key", "value") - - gpt_engine = get_configuration_value(instance_configuration, "GPT_ENGINE") - client = OpenAI( api_key=api_key, ) diff --git a/apiserver/plane/app/views/issue.py b/apiserver/plane/app/views/issue.py index e7605bf14..b03c0ea4f 100644 --- a/apiserver/plane/app/views/issue.py +++ b/apiserver/plane/app/views/issue.py @@ -596,7 +596,7 @@ class IssueActivityEndpoint(BaseAPIView): class IssueCommentViewSet(WebhookMixin, BaseViewSet): serializer_class = IssueCommentSerializer model = IssueComment - webhook_event = "issue_comment" + webhook_event = "issue-comment" permission_classes = [ ProjectLitePermission, ] diff --git a/apiserver/plane/bgtasks/analytic_plot_export.py b/apiserver/plane/bgtasks/analytic_plot_export.py index 8cccc2299..c67399adf 100644 --- a/apiserver/plane/bgtasks/analytic_plot_export.py +++ b/apiserver/plane/bgtasks/analytic_plot_export.py @@ -1,6 +1,7 @@ # Python imports import csv import io +import os # Django imports from django.core.mail import EmailMultiAlternatives, get_connection @@ -32,7 +33,7 @@ row_mapping = { "priority": "Priority", "estimate": "Estimate", "issue_cycle__cycle_id": "Cycle", - "issue_module__module_id": "Module" + "issue_module__module_id": "Module", } ASSIGNEE_ID = "assignees__id" @@ -51,17 +52,55 @@ 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("key", "value") + instance_configuration = InstanceConfiguration.objects.filter( + key__startswith="EMAIL_" + ).values("key", "value") connection = get_connection( - 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")), + host=get_configuration_value( + instance_configuration, "EMAIL_HOST", os.environ.get("EMAIL_HOST") + ), + port=int( + get_configuration_value( + instance_configuration, "EMAIL_PORT", os.environ.get("EMAIL_PORT") + ) + ), + username=get_configuration_value( + instance_configuration, + "EMAIL_HOST_USER", + os.environ.get("EMAIL_HOST_USER"), + ), + password=get_configuration_value( + instance_configuration, + "EMAIL_HOST_PASSWORD", + os.environ.get("EMAIL_HOST_PASSWORD"), + ), + use_tls=bool( + get_configuration_value( + instance_configuration, + "EMAIL_USE_TLS", + os.environ.get("EMAIL_USE_TLS", "1"), + ) + ), + use_ssl=bool( + get_configuration_value( + instance_configuration, + "EMAIL_USE_SSL", + os.environ.get("EMAIL_USE_SSL", "0"), + ) + ), ) - msg = EmailMultiAlternatives(subject=subject, body=text_content, from_email=get_configuration_value(instance_configuration, "EMAIL_FROM"), to=[email], connection=connection) + msg = EmailMultiAlternatives( + subject=subject, + body=text_content, + from_email=get_configuration_value( + instance_configuration, + "EMAIL_FROM", + os.environ.get("EMAIL_FROM", "Team Plane "), + ), + to=[email], + connection=connection, + ) msg.attach(f"{slug}-analytics.csv", csv_buffer.getvalue()) msg.send(fail_silently=False) diff --git a/apiserver/plane/bgtasks/email_verification_task.py b/apiserver/plane/bgtasks/email_verification_task.py index 3a9f52a68..650b73eac 100644 --- a/apiserver/plane/bgtasks/email_verification_task.py +++ b/apiserver/plane/bgtasks/email_verification_task.py @@ -1,3 +1,6 @@ +# Python imports +import os + # Django imports from django.core.mail import EmailMultiAlternatives, get_connection from django.template.loader import render_to_string @@ -14,9 +17,9 @@ from sentry_sdk import capture_exception 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): - try: realtivelink = "/request-email-verification/" + "?token=" + str(token) abs_url = current_site + realtivelink @@ -33,17 +36,56 @@ 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("key", "value") + instance_configuration = InstanceConfiguration.objects.filter( + key__startswith="EMAIL_" + ).values("key", "value") connection = get_connection( - 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")), + host=get_configuration_value( + instance_configuration, "EMAIL_HOST", os.environ.get("EMAIL_HOST") + ), + port=int( + get_configuration_value( + instance_configuration, "EMAIL_PORT", os.environ.get("EMAIL_PORT") + ) + ), + username=get_configuration_value( + instance_configuration, + "EMAIL_HOST_USER", + os.environ.get("EMAIL_HOST_USER"), + ), + password=get_configuration_value( + instance_configuration, + "EMAIL_HOST_PASSWORD", + os.environ.get("EMAIL_HOST_PASSWORD"), + ), + use_tls=bool( + get_configuration_value( + instance_configuration, + "EMAIL_USE_TLS", + os.environ.get("EMAIL_USE_TLS", "1"), + ) + ), + use_ssl=bool( + get_configuration_value( + instance_configuration, + "EMAIL_USE_SSL", + os.environ.get("EMAIL_USE_SSL", "0"), + ) + ), ) # Initiate email alternatives - msg = EmailMultiAlternatives(subject=subject, body=text_content, from_email=get_configuration_value(instance_configuration, "EMAIL_FROM"), to=[email], connection=connection) + msg = EmailMultiAlternatives( + subject=subject, + body=text_content, + from_email=get_configuration_value( + instance_configuration, + "EMAIL_FROM", + os.environ.get("EMAIL_FROM", "Team Plane "), + ), + to=[email], + connection=connection, + ) msg.attach_alternative(html_content, "text/html") msg.send() return diff --git a/apiserver/plane/bgtasks/forgot_password_task.py b/apiserver/plane/bgtasks/forgot_password_task.py index 7eeec3dc4..a2b09cd8d 100644 --- a/apiserver/plane/bgtasks/forgot_password_task.py +++ b/apiserver/plane/bgtasks/forgot_password_task.py @@ -1,3 +1,6 @@ +# Python import +import os + # Django imports from django.core.mail import EmailMultiAlternatives, get_connection from django.template.loader import render_to_string @@ -32,14 +35,51 @@ def forgot_password(first_name, email, uidb64, token, current_site): instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values("key", "value") connection = get_connection( - 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")), + host=get_configuration_value( + instance_configuration, "EMAIL_HOST", os.environ.get("EMAIL_HOST") + ), + port=int( + get_configuration_value( + instance_configuration, "EMAIL_PORT", os.environ.get("EMAIL_PORT") + ) + ), + username=get_configuration_value( + instance_configuration, + "EMAIL_HOST_USER", + os.environ.get("EMAIL_HOST_USER"), + ), + password=get_configuration_value( + instance_configuration, + "EMAIL_HOST_PASSWORD", + os.environ.get("EMAIL_HOST_PASSWORD"), + ), + use_tls=bool( + get_configuration_value( + instance_configuration, + "EMAIL_USE_TLS", + os.environ.get("EMAIL_USE_TLS", "1"), + ) + ), + use_ssl=bool( + get_configuration_value( + instance_configuration, + "EMAIL_USE_SSL", + os.environ.get("EMAIL_USE_SSL", "0"), + ) + ), + ) + + msg = EmailMultiAlternatives( + subject=subject, + body=text_content, + from_email=get_configuration_value( + instance_configuration, + "EMAIL_FROM", + os.environ.get("EMAIL_FROM", "Team Plane "), + ), + to=[email], + connection=connection, ) - # Initiate email alternatives - msg = EmailMultiAlternatives(subject=subject, body=text_content, from_email=get_configuration_value(instance_configuration, "EMAIL_FROM"), to=[email], connection=connection) msg.attach_alternative(html_content, "text/html") msg.send() return diff --git a/apiserver/plane/bgtasks/magic_link_code_task.py b/apiserver/plane/bgtasks/magic_link_code_task.py index 372cafa6e..da84769f6 100644 --- a/apiserver/plane/bgtasks/magic_link_code_task.py +++ b/apiserver/plane/bgtasks/magic_link_code_task.py @@ -1,3 +1,6 @@ +# Python imports +import os + # Django imports from django.core.mail import EmailMultiAlternatives, get_connection from django.template.loader import render_to_string @@ -12,6 +15,7 @@ from sentry_sdk import capture_exception 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): try: @@ -26,17 +30,55 @@ def magic_link(email, key, token, current_site): text_content = strip_tags(html_content) - instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values("key", "value") + instance_configuration = InstanceConfiguration.objects.filter( + key__startswith="EMAIL_" + ).values("key", "value") connection = get_connection( - 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")), + host=get_configuration_value( + instance_configuration, "EMAIL_HOST", os.environ.get("EMAIL_HOST") + ), + port=int( + get_configuration_value( + instance_configuration, "EMAIL_PORT", os.environ.get("EMAIL_PORT") + ) + ), + username=get_configuration_value( + instance_configuration, + "EMAIL_HOST_USER", + os.environ.get("EMAIL_HOST_USER"), + ), + password=get_configuration_value( + instance_configuration, + "EMAIL_HOST_PASSWORD", + os.environ.get("EMAIL_HOST_PASSWORD"), + ), + use_tls=bool( + get_configuration_value( + instance_configuration, + "EMAIL_USE_TLS", + os.environ.get("EMAIL_USE_TLS", "1"), + ) + ), + use_ssl=bool( + get_configuration_value( + instance_configuration, + "EMAIL_USE_SSL", + os.environ.get("EMAIL_USE_SSL", "0"), + ) + ), ) - # Initiate email alternatives - msg = EmailMultiAlternatives(subject=subject, body=text_content, from_email=get_configuration_value(instance_configuration, "EMAIL_FROM"), to=[email], connection=connection) + msg = EmailMultiAlternatives( + subject=subject, + body=text_content, + from_email=get_configuration_value( + instance_configuration, + "EMAIL_FROM", + os.environ.get("EMAIL_FROM", "Team Plane "), + ), + to=[email], + connection=connection, + ) msg.attach_alternative(html_content, "text/html") msg.send() return diff --git a/apiserver/plane/bgtasks/project_invitation_task.py b/apiserver/plane/bgtasks/project_invitation_task.py index 9fd3dd904..ca414d46b 100644 --- a/apiserver/plane/bgtasks/project_invitation_task.py +++ b/apiserver/plane/bgtasks/project_invitation_task.py @@ -1,3 +1,6 @@ +# Python import +import os + # Django imports from django.core.mail import EmailMultiAlternatives, get_connection from django.template.loader import render_to_string @@ -46,14 +49,52 @@ def project_invitation(email, project_id, token, current_site, invitor): # Configure email connection from the database instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values("key", "value") connection = get_connection( - 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")), + host=get_configuration_value( + instance_configuration, "EMAIL_HOST", os.environ.get("EMAIL_HOST") + ), + port=int( + get_configuration_value( + instance_configuration, "EMAIL_PORT", os.environ.get("EMAIL_PORT") + ) + ), + username=get_configuration_value( + instance_configuration, + "EMAIL_HOST_USER", + os.environ.get("EMAIL_HOST_USER"), + ), + password=get_configuration_value( + instance_configuration, + "EMAIL_HOST_PASSWORD", + os.environ.get("EMAIL_HOST_PASSWORD"), + ), + use_tls=bool( + get_configuration_value( + instance_configuration, + "EMAIL_USE_TLS", + os.environ.get("EMAIL_USE_TLS", "1"), + ) + ), + use_ssl=bool( + get_configuration_value( + instance_configuration, + "EMAIL_USE_SSL", + os.environ.get("EMAIL_USE_SSL", "0"), + ) + ), ) - # Initiate email alternatives - msg = EmailMultiAlternatives(subject=subject, body=text_content, from_email=get_configuration_value(instance_configuration, "EMAIL_FROM"), to=[email], connection=connection) + + msg = EmailMultiAlternatives( + subject=subject, + body=text_content, + from_email=get_configuration_value( + instance_configuration, + "EMAIL_FROM", + os.environ.get("EMAIL_FROM", "Team Plane "), + ), + to=[email], + connection=connection, + ) + msg.attach_alternative(html_content, "text/html") msg.send() return diff --git a/apiserver/plane/bgtasks/workspace_invitation_task.py b/apiserver/plane/bgtasks/workspace_invitation_task.py index 767ef07fd..aa527f241 100644 --- a/apiserver/plane/bgtasks/workspace_invitation_task.py +++ b/apiserver/plane/bgtasks/workspace_invitation_task.py @@ -1,3 +1,6 @@ +# Python imports +import os + # Django imports from django.core.mail import EmailMultiAlternatives, get_connection from django.template.loader import render_to_string @@ -55,23 +58,48 @@ def workspace_invitation(email, workspace_id, token, current_site, invitor): key__startswith="EMAIL_" ).values("key", "value") connection = get_connection( - host=get_configuration_value(instance_configuration, "EMAIL_HOST"), - port=int( - get_configuration_value(instance_configuration, "EMAIL_PORT", "587") + host=get_configuration_value( + instance_configuration, "EMAIL_HOST", os.environ.get("EMAIL_HOST") + ), + port=int( + get_configuration_value( + instance_configuration, "EMAIL_PORT", os.environ.get("EMAIL_PORT") + ) + ), + username=get_configuration_value( + instance_configuration, + "EMAIL_HOST_USER", + os.environ.get("EMAIL_HOST_USER"), ), - username=get_configuration_value(instance_configuration, "EMAIL_HOST_USER"), password=get_configuration_value( - instance_configuration, "EMAIL_HOST_PASSWORD" + instance_configuration, + "EMAIL_HOST_PASSWORD", + os.environ.get("EMAIL_HOST_PASSWORD"), ), use_tls=bool( - get_configuration_value(instance_configuration, "EMAIL_USE_TLS", "1") + get_configuration_value( + instance_configuration, + "EMAIL_USE_TLS", + os.environ.get("EMAIL_USE_TLS", "1"), + ) + ), + use_ssl=bool( + get_configuration_value( + instance_configuration, + "EMAIL_USE_SSL", + os.environ.get("EMAIL_USE_SSL", "0"), + ) ), ) - # Initiate email alternatives + msg = EmailMultiAlternatives( subject=subject, body=text_content, - from_email=get_configuration_value(instance_configuration, "EMAIL_FROM"), + from_email=get_configuration_value( + instance_configuration, + "EMAIL_FROM", + os.environ.get("EMAIL_FROM", "Team Plane "), + ), to=[email], connection=connection, )