feat: add option to download json directly from email
This commit is contained in:
parent
5d5d669dc8
commit
eae1c04d81
2 changed files with 14 additions and 7 deletions
|
|
@ -4,8 +4,10 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
import json
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils.verified_command import get_signed_params
|
||||
|
||||
class PersonalDataDownloadRequest(Document):
|
||||
def after_insert(self):
|
||||
|
|
@ -20,7 +22,7 @@ class PersonalDataDownloadRequest(Document):
|
|||
user_name = self.user_name.replace(' ','-')
|
||||
f = frappe.get_doc({
|
||||
'doctype': 'File',
|
||||
'file_name': 'Personal-Data-'+user_name+'-'+self.name+'.txt',
|
||||
'file_name': 'Personal-Data-'+user_name+'-'+self.name+'.json',
|
||||
"attached_to_doctype": 'Personal Data Download Request',
|
||||
"attached_to_name": self.name,
|
||||
'content': str(personal_data),
|
||||
|
|
@ -28,6 +30,8 @@ class PersonalDataDownloadRequest(Document):
|
|||
})
|
||||
f.save(ignore_permissions=True)
|
||||
|
||||
file_link = frappe.utils.get_url("/api/method/frappe.core.doctype.file.file.download_file") +\
|
||||
"?" + get_signed_params({"file_url": f.file_url})
|
||||
host_name = frappe.local.site
|
||||
frappe.sendmail(
|
||||
recipients=frappe.session.user,
|
||||
|
|
@ -36,7 +40,7 @@ class PersonalDataDownloadRequest(Document):
|
|||
args={
|
||||
'user':frappe.session.user,
|
||||
'user_name':self.user_name,
|
||||
'link':"".join(f.file_url),
|
||||
'link':file_link,
|
||||
'host_name':host_name
|
||||
},
|
||||
header=[_("Download Your Data"), "green"]
|
||||
|
|
@ -51,4 +55,4 @@ def get_user_data(user):
|
|||
d += frappe.get_all(hook.get('doctype'), {hook.get('match_field'): user}, ["*"])
|
||||
if d:
|
||||
data.update({ hook.get('doctype'):d })
|
||||
return data
|
||||
return json.dumps(data, indent=2, default=str)
|
||||
|
|
@ -5,6 +5,7 @@ from __future__ import unicode_literals
|
|||
|
||||
import frappe
|
||||
import unittest
|
||||
import json
|
||||
from frappe.website.doctype.personal_data_download_request.personal_data_download_request import get_user_data
|
||||
|
||||
|
||||
|
|
@ -12,9 +13,10 @@ class TestRequestPersonalData(unittest.TestCase):
|
|||
def setUp(self):
|
||||
create_user_if_not_exists(email='test_privacy@example.com')
|
||||
|
||||
def test_user_data(self):
|
||||
user_data = get_user_data('test_privacy@example.com')
|
||||
expected_data = {'Contact': frappe.get_all('Contact', {'email_id':'test_privacy@example.com'},["*"])}
|
||||
def test_user_data_creation(self):
|
||||
user_data = json.loads(get_user_data('test_privacy@example.com'))
|
||||
expected_data = {'Contact': frappe.get_all('Contact', {'email_id':'test_privacy@example.com'}, ["*"])}
|
||||
expected_data = json.loads(json.dumps(expected_data, default=str))
|
||||
self.assertEqual({'Contact': user_data['Contact']}, expected_data)
|
||||
|
||||
def test_file_and_email_creation(self):
|
||||
|
|
@ -44,5 +46,6 @@ def create_user_if_not_exists(email, first_name = None):
|
|||
"user_type": "Website User",
|
||||
"email": email,
|
||||
"send_welcome_email": 0,
|
||||
"first_name": first_name or email.split("@")[0]
|
||||
"first_name": first_name or email.split("@")[0],
|
||||
"birth_date": frappe.utils.now_datetime()
|
||||
}).insert(ignore_permissions=True)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue