From cbf4353403bf60dd0966e060a78893685080ae0b Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Fri, 25 May 2018 11:19:53 +0200 Subject: [PATCH] add command to clean social accounts from unnecessary data --- .../commands/clean_social_accounts.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/wolnelektury/management/commands/clean_social_accounts.py diff --git a/src/wolnelektury/management/commands/clean_social_accounts.py b/src/wolnelektury/management/commands/clean_social_accounts.py new file mode 100644 index 000000000..263ee2c0d --- /dev/null +++ b/src/wolnelektury/management/commands/clean_social_accounts.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +from allauth.socialaccount.models import SocialAccount +from django.core.management.base import BaseCommand + + +KEPT_FIELDS = { + 'facebook': ['link', 'name', 'id', 'locale', 'timezone', 'updated_time', 'verified'], + 'google': ['name', 'picture', 'locale', 'id', 'verified_email', 'link'], +} + + +class Command(BaseCommand): + def handle(self, *args, **options): + for provider, kept_fields in KEPT_FIELDS.iteritems(): + for sa in SocialAccount.objects.filter(provider=provider): + trimmed_data = {k: v for k, v in sa.extra_data.iteritems() if k in kept_fields} + sa.extra_data = trimmed_data + sa.save() -- 2.20.1