-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #890 from fecgov/release/sprint-42
Release/sprint 42
- Loading branch information
Showing
22 changed files
with
312 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
django-backend/fecfiler/committee_accounts/migrations/0004_remove_duplicate_memberships.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Generated by Django 4.2.7 on 2024-02-16 20:43 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def delete_memberships_with_overlapping_emails(apps, schema_editor): | ||
Membership = apps.get_model("committee_accounts", "Membership") # noqa | ||
Committee = apps.get_model("committee_accounts", "CommitteeAccount") # noqa | ||
|
||
for committee in Committee.objects.all(): | ||
committee_memberships = Membership.objects.filter(committee_account=committee) | ||
|
||
unique_pending_emails = set() | ||
emails_to_prune = set() | ||
for membership in committee_memberships: | ||
pending_email = str(membership.pending_email).lower() | ||
if pending_email not in unique_pending_emails: | ||
unique_pending_emails.add(pending_email) | ||
else: | ||
emails_to_prune.add(pending_email) | ||
|
||
for email in list(emails_to_prune): | ||
# ordering by user places any memberships with a user first | ||
overlapping_memberships = list( | ||
committee_memberships.filter(pending_email__iexact=email).order_by('user') | ||
) | ||
for membership_to_delete in overlapping_memberships[1:]: | ||
membership_to_delete.delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [( | ||
'committee_accounts', | ||
'0003_membership_pending_email_alter_membership_id_and_more' | ||
)] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
delete_memberships_with_overlapping_emails, | ||
migrations.RunPython.noop, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...end/fecfiler/contacts/test_serializers.py → ...cfiler/contacts/tests/test_serializers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from ..models import Contact | ||
|
||
|
||
def create_test_individual_contact(last_name, first_name, committee_account_id): | ||
contact = Contact.objects.create( | ||
type=Contact.ContactType.INDIVIDUAL, | ||
last_name=last_name, | ||
first_name=first_name, | ||
committee_account_id=committee_account_id, | ||
) | ||
return contact |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.