diff --git a/organizations/management/commands/transfer_contact_data.py b/organizations/management/commands/transfer_contact_data.py index cacf5c73a215b10060bac0893967302af265093a..f34bc7463fa0fd8f24a21f1424febffd9fe06d9c 100644 --- a/organizations/management/commands/transfer_contact_data.py +++ b/organizations/management/commands/transfer_contact_data.py @@ -4,9 +4,12 @@ __license__ = "AGPL v3" import datetime +from django.contrib.auth.models import Group from django.core.management.base import BaseCommand from django.utils import timezone +from guardian.shortcuts import assign_perm + from partners.models import Partner from organizations.models import Contact, ContactRole @@ -14,7 +17,9 @@ from organizations.models import Contact, ContactRole class Command(BaseCommand): help = ('For Partners, transfer the data of partners.Contact instances ' - 'to organizations.Contact and ContactRole instances.') + 'to organizations.Contact and ContactRole instances. ' + 'This is meant as a temporary, one-off method to be used during ' + 'deprecation of (Prospective)Partners.') def handle(self, *args, **kwargs): for partner in Partner.objects.all(): @@ -26,6 +31,12 @@ class Command(BaseCommand): key_expires=oldcontact.key_expires ) contact.save() + + # Assign permissions and Group + assign_perm('can_view_org_contacts', oldcontact.user, partner.organization) + orgcontacts = Group.objects.get(name='Organization Contacts') + oldcontact.user.groups.add(orgcontacts) + contactrole = ContactRole( contact=contact, organization=partner.organization,