forked from github/plane
dev: analytics export
This commit is contained in:
parent
1570884ffd
commit
26fe0dd457
@ -331,7 +331,7 @@ class EmailCheckEndpoint(BaseAPIView):
|
|||||||
first_time=True,
|
first_time=True,
|
||||||
)
|
)
|
||||||
# Automatically send the email
|
# Automatically send the email
|
||||||
return Response({"is_password_autoset": user.is_password_autoset}, status=status.HTTP_400_BAD_REQUEST)
|
return Response({"is_password_autoset": user.is_password_autoset}, status=status.HTTP_200_OK)
|
||||||
# Existing user
|
# Existing user
|
||||||
else:
|
else:
|
||||||
if type == "magic_code":
|
if type == "magic_code":
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
# Python imports
|
# Python imports
|
||||||
import csv
|
import csv
|
||||||
import io
|
import io
|
||||||
import os
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
# Django imports
|
# Django imports
|
||||||
from django.core.mail import EmailMultiAlternatives, get_connection
|
from django.core.mail import EmailMultiAlternatives, get_connection
|
||||||
@ -17,8 +18,8 @@ from sentry_sdk import capture_exception
|
|||||||
from plane.db.models import Issue
|
from plane.db.models import Issue
|
||||||
from plane.utils.analytics_plot import build_graph_plot
|
from plane.utils.analytics_plot import build_graph_plot
|
||||||
from plane.utils.issue_filters import issue_filters
|
from plane.utils.issue_filters import issue_filters
|
||||||
from plane.license.models import InstanceConfiguration
|
from plane.license.models import InstanceConfiguration, Instance
|
||||||
from plane.license.utils.instance_value import get_configuration_value
|
from plane.license.utils.instance_value import get_email_configuration
|
||||||
|
|
||||||
row_mapping = {
|
row_mapping = {
|
||||||
"state__name": "State",
|
"state__name": "State",
|
||||||
@ -43,7 +44,7 @@ CYCLE_ID = "issue_cycle__cycle_id"
|
|||||||
MODULE_ID = "issue_module__module_id"
|
MODULE_ID = "issue_module__module_id"
|
||||||
|
|
||||||
|
|
||||||
def send_export_email(email, slug, csv_buffer):
|
def send_export_email(email, slug, csv_buffer, rows):
|
||||||
"""Helper function to send export email."""
|
"""Helper function to send export email."""
|
||||||
subject = "Your Export is ready"
|
subject = "Your Export is ready"
|
||||||
html_content = render_to_string("emails/exports/analytics.html", {})
|
html_content = render_to_string("emails/exports/analytics.html", {})
|
||||||
@ -55,47 +56,58 @@ def send_export_email(email, slug, csv_buffer):
|
|||||||
instance_configuration = InstanceConfiguration.objects.filter(
|
instance_configuration = InstanceConfiguration.objects.filter(
|
||||||
key__startswith="EMAIL_"
|
key__startswith="EMAIL_"
|
||||||
).values("key", "value")
|
).values("key", "value")
|
||||||
|
|
||||||
|
(
|
||||||
|
EMAIL_HOST,
|
||||||
|
EMAIL_HOST_USER,
|
||||||
|
EMAIL_HOST_PASSWORD,
|
||||||
|
EMAIL_PORT,
|
||||||
|
EMAIL_USE_TLS,
|
||||||
|
EMAIL_FROM,
|
||||||
|
) = get_email_configuration(instance_configuration=instance_configuration)
|
||||||
|
|
||||||
|
# Send the email if the users don't have smtp configured
|
||||||
|
if EMAIL_HOST and EMAIL_HOST_USER and EMAIL_HOST_PASSWORD:
|
||||||
|
# Check the instance registration
|
||||||
|
instance = Instance.objects.first()
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"x-instance-id": instance.instance_id,
|
||||||
|
"x-api-key": instance.api_key,
|
||||||
|
}
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"email": email,
|
||||||
|
"slug": slug,
|
||||||
|
"rows": rows,
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = requests.post(
|
||||||
|
f"{settings.LICENSE_ENGINE_BASE_URL}/api/instances/users/analytics/",
|
||||||
|
headers=headers,
|
||||||
|
json=payload,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
connection = get_connection(
|
connection = get_connection(
|
||||||
host=get_configuration_value(
|
host=EMAIL_HOST,
|
||||||
instance_configuration, "EMAIL_HOST", os.environ.get("EMAIL_HOST")
|
port=int(EMAIL_PORT),
|
||||||
),
|
username=EMAIL_HOST_USER,
|
||||||
port=int(
|
password=EMAIL_HOST_PASSWORD,
|
||||||
get_configuration_value(
|
use_tls=bool(EMAIL_USE_TLS),
|
||||||
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"),
|
|
||||||
)
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
msg = EmailMultiAlternatives(
|
msg = EmailMultiAlternatives(
|
||||||
subject=subject,
|
subject=subject,
|
||||||
body=text_content,
|
body=text_content,
|
||||||
from_email=get_configuration_value(
|
from_email=EMAIL_FROM,
|
||||||
instance_configuration,
|
|
||||||
"EMAIL_FROM",
|
|
||||||
os.environ.get("EMAIL_FROM", "Team Plane <team@mailer.plane.so>"),
|
|
||||||
),
|
|
||||||
to=[email],
|
to=[email],
|
||||||
connection=connection,
|
connection=connection,
|
||||||
)
|
)
|
||||||
msg.attach(f"{slug}-analytics.csv", csv_buffer.getvalue())
|
msg.attach(f"{slug}-analytics.csv", csv_buffer.getvalue())
|
||||||
msg.send(fail_silently=False)
|
msg.send(fail_silently=False)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def get_assignee_details(slug, filters):
|
def get_assignee_details(slug, filters):
|
||||||
@ -463,8 +475,11 @@ def analytic_export_task(email, data, slug):
|
|||||||
)
|
)
|
||||||
|
|
||||||
csv_buffer = generate_csv_from_rows(rows)
|
csv_buffer = generate_csv_from_rows(rows)
|
||||||
send_export_email(email, slug, csv_buffer)
|
send_export_email(email, slug, csv_buffer, rows)
|
||||||
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
print(e)
|
print(e)
|
||||||
capture_exception(e)
|
capture_exception(e)
|
||||||
|
return
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
||||||
<html>
|
|
||||||
Dear {{username}},<br/>
|
|
||||||
Your requested Issue's data has been successfully exported from Plane. The export includes all relevant information about issues you requested from your selected projects.</br>
|
|
||||||
Please find the attachment and download the CSV file. If you have any questions or need further assistance, please don't hesitate to contact our support team at <a href = "mailto: engineering@plane.com">engineering@plane.so</a>. We're here to help!</br>
|
|
||||||
Thank you for using Plane. We hope this export will aid you in effectively managing your projects.</br>
|
|
||||||
Regards,
|
|
||||||
Team Plane
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue
Block a user