From 6e28f1260ac689cd1ea09a93a084b8d52ea5cdc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Thu, 26 Oct 2017 15:42:28 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Fix=20setup=20of=20the=20kfet=20generic=20u?= =?UTF-8?q?ser=20when=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …a specific migration is targeted. --- kfet/auth/apps.py | 21 +++++++++++++++++++-- kfet/auth/utils.py | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/kfet/auth/apps.py b/kfet/auth/apps.py index d91931f5..d822c80f 100644 --- a/kfet/auth/apps.py +++ b/kfet/auth/apps.py @@ -10,5 +10,22 @@ class KFetAuthConfig(AppConfig): def ready(self): from . import signals # noqa - from .utils import setup_kfet_generic_user - post_migrate.connect(setup_kfet_generic_user, sender=self) + post_migrate.connect(finish_setup_kfet_generic_user, sender=self) + + +def finish_setup_kfet_generic_user(sender, apps, **kwargs): + from kfet.models import Account + from .utils import setup_kfet_generic_user + # Even if no kfetauth migration has been applied, the post_migrate signal + # is issued for KFetAuthConfig. + # Before finishing setup of the kfet generic user, check dependencies are + # ready: kfet.Account model and gestion.Profile (old schema may not use + # this model). + try: + apps.get_model('kfet', 'Account') + apps.get_model('gestion', 'Profile') + Account.objects.get_generic() + except (LookupError, Account.DoesNotExist): + return + + setup_kfet_generic_user() diff --git a/kfet/auth/utils.py b/kfet/auth/utils.py index 053e5798..f4979fef 100644 --- a/kfet/auth/utils.py +++ b/kfet/auth/utils.py @@ -15,7 +15,7 @@ def get_kfet_generic_user(): return Account.objects.get_generic().user -def setup_kfet_generic_user(**kwargs): +def setup_kfet_generic_user(): """ First steps of setup of the kfet generic user are done in a migration, as it is more robust against database schema changes. From 5b378d621a622e1d826b2543255daa7022f0937f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Fri, 27 Oct 2017 03:00:33 +0200 Subject: [PATCH 2/3] Delete GlobalPermissions model (migrations) It is an old model which doesn't exist anymore in kfet.models module. This adds its missing DeleteModel in migrations. --- kfet/migrations/0062_delete_globalpermissions.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 kfet/migrations/0062_delete_globalpermissions.py diff --git a/kfet/migrations/0062_delete_globalpermissions.py b/kfet/migrations/0062_delete_globalpermissions.py new file mode 100644 index 00000000..ee245412 --- /dev/null +++ b/kfet/migrations/0062_delete_globalpermissions.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ('kfet', '0061_add_perms_config'), + ] + + operations = [ + migrations.DeleteModel( + name='GlobalPermissions', + ), + ] From 772d0b6895515b29da0a90a4b67da4826d401cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Fri, 27 Oct 2017 03:40:41 +0200 Subject: [PATCH 3/3] Update kfet migrations history --- .../{0062_generic_profiles.py => 0063_generic_profiles.py} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename kfet/migrations/{0062_generic_profiles.py => 0063_generic_profiles.py} (92%) diff --git a/kfet/migrations/0062_generic_profiles.py b/kfet/migrations/0063_generic_profiles.py similarity index 92% rename from kfet/migrations/0062_generic_profiles.py rename to kfet/migrations/0063_generic_profiles.py index 08b75935..160e29f8 100644 --- a/kfet/migrations/0062_generic_profiles.py +++ b/kfet/migrations/0063_generic_profiles.py @@ -8,7 +8,7 @@ class Migration(migrations.Migration): dependencies = [ ('cof', '0014_move_profile'), - ('kfet', '0061_add_perms_config'), + ('kfet', '0062_delete_globalpermissions'), ] operations = [