fix SiteAffilation roles transfer
This commit is contained in:
parent
306b189725
commit
e6dfa6d74d
|
|
@ -70,10 +70,12 @@ class Command(BaseCommand):
|
||||||
role_choice = getattr(Role, old_role.new_role)
|
role_choice = getattr(Role, old_role.new_role)
|
||||||
sites = SiteSettings.objects.filter(old_id=s.site_id)
|
sites = SiteSettings.objects.filter(old_id=s.site_id)
|
||||||
for site in sites:
|
for site in sites:
|
||||||
role = Role.objects.filter(site=site, role=role_choice)
|
data = {'site': site, 'role': role_choice}
|
||||||
|
|
||||||
|
role = Role.objects.filter(**data)
|
||||||
if not role.exists():
|
if not role.exists():
|
||||||
objects.append(
|
objects.append(
|
||||||
Role(site=site, role=role_choice)
|
Role(**data)
|
||||||
)
|
)
|
||||||
|
|
||||||
Role.objects.bulk_create(objects)
|
Role.objects.bulk_create(objects)
|
||||||
|
|
@ -81,7 +83,7 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
def update_site_role(self):
|
def update_site_role(self):
|
||||||
roles = Role.objects.filter(country__isnull=True).select_related('site')\
|
roles = Role.objects.filter(country__isnull=True).select_related('site')\
|
||||||
.filter(site__id__isnull=False).select_for_update()
|
.filter(site__id__isnull=False).select_for_update()
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
for role in tqdm(roles, desc='Update role country'):
|
for role in tqdm(roles, desc='Update role country'):
|
||||||
role.country = role.site.country
|
role.country = role.site.country
|
||||||
|
|
@ -114,8 +116,7 @@ class Command(BaseCommand):
|
||||||
users = User.objects.filter(old_id=s.account_id)
|
users = User.objects.filter(old_id=s.account_id)
|
||||||
for user in users:
|
for user in users:
|
||||||
for role in roles:
|
for role in roles:
|
||||||
user_role = UserRole.objects.get_or_create(user=user,
|
UserRole.objects.get_or_create(user=user, role=role, state=UserRole.VALIDATED)
|
||||||
role=role)
|
|
||||||
self.stdout.write(self.style.WARNING(f'Added users roles.'))
|
self.stdout.write(self.style.WARNING(f'Added users roles.'))
|
||||||
|
|
||||||
def superuser_role_sql(self):
|
def superuser_role_sql(self):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user