diff --git a/apps/member/migrations/0006_create_note_account_bde_membership.py b/apps/member/migrations/0006_create_note_account_bde_membership.py new file mode 100644 index 0000000000000000000000000000000000000000..a76ac922d55f9aa558c3cc2804e20135700584d0 --- /dev/null +++ b/apps/member/migrations/0006_create_note_account_bde_membership.py @@ -0,0 +1,50 @@ +import sys + +from django.db import migrations + + +def give_note_account_permissions(apps, schema_editor): + """ + Automatically manage the membership of the Note account. + """ + User = apps.get_model("auth", "user") + Membership = apps.get_model("member", "membership") + Role = apps.get_model("permission", "role") + + note = User.objects.filter(username="note") + if not note.exists(): + # We are in a test environment, don't log error message + if len(sys.argv) > 1 and sys.argv[1] == 'test': + return + print("Warning: Note account was not found. The note account was not imported.") + print("Make sure you have imported the NK15 database. The new import script handles correctly the permissions.") + print("This migration will be ignored, you can re-run it if you forgot the note account or ignore it if you " + "don't want this account.") + return + + note = note.get() + + # Set for the two clubs a large expiration date and the correct role. + for m in Membership.objects.filter(user_id=note.id).all(): + m.date_end = "3142-12-12" + m.roles.set(Role.objects.filter(name="PC Kfet").all()) + m.save() + # By default, the note account is only authorized to be logged from localhost. + note.password = "ipbased$127.0.0.1" + note.is_active = False + note.save() + # Ensure that the note of the account is disabled + note.note.inactivity_reason = 'forced' + note.note.is_active = False + note.save() + + +class Migration(migrations.Migration): + dependencies = [ + ('member', '0005_remove_null_tag_on_charfields'), + ('permission', '0001_initial'), + ] + + operations = [ + migrations.RunPython(give_note_account_permissions), + ] diff --git a/apps/scripts b/apps/scripts index 7e27c3b71b04af0867d5fbe4916e2d1278637599..84be9d0062beee2c1dc09f2f7ef082e6f6240ad1 160000 --- a/apps/scripts +++ b/apps/scripts @@ -1 +1 @@ -Subproject commit 7e27c3b71b04af0867d5fbe4916e2d1278637599 +Subproject commit 84be9d0062beee2c1dc09f2f7ef082e6f6240ad1