Skip to content

Commit

Permalink
Remove book contact check (#1533)
Browse files Browse the repository at this point in the history
* Wagtail 4.1.9 upgrade (#1522)

* Updated to wagtail 4.1.9 and replaced WagtailPageTests with WagtailPageTestCase

* Fixes migration conflict

* Added source field to Thank You Note (#1529)

* Update admin.py (#1532)

Co-authored-by: Staxly <[email protected]>

* updating book filter to exclude (#1530)

Co-authored-by: Staxly <[email protected]>
Co-authored-by: Michael Volo <[email protected]>

* remove unused account id field from resource downloads

* do not check for book and contact on resource creation

* remove rejection test

* Require UUID, do not require resource name

* set default uuid to something random

---------

Co-authored-by: Ed Woodward <[email protected]>
Co-authored-by: Colby <[email protected]>
Co-authored-by: Staxly <[email protected]>
  • Loading branch information
4 people authored Jan 2, 2024
1 parent 4e66d25 commit 6995995
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.1.7 on 2023-12-13 19:28

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("salesforce", "0105_auto_20221212_1543"),
]

operations = [
migrations.RemoveIndex(
model_name="resourcedownload",
name="salesforce__account_b11d37_idx",
),
migrations.RemoveField(
model_name="resourcedownload",
name="account_id",
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.1.7 on 2023-12-13 21:42

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("salesforce", "0106_remove_resourcedownload_salesforce__account_b11d37_idx_and_more"),
]

operations = [
migrations.AlterField(
model_name="resourcedownload",
name="account_uuid",
field=models.UUIDField(default="19d58898-0b29-488f-a35a-6288e3c0b44c"),
preserve_default=False,
),
migrations.AlterField(
model_name="resourcedownload",
name="resource_name",
field=models.CharField(blank=True, max_length=255, null=True),
),
]
8 changes: 3 additions & 5 deletions salesforce/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,18 +388,16 @@ class ResourceDownload(models.Model):
('Chegg Reader', 'Chegg Reader'),
)
book = models.ForeignKey(Book, on_delete=models.SET_NULL, null=True, blank=True)
book_format = models.CharField(max_length=100, choices=BOOK_FORMATS, null=True , blank=True)
account_id = models.IntegerField(blank=True, null=True) # TODO: remove this field after migrating data to UUID (see management command)
account_uuid = models.UUIDField(null=True)
book_format = models.CharField(max_length=100, choices=BOOK_FORMATS, null=True, blank=True)
account_uuid = models.UUIDField(null=False)
created = models.DateTimeField(auto_now_add=True)
edited = models.DateTimeField(auto_now=True)
last_access = models.DateTimeField()
resource_name = models.CharField(max_length=255, null=True, blank=False)
resource_name = models.CharField(max_length=255, null=True, blank=True)
contact_id = models.CharField(max_length=100, null=True, blank=True)

class Meta:
indexes = [
models.Index(fields=['account_id', ]),
models.Index(fields=['account_uuid', ]),
models.Index(fields=['book', ]),
]
Expand Down
21 changes: 10 additions & 11 deletions salesforce/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,16 @@ def create(self, validated_data):
resource_name = validated_data.get('resource_name', None)
contact_id = validated_data.get('contact_id', None)
rd = []
if book and contact_id:
try:
rd = ResourceDownload.objects.filter(account_uuid=account_uuid, book=book)
if resource_name:
rd.filter(resource_name=resource_name)

rd = rd[0] # we only need the first result - but there might already be duplicates so this should handle that
rd.contact_id = contact_id
rd.save()
except (ResourceDownload.DoesNotExist, IndexError):
rd = ResourceDownload.objects.create(**validated_data)
try:
rd = ResourceDownload.objects.filter(account_uuid=account_uuid, book=book)
if resource_name:
rd.filter(resource_name=resource_name)

rd = rd[0]
rd.contact_id = contact_id
rd.save()
except (ResourceDownload.DoesNotExist, IndexError):
rd = ResourceDownload.objects.create(**validated_data)

return rd

Expand Down
26 changes: 7 additions & 19 deletions salesforce/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,24 +214,12 @@ def test_resource_download_post(self):
locale=root_page.locale
)
book_index.add_child(instance=book)
data = {"book": book.pk,"book_format": "PDF","account_uuid": "310bb96b-0df8-4d10-a759-c7d366c1f524", "resource_name": "Book PDF", "contact_id": "0032f00003zYVdSAAZ"}
data = {
"book": book.pk,
"book_format": "PDF",
"account_uuid": "310bb96b-0df8-4d10-a759-c7d366c1f524",
"resource_name": "Book PDF",
"contact_id": "0032f00003zYVdSAAZ"
}
response = self.client.post('/apps/cms/api/salesforce/download-tracking/', data, format='json')
self.assertEqual("PDF", response.data['book_format'])

def test_resource_download_post_rejection(self):
root_page = Page.objects.get(title="Root")
book_index = BookIndex.objects.all()[0]
book = Book(title="Biology 2e",
slug="biology-2e",
cnx_id='031da8d3-b525-429c-80cf-6c8ed997744b',
salesforce_book_id='',
description="Test Book",
cover=self.test_doc,
title_image=self.test_doc,
publish_date=datetime.date.today(),
locale=root_page.locale
)
book_index.add_child(instance=book)
data = {"book": book.pk,"book_format": "PDF","account_uuid": "310bb96b-0df8-4d10-a759-c7d366c1f524", "resource_name": "Book PDF", "contact_id": ""}
response = self.client.post('/apps/cms/api/salesforce/download-tracking/', data, format='json')
self.assertEqual(None, response.data['book'])

0 comments on commit 6995995

Please sign in to comment.