From bd41560f45da5f4a161d3bf7ca3179c4cb74077a Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 6 Apr 2020 10:45:32 +0200 Subject: [PATCH] Update permission fixtures --- apps/activity/fixtures/initial.json | 20 + apps/member/views.py | 1 + apps/note/signals.py | 2 +- apps/permission/fixtures/initial.json | 703 ++++++++++++++++---------- apps/registration/forms.py | 2 +- apps/registration/views.py | 23 +- 6 files changed, 478 insertions(+), 273 deletions(-) create mode 100644 apps/activity/fixtures/initial.json diff --git a/apps/activity/fixtures/initial.json b/apps/activity/fixtures/initial.json new file mode 100644 index 00000000..1856bce4 --- /dev/null +++ b/apps/activity/fixtures/initial.json @@ -0,0 +1,20 @@ +[ + { + "model": "activity.activitytype", + "pk": 1, + "fields": { + "name": "Pot", + "can_invite": true, + "guest_entry_fee": 500 + } + }, + { + "model": "activity.activitytype", + "pk": 2, + "fields": { + "name": "Soir\u00e9e de club", + "can_invite": false, + "guest_entry_fee": 0 + } + } +] \ No newline at end of file diff --git a/apps/member/views.py b/apps/member/views.py index b8048d6e..e03c5ff5 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -389,6 +389,7 @@ class ClubAddMemberView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView): club = Club.objects.filter(PermissionBackend.filter_queryset(self.request.user, Club, "view"))\ .get(pk=self.kwargs["club_pk"]) form.fields['credit_amount'].initial = club.membership_fee_paid + form.fields['roles'].initial = Role.objects.filter(name="Membre de club").all() # If the concerned club is the BDE, then we add the option that Société générale pays the membership. if club.name != "BDE": diff --git a/apps/note/signals.py b/apps/note/signals.py index 78312682..37737a45 100644 --- a/apps/note/signals.py +++ b/apps/note/signals.py @@ -10,7 +10,7 @@ def save_user_note(instance, raw, **_kwargs): # When provisionning data, do not try to autocreate return - if instance.profile.registration_valid and instance.is_active: + if (instance.is_superuser or instance.profile.registration_valid) and instance.is_active: # Create note only when the registration is validated from note.models import NoteUser NoteUser.objects.get_or_create(user=instance) diff --git a/apps/permission/fixtures/initial.json b/apps/permission/fixtures/initial.json index 4cf3ecfa..d7eca508 100644 --- a/apps/permission/fixtures/initial.json +++ b/apps/permission/fixtures/initial.json @@ -17,54 +17,61 @@ "model": "member.role", "pk": 3, "fields": { - "name": "Pr\u00e9sident\u00b7e BDE" + "name": "Membre de club" } }, { "model": "member.role", "pk": 4, "fields": { - "name": "Tr\u00e9sorier\u00b7\u00e8re BDE" + "name": "Bureau de club" } }, { "model": "member.role", "pk": 5, "fields": { - "name": "Respo info" + "name": "Pr\u00e9sident\u00b7e de club" } }, { "model": "member.role", "pk": 6, "fields": { - "name": "GC Kfet" + "name": "Tr\u00e9sorier\u00b7\u00e8re de club" } }, { "model": "member.role", "pk": 7, "fields": { - "name": "Pr\u00e9sident\u00b7e de club" + "name": "Pr\u00e9sident\u00b7e BDE" } }, { "model": "member.role", "pk": 8, "fields": { - "name": "Tr\u00e9sorier\u00b7\u00e8re de club" - } - }, - { - "model": "member.role", - "pk": 8, - "fields": { - "name": "Tr\u00e9sorier\u00b7\u00e8re de club" + "name": "Tr\u00e9sorier\u00b7\u00e8re BDE" } }, { "model": "member.role", "pk": 9, + "fields": { + "name": "Respo info" + } + }, + { + "model": "member.role", + "pk": 10, + "fields": { + "name": "GC Kfet" + } + }, + { + "model": "member.role", + "pk": 11, "fields": { "name": "Res[pot]" } @@ -97,10 +104,7 @@ "model": "permission.permission", "pk": 1, "fields": { - "model": [ - "auth", - "user" - ], + "model": 4, "query": "{\"pk\": [\"user\", \"pk\"]}", "type": "view", "mask": 1, @@ -112,10 +116,7 @@ "model": "permission.permission", "pk": 2, "fields": { - "model": [ - "member", - "profile" - ], + "model": 17, "query": "{\"user\": [\"user\"]}", "type": "view", "mask": 1, @@ -127,10 +128,7 @@ "model": "permission.permission", "pk": 3, "fields": { - "model": [ - "note", - "noteuser" - ], + "model": 27, "query": "{\"pk\": [\"user\", \"note\", \"pk\"]}", "type": "view", "mask": 1, @@ -142,10 +140,7 @@ "model": "permission.permission", "pk": 4, "fields": { - "model": [ - "authtoken", - "token" - ], + "model": 8, "query": "{\"user\": [\"user\"]}", "type": "view", "mask": 1, @@ -157,10 +152,7 @@ "model": "permission.permission", "pk": 5, "fields": { - "model": [ - "note", - "transaction" - ], + "model": 22, "query": "[\"OR\", {\"source\": [\"user\", \"note\"]}, {\"destination\": [\"user\", \"note\"]}]", "type": "view", "mask": 1, @@ -172,10 +164,7 @@ "model": "permission.permission", "pk": 6, "fields": { - "model": [ - "note", - "alias" - ], + "model": 19, "query": "[\"OR\", {\"note__in\": [\"NoteUser\", \"objects\", [\"filter\", {\"user__membership__club__name\": \"Kfet\"}], [\"all\"]]}, {\"note__in\": [\"NoteClub\", \"objects\", [\"all\"]]}]", "type": "view", "mask": 1, @@ -187,10 +176,7 @@ "model": "permission.permission", "pk": 7, "fields": { - "model": [ - "auth", - "user" - ], + "model": 4, "query": "{\"pk\": [\"user\", \"pk\"]}", "type": "change", "mask": 1, @@ -202,10 +188,7 @@ "model": "permission.permission", "pk": 8, "fields": { - "model": [ - "auth", - "user" - ], + "model": 4, "query": "{\"pk\": [\"user\", \"pk\"]}", "type": "change", "mask": 1, @@ -217,10 +200,7 @@ "model": "permission.permission", "pk": 9, "fields": { - "model": [ - "auth", - "user" - ], + "model": 4, "query": "{\"pk\": [\"user\", \"pk\"]}", "type": "change", "mask": 1, @@ -232,10 +212,7 @@ "model": "permission.permission", "pk": 10, "fields": { - "model": [ - "auth", - "user" - ], + "model": 4, "query": "{\"pk\": [\"user\", \"pk\"]}", "type": "change", "mask": 1, @@ -247,10 +224,7 @@ "model": "permission.permission", "pk": 11, "fields": { - "model": [ - "auth", - "user" - ], + "model": 4, "query": "{\"pk\": [\"user\", \"pk\"]}", "type": "change", "mask": 1, @@ -262,10 +236,7 @@ "model": "permission.permission", "pk": 12, "fields": { - "model": [ - "authtoken", - "token" - ], + "model": 8, "query": "{\"user\": [\"user\"]}", "type": "delete", "mask": 1, @@ -277,10 +248,7 @@ "model": "permission.permission", "pk": 13, "fields": { - "model": [ - "authtoken", - "token" - ], + "model": 8, "query": "{\"user\": [\"user\"]}", "type": "add", "mask": 1, @@ -292,10 +260,7 @@ "model": "permission.permission", "pk": 14, "fields": { - "model": [ - "note", - "alias" - ], + "model": 19, "query": "{\"note\": [\"user\", \"note\"]}", "type": "delete", "mask": 1, @@ -307,10 +272,7 @@ "model": "permission.permission", "pk": 15, "fields": { - "model": [ - "note", - "alias" - ], + "model": 19, "query": "{\"note\": [\"user\", \"note\"]}", "type": "add", "mask": 1, @@ -322,10 +284,7 @@ "model": "permission.permission", "pk": 16, "fields": { - "model": [ - "note", - "noteuser" - ], + "model": 27, "query": "{\"pk\": [\"user\", \"note\", \"pk\"]}", "type": "change", "mask": 1, @@ -337,10 +296,7 @@ "model": "permission.permission", "pk": 17, "fields": { - "model": [ - "note", - "transaction" - ], + "model": 22, "query": "[\"AND\", {\"source\": [\"user\", \"note\"]}, [\"OR\", {\"amount__lte\": [\"user\", \"note\", \"balance\"]}, {\"valid\": false}]]", "type": "add", "mask": 1, @@ -352,10 +308,7 @@ "model": "permission.permission", "pk": 18, "fields": { - "model": [ - "note", - "note" - ], + "model": 20, "query": "{}", "type": "change", "mask": 1, @@ -367,10 +320,7 @@ "model": "permission.permission", "pk": 19, "fields": { - "model": [ - "note", - "note" - ], + "model": 20, "query": "[\"OR\", {\"pk\": [\"club\", \"note\", \"pk\"]}, {\"pk__in\": [\"NoteUser\", \"objects\", [\"filter\", {\"user__membership__club\": [\"club\"]}], [\"all\"]]}]", "type": "view", "mask": 2, @@ -382,10 +332,7 @@ "model": "permission.permission", "pk": 20, "fields": { - "model": [ - "note", - "transaction" - ], + "model": 22, "query": "[\"AND\", [\"OR\", {\"source\": [\"club\", \"note\"]}, {\"destination\": [\"club\", \"note\"]}], [\"OR\", {\"amount__lte\": {\"F\": [\"ADD\", [\"F\", \"source__balance\"], 5000]}}, {\"valid\": false}]]", "type": "add", "mask": 2, @@ -397,10 +344,7 @@ "model": "permission.permission", "pk": 21, "fields": { - "model": [ - "note", - "recurrenttransaction" - ], + "model": 28, "query": "[\"AND\", {\"destination\": [\"club\", \"note\"]}, [\"OR\", {\"amount__lte\": {\"F\": [\"ADD\", [\"F\", \"source__balance\"], 5000]}}, {\"valid\": false}]]", "type": "add", "mask": 2, @@ -412,10 +356,7 @@ "model": "permission.permission", "pk": 22, "fields": { - "model": [ - "member", - "club" - ], + "model": 15, "query": "{\"pk\": [\"club\", \"pk\"]}", "type": "view", "mask": 1, @@ -427,10 +368,7 @@ "model": "permission.permission", "pk": 23, "fields": { - "model": [ - "note", - "transaction" - ], + "model": 22, "query": "{}", "type": "change", "mask": 1, @@ -442,10 +380,7 @@ "model": "permission.permission", "pk": 24, "fields": { - "model": [ - "note", - "transaction" - ], + "model": 22, "query": "{}", "type": "view", "mask": 2, @@ -457,10 +392,7 @@ "model": "permission.permission", "pk": 25, "fields": { - "model": [ - "note", - "notespecial" - ], + "model": 26, "query": "{}", "type": "view", "mask": 2, @@ -472,10 +404,7 @@ "model": "permission.permission", "pk": 26, "fields": { - "model": [ - "note", - "specialtransaction" - ], + "model": 29, "query": "{}", "type": "add", "mask": 2, @@ -487,10 +416,7 @@ "model": "permission.permission", "pk": 27, "fields": { - "model": [ - "note", - "templatecategory" - ], + "model": 21, "query": "{}", "type": "view", "mask": 2, @@ -502,10 +428,7 @@ "model": "permission.permission", "pk": 28, "fields": { - "model": [ - "note", - "templatecategory" - ], + "model": 21, "query": "{}", "type": "change", "mask": 3, @@ -517,10 +440,7 @@ "model": "permission.permission", "pk": 29, "fields": { - "model": [ - "note", - "templatecategory" - ], + "model": 21, "query": "{}", "type": "add", "mask": 3, @@ -532,10 +452,7 @@ "model": "permission.permission", "pk": 30, "fields": { - "model": [ - "note", - "transactiontemplate" - ], + "model": 23, "query": "{}", "type": "view", "mask": 2, @@ -547,10 +464,7 @@ "model": "permission.permission", "pk": 31, "fields": { - "model": [ - "note", - "transactiontemplate" - ], + "model": 23, "query": "{}", "type": "add", "mask": 3, @@ -562,10 +476,7 @@ "model": "permission.permission", "pk": 32, "fields": { - "model": [ - "note", - "transactiontemplate" - ], + "model": 23, "query": "{}", "type": "change", "mask": 3, @@ -577,10 +488,7 @@ "model": "permission.permission", "pk": 33, "fields": { - "model": [ - "note", - "transaction" - ], + "model": 22, "query": "{}", "type": "add", "mask": 2, @@ -592,10 +500,7 @@ "model": "permission.permission", "pk": 34, "fields": { - "model": [ - "activity", - "activity" - ], + "model": 9, "query": "[\"OR\", {\"valid\": true}, {\"creater\": [\"user\"]}]", "type": "view", "mask": 1, @@ -607,10 +512,7 @@ "model": "permission.permission", "pk": 35, "fields": { - "model": [ - "activity", - "activity" - ], + "model": 9, "query": "[\"AND\", {\"valid\": false}, {\"creater\": [\"user\"]}]", "type": "change", "mask": 1, @@ -622,10 +524,7 @@ "model": "permission.permission", "pk": 36, "fields": { - "model": [ - "activity", - "activity" - ], + "model": 9, "query": "{\"creater\": [\"user\"], \"valid\": false}", "type": "add", "mask": 1, @@ -637,10 +536,7 @@ "model": "permission.permission", "pk": 37, "fields": { - "model": [ - "activity", - "activity" - ], + "model": 9, "query": "{}", "type": "change", "mask": 2, @@ -652,10 +548,7 @@ "model": "permission.permission", "pk": 38, "fields": { - "model": [ - "activity", - "activity" - ], + "model": 9, "query": "{}", "type": "change", "mask": 2, @@ -667,10 +560,7 @@ "model": "permission.permission", "pk": 39, "fields": { - "model": [ - "activity", - "guest" - ], + "model": 12, "query": "{\"inviter\": [\"user\", \"note\"], \"activity__activity_type__can_invite\": true}", "type": "add", "mask": 1, @@ -682,10 +572,7 @@ "model": "permission.permission", "pk": 40, "fields": { - "model": [ - "activity", - "guest" - ], + "model": 12, "query": "{\"inviter\": [\"user\", \"note\"]}", "type": "view", "mask": 1, @@ -697,10 +584,7 @@ "model": "permission.permission", "pk": 41, "fields": { - "model": [ - "activity", - "activity" - ], + "model": 9, "query": "{}", "type": "view", "mask": 2, @@ -712,10 +596,7 @@ "model": "permission.permission", "pk": 42, "fields": { - "model": [ - "activity", - "guest" - ], + "model": 12, "query": "{}", "type": "view", "mask": 2, @@ -727,10 +608,7 @@ "model": "permission.permission", "pk": 43, "fields": { - "model": [ - "activity", - "entry" - ], + "model": 11, "query": "{}", "type": "add", "mask": 2, @@ -742,10 +620,7 @@ "model": "permission.permission", "pk": 44, "fields": { - "model": [ - "activity", - "guesttransaction" - ], + "model": 13, "query": "{}", "type": "add", "mask": 2, @@ -757,10 +632,7 @@ "model": "permission.permission", "pk": 45, "fields": { - "model": [ - "activity", - "guesttransaction" - ], + "model": 13, "query": "{}", "type": "view", "mask": 1, @@ -772,10 +644,7 @@ "model": "permission.permission", "pk": 46, "fields": { - "model": [ - "activity", - "guesttransaction" - ], + "model": 13, "query": "{}", "type": "change", "mask": 2, @@ -787,10 +656,7 @@ "model": "permission.permission", "pk": 47, "fields": { - "model": [ - "member", - "club" - ], + "model": 15, "query": "{\"pk\": [\"club\", \"pk\"]}", "type": "change", "mask": 1, @@ -802,10 +668,7 @@ "model": "permission.permission", "pk": 48, "fields": { - "model": [ - "member", - "membership" - ], + "model": 16, "query": "{\"user\": [\"user\"]}", "type": "view", "mask": 1, @@ -817,10 +680,7 @@ "model": "permission.permission", "pk": 49, "fields": { - "model": [ - "member", - "membership" - ], + "model": 16, "query": "{\"club\": [\"club\"]}", "type": "view", "mask": 1, @@ -832,10 +692,7 @@ "model": "permission.permission", "pk": 50, "fields": { - "model": [ - "member", - "membership" - ], + "model": 16, "query": "{\"club\": [\"club\"]}", "type": "add", "mask": 2, @@ -843,6 +700,234 @@ "description": "Add a membership to a club" } }, + { + "model": "permission.permission", + "pk": 51, + "fields": { + "model": 16, + "query": "{\"club\": [\"club\"]}", + "type": "change", + "mask": 2, + "field": "roles", + "description": "Update user roles" + } + }, + { + "model": "permission.permission", + "pk": 52, + "fields": { + "model": 17, + "query": "{\"user\": [\"user\"]}", + "type": "change", + "mask": 1, + "field": "", + "description": "Change own profile" + } + }, + { + "model": "permission.permission", + "pk": 53, + "fields": { + "model": 17, + "query": "{}", + "type": "change", + "mask": 2, + "field": "", + "description": "Change any profile" + } + }, + { + "model": "permission.permission", + "pk": 54, + "fields": { + "model": 4, + "query": "{}", + "type": "change", + "mask": 2, + "field": "", + "description": "Change any user" + } + }, + { + "model": "permission.permission", + "pk": 55, + "fields": { + "model": 4, + "query": "{}", + "type": "add", + "mask": 1, + "field": "", + "description": "Add user" + } + }, + { + "model": "permission.permission", + "pk": 56, + "fields": { + "model": 17, + "query": "{\"email_confirmed\": false, \"registration_valid\": false}", + "type": "add", + "mask": 1, + "field": "", + "description": "Add profile" + } + }, + { + "model": "permission.permission", + "pk": 57, + "fields": { + "model": 4, + "query": "{\"profile__registration_valid\": false}", + "type": "delete", + "mask": 2, + "field": "", + "description": "Delete pre-registered user" + } + }, + { + "model": "permission.permission", + "pk": 58, + "fields": { + "model": 17, + "query": "{\"registration_valid\": false}", + "type": "delete", + "mask": 2, + "field": "", + "description": "Delete pre-registered user profile" + } + }, + { + "model": "permission.permission", + "pk": 59, + "fields": { + "model": 23, + "query": "{\"destination\": [\"club\", \"note\"]}", + "type": "view", + "mask": 2, + "field": "", + "description": "New club button" + } + }, + { + "model": "permission.permission", + "pk": 60, + "fields": { + "model": 23, + "query": "{\"destination\": [\"club\", \"note\"]}", + "type": "add", + "mask": 2, + "field": "", + "description": "Create club button" + } + }, + { + "model": "permission.permission", + "pk": 61, + "fields": { + "model": 23, + "query": "{\"destination\": [\"club\", \"note\"]}", + "type": "change", + "mask": 2, + "field": "", + "description": "Update club button" + } + }, + { + "model": "permission.permission", + "pk": 62, + "fields": { + "model": 22, + "query": "[\"OR\", {\"source\": [\"club\", \"note\"]}, {\"destination\": [\"club\", \"note\"]}]", + "type": "view", + "mask": 1, + "field": "", + "description": "View transactions of a club" + } + }, + { + "model": "permission.permission", + "pk": 63, + "fields": { + "model": 33, + "query": "{}", + "type": "view", + "mask": 3, + "field": "", + "description": "View invoices" + } + }, + { + "model": "permission.permission", + "pk": 64, + "fields": { + "model": 33, + "query": "{}", + "type": "add", + "mask": 3, + "field": "", + "description": "Add invoice" + } + }, + { + "model": "permission.permission", + "pk": 65, + "fields": { + "model": 33, + "query": "{}", + "type": "change", + "mask": 3, + "field": "", + "description": "Change invoice" + } + }, + { + "model": "permission.permission", + "pk": 66, + "fields": { + "model": 34, + "query": "{}", + "type": "view", + "mask": 3, + "field": "", + "description": "View products" + } + }, + { + "model": "permission.permission", + "pk": 67, + "fields": { + "model": 34, + "query": "{}", + "type": "add", + "mask": 3, + "field": "", + "description": "Add products" + } + }, + { + "model": "permission.permission", + "pk": 68, + "fields": { + "model": 34, + "query": "{}", + "type": "change", + "mask": 3, + "field": "", + "description": "Change product" + } + }, + { + "model": "permission.permission", + "pk": 69, + "fields": { + "model": 34, + "query": "{}", + "type": "delete", + "mask": 3, + "field": "", + "description": "Delete product" + } + }, { "model": "permission.rolepermissions", "pk": 1, @@ -851,12 +936,18 @@ "permissions": [ 1, 2, + 3, + 4, + 5, 7, 8, 9, 10, 11, - 48 + 12, + 13, + 48, + 52 ] } }, @@ -866,19 +957,7 @@ "fields": { "role": 2, "permissions": [ - 1, - 2, - 3, - 4, - 5, 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, 14, 15, 16, @@ -894,23 +973,73 @@ }, { "model": "permission.rolepermissions", - "pk": 3, + "pk": 4, "fields": { - "role": 8, + "role": 4, "permissions": [ - 19, - 20, - 21, - 22 + 22, + 47, + 49 ] } }, { "model": "permission.rolepermissions", - "pk": 4, + "pk": 5, "fields": { - "role": 4, + "role": 5, "permissions": [ + 50, + 51, + 62 + ] + } + }, + { + "model": "permission.rolepermissions", + "pk": 6, + "fields": { + "role": 6, + "permissions": [ + 19, + 21, + 27, + 59, + 60, + 61, + 20, + 62 + ] + } + }, + { + "model": "permission.rolepermissions", + "pk": 7, + "fields": { + "role": 7, + "permissions": [ + 33, + 24, + 25, + 26, + 27 + ] + } + }, + { + "model": "permission.rolepermissions", + "pk": 8, + "fields": { + "role": 8, + "permissions": [ + 32, + 33, + 56, + 58, + 55, + 57, + 53, + 54, 23, 24, 25, @@ -920,44 +1049,21 @@ 29, 30, 31, - 32, - 33 + 64, + 65, + 66, + 67, + 68, + 69, + 63 ] } }, { "model": "permission.rolepermissions", - "pk": 5, + "pk": 9, "fields": { "role": 9, - "permissions": [ - 37, - 38, - 41, - 42, - 43, - 44, - 45, - 46 - ] - } - }, - { - "model": "permission.rolepermissions", - "pk": 6, - "fields": { - "role": 7, - "permissions": [ - 22, - 47 - ] - } - }, - { - "model": "permission.rolepermissions", - "pk": 7, - "fields": { - "role": 5, "permissions": [ 1, 2, @@ -978,7 +1084,6 @@ 17, 18, 19, - 20, 21, 22, 23, @@ -1008,7 +1113,71 @@ 47, 48, 49, - 50 + 50, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + 58, + 59, + 60, + 61, + 20, + 62, + 63, + 64, + 65, + 66, + 67, + 68, + 69 + ] + } + }, + { + "model": "permission.rolepermissions", + "pk": 10, + "fields": { + "role": 10, + "permissions": [ + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 52, + 53, + 54, + 55, + 56, + 57, + 58 + ] + } + }, + { + "model": "permission.rolepermissions", + "pk": 11, + "fields": { + "role": 11, + "permissions": [ + 37, + 38, + 41, + 42, + 43, + 44, + 45, + 46 ] } } diff --git a/apps/registration/forms.py b/apps/registration/forms.py index 4955c4a8..cba5c2ae 100644 --- a/apps/registration/forms.py +++ b/apps/registration/forms.py @@ -68,7 +68,7 @@ class ValidationForm(forms.Form): join_BDE = forms.BooleanField( label=_("Join BDE Club"), - required=True, + required=False, initial=True, ) diff --git a/apps/registration/views.py b/apps/registration/views.py index 2daca037..575ada8f 100644 --- a/apps/registration/views.py +++ b/apps/registration/views.py @@ -12,6 +12,7 @@ from django.utils.http import urlsafe_base64_decode from django.utils.translation import gettext_lazy as _ from django.views import View from django.views.generic import CreateView, TemplateView, DetailView, FormView +from django.views.generic.edit import FormMixin from django_tables2 import SingleTableView from member.forms import ProfileForm from member.models import Membership, Club, Role @@ -88,7 +89,7 @@ class UserValidateView(TemplateView): if user is not None and email_validation_token.check_token(user, token): self.validlink = True # The user must wait that someone validates the account before the user can be active and login. - user.is_active = user.profile.registration_valid + user.is_active = user.profile.registration_valid or user.is_superuser user.profile.email_confirmed = True user.save() user.profile.save() @@ -185,7 +186,7 @@ class FutureUserListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableVi return context -class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView, FormView): +class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, FormMixin, DetailView): """ Display information about a pre-registered user, in order to complete the registration. """ @@ -194,6 +195,14 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView, context_object_name = "user_object" template_name = "registration/future_profile_detail.html" + def post(self, request, *args, **kwargs): + form = self.get_form() + self.object = self.get_object() + if form.is_valid(): + return self.form_valid(form) + else: + return self.form_invalid(form) + def get_queryset(self, **kwargs): """ We only display information of a not registered user. @@ -221,7 +230,7 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView, return form def form_valid(self, form): - user = self.object = self.get_object() + user = self.get_object() # Get form data soge = form.cleaned_data["soge"] @@ -238,6 +247,10 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView, join_BDE = True join_Kfet = True + if not join_BDE: + form.add_error('join_BDE', _("You must join the BDE.")) + return super().form_invalid(form) + fee = 0 bde = Club.objects.get(name="BDE") bde_fee = bde.membership_fee_paid if user.profile.paid else bde.membership_fee_unpaid @@ -254,6 +267,8 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView, credit_amount = fee bank = "Société générale" + print("OK") + if join_Kfet and not join_BDE: form.add_error('join_Kfet', _("You must join BDE club before joining Kfet club.")) @@ -277,7 +292,7 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView, # Save the user and finally validate the registration # Saving the user creates the associated note ret = super().form_valid(form) - user.is_active = user.profile.email_confirmed + user.is_active = user.profile.email_confirmed or user.is_superuser user.profile.registration_valid = True # Store if Société générale paid for next years user.profile.soge = soge