SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit e0bf4cb8 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Add permissions and group to transfer_contact_data temp method

parent 4281f8c0
No related branches found
No related tags found
No related merge requests found
...@@ -4,9 +4,12 @@ __license__ = "AGPL v3" ...@@ -4,9 +4,12 @@ __license__ = "AGPL v3"
import datetime import datetime
from django.contrib.auth.models import Group
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.utils import timezone from django.utils import timezone
from guardian.shortcuts import assign_perm
from partners.models import Partner from partners.models import Partner
from organizations.models import Contact, ContactRole from organizations.models import Contact, ContactRole
...@@ -14,7 +17,9 @@ from organizations.models import Contact, ContactRole ...@@ -14,7 +17,9 @@ from organizations.models import Contact, ContactRole
class Command(BaseCommand): class Command(BaseCommand):
help = ('For Partners, transfer the data of partners.Contact instances ' 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): def handle(self, *args, **kwargs):
for partner in Partner.objects.all(): for partner in Partner.objects.all():
...@@ -26,6 +31,12 @@ class Command(BaseCommand): ...@@ -26,6 +31,12 @@ class Command(BaseCommand):
key_expires=oldcontact.key_expires key_expires=oldcontact.key_expires
) )
contact.save() 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( contactrole = ContactRole(
contact=contact, contact=contact,
organization=partner.organization, organization=partner.organization,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment